Tue, 15 Nov 2011 10:12:37 +0000
[musashi] Fix handling of bus errors
Patch-Author: Andrew Warkentin <andreww591!gmail>
Patch-MessageID: <4EC200CE.2020304@gmail.com>
I have fixed the first page fault test failure in FreeBee (the page fault test now hangs rather than errors out, because it is trying to read from the hard drive to test DMA page faults).
There were actually two bugs (the first bug was masking the second one).
First, the ancient version of Musashi that you used is unable to properly resume from bus errors that happen in the middle of certain instructions (some instructions are fetched in stages, with the PC being advanced to each part of the instruction, so basically what happens is the CPU core attempts to read the memory location referenced by the first operand, the bus error occurs, causing the PC to jump to the exception vector, but the faulting instruction is still in the middle of being fetched, so the PC is then advanced past the beginning of the exception handler). I fixed this by delaying the jump to the bus error vector until after the faulting instruction finishes.
The second bug is simpler - you had the UDS and LDS bits in BSR0 inverted (they are supposed to be active low).
1 #ifndef _KEYBOARD_H
2 #define _KEYBOARD_H
4 #include "SDL.h"
6 /// Keyboard buffer size in bytes
7 #define KEYBOARD_BUFFER_SIZE 256
9 typedef struct {
10 /// Key states
11 int keystate[0x80];
13 /// Keyboard buffer
14 uint8_t buffer[KEYBOARD_BUFFER_SIZE];
16 /// Read pointer
17 size_t readp;
19 /// Write pointer
20 size_t writep;
22 /// Number of bytes in keyboard buffer
23 size_t buflen;
25 /// Transmit Interrupt Enable
26 bool txie;
28 /// Receive Interrupt Enable
29 bool rxie;
31 /// "Keyboard State Changed" flag
32 bool update_flag;
33 } KEYBOARD_STATE;
35 /**
36 * Initialise a keyboard state block.
37 *
38 * Call this once when the keyboard is added to the emulation.
39 */
40 void keyboard_init(KEYBOARD_STATE *ks);
42 /**
43 * SDL_Event delegation routine.
44 *
45 * Call this when an SDL keyup or keydown event is received.
46 */
47 void keyboard_event(KEYBOARD_STATE *ks, SDL_Event *ev);
49 /**
50 * Keyboard scan routine.
51 *
52 * Call this periodically to scan the keyboard. 60 times/sec should be fine.
53 */
54 void keyboard_scan(KEYBOARD_STATE *ks);
56 bool keyboard_get_irq(KEYBOARD_STATE *ks);
57 uint8_t keyboard_read(KEYBOARD_STATE *ks, uint8_t addr);
58 void keyboard_write(KEYBOARD_STATE *ks, uint8_t addr, uint8_t val);
60 #endif