Throwing a BusError in my target #29
-
|
I have been using Moira (v 2.4) for some weeks now, simulating a single-board 68000 I intend to fabricate for a project. I recently had a bug in my code that led me to tie an address decoder to /BERR on the virtual 68000. Grepping through the code, I got the hint to throw a BusErrorException() in the simulator. Hoorah! The simulated 68000 correctly picks up the exception vector from the vector table and calls the exception handler. The fly in the ointment: The 68000 does not stack a complete BusError stack frame -- it is only a 'normal' six-word exception frame (PC, SR). I am not by any stretch of the imagination a C++ programmer, so I am willing to stipulate that I am simply not creating the exception correctly. I did grep through the code on both this project and vAmiga to see if I could find an example, but found no place that actually throws that exception. To quote one of the Apple System-7 engineers I worked with 30 years ago, "You must be testing it wrong." |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
|
Hmm, you are right, Moira does not handle bus errors correctly. Moira has been testes throughly with everything an Amiga can do, but it is impossible to trigger a bus error on that machine. In fact, I never thought anybody would need bus error support on an emulated CPU. Anyways, here is the code that writes the wrong frame format: template <Core C> void
Moira::execException(ExceptionType exc, int nr)
{
...
switch (exc) {
case EXC_BUS_ERROR:
// Write stack frame
writeStackFrame1011<C>(status, reg.pc, reg.pc0, 2);
// Branch to exception handler
jumpToVector<C>(2);
break;
...
}Instead of template <Core C> void
Moira::writeStackFrameAEBE(StackFrame &frame)
{
// Push PC
push<C, Word>((u16)frame.pc);
push<C, Word>(frame.pc >> 16);
// Push SR and IRD
push<C, Word>(frame.sr);
push<C, Word>(frame.ird);
// Push address
push<C, Word>((u16)frame.addr);
push<C, Word>(frame.addr >> 16);
// Push memory access type and function code
push<C, Word>(frame.code);
}However, I don't know which values to write as I only have Amigas which, as mentioned above, cannot generate bus errors. If only the stack format matters rather than the written values, the function could be called with an arbitrary StackFrame object. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks a ton for your speedy reply. You have no idea how great it is to be able to develop software for a future product long before the real hardware is even finish being specified, and this has been critical in that. TBH: Just knowing where the error happened is usually enough to visually examine the code and figure out where it is going off the reservation, but I am a stickler for details. I see in other places you use a function to create the stack frames for all of the myriad variations of AddressError, so I can probably use them as a guide to ScriptKiddie my way into putting something resembling "the right thing" in the BusError frame. FYI: The details are in the 68000UM in Section 6.3.9.1 |
Beta Was this translation helpful? Give feedback.
-
|
Sorry if it doesn’t work. With "Bus error support," I may have been a bit too bold. I introduced a Bus Error type to mirror the existing Address Error type and replicated the address error handling as closely as possible. In theory, the new code should behave much like version 2.4. If it doesn’t, it's due to a bug and insufficient testing on my part. Bottom line: Moira is only "BusError ready", much like those "HD ready" TVs that were sold in Europe years ago as a TV that was "in theory" capable of displaying HD footage 🙄. |
Beta Was this translation helpful? Give feedback.
-
|
i finally got around to using Moira 3, bus error appears to be working, its a shame its not quite handled internally as it could as it looks like all it needs is a front facing pulseBusError(uint32_t address, bool isWrite) or something. the way i got it working was to create a way to throw my own error such as: then make sure you throw this on your read/write operation and throw the error is the emulator code when needed such as: i'm sure this can be done better, but if it helps, this is pretty much how i have used it for Atari ST. |
Beta Was this translation helpful? Give feedback.
-
|
Great! I’ll take a closer look once I have more free time. I agree that Bus Error support should eventually be added, especially since I like the idea of Moira being capable enough to support Atari ST emulation as well. |
Beta Was this translation helpful? Give feedback.
Hmm, you are right, Moira does not handle bus errors correctly. Moira has been testes throughly with everything an Amiga can do, but it is impossible to trigger a bus error on that machine. In fact, I never thought anybody would need bus error support on an emulated CPU.
Anyways, here is the code that writes the wrong frame format:
Instead of
writeStackFrame1011,…