source: rtems/c/src/lib/libbsp/mips/genmongoosev/start/start.S @ ef380d3f

4.104.114.84.9
Last change on this file since ef380d3f was ef380d3f, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 14, 2001 at 5:24:09 PM

2001-03-14 Joel Sherrill <joel@…>

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