MRM_CRT0
  1. define .data
  2. define __unhandled_exception et al.
  3. define .text
  4. set things up so the application will run. This *must* be called start
  5. if the user provided us with flags (symbol name 'crt0_flags') for the startup code, load them now. If not, use defaults.
  6. if user provided an initialization list, process it now this is typically used to set up hardware that is critical to system operation, for example chip selects, watchdog timers, etc.
  7. See if user supplied their own stack (__stack != 0). If not, then leave it as set by the ROM monitor/exception vector. [note: stack is provided]
  8. if the user provided a hardware init function, call it now. this is done first so that hardware is all set up for the rest of crt0 [NOTE: no hook provided]
  9. If bit 0 of crt0_flags is set, then do a jump to the init routine with the return address in D0; otherwise do a normal jsr. [NOTE: bit not set]
  10. If bit 1 of crt0_flags is clear, then zero out the bss section. [NOTE: bit IS clear]
  11. copy .data image, if there is one, from ROM to RAM.
  12. if ADD_DTORS defined then put __do_global_dtors in the atexit list so the destructors get run.
  13. call the main routine from the application to get it going. applications executes, and terminates somehow
  14. drop down into exit incase the user doesn't. This should drop control back to the ROM monitor, if there is one. This calls the exit() from the C library so the C++ tables get cleaned up properly.
  15. Lastly, we define a default handler for exceptions not otherwise handled in the application code.