blob: 70aee78054a3e5a09ea5532fad197f28753c2d14 [file] [log] [blame]
Wolfgang Denk1a459662013-07-08 09:37:19 +02001TRAP ta 0; nop; nop; nop;
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +01002
Wolfgang Denk1a459662013-07-08 09:37:19 +02003/* Software trap. Treat as BAD_TRAP for the time being... */
4#define SOFT_TRAP TRAP(_hwerr)
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +01005
Wolfgang Denk1a459662013-07-08 09:37:19 +02006#define PSR_INIT 0x1FC0 /* Disable traps, set s and ps */
7#define WIM_INIT 2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +01008
Wolfgang Denk1a459662013-07-08 09:37:19 +02009/* All traps low-level code here must end with this macro. */
10#define RESTORE_ALL b ret_trap_entry; clr %l6;
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010011
Wolfgang Denk1a459662013-07-08 09:37:19 +020012#define WRITE_PAUSE nop;nop;nop
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010013
Wolfgang Denk1a459662013-07-08 09:37:19 +020014WINDOWSIZE = (16 * 4)
15ARGPUSHSIZE = (6 * 4)
16ARGPUSH = (WINDOWSIZE + 4)
17MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
18
19/* Number of register windows */
20#ifndef CONFIG_SYS_SPARC_NWINDOWS
21#error Must define number of SPARC register windows, default is 8
22#endif
23
24#define STACK_ALIGN 8
25#define SA(X) (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
26
27 .section ".start", "ax"
28 .globl _starttate */
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010029#undef BAD_TRAP
30#define BAD_TRAP ta 0; nop; nop; nop;
31
32/* Software trap. Treat as BAD_TRAP for the time being... */
33#define SOFT_TRAP TRAP(_hwerr)
34
35#define PSR_INIT 0x1FC0 /* Disable traps, set s and ps */
36#define WIM_INIT 2
37
38/* All traps low-level code here must end with this macro. */
39#define RESTORE_ALL b ret_trap_entry; clr %l6;
40
41#define WRITE_PAUSE nop;nop;nop
42
43WINDOWSIZE = (16 * 4)
44ARGPUSHSIZE = (6 * 4)
45ARGPUSH = (WINDOWSIZE + 4)
46MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
47
48/* Number of register windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020049#ifndef CONFIG_SYS_SPARC_NWINDOWS
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010050#error Must define number of SPARC register windows, default is 8
51#endif
52
53#define STACK_ALIGN 8
54#define SA(X) (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
55
56 .section ".start", "ax"
Wolfgang Denk53677ef2008-05-20 16:00:29 +020057 .globl _start, start, _trap_table
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010058 .globl _irq_entry, nmi_trap
59 .globl _reset_reloc
60
61/* at address 0
62 * Hardware traps
63 */
64start:
65_start:
66_trap_table:
67 TRAPR(_hardreset); ! 00 reset trap
68 BAD_TRAP; ! 01 instruction_access_exception
69 BAD_TRAP; ! 02 illegal_instruction
70 BAD_TRAP; ! 03 priveleged_instruction
71 BAD_TRAP; ! 04 fp_disabled
72 TRAP(_window_overflow); ! 05 window_overflow
73 TRAP(_window_underflow); ! 06 window_underflow
74 BAD_TRAP; ! 07 Memory Address Not Aligned
75 BAD_TRAP; ! 08 Floating Point Exception
76 BAD_TRAP; ! 09 Data Miss Exception
77 BAD_TRAP; ! 0a Tagged Instruction Ovrflw
78 BAD_TRAP; ! 0b Watchpoint Detected
79 BAD_TRAP; ! 0c
80 BAD_TRAP; ! 0d
81 BAD_TRAP; ! 0e
82 BAD_TRAP; ! 0f
83 BAD_TRAP; ! 10
84 TRAPI(1); ! 11 IRQ level 1
85 TRAPI(2); ! 12 IRQ level 2
86 TRAPI(3); ! 13 IRQ level 3
87 TRAPI(4); ! 14 IRQ level 4
88 TRAPI(5); ! 15 IRQ level 5
89 TRAPI(6); ! 16 IRQ level 6
90 TRAPI(7); ! 17 IRQ level 7
91 TRAPI(8); ! 18 IRQ level 8
92 TRAPI(9); ! 19 IRQ level 9
93 TRAPI(10); ! 1a IRQ level 10
94 TRAPI(11); ! 1b IRQ level 11
95 TRAPI(12); ! 1c IRQ level 12
96 TRAPI(13); ! 1d IRQ level 13
97 TRAPI(14); ! 1e IRQ level 14
98 TRAP(_nmi_trap); ! 1f IRQ level 15 /
Wolfgang Denk53677ef2008-05-20 16:00:29 +020099 ! NMI (non maskable interrupt)
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100100 BAD_TRAP; ! 20 r_register_access_error
101 BAD_TRAP; ! 21 instruction access error
102 BAD_TRAP; ! 22
103 BAD_TRAP; ! 23
104 BAD_TRAP; ! 24 co-processor disabled
105 BAD_TRAP; ! 25 uniplemented FLUSH
106 BAD_TRAP; ! 26
107 BAD_TRAP; ! 27
108 BAD_TRAP; ! 28 co-processor exception
109 BAD_TRAP; ! 29 data access error
110 BAD_TRAP; ! 2a division by zero
111 BAD_TRAP; ! 2b data store error
112 BAD_TRAP; ! 2c data access MMU miss
113 BAD_TRAP; ! 2d
114 BAD_TRAP; ! 2e
115 BAD_TRAP; ! 2f
116 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 30-33
117 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 34-37
118 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 38-3b
119 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 3c-3f
120 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 40-43
121 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 44-47
122 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 48-4b
123 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 4c-4f
124 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 50-53
125 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 54-57
126 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 58-5b
127 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 5c-5f
128
129 /* implementaion dependent */
130 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 60-63
131 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 64-67
132 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 68-6b
133 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 6c-6f
134 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 70-73
135 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 74-77
136 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 78-7b
137 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 7c-7f
138
139 /* Software traps, not handled */
140 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 80-83
141 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 84-87
142 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 88-8b
143 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 8c-8f
144 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 90-93
145 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 94-97
146 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 98-9b
147 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 9c-9f
148 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a0-a3
149 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a4-a7
150 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a8-ab
151 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ac-af
152 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b0-b3
153 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b4-b7
154 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b8-bb
155 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! bc-bf
156 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c0-c3
157 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c4-c7
158 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c8-cb
159 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! cc-cf
160 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d0-d3
161 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d4-d7
162 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d8-db
163 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! dc-df
164 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e0-e3
165 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e4-e7
166 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e8-eb
167 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ec-ef
168 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f0-f3
169 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f4-f7
170 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f8-fb
171 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! fc-ff
172/*
173 * Version string
174 */
175
176 .data
177 .extern leon3_snooping_avail
178 .globl version_string
179version_string:
Andreas Bießmann09c2e902011-07-18 20:24:04 +0200180 .ascii U_BOOT_VERSION_STRING, "\0"
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100181
182 .section ".text"
183 .align 4
184
185_hardreset:
1861000:
187 flush
188
189 /* Enable I/D-Cache and Snooping */
190 set 0x0081000f, %g2
191 sta %g2, [%g0] 2
192
193 mov %g0, %y
194 clr %g1
195 clr %g2
196 clr %g3
197 clr %g4
198 clr %g5
199 clr %g6
200 clr %g7
201
202 mov %asr17, %g3
203 and %g3, 0x1f, %g3
204clear_window:
205 mov %g0, %l0
206 mov %g0, %l1
207 mov %g0, %l2
208 mov %g0, %l3
209 mov %g0, %l4
210 mov %g0, %l5
211 mov %g0, %l6
212 mov %g0, %l7
213 mov %g0, %o0
214 mov %g0, %o1
215 mov %g0, %o2
216 mov %g0, %o3
217 mov %g0, %o4
218 mov %g0, %o5
219 mov %g0, %o6
220 mov %g0, %o7
221 subcc %g3, 1, %g3
222 bge clear_window
223 save
224
225wininit:
226 set WIM_INIT, %g3
227 mov %g3, %wim
228
229stackp:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200230 set CONFIG_SYS_INIT_SP_OFFSET, %fp
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100231 andn %fp, 0x0f, %fp
232 sub %fp, 64, %sp
233
234cpu_init_unreloc:
235 call cpu_init_f
236 nop
237
238/* un relocated start address of monitor */
239#define TEXT_START _text
240
241/* un relocated end address of monitor */
242#define DATA_END __init_end
243
244reloc:
245 set TEXT_START,%g2
246 set DATA_END,%g3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200247 set CONFIG_SYS_RELOC_MONITOR_BASE,%g4
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100248reloc_loop:
249 ldd [%g2],%l0
250 ldd [%g2+8],%l2
251 std %l0,[%g4]
252 std %l2,[%g4+8]
253 inc 16,%g2
254 subcc %g3,%g2,%g0
255 bne reloc_loop
256 inc 16,%g4
257
258 clr %l0
259 clr %l1
260 clr %l2
261 clr %l3
262 clr %g2
263
264/* register g4 contain address to start
265 * This means that BSS must be directly after data and code segments
266 *
267 * g3 is length of bss = (__bss_end-__bss_start)
268 *
269 */
270
271clr_bss:
272/* clear bss area (the relocated) */
273 set __bss_start,%g2
274 set __bss_end,%g3
275 sub %g3,%g2,%g3
276 add %g3,%g4,%g3
277 clr %g1 /* std %g0 uses g0 and g1 */
278/* clearing 16byte a time ==> linker script need to align to 16 byte offset */
279clr_bss_16:
280 std %g0,[%g4]
281 std %g0,[%g4+8]
282 inc 16,%g4
283 cmp %g3,%g4
284 bne clr_bss_16
285 nop
286
287/* add offsets to GOT table */
288fixup_got:
289 set __got_start,%g4
290 set __got_end,%g3
291/*
292 * new got offset = (old GOT-PTR (read with ld) -
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200293 * CONFIG_SYS_RELOC_MONITOR_BASE(from define) ) +
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100294 * Destination Address (from define)
295 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200296 set CONFIG_SYS_RELOC_MONITOR_BASE,%g2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100297 set TEXT_START, %g1
298 add %g4,%g2,%g4
299 sub %g4,%g1,%g4
300 add %g3,%g2,%g3
301 sub %g3,%g1,%g3
302 sub %g2,%g1,%g2 ! prepare register with (new base address) -
303 ! (old base address)
304got_loop:
305 ld [%g4],%l0 ! load old GOT-PTR
306 add %l0,%g2,%l0 ! increase with (new base address) -
307 ! (old base)
308 st %l0,[%g4]
309 inc 4,%g4
310 cmp %g3,%g4
311 bne got_loop
312 nop
313
314prom_relocate:
315 set __prom_start, %g2
316 set __prom_end, %g3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200317 set CONFIG_SYS_PROM_OFFSET, %g4
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100318
319prom_relocate_loop:
320 ldd [%g2],%l0
321 ldd [%g2+8],%l2
322 std %l0,[%g4]
323 std %l2,[%g4+8]
324 inc 16,%g2
325 subcc %g3,%g2,%g0
326 bne prom_relocate_loop
327 inc 16,%g4
328
329/* Trap table has been moved, lets tell CPU about
330 * the new trap table address
331 */
332
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200333 set CONFIG_SYS_RELOC_MONITOR_BASE, %g2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100334 wr %g0, %g2, %tbr
335 nop
336 nop
337 nop
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -0700338
339/* If CACHE snooping is available in hardware the
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100340 * variable leon3_snooping_avail will be set to
341 * 0x800000 else 0.
342 */
343snoop_detect:
344 sethi %hi(0x00800000), %o0
345 lda [%g0] 2, %o1
346 and %o0, %o1, %o0
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200347 sethi %hi(leon3_snooping_avail+CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE), %o1
348 st %o0, [%lo(leon3_snooping_avail+CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE)+%o1]
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100349
350/* call relocate*/
351 nop
352/* Call relocated init functions */
353jump:
354 set cpu_init_f2,%o1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200355 set CONFIG_SYS_RELOC_MONITOR_BASE,%o2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100356 add %o1,%o2,%o1
357 sub %o1,%g1,%o1
358 call %o1
359 clr %o0
360
361 set board_init_f,%o1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200362 set CONFIG_SYS_RELOC_MONITOR_BASE,%o2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100363 add %o1,%o2,%o1
364 sub %o1,%g1,%o1
365 call %o1
366 clr %o0
367
368dead: ta 0 ! if call returns...
369 nop
370
371/* Interrupt handler caller,
372 * reg L7: interrupt number
373 * reg L0: psr after interrupt
374 * reg L1: PC
375 * reg L2: next PC
376 * reg L3: wim
377 */
378_irq_entry:
379 SAVE_ALL
380
381 or %l0, PSR_PIL, %g2
382 wr %g2, 0x0, %psr
383 WRITE_PAUSE
384 wr %g2, PSR_ET, %psr
385 WRITE_PAUSE
386 mov %l7, %o0 ! irq level
387 set handler_irq, %o1
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200388 set (CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE), %o2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100389 add %o1, %o2, %o1
390 call %o1
391 add %sp, SF_REGS_SZ, %o1 ! pt_regs ptr
392 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
393 wr %g2, PSR_ET, %psr ! keep ET up
394 WRITE_PAUSE
395
396 RESTORE_ALL
397
398!Window overflow trap handler.
399 .global _window_overflow
400
401_window_overflow:
402
403 mov %wim, %l3 ! Calculate next WIM
404 mov %g1, %l7
405 srl %l3, 1, %g1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200406 sll %l3, (CONFIG_SYS_SPARC_NWINDOWS-1) , %l4
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100407 or %l4, %g1, %g1
408
409 save ! Get into window to be saved.
410 mov %g1, %wim
411 nop;
412 nop;
413 nop
414 st %l0, [%sp + 0];
415 st %l1, [%sp + 4];
416 st %l2, [%sp + 8];
417 st %l3, [%sp + 12];
418 st %l4, [%sp + 16];
419 st %l5, [%sp + 20];
420 st %l6, [%sp + 24];
421 st %l7, [%sp + 28];
422 st %i0, [%sp + 32];
423 st %i1, [%sp + 36];
424 st %i2, [%sp + 40];
425 st %i3, [%sp + 44];
426 st %i4, [%sp + 48];
427 st %i5, [%sp + 52];
428 st %i6, [%sp + 56];
429 st %i7, [%sp + 60];
430 restore ! Go back to trap window.
431 mov %l7, %g1
432 jmp %l1 ! Re-execute save.
433 rett %l2
434
435/* Window underflow trap handler. */
436
437 .global _window_underflow
438
439_window_underflow:
440
441 mov %wim, %l3 ! Calculate next WIM
442 sll %l3, 1, %l4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200443 srl %l3, (CONFIG_SYS_SPARC_NWINDOWS-1), %l5
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100444 or %l5, %l4, %l5
445 mov %l5, %wim
446 nop; nop; nop
447 restore ! Two restores to get into the
448 restore ! window to restore
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200449 ld [%sp + 0], %l0; ! Restore window from the stack
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100450 ld [%sp + 4], %l1;
451 ld [%sp + 8], %l2;
452 ld [%sp + 12], %l3;
453 ld [%sp + 16], %l4;
454 ld [%sp + 20], %l5;
455 ld [%sp + 24], %l6;
456 ld [%sp + 28], %l7;
457 ld [%sp + 32], %i0;
458 ld [%sp + 36], %i1;
459 ld [%sp + 40], %i2;
460 ld [%sp + 44], %i3;
461 ld [%sp + 48], %i4;
462 ld [%sp + 52], %i5;
463 ld [%sp + 56], %i6;
464 ld [%sp + 60], %i7;
465 save ! Get back to the trap window.
466 save
467 jmp %l1 ! Re-execute restore.
468 rett %l2
469
470 retl
471
472_nmi_trap:
473 nop
474 jmp %l1
475 rett %l2
476
477_hwerr:
478 ta 0
479 nop
480 nop
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200481 b _hwerr ! loop infinite
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100482 nop
483
484/* Registers to not touch at all. */
485#define t_psr l0 /* Set by caller */
486#define t_pc l1 /* Set by caller */
487#define t_npc l2 /* Set by caller */
488#define t_wim l3 /* Set by caller */
489#define t_twinmask l4 /* Set at beginning of this entry routine. */
490#define t_kstack l5 /* Set right before pt_regs frame is built */
491#define t_retpc l6 /* If you change this, change winmacro.h header file */
492#define t_systable l7 /* Never touch this, could be the syscall table ptr. */
493#define curptr g6 /* Set after pt_regs frame is built */
494
495trap_setup:
496/* build a pt_regs trap frame. */
497 sub %fp, (SF_REGS_SZ + PT_REGS_SZ), %t_kstack
498 PT_STORE_ALL(t_kstack, t_psr, t_pc, t_npc, g2)
499
500 /* See if we are in the trap window. */
501 mov 1, %t_twinmask
502 sll %t_twinmask, %t_psr, %t_twinmask ! t_twinmask = (1 << psr)
503 andcc %t_twinmask, %t_wim, %g0
504 beq 1f ! in trap window, clean up
505 nop
506
507 /*-------------------------------------------------
508 * Spill , adjust %wim and go.
509 */
510 srl %t_wim, 0x1, %g2 ! begin computation of new %wim
511
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200512 set (CONFIG_SYS_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100513
514 sll %t_wim, %g3, %t_wim ! NWINDOWS-1
515 or %t_wim, %g2, %g2
516 and %g2, 0xff, %g2
517
518 save %g0, %g0, %g0 ! get in window to be saved
519
520 /* Set new %wim value */
521 wr %g2, 0x0, %wim
522
523 /* Save the kernel window onto the corresponding stack. */
524 RW_STORE(sp)
525
526 restore %g0, %g0, %g0
527 /*-------------------------------------------------*/
528
5291:
530 /* Trap from kernel with a window available.
531 * Just do it...
532 */
533 jmpl %t_retpc + 0x8, %g0 ! return to caller
534 mov %t_kstack, %sp ! jump onto new stack
535
536#define twin_tmp1 l4
537#define glob_tmp g4
538#define curptr g6
539ret_trap_entry:
540 wr %t_psr, 0x0, %psr ! enable nesting again, clear ET
541
542 /* Will the rett land us in the invalid window? */
543 mov 2, %g1
544 sll %g1, %t_psr, %g1
545
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200546 set CONFIG_SYS_SPARC_NWINDOWS, %g2 !NWINDOWS
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100547
548 srl %g1, %g2, %g2
549 or %g1, %g2, %g1
550 rd %wim, %g2
551 andcc %g2, %g1, %g0
552 be 1f ! Nope, just return from the trap
553 sll %g2, 0x1, %g1
554
555 /* We have to grab a window before returning. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200556 set (CONFIG_SYS_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100557
558 srl %g2, %g3, %g2
559 or %g1, %g2, %g1
560 and %g1, 0xff, %g1
561
562 wr %g1, 0x0, %wim
563
564 /* Grrr, make sure we load from the right %sp... */
565 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
566
567 restore %g0, %g0, %g0
568 RW_LOAD(sp)
569 b 2f
570 save %g0, %g0, %g0
571
572 /* Reload the entire frame in case this is from a
573 * kernel system call or whatever...
574 */
5751:
576 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
5772:
578 wr %t_psr, 0x0, %psr
579 nop;
580 nop;
581 nop
582
583 jmp %t_pc
584 rett %t_npc
585
586/* This is called from relocated C-code.
587 * It resets the system by jumping to _start
588 */
589_reset_reloc:
590 set start, %l0
591 call %l0
592 nop