summaryrefslogtreecommitdiff
path: root/ports_module/cortex_a7/gnu/example_build/crt0.S
blob: 6150a1671fd78ea7f29564295d6b8792d006063e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

    .syntax unified
#if defined(THUMB_MODE)
    .thumb
#else
    .arm
#endif

/* .text is used instead of .section .text so it works with arm-aout too.  */
    .text
    .align  0

#if defined(THUMB_MODE)
    .thumb_func
#endif
    .global _mainCRTStartup
_mainCRTStartup:
#if defined(THUMB_MODE)
    .thumb_func
#endif
    .global _start
_start:
#if defined(THUMB_MODE)
    .thumb_func
#endif
    .global start
start:

/* Start by setting up a stack */
    /*  Set up the stack pointer to a fixed value */
    ldr r3, .LC0
    mov     sp, r3
    /* Setup a default stack-limit in case the code has been
       compiled with "-mapcs-stack-check".  Hard-wiring this value
       is not ideal, since there is currently no support for
       checking that the heap and stack have not collided, or that
       this default 64k is enough for the program being executed.
       However, it ensures that this simple crt0 world will not
       immediately cause an overflow event:  */
    sub sl, sp, #64 << 10   /* Still assumes 256bytes below sl */
    mov     a2, #0          /* Second arg: fill value */
    mov fp, a2          /* Null frame pointer */
    mov r7, a2          /* Null frame pointer for Thumb */

    ldr a1, .LC1        /* First arg: start of memory block */
    ldr a3, .LC2
    sub a3, a3, a1      /* Third arg: length of block */



        bl      memset
    mov r0, #0      /*  no arguments  */
    mov r1, #0      /*  no argv either */
#ifdef __USES_INITFINI__
    /* Some arm/elf targets use the .init and .fini sections
       to create constructors and destructors, and for these
       targets we need to call the _init function and arrange
       for _fini to be called at program exit.  */
    mov r4, r0
    mov r5, r1
/*        ldr     r0, .Lfini */
        bl      atexit
/*        bl      init */
    mov r0, r4
    mov r1, r5
#endif
        bl      main

        bl      exit         /* Should not return.  */


    /* For Thumb, constants must be after the code since only
       positive offsets are supported for PC relative addresses.  */

    .align 0
.LC0:
.LC1:
    .word   __bss_start__
.LC2:
    .word   __bss_end__
/*
#ifdef __USES_INITFINI__
.Lfini:
    .word   _fini
#endif  */

    /* Return ...  */
    bx  lr

/*  Workspace for Angel calls.  */
    .data
/*  Data returned by monitor SWI.  */
.global __stack_base__
HeapBase:   .word   0
HeapLimit:  .word   0
__stack_base__: .word   0
StackLimit: .word   0