Because our firmware does not want to use the C library, the linker script and C-runtime both need to be written by themselves, but they have not been written yet. It is nothing more than a few lines of the C library. There is nothing to say, so we will write the main record of the avr c-runtime:
1. set the interrupt vector table (vector), which is defined in Datasheet. Each chip is different, and the number of vectors is also different. To achieve this purpose, a vector of more than 100 is defined here, in fact, a separate chip defines _ vectors_size to control the number of vectors in the end;
2. Default interrupt handler. When the user does not register the interrupt handler, it points to the default handler. The default handler is reset;
3. initialize some registers, such as clearing;
4. initialize the. Data Segment and copy data from flash to ram;
The initialization of 4.1 heap is useless and will not be performed;
4.2 stack Address Settings (can be passed in externally );
5. initialization. BSS segments are cleared. This is the function of libgcc. It directly decomassembles a program compiled with aVR-libc and copies several calls, such as _ do_clear_bss. After this, it jumps to main ();
6. Jump to main (). In fact, the jump will be completed in step 5, which is not needed here.
We have just been in touch with AVR for a few days, but we have not seen the details. We have not understood many things and can leave the C library. Compiling and running are the first steps that have been completed successfully.