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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [libgloss/] [mips/] [crt0.S] - Blame information for rev 1774

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

Line No. Rev Author Line
1 39 lampret
/*
2
 * crt0.S -- startup file for MIPS.
3
 *
4
 * Copyright (c) 1995, 1996, 1997 Cygnus Support
5
 *
6
 * The authors hereby grant permission to use, copy, modify, distribute,
7
 * and license this software and its documentation for any purpose, provided
8
 * that existing copyright notices are retained in all copies and that this
9
 * notice is included verbatim in any distributions. No written agreement,
10
 * license, or royalty fee is required for any of the authorized uses.
11
 * Modifications to this software may be copyrighted by their authors
12
 * and need not follow the licensing terms described here, provided that
13
 * the new terms are clearly indicated on the first page of each file where
14
 * they apply.
15
 */
16
 
17
#ifdef __mips16
18
/* This file contains 32 bit assembly code.  */
19
        .set nomips16
20
#endif
21
 
22
#include "regs.S"
23
 
24
/*
25
 * Set up some room for a stack. We just grab a chunk of memory.
26
 */
27
#define STACK_SIZE  0x4000
28
#define GLOBAL_SIZE 0x2000
29
 
30
#define STARTUP_STACK_SIZE      0x0100
31
 
32 56 joel
/* This is for referencing addresses that are not in the .sdata or
33
   .sbss section under embedded-pic, or before we've set up gp.  */
34
#ifdef __mips_embedded_pic
35
# ifdef __mips64
36
#  define LA(t,x) la t,x-PICBASE ; daddu t,s0,t
37
# else
38
#  define LA(t,x) la t,x-PICBASE ; addu t,s0,t
39
# endif
40
#else /* __mips_embedded_pic */
41
# define LA(t,x) la t,x
42
#endif /* __mips_embedded_pic */
43
 
44 39 lampret
        .comm   __memsize, 12
45
        .comm   __lstack, STARTUP_STACK_SIZE
46
        .comm   __stackbase,4
47
 
48
        .text
49
        .align  2
50
 
51
/* Without the following nop, GDB thinks _start is a data variable.
52
 * This is probably a bug in GDB in handling a symbol that is at the
53
 * start of the .text section.
54
 */
55
        nop
56
 
57
        .globl  _start
58
        .ent    _start
59
_start:
60
        .set    noreorder
61 56 joel
#ifdef __mips_embedded_pic
62
        PICBASE = .+8
63
        bal     PICBASE
64
        nop
65
        move    s0,$31
66
#endif
67
 
68 39 lampret
        li      v0, SR_CU1|SR_PE|SR_FR|SR_KX|SR_SX|SR_UX
69
        mtc0    v0, C0_SR
70
        mtc0    zero, C0_CAUSE
71
 
72
/* Check for FPU presence */
73
#ifndef __mips_soft_float
74
/* This doesn't work if there is no FPU.  We get illegal instruction
75
   exceptions.  */
76
        li      t2,0xAAAA5555
77
        mtc1    t2,fp0          /* write to FPR 0 */
78
        mtc1    zero,fp1        /* write to FPR 1 */
79
        mfc1    t0,fp0
80
        mfc1    t1,fp1
81
        nop
82
        bne     t0,t2,1f        /* check for match */
83
        nop
84
        bne     t1,zero,1f      /* double check */
85
        nop
86 56 joel
#ifndef __mips64  /* Clear the FR bit */
87
        li      v0, SR_CU1|SR_PE|SR_KX|SR_SX|SR_UX
88
        mtc0    v0, C0_SR
89
#endif
90
        j       2f
91 39 lampret
        nop
92
#endif
93
1:
94
        li      v0, SR_PE|SR_FR|SR_KX|SR_SX|SR_UX
95
        mtc0    v0, C0_SR
96
2:
97 56 joel
/* Fix high bits, if any, of the PC so that exception handling
98
   doesn't get confused.  */
99
        LA (v0, 3f)
100
        jr      v0
101
        nop
102
3:
103
        LA (gp, _gp)                            # set the global data pointer
104 39 lampret
        .end _start
105
 
106
/*
107
 * zero out the bss section.
108
 */
109
        .globl  __memsize
