📄 at91_cstartup.s79
字号:
cmp r0,#0
beq after__segment_init
mov lr,r7
bx r6
LTORG
CPU_MODE
after__segment_init:
REQUIRE ?jump_to_main
; Call the constructors of all global objects. This code will only
; be used if any EC++ modules defines global objects that need to
; have its constructor called before main.
#ifdef _ECPLUSPLUS
RSEG ICODE:CODE:NOROOT(2)
PUBLIC ?call_ctors
CPU_MODE
?call_ctors:
ldr r0,=SFB(DIFUNCT)
ldr r1,=SFE(DIFUNCT)
ldr r4,=__call_ctors
ldr r5,=after__call_ctors
mov lr,r5
bx r4
LTORG
CPU_MODE
after__call_ctors:
#endif /* _ECPLUSPLUS */
; Jump to main, using BX. Set _exit as the return address.
; main may be located anywhere in memory, and be of
; either ARM or Thumb mode, since BX is used.
; main is assumed to return using BX (__interwork) if it is of
; a different mode than cstartup, otherwise it will return
; in the wrong mode, causing unpredicatble behaviour.
RSEG ICODE:CODE:NOROOT(2)
PUBLIC __main
CPU_MODE
?jump_to_main:
LDR r1,=INT_Vectors ; Pickup address of our vectors
MOV r2,#0x4 ; Pickup address of vector table
ldmia r1!,{r4-r7}
stmia r2!,{r4-r7}
ldr r4,=main
ldr r5,=__main
mov r0,#0 ; No parameters
mov lr,r5
bx r4
CPU_MODE
__main:
?call_exit:
ldr r4,=exit
ldr r5,=_exit
mov lr,r5
bx r4
LTORG
INT_Vectors:
LDR pc,Undef_Inst_Addr ; Undefined Instruction
LDR pc,Software_Addr ; Software Generated
LDR pc,Abort_Prefetch_Addr ; Abort Prefetch
LDR pc,Abort_Data_Addr ; Abort Data
LDR pc,Reserved_Addr ; Reserved
Undef_Inst_Addr DCD INT_Undef_Inst
Software_Addr DCD INT_Software
Abort_Prefetch_Addr DCD INT_Abort_Prefetch
Abort_Data_Addr DCD INT_Abort_Data
Reserved_Addr DCD INT_Reserved
EXPORT INT_Undef_Inst
INT_Undef_Inst
B INT_Undef_Inst ; Undefined Instruction
;
EXPORT INT_Software
INT_Software
B INT_Software ; Software Generated
;
EXPORT INT_Abort_Prefetch
INT_Abort_Prefetch
B INT_Abort_Prefetch ; Abort Prefetch
;
EXPORT INT_Abort_Data
INT_Abort_Data
B INT_Abort_Data ; Abort Data
;
EXPORT INT_Reserved
INT_Reserved
B INT_Reserved ; Reserved
;
LTORG
ENDMOD
;---------------------------------------------------------------
; ?_EXIT
; main may return an exit code in R0, or _exit may be called with
; the exit code in R0.
; If the exit code is needed for som reason, R0 should be stored
; in e.g. one of the registers R4-R7, so that the value is
; preserved when calling __call_dtors and _Close_all.
;---------------------------------------------------------------
MODULE ?_EXIT
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
PUBLIC _exit
REQUIRE ?jump_to_exit
CPU_MODE
_exit:
; Fall through to the next module
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
REQUIRE ?exit_restore
PUBLIC ?exit_save
CPU_MODE
?exit_save:
mov r7,r0
;---------------------------------------------------------------
; ?CALL_DTORS
; This module is only linked if needed by atexit.
;---------------------------------------------------------------
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
PUBLIC __cstart_call_dtors
REQUIRE ?exit_save
CPU_MODE
; This label is required by "__record_needed_destruction".
__cstart_call_dtors:
ldr r4,?constants ; =__call_dtors
ldr r5,?constants+4 ; =after__call_dtors
mov lr,r5
bx r4
after__call_dtors:
; Fall through to the next segment part
;---------------------------------------------------------------
; ?CALL_CLOSE
; This segment part is only linked if needed for closing files.
;---------------------------------------------------------------
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
PUBLIC __cstart_closeall
EXTERN _Close_all
REQUIRE ?exit_save
CPU_MODE
; This label is required by functions operating on files
__cstart_closeall:
ldr r4,?constants+8 ; =_Close_all
ldr r5,?constants+12 ; =after_Close_all
mov lr,r5
bx r4
after_Close_all:
; Fall through to the next segment part
;---------------------------------------------------------------
; ?_EXIT_END
; Restore the argument previously stored by the "save" section
; above.
;---------------------------------------------------------------
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
PUBLIC ?exit_restore
CPU_MODE
?exit_restore:
mov r0,r7
;; Fall through to the __exit code below
;---------------------------------------------------------------
; ?JUMP_TO_EXIT
;---------------------------------------------------------------
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
PUBLIC ?jump_to_exit
EXTERN __exit
; It is not possible to fall through to __exit, because the following
; module is only used when linking for debugging (XLINK -r).
?jump_to_exit:
ldr r4,?constants+16 ; =__exit
mov lr,r4
bx r4
RSEG LIB_SEGMENT:CODE:NOROOT(SEGMENT_ALIGN)
EXTERN __call_dtors
EXTERN _Close_all
EXTERN __exit
DATA
?constants:
DC32 __call_dtors
DC32 after__call_dtors
DC32 _Close_all
DC32 after_Close_all
DC32 __exit
ENDMOD
;---------------------------------------------------------------
; ?__EXIT
; __exit is declared PUBWEAK, which makes XLINK skip this module
; if another module containing a PUBLIC __exit is linked.
;---------------------------------------------------------------
MODULE ?__EXIT
RSEG LIB_SEGMENT:CODE:NOROOT(2)
PUBWEAK __exit
CPU_MODE ; Either Thumb or ARM mode
__exit
#ifdef __THUMB_LIBRARY__
bx pc
nop
#endif
CODE32
b . ; Eternal loop
ENDMOD
;---------------------------------------------------------------
; ?INITTAB
; This module is only linked if needed by e.g. __segment_init.
; The INITTAB segment contains segment initialization entries.
; See segment_init.h.
;---------------------------------------------------------------
MODULE ?INITTAB
RSEG INITTAB:CONST(2) ; Declaration for SFB/SFE below
RSEG HUGE_C:CONST:NOROOT(2)
DATA
PUBLIC __segment_begin_INITTAB
PUBLIC __segment_end_INITTAB
__segment_begin_INITTAB DC32 SFB(INITTAB)
__segment_end_INITTAB DC32 SFE(INITTAB)
ENDMOD
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -