1 | /* |
---|
2 | |
---|
3 | Based upon IDT provided code with the following release: |
---|
4 | |
---|
5 | This source code has been made available to you by IDT on an AS-IS |
---|
6 | basis. Anyone receiving this source is licensed under IDT copyrights |
---|
7 | to use it in any way he or she deems fit, including copying it, |
---|
8 | modifying it, compiling it, and redistributing it either with or |
---|
9 | without modifications. No license under IDT patents or patent |
---|
10 | applications is to be implied by the copyright license. |
---|
11 | |
---|
12 | Any user of this software should understand that IDT cannot provide |
---|
13 | technical support for this software and will not be responsible for |
---|
14 | any consequences resulting from the use of this software. |
---|
15 | |
---|
16 | Any person who transfers this source code or any derivative work must |
---|
17 | include the IDT copyright notice, this paragraph, and the preceeding |
---|
18 | two paragraphs in the transferred software. |
---|
19 | |
---|
20 | COPYRIGHT IDT CORPORATION 1996 |
---|
21 | LICENSED MATERIAL - PROGRAM PROPERTY OF IDT |
---|
22 | */ |
---|
23 | |
---|
24 | /************************************************************************* |
---|
25 | ** |
---|
26 | ** Copyright 1991-95 Integrated Device Technology, Inc. |
---|
27 | ** All Rights Reserved |
---|
28 | ** |
---|
29 | **************************************************************************/ |
---|
30 | |
---|
31 | /* |
---|
32 | * $Id$ |
---|
33 | */ |
---|
34 | |
---|
35 | #include <rtems/mips/iregdef.h> |
---|
36 | #include <rtems/mips/idtcpu.h> |
---|
37 | #include <rtems/asm.h> |
---|
38 | |
---|
39 | |
---|
40 | #if 0 |
---|
41 | .extern _fdata,4 /* this is defined by the linker */ |
---|
42 | .extern _edata,4 /* this is defined by the linker */ |
---|
43 | .extern _idata,4 /* this is defined by the linker */ |
---|
44 | #endif |
---|
45 | .extern _fbss,4 /* this is defined by the linker */ |
---|
46 | .extern end,4 /* this is defined by the linker */ |
---|
47 | |
---|
48 | .lcomm sim_mem_cfg_struct,12 |
---|
49 | |
---|
50 | .text |
---|
51 | |
---|
52 | /* For the V3 Eval board, we can safely assume that we have |
---|
53 | at least 16 megabytes of RAM */ |
---|
54 | #define HARD_CODED_MEM_SIZE 0x1000000 |
---|
55 | |
---|
56 | #define TMP_STKSIZE 1024 |
---|
57 | |
---|
58 | /* |
---|
59 | ** P_STACKSIZE is the size of the Prom Stack. |
---|
60 | ** the prom stack grows downward |
---|
61 | */ |
---|
62 | #define P_STACKSIZE 0x2000 /* sets stack size to 8k */ |
---|
63 | |
---|
64 | /************************************************************************** |
---|
65 | ** |
---|
66 | ** start - Typical standalone start up code required for R3000/R4000 |
---|
67 | ** |
---|
68 | ** |
---|
69 | ** 1) Initialize the STATUS Register |
---|
70 | ** a) Clear parity error bit |
---|
71 | ** b) Set co_processor 1 usable bit ON |
---|
72 | ** c) Clear all IntMask Enables |
---|
73 | ** d) Set kernel/disabled mode |
---|
74 | ** 2) Initialize Cause Register |
---|
75 | ** a) clear software interrupt bits |
---|
76 | ** 3) Determine FPU installed or not |
---|
77 | ** if not, clear CoProcessor 1 usable bit |
---|
78 | ** 4) Clear bss area |
---|
79 | ** 5) MUST allocate temporary stack until memory size determined |
---|
80 | ** It MUST be uncached to prevent overwriting when caches are cleared |
---|
81 | ** 6) Install exception handlers |
---|
82 | ** 7) Determine memory and cache sizes |
---|
83 | ** 8) Establish permanent stack (cached or uncached as defined by bss) |
---|
84 | ** 9) Flush Instruction and Data caches |
---|
85 | ** 10) If there is a Translation Lookaside Buffer, Clear the TLB |
---|
86 | ** 11) Execute initialization code if the IDT/c library is to be used |
---|
87 | ** |
---|
88 | ** 12) Jump to user's "main()" (boot_card() for RTEMS) |
---|
89 | ** 13) Jump to promexit |
---|
90 | ** |
---|
91 | ** IDT/C 5.x defines _R3000, IDT/C 6.x defines _R4000 internally. |
---|
92 | ** This is used to mark code specific to R3xxx or R4xxx processors. |
---|
93 | ** IDT/C 6.x defines __mips to be the ISA level for which we're |
---|
94 | ** generating code. This is used to make sure the stack etc. is |
---|
95 | ** double word aligned, when using -mips3 (default) or -mips2, |
---|
96 | ** when compiling with IDT/C6.x |
---|
97 | ** |
---|
98 | ***************************************************************************/ |
---|
99 | |
---|
100 | FRAME(start,sp,0,ra) |
---|
101 | |
---|
102 | .set noreorder |
---|
103 | #if __mips_fpr == 64 |
---|
104 | li v0,SR_CU1|SR_FR|SR_DE /* initally clear ERL, enable FPU with 64 bit regs, disable cache errors */ |
---|
105 | #else |
---|
106 | li v0,SR_CU1|SR_DE /* initally clear ERL, enable FPU with 32 bit regs, disable cache errors */ |
---|
107 | #endif |
---|
108 | |
---|
109 | mtc0 v0,C0_SR /* clr IntMsks/ kernel/disabled mode */ |
---|
110 | nop |
---|
111 | mtc0 zero,C0_CAUSE /* clear software interrupts */ |
---|
112 | nop |
---|
113 | |
---|
114 | la t0,0xBE200000 /* on Hurricane board, enable interrupt output signal from UART ch. B */ |
---|
115 | li t1,0x8 /* UART INT B signal is left tri-state'd after reset, this results in processor interrupt signal being driven active low */ |
---|
116 | sw t1,0x10(t0) |
---|
117 | |
---|
118 | li v0,CFG_C_NONCOHERENT # initialise default cache mode |
---|
119 | mtc0 v0,C0_CONFIG |
---|
120 | |
---|
121 | /* |
---|
122 | ** check to see if an fpu is really plugged in |
---|
123 | */ |
---|
124 | li t3,0xaaaa5555 /* put a's and 5's in t3 */ |
---|
125 | mtc1 t3,fp0 /* try to write them into fp0 */ |
---|
126 | mtc1 zero,fp1 /* try to write zero in fp */ |
---|
127 | mfc1 t0,fp0 |
---|
128 | mfc1 t1,fp1 |
---|
129 | nop |
---|
130 | bne t0,t3,1f /* branch if no match */ |
---|
131 | nop |
---|
132 | bne t1,zero,1f /* double check for positive id */ |
---|
133 | nop |
---|
134 | /* We have a FPU. clear fcsr */ |
---|
135 | ctc1 zero, fcr31 |
---|
136 | j 2f /* status register already correct */ |
---|
137 | nop |
---|
138 | 1: |
---|
139 | li v0,SR_DE /* clear ERL and disable FPA */ |
---|
140 | |
---|
141 | mtc0 v0, C0_SR /* reset status register */ |
---|
142 | 2: |
---|
143 | la gp, _gp |
---|
144 | |
---|
145 | #if 0 |
---|
146 | /* Initialize data sections from "rom" copy */ |
---|
147 | la t0,_idata /* address of initialization data (copy of data sections placed in ROM) */ |
---|
148 | la t1,_fdata /* start of initialized data section */ |
---|
149 | la t2,_edata /* end of initialized data section */ |
---|
150 | 3: |
---|
151 | lw t3,0(t0) |
---|
152 | sw t3,0(t1) |
---|
153 | addiu t1,t1,4 |
---|
154 | bne t1,t2,3b |
---|
155 | addiu t0,t0,4 |
---|
156 | #endif |
---|
157 | |
---|
158 | /* clear bss before using it */ |
---|
159 | la v0,_fbss /* start of bss */ |
---|
160 | la v1,end /* end of bss */ |
---|
161 | 4: sw zero,0(v0) |
---|
162 | bltu v0,v1,4b |
---|
163 | add v0,4 |
---|
164 | |
---|
165 | |
---|
166 | /************************************************************************ |
---|
167 | ** |
---|
168 | ** Temporary Stack - needed to handle stack saves until |
---|
169 | ** memory size is determined and permanent stack set |
---|
170 | ** |
---|
171 | ** MUST be uncached to avoid confusion at cache |
---|
172 | ** switching during memory sizing |
---|
173 | ** |
---|
174 | *************************************************************************/ |
---|
175 | /* For MIPS 3, we need to be sure that the stack is aligned on a |
---|
176 | * double word boundary. |
---|
177 | */ |
---|
178 | andi t0, v0, 0x7 |
---|
179 | beqz t0, 11f /* Last three bits Zero, already aligned */ |
---|
180 | nop |
---|
181 | add v0, 4 |
---|
182 | 11: |
---|
183 | |
---|
184 | or v0, K1BASE /* switch to uncached */ |
---|
185 | add v1, v0, TMP_STKSIZE /* end of bss + length of tmp stack */ |
---|
186 | sub v1, v1, (4*4) /* overhead */ |
---|
187 | move sp, v1 /* set sp to top of stack */ |
---|
188 | 4: sw zero, 0(v0) |
---|
189 | bltu v0, v1, 4b /* clear out temp stack */ |
---|
190 | add v0, 4 |
---|
191 | |
---|
192 | /* jal init_exc_vecs */ /* install exception handlers */ |
---|
193 | /* nop */ /* MUST do before memory probes */ |
---|
194 | |
---|
195 | /* Force processor into uncached space during memory/cache probes */ |
---|
196 | la v0, 5f |
---|
197 | li v1, K1BASE |
---|
198 | or v0, v1 |
---|
199 | j v0 |
---|
200 | nop |
---|
201 | 5: |
---|
202 | |
---|
203 | li a0, HARD_CODED_MEM_SIZE /* Set memory size global */ |
---|
204 | jal set_memory_size |
---|
205 | nop |
---|
206 | |
---|
207 | la a0, sim_mem_cfg_struct |
---|
208 | jal get_mem_conf /* Make call to get mem size */ |
---|
209 | nop |
---|
210 | la a0, sim_mem_cfg_struct |
---|
211 | lw a0, 0(a0) /* Get memory size from struct */ |
---|
212 | |
---|
213 | jal config_cache /* determine size of D & I caches */ |
---|
214 | nop |
---|
215 | |
---|
216 | move v0, a0 /* mem_size */ |
---|
217 | |
---|
218 | /* For MIPS 3, we need to be sure that the stack (and hence v0 |
---|
219 | * here) is aligned on a double word boundary. |
---|
220 | */ |
---|
221 | andi t0, v0, 0x7 |
---|
222 | beqz t0, 12f /* Last three bits Zero, already aligned */ |
---|
223 | nop |
---|
224 | subu v0, 4 /* mem_size was not aligned on doubleword bdry????*/ |
---|
225 | 12: |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | /************************************************************************** |
---|
230 | ** |
---|
231 | ** Permanent Stack - now know top of memory, put permanent stack there |
---|
232 | ** |
---|
233 | ***************************************************************************/ |
---|
234 | |
---|
235 | la t2, _fbss /* cache mode as linked */ |
---|
236 | and t2, 0xF0000000 /* isolate segment */ |
---|
237 | la t1, 6f |
---|
238 | j t1 /* back to original cache mode */ |
---|
239 | nop |
---|
240 | 6: |
---|
241 | or v0, t2 /* stack back to original cache mode */ |
---|
242 | addiu v0,v0,-16 /* overhead */ |
---|
243 | move sp, v0 /* now replace count w top of memory */ |
---|
244 | move v1, v0 |
---|
245 | subu v1, P_STACKSIZE /* clear requested stack size */ |
---|
246 | |
---|
247 | 7: sw zero, 0(v1) /* clear P_STACKSIZE stack */ |
---|
248 | bltu v1,v0,7b |
---|
249 | add v1, 4 |
---|
250 | .set reorder |
---|
251 | |
---|
252 | /* FIX THIS - This corrupts memory spaces */ |
---|
253 | /* jal flush_cache_nowrite */ /* flush Data & Instruction caches */ |
---|
254 | |
---|
255 | /* jal mon_flush_cache */ |
---|
256 | |
---|
257 | /************************************************************************** |
---|
258 | ** |
---|
259 | ** If this chip supports a Translation Lookaside Buffer, clear it |
---|
260 | ** |
---|
261 | ***************************************************************************/ |
---|
262 | |
---|
263 | .set noreorder |
---|
264 | mfc0 t1, C0_SR /* look at Status Register */ |
---|
265 | nop |
---|
266 | .set reorder |
---|
267 | |
---|
268 | jal init_tlb /* clear the tlb */ |
---|
269 | |
---|
270 | /* Force processor into cached instruction space for rest of initialization */ |
---|
271 | #if 0 |
---|
272 | la t0, 1f |
---|
273 | li t1, K0BASE /* force into cached space */ |
---|
274 | or t0, t1 |
---|
275 | j t0 |
---|
276 | nop |
---|
277 | 1: |
---|
278 | #endif |
---|
279 | |
---|
280 | /************************************************************************ |
---|
281 | ** |
---|
282 | ** Initialization required if using IDT/c or libc.a, standard C Lib |
---|
283 | ** |
---|
284 | ** can SKIP if not necessary for application |
---|
285 | ** |
---|
286 | ************************************************************************/ |
---|
287 | 8: |
---|
288 | |
---|
289 | /* FIX THIS - Need the pmon equivalent |
---|
290 | jal idtsim_init_sbrk |
---|
291 | jal idtsim_init_file |
---|
292 | */ |
---|
293 | |
---|
294 | /*********************** END I/O initialization **********************/ |
---|
295 | |
---|
296 | |
---|
297 | move a0,zero /* Set argc passed to main */ |
---|
298 | move a1,zero /* Set argv passed to main */ |
---|
299 | jal boot_card |
---|
300 | nop |
---|
301 | |
---|
302 | # jump to the "exit" routine |
---|
303 | jal _idtsim_exit |
---|
304 | move a0,v0 # pass through the exit code |
---|
305 | |
---|
306 | |
---|
307 | # FIX THIS - Need the pmon equivalent |
---|
308 | # jal idtsim_promexit |
---|
309 | |
---|
310 | 1: |
---|
311 | beq zero,zero,1b |
---|
312 | nop |
---|
313 | |
---|
314 | ENDFRAME(start) |
---|
315 | |
---|
316 | /* |
---|
317 | * _sys_exit -- Exit from the application. Normally we cause a user trap |
---|
318 | * to return to the ROM monitor for another run. NOTE: This is |
---|
319 | * the only other routine we provide in the crt0.o object, since |
---|
320 | * it may be tied to the "_start" routine. It also allows |
---|
321 | * executables that contain a complete world to be linked with |
---|
322 | * just the crt0.o object. |
---|
323 | */ |
---|
324 | FRAME(_sys_exit,sp,0,ra) |
---|
325 | |
---|
326 | break 1023 |
---|
327 | nop |
---|
328 | 13: |
---|
329 | b 13b # but loop back just in-case |
---|
330 | nop |
---|
331 | |
---|
332 | ENDFRAME(_sys_exit) |
---|
333 | |
---|
334 | |
---|
335 | |
---|
336 | .globl __sizemem |
---|
337 | .ent __sizemem |
---|
338 | __sizemem: |
---|
339 | li v0,HARD_CODED_MEM_SIZE |
---|
340 | j ra |
---|
341 | nop |
---|
342 | .end __sizemem |
---|