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