blob: 56ae88d6492b8d5623921427063c9f6635c30cfb [file] [log] [blame]
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +01001/* This is where the SPARC/LEON3 starts
2 * Copyright (C) 2007,
3 * Daniel Hellstrom, daniel@gaisler.com
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Wolfgang Denk25ddd1f2010-10-26 14:34:52 +020024#include <asm-offsets.h>
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010025#include <config.h>
26#include <asm/asmmacro.h>
27#include <asm/winmacro.h>
28#include <asm/psr.h>
29#include <asm/stack.h>
30#include <asm/leon.h>
Peter Tyser561858e2008-11-03 09:30:59 -060031#include <timestamp.h>
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010032#include <version.h>
33
34/* Entry for traps which jump to a programmer-specified trap handler. */
35#define TRAPR(H) \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020036 wr %g0, 0xfe0, %psr; \
37 mov %g0, %tbr; \
38 ba (H); \
39 mov %g0, %wim;
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010040
41#define TRAP(H) \
42 mov %psr, %l0; \
43 ba (H); \
44 nop; nop;
45
46#define TRAPI(ilevel) \
Wolfgang Denk53677ef2008-05-20 16:00:29 +020047 mov ilevel, %l7; \
48 mov %psr, %l0; \
49 b _irq_entry; \
50 mov %wim, %l3
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010051
52/* Unexcpected trap will halt the processor by forcing it to error state */
53#undef BAD_TRAP
54#define BAD_TRAP ta 0; nop; nop; nop;
55
56/* Software trap. Treat as BAD_TRAP for the time being... */
57#define SOFT_TRAP TRAP(_hwerr)
58
59#define PSR_INIT 0x1FC0 /* Disable traps, set s and ps */
60#define WIM_INIT 2
61
62/* All traps low-level code here must end with this macro. */
63#define RESTORE_ALL b ret_trap_entry; clr %l6;
64
65#define WRITE_PAUSE nop;nop;nop
66
67WINDOWSIZE = (16 * 4)
68ARGPUSHSIZE = (6 * 4)
69ARGPUSH = (WINDOWSIZE + 4)
70MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
71
72/* Number of register windows */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020073#ifndef CONFIG_SYS_SPARC_NWINDOWS
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010074#error Must define number of SPARC register windows, default is 8
75#endif
76
77#define STACK_ALIGN 8
78#define SA(X) (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
79
80 .section ".start", "ax"
Wolfgang Denk53677ef2008-05-20 16:00:29 +020081 .globl _start, start, _trap_table
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +010082 .globl _irq_entry, nmi_trap
83 .globl _reset_reloc
84
85/* at address 0
86 * Hardware traps
87 */
88start:
89_start:
90_trap_table:
91 TRAPR(_hardreset); ! 00 reset trap
92 BAD_TRAP; ! 01 instruction_access_exception
93 BAD_TRAP; ! 02 illegal_instruction
94 BAD_TRAP; ! 03 priveleged_instruction
95 BAD_TRAP; ! 04 fp_disabled
96 TRAP(_window_overflow); ! 05 window_overflow
97 TRAP(_window_underflow); ! 06 window_underflow
98 BAD_TRAP; ! 07 Memory Address Not Aligned
99 BAD_TRAP; ! 08 Floating Point Exception
100 BAD_TRAP; ! 09 Data Miss Exception
101 BAD_TRAP; ! 0a Tagged Instruction Ovrflw
102 BAD_TRAP; ! 0b Watchpoint Detected
103 BAD_TRAP; ! 0c
104 BAD_TRAP; ! 0d
105 BAD_TRAP; ! 0e
106 BAD_TRAP; ! 0f
107 BAD_TRAP; ! 10
108 TRAPI(1); ! 11 IRQ level 1
109 TRAPI(2); ! 12 IRQ level 2
110 TRAPI(3); ! 13 IRQ level 3
111 TRAPI(4); ! 14 IRQ level 4
112 TRAPI(5); ! 15 IRQ level 5
113 TRAPI(6); ! 16 IRQ level 6
114 TRAPI(7); ! 17 IRQ level 7
115 TRAPI(8); ! 18 IRQ level 8
116 TRAPI(9); ! 19 IRQ level 9
117 TRAPI(10); ! 1a IRQ level 10
118 TRAPI(11); ! 1b IRQ level 11
119 TRAPI(12); ! 1c IRQ level 12
120 TRAPI(13); ! 1d IRQ level 13
121 TRAPI(14); ! 1e IRQ level 14
122 TRAP(_nmi_trap); ! 1f IRQ level 15 /
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200123 ! NMI (non maskable interrupt)
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100124 BAD_TRAP; ! 20 r_register_access_error
125 BAD_TRAP; ! 21 instruction access error
126 BAD_TRAP; ! 22
127 BAD_TRAP; ! 23
128 BAD_TRAP; ! 24 co-processor disabled
129 BAD_TRAP; ! 25 uniplemented FLUSH
130 BAD_TRAP; ! 26
131 BAD_TRAP; ! 27
132 BAD_TRAP; ! 28 co-processor exception
133 BAD_TRAP; ! 29 data access error
134 BAD_TRAP; ! 2a division by zero
135 BAD_TRAP; ! 2b data store error
136 BAD_TRAP; ! 2c data access MMU miss
137 BAD_TRAP; ! 2d
138 BAD_TRAP; ! 2e
139 BAD_TRAP; ! 2f
140 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 30-33
141 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 34-37
142 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 38-3b
143 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 3c-3f
144 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 40-43
145 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 44-47
146 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 48-4b
147 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 4c-4f
148 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 50-53
149 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 54-57
150 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 58-5b
151 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 5c-5f
152
153 /* implementaion dependent */
154 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 60-63
155 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 64-67
156 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 68-6b
157 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 6c-6f
158 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 70-73
159 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 74-77
160 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 78-7b
161 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 7c-7f
162
163 /* Software traps, not handled */
164 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 80-83
165 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 84-87
166 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 88-8b
167 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 8c-8f
168 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 90-93
169 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 94-97
170 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 98-9b
171 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 9c-9f
172 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a0-a3
173 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a4-a7
174 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a8-ab
175 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ac-af
176 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b0-b3
177 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b4-b7
178 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b8-bb
179 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! bc-bf
180 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c0-c3
181 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c4-c7
182 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c8-cb
183 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! cc-cf
184 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d0-d3
185 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d4-d7
186 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d8-db
187 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! dc-df
188 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e0-e3
189 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e4-e7
190 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e8-eb
191 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ec-ef
192 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f0-f3
193 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f4-f7
194 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f8-fb
195 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! fc-ff
196/*
197 * Version string
198 */
199
200 .data
201 .extern leon3_snooping_avail
202 .globl version_string
203version_string:
204 .ascii U_BOOT_VERSION
Peter Tyser561858e2008-11-03 09:30:59 -0600205 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100206 .ascii CONFIG_IDENT_STRING, "\0"
207
208 .section ".text"
209 .align 4
210
211_hardreset:
2121000:
213 flush
214
215 /* Enable I/D-Cache and Snooping */
216 set 0x0081000f, %g2
217 sta %g2, [%g0] 2
218
219 mov %g0, %y
220 clr %g1
221 clr %g2
222 clr %g3
223 clr %g4
224 clr %g5
225 clr %g6
226 clr %g7
227
228 mov %asr17, %g3
229 and %g3, 0x1f, %g3
230clear_window:
231 mov %g0, %l0
232 mov %g0, %l1
233 mov %g0, %l2
234 mov %g0, %l3
235 mov %g0, %l4
236 mov %g0, %l5
237 mov %g0, %l6
238 mov %g0, %l7
239 mov %g0, %o0
240 mov %g0, %o1
241 mov %g0, %o2
242 mov %g0, %o3
243 mov %g0, %o4
244 mov %g0, %o5
245 mov %g0, %o6
246 mov %g0, %o7
247 subcc %g3, 1, %g3
248 bge clear_window
249 save
250
251wininit:
252 set WIM_INIT, %g3
253 mov %g3, %wim
254
255stackp:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200256 set CONFIG_SYS_INIT_SP_OFFSET, %fp
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100257 andn %fp, 0x0f, %fp
258 sub %fp, 64, %sp
259
260cpu_init_unreloc:
261 call cpu_init_f
262 nop
263
264/* un relocated start address of monitor */
265#define TEXT_START _text
266
267/* un relocated end address of monitor */
268#define DATA_END __init_end
269
270reloc:
271 set TEXT_START,%g2
272 set DATA_END,%g3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200273 set CONFIG_SYS_RELOC_MONITOR_BASE,%g4
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100274reloc_loop:
275 ldd [%g2],%l0
276 ldd [%g2+8],%l2
277 std %l0,[%g4]
278 std %l2,[%g4+8]
279 inc 16,%g2
280 subcc %g3,%g2,%g0
281 bne reloc_loop
282 inc 16,%g4
283
284 clr %l0
285 clr %l1
286 clr %l2
287 clr %l3
288 clr %g2
289
290/* register g4 contain address to start
291 * This means that BSS must be directly after data and code segments
292 *
293 * g3 is length of bss = (__bss_end-__bss_start)
294 *
295 */
296
297clr_bss:
298/* clear bss area (the relocated) */
299 set __bss_start,%g2
300 set __bss_end,%g3
301 sub %g3,%g2,%g3
302 add %g3,%g4,%g3
303 clr %g1 /* std %g0 uses g0 and g1 */
304/* clearing 16byte a time ==> linker script need to align to 16 byte offset */
305clr_bss_16:
306 std %g0,[%g4]
307 std %g0,[%g4+8]
308 inc 16,%g4
309 cmp %g3,%g4
310 bne clr_bss_16
311 nop
312
313/* add offsets to GOT table */
314fixup_got:
315 set __got_start,%g4
316 set __got_end,%g3
317/*
318 * new got offset = (old GOT-PTR (read with ld) -
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200319 * CONFIG_SYS_RELOC_MONITOR_BASE(from define) ) +
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100320 * Destination Address (from define)
321 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200322 set CONFIG_SYS_RELOC_MONITOR_BASE,%g2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100323 set TEXT_START, %g1
324 add %g4,%g2,%g4
325 sub %g4,%g1,%g4
326 add %g3,%g2,%g3
327 sub %g3,%g1,%g3
328 sub %g2,%g1,%g2 ! prepare register with (new base address) -
329 ! (old base address)
330got_loop:
331 ld [%g4],%l0 ! load old GOT-PTR
332 add %l0,%g2,%l0 ! increase with (new base address) -
333 ! (old base)
334 st %l0,[%g4]
335 inc 4,%g4
336 cmp %g3,%g4
337 bne got_loop
338 nop
339
340prom_relocate:
341 set __prom_start, %g2
342 set __prom_end, %g3
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200343 set CONFIG_SYS_PROM_OFFSET, %g4
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100344
345prom_relocate_loop:
346 ldd [%g2],%l0
347 ldd [%g2+8],%l2
348 std %l0,[%g4]
349 std %l2,[%g4+8]
350 inc 16,%g2
351 subcc %g3,%g2,%g0
352 bne prom_relocate_loop
353 inc 16,%g4
354
355/* Trap table has been moved, lets tell CPU about
356 * the new trap table address
357 */
358
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200359 set CONFIG_SYS_RELOC_MONITOR_BASE, %g2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100360 wr %g0, %g2, %tbr
361 nop
362 nop
363 nop
Wolfgang Denk1aeed8d2008-04-13 09:59:26 -0700364
365/* If CACHE snooping is available in hardware the
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100366 * variable leon3_snooping_avail will be set to
367 * 0x800000 else 0.
368 */
369snoop_detect:
370 sethi %hi(0x00800000), %o0
371 lda [%g0] 2, %o1
372 and %o0, %o1, %o0
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200373 sethi %hi(leon3_snooping_avail+CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE), %o1
374 st %o0, [%lo(leon3_snooping_avail+CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE)+%o1]
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100375
376/* call relocate*/
377 nop
378/* Call relocated init functions */
379jump:
380 set cpu_init_f2,%o1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200381 set CONFIG_SYS_RELOC_MONITOR_BASE,%o2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100382 add %o1,%o2,%o1
383 sub %o1,%g1,%o1
384 call %o1
385 clr %o0
386
387 set board_init_f,%o1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200388 set CONFIG_SYS_RELOC_MONITOR_BASE,%o2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100389 add %o1,%o2,%o1
390 sub %o1,%g1,%o1
391 call %o1
392 clr %o0
393
394dead: ta 0 ! if call returns...
395 nop
396
397/* Interrupt handler caller,
398 * reg L7: interrupt number
399 * reg L0: psr after interrupt
400 * reg L1: PC
401 * reg L2: next PC
402 * reg L3: wim
403 */
404_irq_entry:
405 SAVE_ALL
406
407 or %l0, PSR_PIL, %g2
408 wr %g2, 0x0, %psr
409 WRITE_PAUSE
410 wr %g2, PSR_ET, %psr
411 WRITE_PAUSE
412 mov %l7, %o0 ! irq level
413 set handler_irq, %o1
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200414 set (CONFIG_SYS_RELOC_MONITOR_BASE-CONFIG_SYS_TEXT_BASE), %o2
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100415 add %o1, %o2, %o1
416 call %o1
417 add %sp, SF_REGS_SZ, %o1 ! pt_regs ptr
418 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
419 wr %g2, PSR_ET, %psr ! keep ET up
420 WRITE_PAUSE
421
422 RESTORE_ALL
423
424!Window overflow trap handler.
425 .global _window_overflow
426
427_window_overflow:
428
429 mov %wim, %l3 ! Calculate next WIM
430 mov %g1, %l7
431 srl %l3, 1, %g1
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200432 sll %l3, (CONFIG_SYS_SPARC_NWINDOWS-1) , %l4
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100433 or %l4, %g1, %g1
434
435 save ! Get into window to be saved.
436 mov %g1, %wim
437 nop;
438 nop;
439 nop
440 st %l0, [%sp + 0];
441 st %l1, [%sp + 4];
442 st %l2, [%sp + 8];
443 st %l3, [%sp + 12];
444 st %l4, [%sp + 16];
445 st %l5, [%sp + 20];
446 st %l6, [%sp + 24];
447 st %l7, [%sp + 28];
448 st %i0, [%sp + 32];
449 st %i1, [%sp + 36];
450 st %i2, [%sp + 40];
451 st %i3, [%sp + 44];
452 st %i4, [%sp + 48];
453 st %i5, [%sp + 52];
454 st %i6, [%sp + 56];
455 st %i7, [%sp + 60];
456 restore ! Go back to trap window.
457 mov %l7, %g1
458 jmp %l1 ! Re-execute save.
459 rett %l2
460
461/* Window underflow trap handler. */
462
463 .global _window_underflow
464
465_window_underflow:
466
467 mov %wim, %l3 ! Calculate next WIM
468 sll %l3, 1, %l4
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200469 srl %l3, (CONFIG_SYS_SPARC_NWINDOWS-1), %l5
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100470 or %l5, %l4, %l5
471 mov %l5, %wim
472 nop; nop; nop
473 restore ! Two restores to get into the
474 restore ! window to restore
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200475 ld [%sp + 0], %l0; ! Restore window from the stack
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100476 ld [%sp + 4], %l1;
477 ld [%sp + 8], %l2;
478 ld [%sp + 12], %l3;
479 ld [%sp + 16], %l4;
480 ld [%sp + 20], %l5;
481 ld [%sp + 24], %l6;
482 ld [%sp + 28], %l7;
483 ld [%sp + 32], %i0;
484 ld [%sp + 36], %i1;
485 ld [%sp + 40], %i2;
486 ld [%sp + 44], %i3;
487 ld [%sp + 48], %i4;
488 ld [%sp + 52], %i5;
489 ld [%sp + 56], %i6;
490 ld [%sp + 60], %i7;
491 save ! Get back to the trap window.
492 save
493 jmp %l1 ! Re-execute restore.
494 rett %l2
495
496 retl
497
498_nmi_trap:
499 nop
500 jmp %l1
501 rett %l2
502
503_hwerr:
504 ta 0
505 nop
506 nop
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200507 b _hwerr ! loop infinite
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100508 nop
509
510/* Registers to not touch at all. */
511#define t_psr l0 /* Set by caller */
512#define t_pc l1 /* Set by caller */
513#define t_npc l2 /* Set by caller */
514#define t_wim l3 /* Set by caller */
515#define t_twinmask l4 /* Set at beginning of this entry routine. */
516#define t_kstack l5 /* Set right before pt_regs frame is built */
517#define t_retpc l6 /* If you change this, change winmacro.h header file */
518#define t_systable l7 /* Never touch this, could be the syscall table ptr. */
519#define curptr g6 /* Set after pt_regs frame is built */
520
521trap_setup:
522/* build a pt_regs trap frame. */
523 sub %fp, (SF_REGS_SZ + PT_REGS_SZ), %t_kstack
524 PT_STORE_ALL(t_kstack, t_psr, t_pc, t_npc, g2)
525
526 /* See if we are in the trap window. */
527 mov 1, %t_twinmask
528 sll %t_twinmask, %t_psr, %t_twinmask ! t_twinmask = (1 << psr)
529 andcc %t_twinmask, %t_wim, %g0
530 beq 1f ! in trap window, clean up
531 nop
532
533 /*-------------------------------------------------
534 * Spill , adjust %wim and go.
535 */
536 srl %t_wim, 0x1, %g2 ! begin computation of new %wim
537
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200538 set (CONFIG_SYS_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100539
540 sll %t_wim, %g3, %t_wim ! NWINDOWS-1
541 or %t_wim, %g2, %g2
542 and %g2, 0xff, %g2
543
544 save %g0, %g0, %g0 ! get in window to be saved
545
546 /* Set new %wim value */
547 wr %g2, 0x0, %wim
548
549 /* Save the kernel window onto the corresponding stack. */
550 RW_STORE(sp)
551
552 restore %g0, %g0, %g0
553 /*-------------------------------------------------*/
554
5551:
556 /* Trap from kernel with a window available.
557 * Just do it...
558 */
559 jmpl %t_retpc + 0x8, %g0 ! return to caller
560 mov %t_kstack, %sp ! jump onto new stack
561
562#define twin_tmp1 l4
563#define glob_tmp g4
564#define curptr g6
565ret_trap_entry:
566 wr %t_psr, 0x0, %psr ! enable nesting again, clear ET
567
568 /* Will the rett land us in the invalid window? */
569 mov 2, %g1
570 sll %g1, %t_psr, %g1
571
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200572 set CONFIG_SYS_SPARC_NWINDOWS, %g2 !NWINDOWS
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100573
574 srl %g1, %g2, %g2
575 or %g1, %g2, %g1
576 rd %wim, %g2
577 andcc %g2, %g1, %g0
578 be 1f ! Nope, just return from the trap
579 sll %g2, 0x1, %g1
580
581 /* We have to grab a window before returning. */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200582 set (CONFIG_SYS_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
Daniel Hellstrom1e9a1642008-03-26 22:51:29 +0100583
584 srl %g2, %g3, %g2
585 or %g1, %g2, %g1
586 and %g1, 0xff, %g1
587
588 wr %g1, 0x0, %wim
589
590 /* Grrr, make sure we load from the right %sp... */
591 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
592
593 restore %g0, %g0, %g0
594 RW_LOAD(sp)
595 b 2f
596 save %g0, %g0, %g0
597
598 /* Reload the entire frame in case this is from a
599 * kernel system call or whatever...
600 */
6011:
602 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
6032:
604 wr %t_psr, 0x0, %psr
605 nop;
606 nop;
607 nop
608
609 jmp %t_pc
610 rett %t_npc
611
612/* This is called from relocated C-code.
613 * It resets the system by jumping to _start
614 */
615_reset_reloc:
616 set start, %l0
617 call %l0
618 nop