mixed commit: disk overlay for snapshots/state-dumps, compile fixes for ESP32
This commit is contained in:
parent
7c0133dc8d
commit
1da19f0241
21 changed files with 244 additions and 91 deletions
|
@ -1,4 +1,4 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
#define NEOPIXELS_PIN 25
|
#define NEOPIXELS_PIN 25
|
||||||
|
|
||||||
console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports, const int t_width, const int t_height) :
|
console_esp32::console_esp32(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports, const int t_width, const int t_height) :
|
||||||
console(stop_event, b, t_width, t_height),
|
console(stop_event, t_width, t_height),
|
||||||
io_ports(io_ports)
|
io_ports(io_ports)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
@ -18,7 +18,7 @@ protected:
|
||||||
void put_char_ll(const char c) override;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_esp32(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports, const int t_width, const int t_height);
|
console_esp32(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports, const int t_width, const int t_height);
|
||||||
virtual ~console_esp32();
|
virtual ~console_esp32();
|
||||||
|
|
||||||
void put_string_lf(const std::string & what) override;
|
void put_string_lf(const std::string & what) override;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#define COLORED 0
|
#define COLORED 0
|
||||||
#define UNCOLORED 1
|
#define UNCOLORED 1
|
||||||
|
|
||||||
console_shabadge::console_shabadge(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports) :
|
console_shabadge::console_shabadge(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports) :
|
||||||
console_esp32(stop_event, b, io_ports, 296 / 8, 128 / 8)
|
console_esp32(stop_event, io_ports, 296 / 8, 128 / 8)
|
||||||
{
|
{
|
||||||
if (epd.Init() != 0)
|
if (epd.Init() != 0)
|
||||||
Serial.println("Init of DEPG0290B01 failed");
|
Serial.println("Init of DEPG0290B01 failed");
|
||||||
|
|
|
@ -22,7 +22,7 @@ private:
|
||||||
void put_char_ll(const char c) override;
|
void put_char_ll(const char c) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_shabadge(std::atomic_uint32_t *const stop_event, bus *const b, std::vector<Stream *> & io_ports);
|
console_shabadge(std::atomic_uint32_t *const stop_event, std::vector<Stream *> & io_ports);
|
||||||
virtual ~console_shabadge();
|
virtual ~console_shabadge();
|
||||||
|
|
||||||
void panel_update_thread() override;
|
void panel_update_thread() override;
|
||||||
|
|
|
@ -29,7 +29,7 @@ void disk_backend_esp32::emit_error()
|
||||||
DOLOG(ll_error, true, "SdFat error: %d/%d", sd.sdErrorCode(), sd.sdErrorData());
|
DOLOG(ll_error, true, "SdFat error: %d/%d", sd.sdErrorCode(), sd.sdErrorData());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_esp32::begin()
|
bool disk_backend_esp32::begin(const bool dummy)
|
||||||
{
|
{
|
||||||
if (!fh->open(filename.c_str(), O_RDWR)) {
|
if (!fh->open(filename.c_str(), O_RDWR)) {
|
||||||
DOLOG(ll_error, true, "rk05: cannot open \"%s\"", filename.c_str());
|
DOLOG(ll_error, true, "rk05: cannot open \"%s\"", filename.c_str());
|
||||||
|
@ -41,7 +41,7 @@ bool disk_backend_esp32::begin()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const target)
|
bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t *const from)
|
bool disk_backend_esp32::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_esp32::write: write %zu bytes to offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_esp32::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,11 @@ public:
|
||||||
disk_backend_esp32(const std::string & filename);
|
disk_backend_esp32(const std::string & filename);
|
||||||
virtual ~disk_backend_esp32();
|
virtual ~disk_backend_esp32();
|
||||||
|
|
||||||
bool begin() override;
|
std::string get_identifier() const { return filename; }
|
||||||
|
|
||||||
bool read(const off_t offset, const size_t n, uint8_t *const target) override;
|
bool begin(const bool dummy) override;
|
||||||
|
|
||||||
bool write(const off_t offset, const size_t n, const uint8_t *const from) override;
|
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
|
||||||
|
|
||||||
|
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
#include "esp32.h"
|
#include "esp32.h"
|
||||||
#endif
|
#endif
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
#include "kw11-l.h"
|
|
||||||
#include "loaders.h"
|
#include "loaders.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
|
@ -286,13 +285,11 @@ void setup() {
|
||||||
|
|
||||||
std::vector<Stream *> serial_ports { &Serial_RS232, &Serial };
|
std::vector<Stream *> serial_ports { &Serial_RS232, &Serial };
|
||||||
#if defined(SHA2017)
|
#if defined(SHA2017)
|
||||||
cnsl = new console_shabadge(&stop_event, b, serial_ports);
|
cnsl = new console_shabadge(&stop_event, serial_ports);
|
||||||
#elif defined(ESP32) || defined(BUILD_FOR_RP2040)
|
#elif defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
cnsl = new console_esp32(&stop_event, b, serial_ports, 80, 25);
|
cnsl = new console_esp32(&stop_event, serial_ports, 80, 25);
|
||||||
#endif
|
#endif
|
||||||
|
cnsl->set_bus(b);
|
||||||
Serial.println(F("Start line-frequency interrupt"));
|
|
||||||
kw11_l *lf = new kw11_l(b, cnsl);
|
|
||||||
|
|
||||||
running = cnsl->get_running_flag();
|
running = cnsl->get_running_flag();
|
||||||
|
|
||||||
|
|
1
ESP32/mmu.cpp
Symbolic link
1
ESP32/mmu.cpp
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../mmu.cpp
|
1
ESP32/mmu.h
Symbolic link
1
ESP32/mmu.h
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../mmu.h
|
|
@ -125,7 +125,7 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
|
|
||||||
disk_backend *d = new disk_backend_nbd(nbd_host.c_str(), nbd_port);
|
disk_backend *d = new disk_backend_nbd(nbd_host.c_str(), nbd_port);
|
||||||
|
|
||||||
if (d->begin() == false) {
|
if (d->begin(false) == false) {
|
||||||
c->put_string_lf("Cannot initialize NBD client from configuration file");
|
c->put_string_lf("Cannot initialize NBD client from configuration file");
|
||||||
delete d;
|
delete d;
|
||||||
return { };
|
return { };
|
||||||
|
@ -273,7 +273,7 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
|
|
||||||
disk_backend *d = new disk_backend_nbd(hostname, atoi(port_str.c_str()));
|
disk_backend *d = new disk_backend_nbd(hostname, atoi(port_str.c_str()));
|
||||||
|
|
||||||
if (d->begin() == false) {
|
if (d->begin(false) == false) {
|
||||||
c->put_string_lf("Cannot initialize NBD client");
|
c->put_string_lf("Cannot initialize NBD client");
|
||||||
delete d;
|
delete d;
|
||||||
return { };
|
return { };
|
||||||
|
@ -397,7 +397,7 @@ std::optional<std::tuple<std::vector<disk_backend *>, std::vector<disk_backend *
|
||||||
disk_backend *temp = new disk_backend_esp32(selected_file);
|
disk_backend *temp = new disk_backend_esp32(selected_file);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!temp->begin()) {
|
if (!temp->begin(false)) {
|
||||||
c->put_string("Cannot use: ");
|
c->put_string("Cannot use: ");
|
||||||
c->put_string_lf(selected_file.c_str());
|
c->put_string_lf(selected_file.c_str());
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,10 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
|
#if IS_POSIX
|
||||||
#include "disk_backend_file.h"
|
#include "disk_backend_file.h"
|
||||||
#include "disk_backend_nbd.h"
|
#include "disk_backend_nbd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
disk_backend::disk_backend()
|
disk_backend::disk_backend()
|
||||||
|
@ -17,6 +19,80 @@ disk_backend::~disk_backend()
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IS_POSIX
|
#if IS_POSIX
|
||||||
|
void disk_backend::store_object_in_overlay(const off_t id, const std::vector<uint8_t> & data)
|
||||||
|
{
|
||||||
|
overlay.insert_or_assign(id, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::vector<uint8_t> > disk_backend::get_object_from_overlay(const off_t id)
|
||||||
|
{
|
||||||
|
auto it = overlay.find(id);
|
||||||
|
if (it != overlay.end())
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::vector<uint8_t> > disk_backend::get_from_overlay(const off_t offset, const size_t sector_size)
|
||||||
|
{
|
||||||
|
assert((offset % sector_size) == 0);
|
||||||
|
|
||||||
|
if (use_overlay)
|
||||||
|
return get_object_from_overlay(offset / sector_size);
|
||||||
|
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
|
bool disk_backend::store_mem_range_in_overlay(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
|
{
|
||||||
|
assert((offset % sector_size) == 0);
|
||||||
|
assert((n % sector_size) == 0);
|
||||||
|
|
||||||
|
if (use_overlay) {
|
||||||
|
for(size_t o=0; o<n; o += sector_size)
|
||||||
|
store_object_in_overlay((offset + o) / sector_size, std::vector<uint8_t>(from + o, from + o + sector_size));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_t *disk_backend::serialize_overlay() const
|
||||||
|
{
|
||||||
|
json_t *out = json_object();
|
||||||
|
|
||||||
|
for(auto & id: overlay) {
|
||||||
|
json_t *j_data = json_array();
|
||||||
|
|
||||||
|
for(size_t i=0; i<id.second.size(); i++)
|
||||||
|
json_array_append(j_data, json_integer(id.second.at(i)));
|
||||||
|
|
||||||
|
json_object_set(out, format("%u", id.first).c_str(), j_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disk_backend::deserialize_overlay(const json_t *const j)
|
||||||
|
{
|
||||||
|
json_t *input = json_object_get(j, "overlay");
|
||||||
|
if (!input) // we can have state-dumps without overlay
|
||||||
|
return;
|
||||||
|
|
||||||
|
const char *key = nullptr;
|
||||||
|
json_t *value = nullptr;
|
||||||
|
json_object_foreach(input, key, value) {
|
||||||
|
uint32_t id = std::atoi(key);
|
||||||
|
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
for(size_t i=0; i<json_array_size(value); i++)
|
||||||
|
data.push_back(json_integer_value(json_array_get(value, i)));
|
||||||
|
|
||||||
|
store_object_in_overlay(id, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
disk_backend *disk_backend::deserialize(const json_t *const j)
|
disk_backend *disk_backend::deserialize(const json_t *const j)
|
||||||
{
|
{
|
||||||
std::string type = json_string_value(json_object_get(j, "disk-backend-type"));
|
std::string type = json_string_value(json_object_get(j, "disk-backend-type"));
|
||||||
|
@ -32,7 +108,10 @@ disk_backend *disk_backend::deserialize(const json_t *const j)
|
||||||
// should not be reached
|
// should not be reached
|
||||||
assert(d);
|
assert(d);
|
||||||
|
|
||||||
d->begin();
|
d->deserialize_overlay(j);
|
||||||
|
|
||||||
|
// assume we want snapshots (again?)
|
||||||
|
d->begin(true);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <optional>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
|
@ -11,6 +15,20 @@
|
||||||
|
|
||||||
class disk_backend
|
class disk_backend
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
|
#if IS_POSIX
|
||||||
|
bool use_overlay { false };
|
||||||
|
std::map<off_t, std::vector<uint8_t> > overlay;
|
||||||
|
|
||||||
|
void store_object_in_overlay(const off_t id, const std::vector<uint8_t> & data);
|
||||||
|
bool store_mem_range_in_overlay(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size);
|
||||||
|
std::optional<std::vector<uint8_t> > get_object_from_overlay(const off_t id);
|
||||||
|
std::optional<std::vector<uint8_t> > get_from_overlay(const off_t offset, const size_t sector_size);
|
||||||
|
|
||||||
|
json_t *serialize_overlay() const;
|
||||||
|
void deserialize_overlay(const json_t *const j);
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
disk_backend();
|
disk_backend();
|
||||||
virtual ~disk_backend();
|
virtual ~disk_backend();
|
||||||
|
@ -20,9 +38,11 @@ public:
|
||||||
static disk_backend *deserialize(const json_t *const j);
|
static disk_backend *deserialize(const json_t *const j);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual bool begin() = 0;
|
virtual std::string get_identifier() const = 0;
|
||||||
|
|
||||||
virtual bool read(const off_t offset, const size_t n, uint8_t *const target) = 0;
|
virtual bool begin(const bool disk_snapshots) = 0;
|
||||||
|
|
||||||
virtual bool write(const off_t offset, const size_t n, const uint8_t *const from) = 0;
|
virtual bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) = 0;
|
||||||
|
|
||||||
|
virtual bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
// (C) 2018-2024 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "disk_backend_file.h"
|
#include "disk_backend_file.h"
|
||||||
|
#include "gen.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +28,8 @@ json_t *disk_backend_file::serialize() const
|
||||||
|
|
||||||
json_object_set(j, "disk-backend-type", json_string("file"));
|
json_object_set(j, "disk-backend-type", json_string("file"));
|
||||||
|
|
||||||
|
json_object_set(j, "overlay", serialize_overlay());
|
||||||
|
|
||||||
// TODO store checksum of backend
|
// TODO store checksum of backend
|
||||||
json_object_set(j, "filename", json_string(filename.c_str()));
|
json_object_set(j, "filename", json_string(filename.c_str()));
|
||||||
|
|
||||||
|
@ -39,8 +43,10 @@ disk_backend_file *disk_backend_file::deserialize(const json_t *const j)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool disk_backend_file::begin()
|
bool disk_backend_file::begin(const bool snapshots)
|
||||||
{
|
{
|
||||||
|
use_overlay = snapshots;
|
||||||
|
|
||||||
fd = open(filename.c_str(), O_RDWR);
|
fd = open(filename.c_str(), O_RDWR);
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
@ -52,30 +58,48 @@ bool disk_backend_file::begin()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_file::read(const off_t offset, const size_t n, uint8_t *const target)
|
bool disk_backend_file::read(const off_t offset_in, const size_t n, uint8_t *const target, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_file::read: read %zu bytes from offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_file::read: read %zu bytes from offset %zu", n, offset_in);
|
||||||
|
|
||||||
|
assert((offset % sector_size) == 0);
|
||||||
|
assert((n % sector_size) == 0);
|
||||||
|
|
||||||
|
for(off_t o=0; o<off_t(n); o+=sector_size) {
|
||||||
|
off_t offset = offset_in + o;
|
||||||
|
#if IS_POSIX
|
||||||
|
auto o_rc = get_from_overlay(offset, sector_size);
|
||||||
|
if (o_rc.has_value()) {
|
||||||
|
memcpy(&target[o], o_rc.value().data(), sector_size);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) // hope for the best
|
#if defined(_WIN32) // hope for the best
|
||||||
if (lseek(fd, offset, SEEK_SET) == -1)
|
if (lseek(fd, offset, SEEK_SET) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return ::read(fd, target, n) == ssize_t(n);
|
if (::read(fd, target, n) != ssize_t(n))
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
ssize_t rc = pread(fd, target, n, offset);
|
ssize_t rc = pread(fd, target, n, offset);
|
||||||
if (rc != ssize_t(n)) {
|
if (rc != ssize_t(n)) {
|
||||||
DOLOG(warning, false, "disk_backend_file::read: read failure. expected %zu bytes, got %zd", n, rc);
|
DOLOG(warning, false, "disk_backend_file::read: read failure. expected %zu bytes, got %zd", n, rc);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_file::write(const off_t offset, const size_t n, const uint8_t *const from)
|
bool disk_backend_file::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
|
if (store_mem_range_in_overlay(offset, n, from, sector_size))
|
||||||
|
return true;
|
||||||
|
|
||||||
#if defined(_WIN32) // hope for the best
|
#if defined(_WIN32) // hope for the best
|
||||||
if (lseek(fd, offset, SEEK_SET) == -1)
|
if (lseek(fd, offset, SEEK_SET) == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -22,9 +22,11 @@ public:
|
||||||
static disk_backend_file *deserialize(const json_t *const j);
|
static disk_backend_file *deserialize(const json_t *const j);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool begin() override;
|
std::string get_identifier() const override { return filename; }
|
||||||
|
|
||||||
bool read(const off_t offset, const size_t n, uint8_t *const target) override;
|
bool begin(const bool snapshots) override;
|
||||||
|
|
||||||
bool write(const off_t offset, const size_t n, const uint8_t *const from) override;
|
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
|
||||||
|
|
||||||
|
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// (C) 2018-2024 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
@ -54,6 +55,8 @@ json_t *disk_backend_nbd::serialize() const
|
||||||
|
|
||||||
json_object_set(j, "disk-backend-type", json_string("nbd"));
|
json_object_set(j, "disk-backend-type", json_string("nbd"));
|
||||||
|
|
||||||
|
json_object_set(j, "overlay", serialize_overlay());
|
||||||
|
|
||||||
// TODO store checksum of backend
|
// TODO store checksum of backend
|
||||||
json_object_set(j, "host", json_string(host.c_str()));
|
json_object_set(j, "host", json_string(host.c_str()));
|
||||||
json_object_set(j, "port", json_integer(port));
|
json_object_set(j, "port", json_integer(port));
|
||||||
|
@ -68,8 +71,12 @@ disk_backend_nbd *disk_backend_nbd::deserialize(const json_t *const j)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool disk_backend_nbd::begin()
|
bool disk_backend_nbd::begin(const bool snapshots)
|
||||||
{
|
{
|
||||||
|
#if IS_POSIX
|
||||||
|
use_overlay = snapshots;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!connect(false)) {
|
if (!connect(false)) {
|
||||||
DOLOG(ll_error, true, "disk_backend_nbd: cannot connect to NBD server");
|
DOLOG(ll_error, true, "disk_backend_nbd: cannot connect to NBD server");
|
||||||
return false;
|
return false;
|
||||||
|
@ -154,14 +161,27 @@ bool disk_backend_nbd::connect(const bool retry)
|
||||||
return fd != -1;
|
return fd != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_nbd::read(const off_t offset, const size_t n, uint8_t *const target)
|
bool disk_backend_nbd::read(const off_t offset_in, const size_t n, uint8_t *const target, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_nbd::read: read %zu bytes from offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_nbd::read: read %zu bytes from offset %zu", n, offset_in);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
do {
|
size_t o = 0;
|
||||||
|
off_t offset = offset_in;
|
||||||
|
|
||||||
|
while(offset < offset_in + off_t(n)) {
|
||||||
|
#if IS_POSIX
|
||||||
|
auto o_rc = get_from_overlay(offset, sector_size);
|
||||||
|
if (o_rc.has_value()) {
|
||||||
|
memcpy(&target[o], o_rc.value().data(), sector_size);
|
||||||
|
offset += sector_size;
|
||||||
|
o += sector_size;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fd == -1 && !connect(true)) {
|
if (fd == -1 && !connect(true)) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::read: (re-)connect");
|
DOLOG(warning, true, "disk_backend_nbd::read: (re-)connect");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
@ -179,7 +199,7 @@ bool disk_backend_nbd::read(const off_t offset, const size_t n, uint8_t *const t
|
||||||
nbd_request.magic = ntohl(0x25609513);
|
nbd_request.magic = ntohl(0x25609513);
|
||||||
nbd_request.type = 0; // READ
|
nbd_request.type = 0; // READ
|
||||||
nbd_request.offset = HTONLL(uint64_t(offset));
|
nbd_request.offset = HTONLL(uint64_t(offset));
|
||||||
nbd_request.length = htonl(n);
|
nbd_request.length = htonl(sector_size);
|
||||||
|
|
||||||
if (WRITE(fd, reinterpret_cast<const char *>(&nbd_request), sizeof nbd_request) != sizeof nbd_request) {
|
if (WRITE(fd, reinterpret_cast<const char *>(&nbd_request), sizeof nbd_request) != sizeof nbd_request) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::read: problem sending request");
|
DOLOG(warning, true, "disk_backend_nbd::read: problem sending request");
|
||||||
|
@ -217,26 +237,33 @@ bool disk_backend_nbd::read(const off_t offset, const size_t n, uint8_t *const t
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (READ(fd, reinterpret_cast<char *>(target), n) != ssize_t(n)) {
|
if (READ(fd, reinterpret_cast<char *>(target), sector_size) != ssize_t(sector_size)) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::read: problem receiving payload");
|
DOLOG(warning, true, "disk_backend_nbd::read: problem receiving payload");
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
offset += sector_size;
|
||||||
|
o += sector_size;
|
||||||
}
|
}
|
||||||
while(fd == -1);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *const from)
|
bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size)
|
||||||
{
|
{
|
||||||
DOLOG(debug, false, "disk_backend_nbd::write: write %zu bytes to offset %zu", n, offset);
|
DOLOG(debug, false, "disk_backend_nbd::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
|
if (store_mem_range_in_overlay(offset, n, from, sector_size))
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!connect(true)) {
|
if (!connect(true)) {
|
||||||
DOLOG(warning, true, "disk_backend_nbd::write: (re-)connect");
|
DOLOG(warning, true, "disk_backend_nbd::write: (re-)connect");
|
||||||
|
@ -250,7 +277,7 @@ bool disk_backend_nbd::write(const off_t offset, const size_t n, const uint8_t *
|
||||||
uint64_t handle;
|
uint64_t handle;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
} nbd_request { 0 };
|
} nbd_request { };
|
||||||
|
|
||||||
nbd_request.magic = ntohl(0x25609513);
|
nbd_request.magic = ntohl(0x25609513);
|
||||||
nbd_request.type = 1; // WRITE
|
nbd_request.type = 1; // WRITE
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// (C) 2018-2023 by Folkert van Heusden
|
// (C) 2018-2024 by Folkert van Heusden
|
||||||
// Released under MIT license
|
// Released under MIT license
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
class disk_backend_nbd : public disk_backend
|
class disk_backend_nbd : public disk_backend
|
||||||
|
@ -26,9 +27,11 @@ public:
|
||||||
static disk_backend_nbd *deserialize(const json_t *const j);
|
static disk_backend_nbd *deserialize(const json_t *const j);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool begin() override;
|
std::string get_identifier() const override { return format("%s:%d", host.c_str(), port); }
|
||||||
|
|
||||||
bool read(const off_t offset, const size_t n, uint8_t *const target) override;
|
bool begin(const bool snapshots) override;
|
||||||
|
|
||||||
bool write(const off_t offset, const size_t n, const uint8_t *const from) override;
|
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
|
||||||
|
|
||||||
|
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
|
||||||
};
|
};
|
||||||
|
|
7
gen.h
7
gen.h
|
@ -13,8 +13,11 @@ typedef enum { wm_word = 0, wm_byte = 1 } word_mode_t;
|
||||||
|
|
||||||
typedef enum { rm_prev, rm_cur } rm_selection_t;
|
typedef enum { rm_prev, rm_cur } rm_selection_t;
|
||||||
|
|
||||||
#define IS_POSIX (defined(linux) || defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)))
|
#if (defined(linux) || defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)))
|
||||||
#define IS_UP (!(IS_POSIX)) /* is microprocessor */
|
#define IS_POSIX 1
|
||||||
|
#else
|
||||||
|
#define IS_POSIX 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if IS_POSIX
|
#if IS_POSIX
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
|
52
main.cpp
52
main.cpp
|
@ -295,10 +295,19 @@ void get_metrics(cpu *const c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start_disk_devices(const std::vector<disk_backend *> & backends, const bool enable_snapshots)
|
||||||
|
{
|
||||||
|
for(auto & backend: backends) {
|
||||||
|
if (backend->begin(enable_snapshots) == false)
|
||||||
|
error_exit(false, "Failed to initialize disk backend \"%s\"", backend->get_identifier().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
printf("-h this help\n");
|
printf("-h this help\n");
|
||||||
printf("-D x deserialize state from file\n");
|
printf("-D x deserialize state from file\n");
|
||||||
|
printf("-P when serializing state to file (in the debugger), include an overlay: changes to disk-files are then non-persistent, they only exist in the state-dump\n");
|
||||||
printf("-T t.bin load file as a binary tape file (like simh \"load\" command), also for .BIC files\n");
|
printf("-T t.bin load file as a binary tape file (like simh \"load\" command), also for .BIC files\n");
|
||||||
printf("-B run tape file as a unit test (for .BIC files)\n");
|
printf("-B run tape file as a unit test (for .BIC files)\n");
|
||||||
printf("-R d.rk load file as a RK05 disk device\n");
|
printf("-R d.rk load file as a RK05 disk device\n");
|
||||||
|
@ -318,27 +327,8 @@ void help()
|
||||||
printf("-M log metrics\n");
|
printf("-M log metrics\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "breakpoint_parser.h"
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
{
|
|
||||||
bus *b = new bus();
|
|
||||||
cpu *c = new cpu(b, &event);
|
|
||||||
b->add_cpu(c);
|
|
||||||
|
|
||||||
std::pair<breakpoint *, std::optional<std::string> > rc = parse_breakpoint(b, "(pc=0123 and (r0=01456 or r2=1) and memWV[0444]=0222)");
|
|
||||||
printf("%p\n", rc.first);
|
|
||||||
|
|
||||||
if (rc.second.has_value())
|
|
||||||
printf("%s\n", rc.second.value().c_str());
|
|
||||||
delete rc.first;
|
|
||||||
delete b;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//setlocale(LC_ALL, "");
|
//setlocale(LC_ALL, "");
|
||||||
|
|
||||||
std::vector<disk_backend *> rk05_files;
|
std::vector<disk_backend *> rk05_files;
|
||||||
|
@ -365,7 +355,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
std::string test;
|
std::string test;
|
||||||
|
|
||||||
disk_backend *temp_d = nullptr;
|
bool disk_snapshots = false;
|
||||||
|
|
||||||
std::optional<int> set_ram_size;
|
std::optional<int> set_ram_size;
|
||||||
|
|
||||||
|
@ -376,7 +366,7 @@ int main(int argc, char *argv[])
|
||||||
std::string deserialize;
|
std::string deserialize;
|
||||||
|
|
||||||
int opt = -1;
|
int opt = -1;
|
||||||
while((opt = getopt(argc, argv, "hD:MT:Br:R:p:ndtL:bl:s:Q:N:J:XS:")) != -1)
|
while((opt = getopt(argc, argv, "hD:MT:Br:R:p:ndtL:bl:s:Q:N:J:XS:P")) != -1)
|
||||||
{
|
{
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -441,17 +431,11 @@ int main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'R':
|
case 'R':
|
||||||
temp_d = new disk_backend_file(optarg);
|
rk05_files.push_back(new disk_backend_file(optarg));
|
||||||
if (!temp_d->begin())
|
|
||||||
error_exit(false, "Cannot use file \"%s\" for RK05", optarg);
|
|
||||||
rk05_files.push_back(temp_d);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
temp_d = new disk_backend_file(optarg);
|
rl02_files.push_back(new disk_backend_file(optarg));
|
||||||
if (!temp_d->begin())
|
|
||||||
error_exit(false, "Cannot use file \"%s\" for RL02", optarg);
|
|
||||||
rl02_files.push_back(temp_d);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'N': {
|
case 'N': {
|
||||||
|
@ -459,7 +443,7 @@ int main(int argc, char *argv[])
|
||||||
if (parts.size() != 3)
|
if (parts.size() != 3)
|
||||||
error_exit(false, "-N: parameter missing");
|
error_exit(false, "-N: parameter missing");
|
||||||
|
|
||||||
temp_d = new disk_backend_nbd(parts.at(0), atoi(parts.at(1).c_str()));
|
disk_backend *temp_d = new disk_backend_nbd(parts.at(0), atoi(parts.at(1).c_str()));
|
||||||
|
|
||||||
if (parts.at(2) == "rk05")
|
if (parts.at(2) == "rk05")
|
||||||
rk05_files.push_back(temp_d);
|
rk05_files.push_back(temp_d);
|
||||||
|
@ -494,6 +478,10 @@ int main(int argc, char *argv[])
|
||||||
set_ram_size = std::stoi(optarg);
|
set_ram_size = std::stoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
disk_snapshots = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "-%c is not understood\n", opt);
|
fprintf(stderr, "-%c is not understood\n", opt);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -511,6 +499,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
DOLOG(info, true, "Built on: " __DATE__ " " __TIME__);
|
DOLOG(info, true, "Built on: " __DATE__ " " __TIME__);
|
||||||
|
|
||||||
|
start_disk_devices(rk05_files, disk_snapshots);
|
||||||
|
|
||||||
|
start_disk_devices(rl02_files, disk_snapshots);
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
if (withUI)
|
if (withUI)
|
||||||
cnsl = new console_ncurses(&event);
|
cnsl = new console_ncurses(&event);
|
||||||
|
|
2
mmu.h
2
mmu.h
|
@ -41,8 +41,10 @@ private:
|
||||||
uint16_t PIR { 0 };
|
uint16_t PIR { 0 };
|
||||||
uint16_t CSR { 0 };
|
uint16_t CSR { 0 };
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
void add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name) const;
|
void add_par_pdr(json_t *const target, const int run_mode, const bool is_d, const std::string & name) const;
|
||||||
void set_par_pdr(const json_t *const j_in, const int run_mode, const bool is_d, const std::string & name);
|
void set_par_pdr(const json_t *const j_in, const int run_mode, const bool is_d, const std::string & name);
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
mmu();
|
mmu();
|
||||||
|
|
4
rk05.cpp
4
rk05.cpp
|
@ -156,7 +156,7 @@ void rk05::writeWord(const uint16_t addr, const uint16_t v)
|
||||||
for(size_t i=0; i<cur; i++)
|
for(size_t i=0; i<cur; i++)
|
||||||
xfer_buffer[i] = b->readUnibusByte(work_memoff++);
|
xfer_buffer[i] = b->readUnibusByte(work_memoff++);
|
||||||
|
|
||||||
if (!fhs.at(device)->write(work_diskoffb, cur, xfer_buffer))
|
if (!fhs.at(device)->write(work_diskoffb, cur, xfer_buffer, 512))
|
||||||
DOLOG(ll_error, true, "RK05(%d) write error %s to %u len %u", device, strerror(errno), work_diskoffb, cur);
|
DOLOG(ll_error, true, "RK05(%d) write error %s to %u len %u", device, strerror(errno), work_diskoffb, cur);
|
||||||
|
|
||||||
work_diskoffb += cur;
|
work_diskoffb += cur;
|
||||||
|
@ -191,7 +191,7 @@ void rk05::writeWord(const uint16_t addr, const uint16_t v)
|
||||||
while(temp > 0) {
|
while(temp > 0) {
|
||||||
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), temp);
|
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), temp);
|
||||||
|
|
||||||
if (!fhs.at(device)->read(temp_diskoffb, cur, xfer_buffer)) {
|
if (!fhs.at(device)->read(temp_diskoffb, cur, xfer_buffer, 512)) {
|
||||||
DOLOG(ll_error, true, "RK05 read error %s from %u len %u", strerror(errno), temp_diskoffb, cur);
|
DOLOG(ll_error, true, "RK05 read error %s from %u len %u", strerror(errno), temp_diskoffb, cur);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
4
rl02.cpp
4
rl02.cpp
|
@ -271,7 +271,7 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
mpr[0]++;
|
mpr[0]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fhs.at(device)->write(temp_disk_offset, cur, xfer_buffer)) {
|
if (!fhs.at(device)->write(temp_disk_offset, cur, xfer_buffer, 256)) {
|
||||||
DOLOG(ll_error, true, "RL02: write error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
DOLOG(ll_error, true, "RL02: write error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ void rl02::writeWord(const uint16_t addr, uint16_t v)
|
||||||
while(count > 0) {
|
while(count > 0) {
|
||||||
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), count);
|
uint32_t cur = std::min(uint32_t(sizeof xfer_buffer), count);
|
||||||
|
|
||||||
if (!fhs.at(device)->read(temp_disk_offset, cur, xfer_buffer)) {
|
if (!fhs.at(device)->read(temp_disk_offset, cur, xfer_buffer, 256)) {
|
||||||
DOLOG(ll_error, true, "RL02: read error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
DOLOG(ll_error, true, "RL02: read error, device %d, disk offset %u, read size %u, cylinder %d, head %d, sector %d", device, temp_disk_offset, cur, track, head, sector);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue