NewtonOS:      Memory   ·   Sample   ·   PC   ·   SP   ·   «Einstein»   ·   Contribute


Debugging the emulation with the Monitor

Einstein has a built-in debugger on OS X and Linux. The debugger is calle Monitor and can be accessed via Option+Command+M. The Monitor window has an output area at the top that shows CPU registers and some hardware registers on the left when the CPU is stopped, and general output on the right. The bottom line is used to enter commands. The commandline interpreter is not very forgiving. Make sure that you enter the commands exacty as described on the help page.

The Monitor has all the basic commands needed to debug the emulated code. The list below focusses on the commands that may be useful for retargeting.

If you like to give Retargeting a try, I recommend that you compile Einstein from scratch from the current SVN.


Watchpoints

Watchpoints are a way to mark points in memory that trigger a breakpoint when they are read or written. They are not essential for retargeting, but useful for following memory access.

Example:

Let's say you want to know who reads the variable gCurrentGlobals located at 0x0C10105C in RAM.

Start Einstein, open the Monitor (Alt+Cmd+M) and type stop. Now enter wpr 0C10105C, then type run. The next time, this address is read, execution will stop and you can find the function that reads this variable (in my sample case, it was IRQCleanUp()).


Retargeting

I added retargeting commands to the Monitor. These commands create "C" code that replaces individual functions inside the ROM using code as it would be generated by the JIT compiler. You can immediately drop-in that code, or hand-optimize it if you wish.

Example:

  • Launch Einstein, open the Monitor. Type help rt to see your options.
  • Type rt open /Users/my name/test to create two files, test.h and test.cp, to receive the transcoded function.
  • Type rt cjit 0009C77C-0009C7C4 TDoubleQContainer::Remove(...) to create the "C" code
  • Type rt close to close the files.

Take a look at test.cp and test.h . These files should contain code that you can simply copy into Newt/SimCollection1.cp and Newt/SimCollection1.h in your Einstein Source Tree. The code will hook itself into the Newton ROM and will be executed instead of the ROM code.

If the translated code should trigger a DataAbort, control is given back to emulator.

Instead of an address, rt cjit can also handle symbolic names of functions if the symbol table has been loaded, for example: rt cjit GetCurrentHeap .

It is perfectly legal to translate only parts os a function, however you must make sure that no branch instruction jumps outside of the given range.


Scripting

It has becode tedious to type retargeting commands for multiple functions. Using the !filenae command runs every line of text in that file as if it was entered into the monitor (the command syntax is an exclamation mark, directly followed by the full path and filename of a text file).