@@ -40,6 +40,9 @@ static const struct bus_mem_slot bus_mem_slots[] = {
4040};
4141
4242static 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
4447typedef uint8_t (* bus_io_read_t )(ceda_ioaddr_t address );
4548typedef void (* bus_io_write_t )(ceda_ioaddr_t address , uint8_t value );
@@ -63,6 +66,9 @@ static const struct bus_io_slot bus_io_slots[] = {
6366};
6467
6568uint8_t bus_mem_read (ceda_address_t address ) {
69+ if (is_rom_overriding )
70+ return rom_bios_read (address % 0x1000 );
71+
6672 if (!is_mem_switched ) {
6773 for (size_t i = 0 ; i < ARRAY_SIZE (bus_mem_slots ); ++ i ) {
6874 const struct bus_mem_slot * slot = & bus_mem_slots [i ];
@@ -93,6 +99,10 @@ void bus_mem_readsome(uint8_t *blob, ceda_address_t address, ceda_size_t len) {
9399void bus_mem_write (ceda_address_t address , uint8_t value ) {
94100 LOG_DEBUG ("%s: [%04x] <= %02x\n" , __func__ , address , value );
95101
102+ // ROM can't handle write operations, just return
103+ if (is_rom_overriding )
104+ return ;
105+
96106 if (!is_mem_switched ) {
97107 for (size_t i = 0 ; i < ARRAY_SIZE (bus_mem_slots ); ++ i ) {
98108 const struct bus_mem_slot * slot = & bus_mem_slots [i ];
@@ -112,6 +122,9 @@ void bus_mem_write(ceda_address_t address, uint8_t value) {
112122uint8_t bus_io_in (ceda_ioaddr_t address ) {
113123 LOG_DEBUG ("%s: [%02x]\n" , __func__ , (zuint8 )address );
114124
125+ // IO access, rom override condition is de-asserted
126+ is_rom_overriding = false;
127+
115128 for (size_t i = 0 ; i < ARRAY_SIZE (bus_io_slots ); ++ i ) {
116129 const struct bus_io_slot * slot = & bus_io_slots [i ];
117130 if (address >= slot -> base && address < slot -> top ) {
@@ -128,6 +141,9 @@ void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
128141 const zuint8 address = (zuint8 )_address ;
129142 LOG_DEBUG ("%s: [%02x] <= %02x\n" , __func__ , address , value );
130143
144+ // IO access, rom override condition is de-asserted
145+ is_rom_overriding = false;
146+
131147 for (size_t i = 0 ; i < ARRAY_SIZE (bus_io_slots ); ++ i ) {
132148 const struct bus_io_slot * slot = & bus_io_slots [i ];
133149 if (address >= slot -> base && address < slot -> top ) {
@@ -141,28 +157,15 @@ void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
141157 ubus_io_out (address , value );
142158}
143159
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-
155160static bool bus_restart (void ) {
156161 is_mem_switched = false;
157- bus_prepareFirstAccess () ;
162+ is_rom_overriding = true ;
158163 return true;
159164}
160165
161166void bus_init (CEDAModule * mod ) {
162167 memset (mod , 0 , sizeof (* mod ));
163168 mod -> restart = bus_restart ;
164-
165- bus_prepareFirstAccess ();
166169}
167170
168171void bus_memSwitch (bool switched ) {
0 commit comments