110
        .globl  get_mem_info .text
111
        .globl  __stack
112
        .globl  __global
113
        .globl  zerobss
114
        .ent    zerobss
115
zerobss:
116 56 joel
        LA (v0, _fbss)
117
        LA (v1, _end)
118 39 lampret
3:
119
        sw      zero,0(v0)
120
        bltu    v0,v1,3b
121
        addiu   v0,v0,4                         # executed in delay slot
122
 
123
        la      t0, __lstack                    # make a small stack so we
124
        addiu   sp, t0, STARTUP_STACK_SIZE      # can run some C code
125
        la      a0, __memsize                   # get the usable memory size
126
        jal     get_mem_info
127
        nop
128
 
129
        /* setup the stack pointer */
130 56 joel
        LA (t0, __stack)                        # is __stack set ?
131 39 lampret
        bne     t0,zero,4f
132
        nop
133
 
134
        /* NOTE: a0[0] contains the amount of memory available, and
135
                 not the last memory address. */
136
        lw      t0,0(a0)                        # last address of memory available
137
        la      t1,K0BASE                       # cached kernel memory
138
        addu    t0,t0,t1                        # get the end of memory address
139
        /* We must subtract 24 bytes for the 3 8 byte arguments to main, in
140
           case main wants to write them back to the stack.  The caller is
141
           supposed to allocate stack space for parameters in registers in
142
           the old MIPS ABIs.  We must do this even though we aren't passing
143
           arguments, because main might be declared to have them.
144
 
145
           Some ports need a larger alignment for the stack, so we subtract
146
           32, which satisifes the stack for the arguments and keeps the
147
           stack pointer better aligned.  */
148
        subu    t0,t0,32                        # and generate a starting stack-pointer
149
4:
150
        move    sp,t0                           # set stack pointer
151
        sw      sp,__stackbase                  # keep this for future ref
152
        .end    zerobss
153
 
154
/*
155
 * initialize target specific stuff. Only execute these
156
 * functions it they exist.
157
 */
158
        .globl  hardware_init_hook .text
159
        .globl  software_init_hook .text
160
        .globl  __do_global_dtors .text
161
        .globl  atexit .text
162
        .globl  exit .text
163
        .globl  init
164
        .ent    init
165
init:
166 56 joel
        LA (t9, hardware_init_hook)             # init the hardware if needed
167 39 lampret
        beq     t9,zero,6f
168
        nop
169
        jal     t9
170
        nop
171
6:
172 56 joel
        LA (t9, software_init_hook)             # init the hardware if needed
173 39 lampret
        beq     t9,zero,7f
174
        nop
175
        jal     t9
176
        nop
177
7:
178 56 joel
        LA (a0, __do_global_dtors)
179 39 lampret
        jal     atexit
180
        nop
181
 
182
#ifdef GCRT0
183
        .globl  _ftext
184
        .globl  _extext
185 56 joel
        LA (a0, _ftext)
186
        LA (a1, _etext)
187 39 lampret
        jal     monstartup
188
        nop
189
#endif
190
 
191 56 joel
        move    a0,zero                         # set argc to 0
192 39 lampret
        jal     main                            # call the program start function
193
        nop
194
 
195
        # fall through to the "exit" routine
196
        jal     exit                            # call libc exit to run the G++
197
                                                # destructors
198
        move    a0,v0                           # pass through the exit code
199
        .end    init
200
 
201
/*
202
 * _exit -- Exit from the application. Normally we cause a user trap
203
 *          to return to the ROM monitor for another run. NOTE: This is
204
 *          the only other routine we provide in the crt0.o object, since
205
 *          it may be tied to the "_start" routine. It also allows
206
 *          executables that contain a complete world to be linked with
207
 *          just the crt0.o object.
208
 */
209
        .globl  _exit
210
        .ent _exit
211
_exit:
212
7:
213
#ifdef GCRT0
214
        jal     _mcleanup
215
        nop
216
#endif
217
        # break instruction can cope with 0xfffff, but GAS limits the range:
218
        break   1023
219
        nop
220
        b       7b                              # but loop back just in-case
221
        nop
222
        .end _exit
223
 
224
/* EOF crt0.S */

powered by: WebSVN 2.1.0

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