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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [libgloss/] [sparc/] [libsys/] [libsys-crt0.S] - Blame information for rev 1767

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

Line No. Rev Author Line
1 39 lampret
! 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 "syscallasm.h"
52
 
53
#ifndef TARGET_PTR_SIZE
54
#define TARGET_PTR_SIZE 32
55
#endif
56
 
57
        TEXT_SECTION
58
        ALIGN (4)
59
        GLOBAL (ASM_PRIVATE_SYMBOL (start))
60
ASM_PRIVATE_SYMBOL (start):
61
        clr     %fp
62
 
63
! We use %g4 even if the code model is Medium/Low (simplifies the code).
64
 
65
        clr     %g4                     ! Medium/Anywhere base reg
66
 
67
! If there is a stack bias in effect, account for it in %g5.  Then always
68
! add %g5 to stack references below.  This way the code can be used with
69
! or without an imposed bias.
70
 
71
        andcc   %sp, 1, %g5
72
        bnz,a   .LHaveBias
73
        mov     2047, %g5
74
.LHaveBias:
75
        add     %sp, %g5, %sp
76
 
77
#if TARGET_PTR_SIZE == 32
78
        ! FIXME: We apparently assume here that there is no reserved word.
79
        ! This is probably correct, but try to verify it.
80
        ld      [%sp + 0x80], %o0       ! argc
81
        add     %sp, 0x84, %o1          ! argv
82
        add     %o0, 1, %o2
83
        sll     %o2, 2, %o2
84
#else /* TARGET_PTR_SIZE == 64 */
85
        ld      [%sp + 0x8c], %o0       ! argc.lo
86
        add     %sp, 0x90, %o1          ! argv
87
        add     %o0, 1, %o2
88
        sll     %o2, 3, %o2
89
#endif
90
        add     %o1, %o2, %o2           ! envp
91
        sethi   %hi (ASM_SYMBOL (environ)), %o3
92
        or      %o3, %lo (ASM_SYMBOL (environ)), %o3
93
#if TARGET_PTR_SIZE == 32
94
        st      %o2, [%o3 + %g4]
95
#else /* TARGET_PTR_SIZE == 64 */
96
        stx     %o2, [%o3 + %g4]
97
#endif
98
 
99
! Restore any stack bias before we call main() ...
100
 
101
        sub     %sp, %g5, %sp
102
 
103
        GLOBAL (ASM_SYMBOL (main))
104
        call    ASM_SYMBOL (main)
105
 
106
! FIXME: Not sure if this is needed anymore.
107
#if TARGET_PTR_SIZE == 32
108
        sub     %sp, 0x20, %sp          ! room to push args
109
#else /* TARGET_PTR_SIZE == 64 */
110
        sub     %sp, 0x30, %sp          ! room to push args
111
#endif
112
 
113
        GLOBAL (ASM_SYMBOL (exit))
114
        call    ASM_SYMBOL (exit)
115
        nop
116
 
117
        GLOBAL (ASM_SYMBOL (_exit))
118
        call    ASM_SYMBOL (_exit)
119
        nop
120
 
121
        set     SYS_exit, %g1
122
        ta      SYSCALL_TRAP            ! in case user redefines __exit
123
 
124
! If all the above methods fail to terminate the program, try an illegal insn.
125
! If that does not work, the o/s is hosed more than we are.
126
 
127
        WORD (0)

powered by: WebSVN 2.1.0

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