crt0.s

"crt" stands for"C runtime" (the zero stands for "the very beginning").

More formally,crt0 is an object file called crt0.o, which is generally written inassembly language, and then linked by the linker to the object filecomplied from the source code(C/C++).

crt0 is a set ofexecution startup routines compiled into a program which performany initialization work required before calling the program's mainfunction – it is a basic runtime library/run-time system. The workperformed by crt0 depends on the program's language, compiler,operating system and C standard library implementation.

 crt0.s_第1张图片
【参考】C:\WindRiver\diab\5.9.1.0\src\crt68

=========================================================================

// src/crt68/crt0.s: startup for anembedded environment: 68xxx

//------------------------------------------------------------

//

// Written by Tomas Evensen1993-04-17.

// Copyright 1993-1998 Diab Data,Inc.

 

.file "crt0.s"

PSECT

XDEF start

ALIGN 4 nop | Debuggers may object tostarting at 0.

 

start:

//

// Insert/modify code here to initialize(if necessary):

// - sp (stack pointer)

// - a5 (data pointer)

// - the cache

// - exception vectors

// - fpu control registers

//

move.l #___SP_INIT,a7 | Initialize stackpointer a7 to value in | linker command file.

move.l #__SDA_BASE_,a5 | Initialize a5 tosdata (provided by linker).

// Initialize cache.

// MC68EC040

// cinva bc | Invalidate cache.

// move.l #0xe020,d0 | Make first 16 MBcopy-back (MC68EC040).

// movc d0,dacr0

// move.l #0x80008000,d0 | Enable data andinstruction caches.

// movc d0,cacr

 

jsr ___init_main | Finish initialization#call main().

move.l d0,-(a7) | Pass exit() value ifreturned by main().

jsr _exit | Never returns.

jsr _main | Dummy to pull in main() assoon as possible.

 

------------------------------------------------------------
MEMORY
{
       ram:    org =0x8000, len = 0x100000
}

SECTIONS
{
       GROUP : {
               .text (TEXT)   : {
                       *(.text)
                       *(.rdata)
                       *(.rodata)
                       *(.frame_info)
                       *(.j_class_table)
                       *(.init)
                       *(.fini)
               }
               .sdata2 (TEXT)  :{}  
       } > ram

       GROUP : {
               __DATA_ROM     = .;
               __DATA_RAM     = .;
               .data (DATA)   : {}
               .j_pdata (DATA) : {}
              
               .ctors ALIGN(4) : { ctordtor.o(.ctors) *(.ctors) }
               .dtors ALIGN(4) : { ctordtor.o(.dtors) *(.dtors) }

               .sdata (DATA)   : { *(.sdata)*(.j_spdata) }
               __DATA_END     = .;

               __BSS_START    = .;
               .sbss(BSS)    : {}
               .bss (BSS)    : {}
               __BSS_END      = .;
             

你可能感兴趣的:(crt0.s)