@@ -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 switched over the whole
44+ // addressing space, until the first I/O access is performed
45+ static bool is_bios_rom_switched = 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_bios_rom_switched )
70+ return rom_bios_read (address & 0xFFF );
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,9 @@ 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+ if (is_bios_rom_switched )
103+ return ;
104+
96105 if (!is_mem_switched ) {
97106 for (size_t i = 0 ; i < ARRAY_SIZE (bus_mem_slots ); ++ i ) {
98107 const struct bus_mem_slot * slot = & bus_mem_slots [i ];
@@ -112,6 +121,9 @@ void bus_mem_write(ceda_address_t address, uint8_t value) {
112121uint8_t bus_io_in (ceda_ioaddr_t address ) {
113122 LOG_DEBUG ("%s: [%02x]\n" , __func__ , (zuint8 )address );
114123
124+ // IO access, rom override condition is de-asserted
125+ is_bios_rom_switched = false;
126+
115127 for (size_t i = 0 ; i < ARRAY_SIZE (bus_io_slots ); ++ i ) {
116128 const struct bus_io_slot * slot = & bus_io_slots [i ];
117129 if (address >= slot -> base && address < slot -> top ) {
@@ -128,6 +140,9 @@ void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
128140 const zuint8 address = (zuint8 )_address ;
129141 LOG_DEBUG ("%s: [%02x] <= %02x\n" , __func__ , address , value );
130142
143+ // IO access, rom override condition is de-asserted
144+ is_bios_rom_switched = false;
145+
131146 for (size_t i = 0 ; i < ARRAY_SIZE (bus_io_slots ); ++ i ) {
132147 const struct bus_io_slot * slot = & bus_io_slots [i ];
133148 if (address >= slot -> base && address < slot -> top ) {
@@ -141,28 +156,15 @@ void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
141156 ubus_io_out (address , value );
142157}
143158
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-
155159static bool bus_restart (void ) {
156160 is_mem_switched = false;
157- bus_prepareFirstAccess () ;
161+ is_bios_rom_switched = true ;
158162 return true;
159163}
160164
161165void bus_init (CEDAModule * mod ) {
162166 memset (mod , 0 , sizeof (* mod ));
163167 mod -> restart = bus_restart ;
164-
165- bus_prepareFirstAccess ();
166168}
167169
168170void bus_memSwitch (bool switched ) {
0 commit comments