source: rtems/c/src/lib/libbsp/mips/jmr3904/start/start.S @ c8471315

4.104.114.84.95
Last change on this file since c8471315 was c8471315, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 25, 2000 at 6:58:05 PM

2000-11-25 Joel Sherrill <joel@…>

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