OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [arm/] [crt0.S] - Blame information for rev 1325

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* When we enter this piece of code, the program stack looks like this:
2
        argc            argument counter (integer)
3
        argv[0]         program name (pointer)
4
        argv[1...N]     program args (pointers)
5
        argv[argc-1]    end of args (integer)
6
        NULL
7
        env[0...N]      environment variables (pointers)
8
        NULL
9
 
10
   For uClinux it looks like this:
11
 
12
        argc            argument counter (integer)
13
        argv            char *argv[]
14
        envp            char *envp[]
15
        argv[0]         program name (pointer)
16
        argv[1...N]     program args (pointers)
17
        argv[argc-1]    end of args (integer)
18
        NULL
19
        env[0...N]      environment variables (pointers)
20
        NULL
21
 
22
   When we are done here, we want
23
        a1=argc
24
        a2=argv[0]
25
        a3=argv[argc+1]
26
 
27
ARM register quick reference:
28
 
29
    Name    Number       ARM Procedure Calling Standard Role
30
 
31
    a1      r0           argument 1 / integer result / scratch register / argc
32
    a2      r1           argument 2 / scratch register / argv
33
    a3      r2           argument 3 / scratch register / envp
34
    a4      r3           argument 4 / scratch register
35
    v1      r4           register variable
36
    v2      r5           register variable
37
    v3      r6           register variable
38
    v4      r7           register variable
39
    v5      r8           register variable
40
    sb/v6   r9           static base / register variable
41
    sl/v7   r10          stack limit / stack chunk handle / reg. variable
42
    fp      r11          frame pointer
43
    ip      r12          scratch register / new-sb in inter-link-unit calls
44
    sp      r13          lower end of current stack frame
45
    lr      r14          link address / scratch register
46
    pc      r15          program counter
47
*/
48
 
49
#include 
50
 
51
.text
52
        .global _start
53
        .type   _start,%function
54
#if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__
55
        .type   __uClibc_main,%function
56
#else
57
        .weak   _init
58
        .weak   _fini
59
        .type   __uClibc_start_main,%function
60
#endif
61
/* Stick in a dummy reference to main(), so that if an application
62
 * is linking when the main() function is in a static library (.a)
63
 * we can be sure that main() actually gets linked in */
64
        .type   main,%function
65
 
66
 
67
.text
68
_start:
69
        /* clear the frame pointer */
70
        mov     fp, #0
71
 
72
#ifdef __UCLIBC_HAS_MMU__
73
        /* Load register r0 (argc) from the stack to its final resting place */
74
        ldr     r0, [sp], #4
75
 
76
        /* Copy argv pointer into r1 -- which its final resting place */
77
        mov     r1, sp
78
 
79
        /* Skip to the end of argv and put a pointer to whatever
80
           we find there (hopefully the environment) in r2 */
81
        add     r2, r1, r0, lsl #2
82
        add     r2, r2, #4
83
 
84
#else
85
        /*
86
         * uClinux stacks look a little different from normal
87
         * MMU-full Linux stacks (for no good reason)
88
         */
89
        /* pull argc, argv and envp off the stack */
90
        ldr r0,[sp, #0]
91
        ldr r1,[sp, #4]
92
        ldr r2,[sp, #8]
93
#endif
94
 
95
#if (defined L_crt1 || defined L_gcrt1 ) && defined __UCLIBC_CTOR_DTOR__
96
        /* Store the address of _init in r3 as an argument to main() */
97
        ldr r3, =_init
98
 
99
        /* Push _fini onto the stack as the final argument to main() */
100
        ldr r4, =_fini
101
        stmfd sp!, {r4}
102
 
103
        /* Ok, now run uClibc's main() -- shouldn't return */
104
        bl      __uClibc_start_main
105
#else
106
        bl      __uClibc_main
107
#endif
108
 
109
        /* Crash if somehow `exit' returns anyways.  */
110
        bl abort
111
 
112
/* We need this stuff to make gdb behave itself, otherwise
113
   gdb will chokes with SIGILL when trying to debug apps.
114
*/
115
        .section ".note.ABI-tag", "a"
116
        .align 4
117
        .long 1f - 0f
118
        .long 3f - 2f
119
        .long  1
120
0:      .asciz "GNU"
121
1:      .align 4
122
2:      .long 0
123
        .long 2,0,0
124
3:      .align 4
125
 
126
#if defined L_gcrt1 && defined __UCLIBC_PROFILING__
127
# include "./gmon-start.S"
128
#endif
129
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.