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