Skip to content

Commit 120ebdd

Browse files
committed
ROM overrides addressing when system is resetted
1 parent 5d2787e commit 120ebdd

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/bus.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static const struct bus_mem_slot bus_mem_slots[] = {
4040
};
4141

4242
static bool is_mem_switched = false;
43+
// when starting, BIOS ROM is virtually repeated over the whole addressing space
44+
// until the first I/O access is performed,
45+
static bool is_rom_overriding = true;
4346

4447
typedef uint8_t (*bus_io_read_t)(ceda_ioaddr_t address);
4548
typedef void (*bus_io_write_t)(ceda_ioaddr_t address, uint8_t value);
@@ -62,8 +65,15 @@ static const struct bus_io_slot bus_io_slots[] = {
6265
{0xE0, 0xE4, timer_in, timer_out},
6366
};
6467

68+
static ceda_address_t force_rom_address(ceda_address_t address) {
69+
return 0xC000 + (address % 0x1000);
70+
}
71+
6572
uint8_t bus_mem_read(ceda_address_t address) {
66-
if (!is_mem_switched) {
73+
if (is_rom_overriding)
74+
address = force_rom_address(address);
75+
76+
if (is_rom_overriding || !is_mem_switched) {
6777
for (size_t i = 0; i < ARRAY_SIZE(bus_mem_slots); ++i) {
6878
const struct bus_mem_slot *slot = &bus_mem_slots[i];
6979
if (address >= slot->base && address < slot->top) {
@@ -93,7 +103,10 @@ void bus_mem_readsome(uint8_t *blob, ceda_address_t address, ceda_size_t len) {
93103
void bus_mem_write(ceda_address_t address, uint8_t value) {
94104
LOG_DEBUG("%s: [%04x] <= %02x\n", __func__, address, value);
95105

96-
if (!is_mem_switched) {
106+
if (is_rom_overriding)
107+
address = force_rom_address(address);
108+
109+
if (is_rom_overriding || !is_mem_switched) {
97110
for (size_t i = 0; i < ARRAY_SIZE(bus_mem_slots); ++i) {
98111
const struct bus_mem_slot *slot = &bus_mem_slots[i];
99112
if (address >= slot->base && address < slot->top) {
@@ -112,6 +125,9 @@ void bus_mem_write(ceda_address_t address, uint8_t value) {
112125
uint8_t bus_io_in(ceda_ioaddr_t address) {
113126
LOG_DEBUG("%s: [%02x]\n", __func__, (zuint8)address);
114127

128+
// IO access, rom override condition is de-asserted
129+
is_rom_overriding = false;
130+
115131
for (size_t i = 0; i < ARRAY_SIZE(bus_io_slots); ++i) {
116132
const struct bus_io_slot *slot = &bus_io_slots[i];
117133
if (address >= slot->base && address < slot->top) {
@@ -128,6 +144,9 @@ void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
128144
const zuint8 address = (zuint8)_address;
129145
LOG_DEBUG("%s: [%02x] <= %02x\n", __func__, address, value);
130146

147+
// IO access, rom override condition is de-asserted
148+
is_rom_overriding = false;
149+
131150
for (size_t i = 0; i < ARRAY_SIZE(bus_io_slots); ++i) {
132151
const struct bus_io_slot *slot = &bus_io_slots[i];
133152
if (address >= slot->base && address < slot->top) {
@@ -141,28 +160,15 @@ void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
141160
ubus_io_out(address, value);
142161
}
143162

144-
static void bus_prepareFirstAccess(void) {
145-
// when starting, BIOS ROM is mounted at 0x0,
146-
// until the first I/O access is performed,
147-
// but we'll just emulate this behaviour with an equivalent
148-
// jmp $c030
149-
static const uint8_t jmp[] = {0xc3, 0x30, 0xc0};
150-
for (uint8_t address = 0; address < (uint8_t)ARRAY_SIZE(jmp); ++address) {
151-
dyn_ram_write(address, jmp[address]);
152-
}
153-
}
154-
155163
static bool bus_restart(void) {
156164
is_mem_switched = false;
157-
bus_prepareFirstAccess();
165+
is_rom_overriding = true;
158166
return true;
159167
}
160168

161169
void bus_init(CEDAModule *mod) {
162170
memset(mod, 0, sizeof(*mod));
163171
mod->restart = bus_restart;
164-
165-
bus_prepareFirstAccess();
166172
}
167173

168174
void bus_memSwitch(bool switched) {

0 commit comments

Comments
 (0)