:dancing banana: (sort of)
After more than four months of chasing my own tail on this problem, I had managed to fix up the JIT compiling to let the Kickstart boot using compiled code. (See disclaimer below...)
*Phew*, there were times when I thought I am not going to write this down ever in the blog. I was this >> << close to give it up on some days. Since the world hasn't ended in 2012, I realized I have to go on, there is no escape.
I am proud to announce: the project stepped into Alpha stage on SourceForge with this update. Details of the changes are:
For the Kickstart boot these fixes were needed:
- Added compiling stop (jump) flag to instructions which might trigger interrupt for supervisor mode: OR.W #imm,SR, AND.W #imm,SR, EOR.W #imm,SR
- Temporary registers are flushed at the end of the compiling cycle, but before the code generation.
- Stop the block processing when the special flags were set in the block (an interrupt might be triggered).
- Reload the emulated program counter register when the block finishes with a supported instruction.
- Fixed wrong function epilog implementation: the return address was read from the wrong position in the stack.
- Old executed instruction pointer and emulated PC register is synchronized on PC reload.
Other fixes for the bugs I have discovered while I extensively debugged the emulation:
- Fixed missing releasing of the compiling buffer on quitting the emulator (memory leak).
- Prevent compiling of tiny blocks (less than 4 instructions in a row): the overhead of the block calling is too much.
- Fixed compiling buffer overflow checking and misleading help text for the compiling buffer unit size.
- Removed supported status for not-yet-implemented EOR.x reg,mem instruction, which was added accidentally before.
(Disclaimer) Before all of you rejoice in dancing banana overload on the user portal of your choice, there is a catch: the Kickstart is not able to start up with JIT compiled instructions, only if the original interpretive instructions are called one-by-one from the compiled code.
So, there is no practical use of the sources yet, but this was the big question: is the compiled code handling able to deal with something as complex as the Kickstart? And for a long time the answer was: no.
Some über-geeky details about the fixes (you like when I'm talking dirty, right?):
As you can see from the changes there were numerous problems around the code, all of these changes were needed for the final result. There were the usual ridiculous issues like a missing negative sign in the function Epilog (line 2308) when it tried to read back the return address from the stack - from the wrong offset.
It essentially means that the execution returned from every compiled block to the parent function instead of the block call loop. The funny familiar feeling that every coder experiences sooner or later: how on EARTH this thing ever worked? ;)
The trickiest part was finding the bug about the interrupt handling: I waded through a few hundred gigabytes of debug dump following the execution. Unfortunately, I was not able to compare the different execution sessions as I mentioned earlier in the comments for the previous post.
At last, I have found out that the OS is switching between User and Supervisor mode in the Exec.lib/Supervisor() function using the special OR immediate instruction by flipping the S flag in the Status Register. This step triggers an exception which is captured by the OS and the position of the triggering instruction identified in the ROM exactly.
The bug was: I never considered this OR instruction to be similar to a TRAP or an ILLEGAL instruction, which instructions change the Program Counter by raising an exception - which is essentially a jump. Thus the compiling hadn't stopped to give back the execution to the interpretive emulation.
As a result the compiled block contained the next instruction after the OR consecutively and later the exception was triggered separately: train-wrecking the boot completely. The only way to get out of there for the OS was to reboot, this is how the reboot-loop happened.
Promises?
Now, it gets a lot easier to fix up the different instruction implementations and implement the rest of the missing instructions. As soon as the former is done the OS will be usable and the latter can be done gradually.
I would like to thank to Toni Wilen for his hints regarding the possible ways of tracking down bugs inside UAE. His suggestions gave me ideas which eventually led to the required fixes.
Yet lot more work should be done, but at least I can see the light at the end of the tunnel. (What a cliché, man. Put yourself together!)
And finally, here is a picture of me, made by my wife to capture the moment when the freakin’ thing started up for the very first time:
OMG, who is this ork-face? |
See you all soon(ish) – my holiday is over tomorrow (#sadface).