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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [sparc64/] [crt0.S] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
! C run time start off
2
 
3
! This file supports:
4
!
5
! - both 32bit pointer and 64bit pointer environments (at compile time)
6
! - an imposed stack bias (of 2047) (at run time)
7
! - medium/low and medium/anywhere code models (at run time)
8
 
9
! Initial stack setup:
10
!
11
!    bottom of stack (higher memory address)
12
!       ...
13
!       text of environment strings
14
!       text of argument strings
15
!       envp[envc] = 0 (4/8 bytes)
16
!       ...
17
!       env[0] (4/8 bytes)
18
!       argv[argc] = 0 (4/8 bytes)
19
!       ...
20
!       argv[0] (4/8 bytes)
21
!       argc (4/8 bytes)
22
!       register save area (64 bits by 16 registers = 128 bytes)
23
!       top of stack (%sp)
24
 
25
! Stack Bias:
26
!
27
! It is the responsibility of the o/s to set this up.
28
! We handle both a 0 and 2047 value for the stack bias.
29
 
30
! Medium/Anywhere code model support:
31
!
32
! In this model %g4 points to the start of the data segment.
33
! The text segment can go anywhere, but %g4 points to the *data* segment.
34
! It is up to the compiler/linker to get this right.
35
!
36
! Since this model is statically linked the start of the data segment
37
! is known at link time.  Eg:
38
!
39
!       sethi   %hh(data_start), %g1
40
!       sethi   %lm(data_start), %g4
41
!       or      %g1, %hm(data_start), %g1
42
!       or      %g4, %lo(data_start), %g4
43
!       sllx    %g1, 32, %g1
44
!       or      %g4, %g1, %g4
45
!
46
! FIXME: For now we just assume 0.
47
 
48
! FIXME: if %g1 contains a non-zero value, atexit() should be invoked
49
! with this value.
50
 
51
#include 
52
 
53
        TEXT_SECTION
54
        ALIGN (4)
55
        GLOBAL (ASM_PRIVATE_SYMBOL (start))
56
ASM_PRIVATE_SYMBOL (start):
57
        clr     %fp
58
 
59
! We use %g4 even if the code model is Medium/Low (simplifies the code).
60
 
61
        clr     %g4                     ! Medium/Anywhere base reg
62
 
63
! If there is a stack bias in effect, account for it in %g5.  Then always
64
! add %g5 to stack references below.  This way the code can be used with
65
! or without an imposed bias.
66
 
67
        andcc   %sp, 1, %g5
68
        bnz,a   .LHaveBias
69
        mov     2047, %g5
70
.LHaveBias:
71
        add     %sp, %g5, %sp
72
 
73
#if TARGET_PTR_SIZE == 32
74
        ! FIXME: We apparently assume here that there is no reserved word.
75
        ! This is probably correct, but try to verify it.
76
        ld      [%sp + 0x80], %o0       ! argc
77
        add     %sp, 0x84, %o1          ! argv
78
        add     %o0, 1, %o2
79
        sll     %o2, 2, %o2
80
#else /* TARGET_PTR_SIZE == 64 */
81
        ld      [%sp + 0x8c], %o0       ! argc.lo
82
        add     %sp, 0x90, %o1          ! argv
83
        add     %o0, 1, %o2
84
        sll     %o2, 3, %o2
85
#endif
86
        add     %o1, %o2, %o2           ! envp
87
        sethi   %hi (ASM_SYMBOL (environ)), %o3
88
        or      %o3, %lo (ASM_SYMBOL (environ)), %o3
89
#if TARGET_PTR_SIZE == 32
90
        st      %o2, [%o3 + %g4]
91
#else /* TARGET_PTR_SIZE == 64 */
92
        stx     %o2, [%o3 + %g4]
93
#endif
94
 
95
! Restore any stack bias before we call main() ...
96
 
97
        sub     %sp, %g5, %sp
98
 
99
        GLOBAL (ASM_SYMBOL (main))
100
        call    ASM_SYMBOL (main)
101
 
102
! FIXME: Not sure if this is needed anymore.
103
#if TARGET_PTR_SIZE == 32
104
        sub     %sp, 0x20, %sp          ! room to push args
105
#else /* TARGET_PTR_SIZE == 64 */
106
        sub     %sp, 0x30, %sp          ! room to push args
107
#endif
108
 
109
        GLOBAL (ASM_SYMBOL (exit))
110
        call    ASM_SYMBOL (exit)
111
        nop
112
 
113
        GLOBAL (ASM_SYMBOL (_exit))
114
        call    ASM_SYMBOL (_exit)
115
        nop
116
 
117
        set     SYS_exit, %g1
118
        ta      SYSCALL_TRAP            ! in case user redefines __exit
119
 
120
! If all the above methods fail to terminate the program, try an illegal insn.
121
! If that does not work, the o/s is hosed more than we are.
122
 
123
        WORD (0)

powered by: WebSVN 2.1.0

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