Merge branch 'master' into psram

This commit is contained in:
folkert van heusden 2024-04-27 23:40:42 +02:00
commit a78fb22516
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
11 changed files with 42 additions and 20 deletions

View file

@ -18,6 +18,9 @@
#include <sys/socket.h>
#include <sys/types.h>
#endif
#if defined(ESP32)
#include "esp_heap_caps.h"
#endif
#if defined(SHA2017)
#include "console_shabadge.h"
@ -210,6 +213,14 @@ void set_tty_serial_speed(console *const c, const uint32_t bps)
c->put_string_lf("Failed to store configuration file with serial settings");
}
#if defined(ESP32)
void heap_caps_alloc_failed_hook(size_t requested_size, uint32_t caps, const char *function_name)
{
printf("%s was called but failed to allocate %d bytes with 0x%X capabilities\r\n", function_name, requested_size, caps);
}
#endif
void setup() {
Serial.begin(115200);
@ -224,6 +235,10 @@ void setup() {
Serial.print(F("Size of int: "));
Serial.println(sizeof(int));
#if defined(ESP32)
heap_caps_register_failed_alloc_callback(heap_caps_alloc_failed_hook);
#endif
#if !defined(BUILD_FOR_RP2040)
Serial.print(F("CPU clock frequency (MHz): "));
Serial.println(getCpuFrequencyMhz());

View file

@ -1 +0,0 @@
../win32.cpp

View file

@ -1 +0,0 @@
../win32.h

16
bus.cpp
View file

@ -120,8 +120,6 @@ bus *bus::deserialize(const json_t *const j, console *const cnsl, std::atomic_ui
void bus::set_memory_size(const int n_pages)
{
this->n_pages = n_pages;
uint32_t n_bytes = n_pages * 8192l;
delete m;
@ -474,7 +472,7 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
}
// LO size register field must be all 1s, so subtract 1
uint32_t system_size = n_pages * 8192l / 64 - 1;
uint32_t system_size = m->get_memory_size() / 64 - 1;
if (a == ADDR_SYSSIZE + 2) { // system size HI
uint16_t temp = system_size >> 16;
@ -505,7 +503,7 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
return 0;
}
if (m_offset >= uint32_t(n_pages * 8192)) {
if (m_offset >= m->get_memory_size()) {
if (peek_only) {
DOLOG(debug, false, "READ from %06o - out of range!", addr_in);
return 0;
@ -696,8 +694,8 @@ uint32_t bus::calculate_physical_address(const int run_mode, const uint16_t a, c
}
}
if (m_offset >= n_pages * 8192l && !is_io) [[unlikely]] {
DOLOG(debug, !peek_only, "bus::calculate_physical_address %o >= %o", m_offset, n_pages * 8192l);
if (m_offset >= m->get_memory_size() && !is_io) [[unlikely]] {
DOLOG(debug, !peek_only, "bus::calculate_physical_address %o >= %o", m_offset, m->get_memory_size());
DOLOG(debug, false, "TRAP(04) (throw 6) on address %06o", a);
if (mmu_->is_locked() == false) {
@ -1025,7 +1023,7 @@ write_rc_t bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint1
DOLOG(debug, false, "WRITE to %06o/%07o %c %c: %06o", addr_in, m_offset, space == d_space ? 'D' : 'I', word_mode == wm_byte ? 'B' : 'W', value);
if (m_offset >= uint32_t(n_pages * 8192)) {
if (m_offset >= m->get_memory_size()) {
c->trap(004); // no such RAM
throw 1;
}
@ -1042,7 +1040,7 @@ void bus::writePhysical(const uint32_t a, const uint16_t value)
{
DOLOG(debug, false, "physicalWRITE %06o to %o", value, a);
if (a >= n_pages * 8192l) {
if (a >= m->get_memory_size()) {
DOLOG(debug, false, "physicalWRITE to %o: trap 004", a);
c->trap(004);
throw 12;
@ -1054,7 +1052,7 @@ void bus::writePhysical(const uint32_t a, const uint16_t value)
uint16_t bus::readPhysical(const uint32_t a)
{
if (a >= n_pages * 8192l) {
if (a >= m->get_memory_size()) {
DOLOG(debug, false, "physicalREAD from %o: trap 004", a);
c->trap(004);
throw 13;

4
bus.h
View file

@ -75,10 +75,7 @@ private:
rl02 *rl02_ { nullptr };
tty *tty_ { nullptr };
kw11_l *kw11_l_ { nullptr };
mmu *mmu_ { nullptr };
int n_pages { DEFAULT_N_PAGES };
memory *m { nullptr };
uint16_t microprogram_break_register { 0 };
@ -104,7 +101,6 @@ public:
void set_debug_mode() { console_switches |= 128; }
uint16_t get_console_leds() { return console_leds; }
int get_memory_size() const { return n_pages; }
void set_memory_size(const int n_pages);
void mmudebug(const uint16_t a);

View file

@ -26,6 +26,7 @@
#include "disk_backend_nbd.h"
#include "loaders.h"
#include "log.h"
#include "memory.h"
#include "tty.h"
#include "utils.h"
@ -821,6 +822,12 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
continue;
}
#if defined(ESP32)
else if (cmd == "debug") {
if (heap_caps_check_integrity_all(true) == false)
cnsl->put_string_lf("HEAP corruption!");
continue;
}
else if (cmd == "cfgnet") {
configure_network(cnsl);
@ -859,7 +866,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
if (parts.size() == 2)
b->set_memory_size(std::stoi(parts.at(1)));
else {
int n_pages = b->get_memory_size();
int n_pages = b->getRAM()->get_memory_size();
cnsl->put_string_lf(format("Memory size: %u pages or %u kB (decimal)", n_pages, n_pages * 8192 / 1024));
}
@ -1016,6 +1023,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
"startnet - start network",
"chknet - check network status",
"serspd - set serial speed in bps (8N1 are default)",
"debug - debugging info",
#endif
"cfgdisk - configure disk",
nullptr

View file

@ -4,6 +4,7 @@
#include <cassert>
#include "disk_backend.h"
#include "gen.h"
#if IS_POSIX
#include "disk_backend_file.h"
#include "disk_backend_nbd.h"

View file

@ -91,10 +91,10 @@ bool disk_backend_nbd::connect(const bool retry)
{
do {
// LOOP until connected, logging message, exponential backoff?
addrinfo *res = nullptr;
addrinfo *res = nullptr;
addrinfo hints { 0 };
hints.ai_family = AF_INET;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
char port_str[8] { 0 };
@ -137,7 +137,7 @@ bool disk_backend_nbd::connect(const bool retry)
uint64_t size;
uint32_t flags;
uint8_t padding[124];
} nbd_hello;
} nbd_hello { };
if (fd != -1) {
if (READ(fd, reinterpret_cast<char *>(&nbd_hello), sizeof nbd_hello) != sizeof nbd_hello) {
@ -194,7 +194,7 @@ bool disk_backend_nbd::read(const off_t offset_in, const size_t n, uint8_t *cons
uint64_t handle;
uint64_t offset;
uint32_t length;
} nbd_request { 0 };
} nbd_request { };
nbd_request.magic = ntohl(0x25609513);
nbd_request.type = 0; // READ

View file

@ -15,7 +15,9 @@
#include "error.h"
#include "log.h"
#include "utils.h"
#if defined(_WIN32)
#include "win32.h"
#endif
static const char *logfile = strdup("/tmp/kek.log");

View file

@ -18,6 +18,8 @@ public:
memory(const uint32_t size);
~memory();
uint32_t get_memory_size() const { return size; }
void reset();
#if IS_POSIX
json_t *serialize() const;

View file

@ -19,7 +19,9 @@
#include <vector>
#include <sys/time.h>
#if defined(_WIN32)
#include "win32.h"
#endif
void setBit(uint16_t & v, const int bit, const bool vb)