1 /* This is where the SPARC/LEON3 starts
3 * Daniel Hellstrom, daniel@gaisler.com
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 #include <asm/asmmacro.h>
26 #include <asm/winmacro.h>
28 #include <asm/stack.h>
32 /* Entry for traps which jump to a programmer-specified trap handler. */
34 wr %g0, 0xfe0, %psr; \
44 #define TRAPI(ilevel) \
50 /* Unexcpected trap will halt the processor by forcing it to error state */
52 #define BAD_TRAP ta 0; nop; nop; nop;
54 /* Software trap. Treat as BAD_TRAP for the time being... */
55 #define SOFT_TRAP TRAP(_hwerr)
57 #define PSR_INIT 0x1FC0 /* Disable traps, set s and ps */
60 /* All traps low-level code here must end with this macro. */
61 #define RESTORE_ALL b ret_trap_entry; clr %l6;
63 #define WRITE_PAUSE nop;nop;nop
67 ARGPUSH = (WINDOWSIZE + 4)
68 MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
70 /* Number of register windows */
71 #ifndef CFG_SPARC_NWINDOWS
72 #error Must define number of SPARC register windows, default is 8
76 #define SA(X) (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
78 .section ".start", "ax"
79 .globl _start, start, _trap_table
80 .globl _irq_entry, nmi_trap
89 TRAPR(_hardreset); ! 00 reset trap
90 BAD_TRAP; ! 01 instruction_access_exception
91 BAD_TRAP; ! 02 illegal_instruction
92 BAD_TRAP; ! 03 priveleged_instruction
93 BAD_TRAP; ! 04 fp_disabled
94 TRAP(_window_overflow); ! 05 window_overflow
95 TRAP(_window_underflow); ! 06 window_underflow
96 BAD_TRAP; ! 07 Memory Address Not Aligned
97 BAD_TRAP; ! 08 Floating Point Exception
98 BAD_TRAP; ! 09 Data Miss Exception
99 BAD_TRAP; ! 0a Tagged Instruction Ovrflw
100 BAD_TRAP; ! 0b Watchpoint Detected
106 TRAPI(1); ! 11 IRQ level 1
107 TRAPI(2); ! 12 IRQ level 2
108 TRAPI(3); ! 13 IRQ level 3
109 TRAPI(4); ! 14 IRQ level 4
110 TRAPI(5); ! 15 IRQ level 5
111 TRAPI(6); ! 16 IRQ level 6
112 TRAPI(7); ! 17 IRQ level 7
113 TRAPI(8); ! 18 IRQ level 8
114 TRAPI(9); ! 19 IRQ level 9
115 TRAPI(10); ! 1a IRQ level 10
116 TRAPI(11); ! 1b IRQ level 11
117 TRAPI(12); ! 1c IRQ level 12
118 TRAPI(13); ! 1d IRQ level 13
119 TRAPI(14); ! 1e IRQ level 14
120 TRAP(_nmi_trap); ! 1f IRQ level 15 /
121 ! NMI (non maskable interrupt)
122 BAD_TRAP; ! 20 r_register_access_error
123 BAD_TRAP; ! 21 instruction access error
126 BAD_TRAP; ! 24 co-processor disabled
127 BAD_TRAP; ! 25 uniplemented FLUSH
130 BAD_TRAP; ! 28 co-processor exception
131 BAD_TRAP; ! 29 data access error
132 BAD_TRAP; ! 2a division by zero
133 BAD_TRAP; ! 2b data store error
134 BAD_TRAP; ! 2c data access MMU miss
138 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 30-33
139 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 34-37
140 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 38-3b
141 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 3c-3f
142 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 40-43
143 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 44-47
144 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 48-4b
145 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 4c-4f
146 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 50-53
147 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 54-57
148 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 58-5b
149 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 5c-5f
151 /* implementaion dependent */
152 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 60-63
153 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 64-67
154 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 68-6b
155 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 6c-6f
156 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 70-73
157 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 74-77
158 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 78-7b
159 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 7c-7f
161 /* Software traps, not handled */
162 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 80-83
163 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 84-87
164 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 88-8b
165 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 8c-8f
166 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 90-93
167 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 94-97
168 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 98-9b
169 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 9c-9f
170 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a0-a3
171 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a4-a7
172 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a8-ab
173 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ac-af
174 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b0-b3
175 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b4-b7
176 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b8-bb
177 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! bc-bf
178 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c0-c3
179 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c4-c7
180 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c8-cb
181 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! cc-cf
182 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d0-d3
183 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d4-d7
184 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d8-db
185 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! dc-df
186 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e0-e3
187 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e4-e7
188 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e8-eb
189 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ec-ef
190 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f0-f3
191 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f4-f7
192 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f8-fb
193 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! fc-ff
199 .extern leon3_snooping_avail
200 .globl version_string
202 .ascii U_BOOT_VERSION
203 .ascii " (", __DATE__, " - ", __TIME__, ")"
204 .ascii CONFIG_IDENT_STRING, "\0"
213 /* Enable I/D-Cache and Snooping */
254 set CFG_INIT_SP_OFFSET, %fp
262 /* un relocated start address of monitor */
263 #define TEXT_START _text
265 /* un relocated end address of monitor */
266 #define DATA_END __init_end
271 set CFG_RELOC_MONITOR_BASE,%g4
288 /* register g4 contain address to start
289 * This means that BSS must be directly after data and code segments
291 * g3 is length of bss = (__bss_end-__bss_start)
296 /* clear bss area (the relocated) */
301 clr %g1 /* std %g0 uses g0 and g1 */
302 /* clearing 16byte a time ==> linker script need to align to 16 byte offset */
311 /* add offsets to GOT table */
316 * new got offset = (old GOT-PTR (read with ld) -
317 * CFG_RELOC_MONITOR_BASE(from define) ) +
318 * Destination Address (from define)
320 set CFG_RELOC_MONITOR_BASE,%g2
326 sub %g2,%g1,%g2 ! prepare register with (new base address) -
329 ld [%g4],%l0 ! load old GOT-PTR
330 add %l0,%g2,%l0 ! increase with (new base address) -
339 set __prom_start, %g2
341 set CFG_PROM_OFFSET, %g4
350 bne prom_relocate_loop
353 /* Trap table has been moved, lets tell CPU about
354 * the new trap table address
357 set CFG_RELOC_MONITOR_BASE, %g2
363 /* If CACHE snooping is available in hardware the
364 * variable leon3_snooping_avail will be set to
368 sethi %hi(0x00800000), %o0
371 sethi %hi(leon3_snooping_avail+CFG_RELOC_MONITOR_BASE-TEXT_BASE), %o1
372 st %o0, [%lo(leon3_snooping_avail+CFG_RELOC_MONITOR_BASE-TEXT_BASE)+%o1]
376 /* Call relocated init functions */
379 set CFG_RELOC_MONITOR_BASE,%o2
386 set CFG_RELOC_MONITOR_BASE,%o2
392 dead: ta 0 ! if call returns...
395 /* Interrupt handler caller,
396 * reg L7: interrupt number
397 * reg L0: psr after interrupt
410 mov %l7, %o0 ! irq level
412 set (CFG_RELOC_MONITOR_BASE-TEXT_BASE), %o2
415 add %sp, SF_REGS_SZ, %o1 ! pt_regs ptr
416 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
417 wr %g2, PSR_ET, %psr ! keep ET up
422 !Window overflow trap handler.
423 .global _window_overflow
427 mov %wim, %l3 ! Calculate next WIM
430 sll %l3, (CFG_SPARC_NWINDOWS-1) , %l4
433 save ! Get into window to be saved.
454 restore ! Go back to trap window.
456 jmp %l1 ! Re-execute save.
459 /* Window underflow trap handler. */
461 .global _window_underflow
465 mov %wim, %l3 ! Calculate next WIM
467 srl %l3, (CFG_SPARC_NWINDOWS-1), %l5
471 restore ! Two restores to get into the
472 restore ! window to restore
473 ld [%sp + 0], %l0; ! Restore window from the stack
489 save ! Get back to the trap window.
491 jmp %l1 ! Re-execute restore.
505 b _hwerr ! loop infinite
508 /* Registers to not touch at all. */
509 #define t_psr l0 /* Set by caller */
510 #define t_pc l1 /* Set by caller */
511 #define t_npc l2 /* Set by caller */
512 #define t_wim l3 /* Set by caller */
513 #define t_twinmask l4 /* Set at beginning of this entry routine. */
514 #define t_kstack l5 /* Set right before pt_regs frame is built */
515 #define t_retpc l6 /* If you change this, change winmacro.h header file */
516 #define t_systable l7 /* Never touch this, could be the syscall table ptr. */
517 #define curptr g6 /* Set after pt_regs frame is built */
520 /* build a pt_regs trap frame. */
521 sub %fp, (SF_REGS_SZ + PT_REGS_SZ), %t_kstack
522 PT_STORE_ALL(t_kstack, t_psr, t_pc, t_npc, g2)
524 /* See if we are in the trap window. */
526 sll %t_twinmask, %t_psr, %t_twinmask ! t_twinmask = (1 << psr)
527 andcc %t_twinmask, %t_wim, %g0
528 beq 1f ! in trap window, clean up
531 /*-------------------------------------------------
532 * Spill , adjust %wim and go.
534 srl %t_wim, 0x1, %g2 ! begin computation of new %wim
536 set (CFG_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
538 sll %t_wim, %g3, %t_wim ! NWINDOWS-1
542 save %g0, %g0, %g0 ! get in window to be saved
544 /* Set new %wim value */
547 /* Save the kernel window onto the corresponding stack. */
550 restore %g0, %g0, %g0
551 /*-------------------------------------------------*/
554 /* Trap from kernel with a window available.
557 jmpl %t_retpc + 0x8, %g0 ! return to caller
558 mov %t_kstack, %sp ! jump onto new stack
564 wr %t_psr, 0x0, %psr ! enable nesting again, clear ET
566 /* Will the rett land us in the invalid window? */
570 set CFG_SPARC_NWINDOWS, %g2 !NWINDOWS
576 be 1f ! Nope, just return from the trap
579 /* We have to grab a window before returning. */
580 set (CFG_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
588 /* Grrr, make sure we load from the right %sp... */
589 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
591 restore %g0, %g0, %g0
596 /* Reload the entire frame in case this is from a
597 * kernel system call or whatever...
600 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
610 /* This is called from relocated C-code.
611 * It resets the system by jumping to _start