Fast and simple insert code into crt0.s

|

Some time ago there was a question of the sort, "How do I make my own crt0.o file". Then the buzz started, and everyone was talking about how to do these things, including relocating RAM and other hardware configuration.

It seemed overly dificult to worry about things like finding the original crt0.s file (I've only found it burried in the GCC source code), and taking chances of changing too much so it didn't properly initialize RAM and such. Well, I have a solution where all I do is insert my startup code in a specific slot within the default crt0.s without having to edit that file!

Here is my entire "startup.s" file:

===startup.s===
;;; Startup code
;;; Author Jefferson Smith
.section .install1
movb #0x39,0x10 ; INITRM: end 0x3fff
movb #0x00,0x11 ; INITRG: start 0
movb #0x08,0x12 ; INITEE: end 0x0fff

===
Referring to the guide "Using the GNU Development Tools for 68HC11 and 68HC12" section 4.2, I notice that the memory section ".install1" is a "placeholder for applications". The reason is that if I add code to this section, it is automatically inserted between the stack pointer initialization and the default RAM initialization. This is a wonderful place to relocate RAM or hardware registers because no stack was used (have not called __premain() yet) and no memory was accessed except the instruction to initialize SP.

If you have quite a lot of code to insert here, you could `call` into a PPAGE bank so the init code doesn't take up fixed Flash space.

This is an example of the link commandline that uses startup.s:

m6811-elf-gcc -m68hcs12 -mshort -Wl,-T,ldscript-rom.x -mrelax -o test.elf test.o vectors.o startup.o -lm -lbcc -lc -lbcc

Simply adding startup.o to the list of objects inserts the code.