Programming
Some information on programming and debugging on the Toppy. There are also some useful Toppy programming links in the section.
— Low-Level Overview —
An low-level overview of the Toppy firmware:
- Code execution starts at 0x80000000, which is where the firmware is loaded
- actually the Toppy boots into the Primary Loader at 0xbfc00000 (raw code in flash memory)
- which then decompresses and runs the Secondary Loader to 0x81000000
- (which may notice an attempt to upload a new firmware or settings)
- which then decompresses and runs the Firmware to 0x80000000
- (which may have been aXeL, so it then decompresses and runs the real firmware to 0x80000000)
- Interrupts call the exception handler at 0x80000180 (this handles task switching)
- Function arguments are passed in registers a0 to a3, then placed on the stack: 16(sp), 20(sp), 24(sp)... as needed
- Registers s0 to s8 (s8 is also known as fp) have to be preserved by function calls, so the first bit of function code will usually save the ones it uses to the stack, and the last bit of code will restore them
- ra contains the address of the caller, so must be preserved if a function makes calls other functions
- gp is used as the base of global data — the firmware and TAPs have different global data stores so this register is altered when the firmware calls a TAP's EventHandler and TAP API functions must temporarily restore the firmware's gp in order to use the lower-level firmware functions
- Some other global data falls outside the scope of a gp reference so is statically located by absolute address — on the MIPS processor this requires two instructions: a lui and an add (or an or)
- The Toppy does real multi-tasking, but most of the work (including running TAPs) is done by the first, main task
- In addition to tasks there are lots of TSRs which are run by the main task at regular intervals (e.g. for decrementing the Sleep Timer)
- There is message passing internally (of several different kinds!) for most of the significant stuff, such as handling inter-task communcation and key events from the Front Panel