Deep-diving into memory
Since I just bought a new SSD and I am about to reinstall my laptop, it is time to do another update on the project: another batch is uploaded to the SourceForge repository. (I hope I won’t lose the sources… ;)
So, what was made into this update? A quick list about what happened in the last two weeks:
- Direct memory writing support
- Detecting of special memory accesses per instruction and calling the chipset emulation on memory writes from the compiled code
- Implementation of some instructions:
- MOVE.x register to memory;
- MOVE.x register to register;
- Implementation of some addressing modes:
- immediate quick, like: ADDQ.L #x,reg;
- indirect addressing with post increment, like: MOVE.x reg,(Ay)+;
- Misc fixed stuff:
- proper logging for JIT (with a new configuration item: comp_log);
- slightly reworked temporary register handling;
- better handling of reloading/saving of flags and the base register;
- reloading of the emulated PC before leaving the compiled code is added (probably this was responsible for the reboot-loop at booting the OS, see below).
The most important change was the handling of the memory writes. When I started to plan the project this was one of the concerns: how to figure out which memory access requires special handling and which one can hit directly the emulated memory. By overcome of this issue all three problems are resolved:
- memory accesses are emulated as it is needed;
- self-modifying code is handled by using the processor cache;
- translated code lookup is managed by simulating the cache lines.
Luckily, the x86 JIT implementation already solved this issue (too): every instruction is executed by the interpretive emulator first for a couple times to prevent unnecessary translation of the code pieces that won’t be executed often (like initialization/cleanup code). While it is doing that it collects some information about the executed code that can be reused for the translation. One of these is the memory access type. Very clever solution, I must admit.
I am still chasing the ghost-bug that prevents the OS from booting. The recent fixes for the PC register (program counter) reloading changed the behaviour. Instead of running around in a reboot-loop, the OS is waiting for something to happen, most likely some hardware to trigger something. So, it is still no good, but looks a bit better.
Where to go from here: more addressing modes and instructions will be implemented before I start working on the implementation of the optimizing routines. First, I want to make sure that most of the Mandelbrot test is executed using compiled code, thus it will be easier to test the optimization and finally we can see how better the JIT performs than the interpretive. Exciting!
You have probably noticed that the state of the project on SourceForge is still pre-alpha. I don’t want to change it while the OS cannot be run on the emulation, so this is the other important goal.
So much for today. While you are enjoying the sunny, warm summer, don’t forget about us who are suffering from the cold, rainy days: Winter is coming… :/