1
2/* .text is used instead of .section .text so it works with arm-aout too.  */
3    .text
4    .code 32
5    .align  0
6
7    .global _mainCRTStartup
8    .global _start
9    .global start
10start:
11_start:
12_mainCRTStartup:
13
14/* Start by setting up a stack */
15    /*  Set up the stack pointer to a fixed value */
16    ldr r3, .LC0
17    mov     sp, r3
18    /* Setup a default stack-limit in case the code has been
19       compiled with "-mapcs-stack-check".  Hard-wiring this value
20       is not ideal, since there is currently no support for
21       checking that the heap and stack have not collided, or that
22       this default 64k is enough for the program being executed.
23       However, it ensures that this simple crt0 world will not
24       immediately cause an overflow event:  */
25    sub sl, sp, #64 << 10   /* Still assumes 256bytes below sl */
26    mov     a2, #0          /* Second arg: fill value */
27    mov fp, a2          /* Null frame pointer */
28    mov r7, a2          /* Null frame pointer for Thumb */
29
30    ldr a1, .LC1        /* First arg: start of memory block */
31    ldr a3, .LC2
32    sub a3, a3, a1      /* Third arg: length of block */
33
34
35
36        bl      memset
37    mov r0, #0      /*  no arguments  */
38    mov r1, #0      /*  no argv either */
39#ifdef __USES_INITFINI__
40    /* Some arm/elf targets use the .init and .fini sections
41       to create constructors and destructors, and for these
42       targets we need to call the _init function and arrange
43       for _fini to be called at program exit.  */
44    mov r4, r0
45    mov r5, r1
46/*        ldr     r0, .Lfini */
47        bl      atexit
48/*        bl      init */
49    mov r0, r4
50    mov r1, r5
51#endif
52        bl      main
53
54        bl      exit         /* Should not return.  */
55
56
57    /* For Thumb, constants must be after the code since only
58       positive offsets are supported for PC relative addresses.  */
59
60    .align 0
61.LC0:
62.LC1:
63    .word   __bss_start__
64.LC2:
65    .word   __bss_end__
66/*
67#ifdef __USES_INITFINI__
68.Lfini:
69    .word   _fini
70#endif  */
71    /* Return ...  */
72#ifdef __APCS_26__
73    movs    pc, lr
74#else
75#ifdef __THUMB_INTERWORK
76    bx  lr
77#else
78    mov pc, lr
79#endif
80#endif
81
82    .global  _fini
83    .type    _fini,function
84_fini:
85#ifdef __THUMB_INTERWORK
86    BX      lr                                  // Return to caller
87#else
88    MOV     pc, lr                              // Return to caller
89#endif
90
91/*  Workspace for Angel calls.  */
92    .data
93/*  Data returned by monitor SWI.  */
94.global __stack_base__
95HeapBase:   .word   0
96HeapLimit:  .word   0
97__stack_base__: .word   0
98StackLimit: .word   0
99