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>
30 #include <timestamp.h>
33 /* Entry for traps which jump to a programmer-specified trap handler. */
35 wr %g0, 0xfe0, %psr; \
45 #define TRAPI(ilevel) \
51 /* Unexcpected trap will halt the processor by forcing it to error state */
53 #define BAD_TRAP ta 0; nop; nop; nop;
55 /* Software trap. Treat as BAD_TRAP for the time being... */
56 #define SOFT_TRAP TRAP(_hwerr)
58 #define PSR_INIT 0x1FC0 /* Disable traps, set s and ps */
61 /* All traps low-level code here must end with this macro. */
62 #define RESTORE_ALL b ret_trap_entry; clr %l6;
64 #define WRITE_PAUSE nop;nop;nop
68 ARGPUSH = (WINDOWSIZE + 4)
69 MINFRAME = (WINDOWSIZE + ARGPUSHSIZE + 4)
71 /* Number of register windows */
72 #ifndef CONFIG_SYS_SPARC_NWINDOWS
73 #error Must define number of SPARC register windows, default is 8
77 #define SA(X) (((X)+(STACK_ALIGN-1)) & ~(STACK_ALIGN-1))
79 .section ".start", "ax"
80 .globl _start, start, _trap_table
81 .globl _irq_entry, nmi_trap
90 TRAPR(_hardreset); ! 00 reset trap
91 BAD_TRAP; ! 01 instruction_access_exception
92 BAD_TRAP; ! 02 illegal_instruction
93 BAD_TRAP; ! 03 priveleged_instruction
94 BAD_TRAP; ! 04 fp_disabled
95 TRAP(_window_overflow); ! 05 window_overflow
96 TRAP(_window_underflow); ! 06 window_underflow
97 BAD_TRAP; ! 07 Memory Address Not Aligned
98 BAD_TRAP; ! 08 Floating Point Exception
99 BAD_TRAP; ! 09 Data Miss Exception
100 BAD_TRAP; ! 0a Tagged Instruction Ovrflw
101 BAD_TRAP; ! 0b Watchpoint Detected
107 TRAPI(1); ! 11 IRQ level 1
108 TRAPI(2); ! 12 IRQ level 2
109 TRAPI(3); ! 13 IRQ level 3
110 TRAPI(4); ! 14 IRQ level 4
111 TRAPI(5); ! 15 IRQ level 5
112 TRAPI(6); ! 16 IRQ level 6
113 TRAPI(7); ! 17 IRQ level 7
114 TRAPI(8); ! 18 IRQ level 8
115 TRAPI(9); ! 19 IRQ level 9
116 TRAPI(10); ! 1a IRQ level 10
117 TRAPI(11); ! 1b IRQ level 11
118 TRAPI(12); ! 1c IRQ level 12
119 TRAPI(13); ! 1d IRQ level 13
120 TRAPI(14); ! 1e IRQ level 14
121 TRAP(_nmi_trap); ! 1f IRQ level 15 /
122 ! NMI (non maskable interrupt)
123 BAD_TRAP; ! 20 r_register_access_error
124 BAD_TRAP; ! 21 instruction access error
127 BAD_TRAP; ! 24 co-processor disabled
128 BAD_TRAP; ! 25 uniplemented FLUSH
131 BAD_TRAP; ! 28 co-processor exception
132 BAD_TRAP; ! 29 data access error
133 BAD_TRAP; ! 2a division by zero
134 BAD_TRAP; ! 2b data store error
135 BAD_TRAP; ! 2c data access MMU miss
139 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 30-33
140 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 34-37
141 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 38-3b
142 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 3c-3f
143 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 40-43
144 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 44-47
145 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 48-4b
146 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 4c-4f
147 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 50-53
148 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 54-57
149 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 58-5b
150 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 5c-5f
152 /* implementaion dependent */
153 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 60-63
154 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 64-67
155 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 68-6b
156 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 6c-6f
157 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 70-73
158 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 74-77
159 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 78-7b
160 BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 7c-7f
162 /* Software traps, not handled */
163 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 80-83
164 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 84-87
165 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 88-8b
166 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 8c-8f
167 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 90-93
168 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 94-97
169 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 98-9b
170 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! 9c-9f
171 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a0-a3
172 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a4-a7
173 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! a8-ab
174 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ac-af
175 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b0-b3
176 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b4-b7
177 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! b8-bb
178 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! bc-bf
179 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c0-c3
180 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c4-c7
181 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! c8-cb
182 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! cc-cf
183 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d0-d3
184 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d4-d7
185 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! d8-db
186 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! dc-df
187 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e0-e3
188 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e4-e7
189 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! e8-eb
190 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! ec-ef
191 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f0-f3
192 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f4-f7
193 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! f8-fb
194 SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; ! fc-ff
200 .globl version_string
202 .ascii U_BOOT_VERSION
203 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
204 .ascii CONFIG_IDENT_STRING, "\0"
217 set (LEON2_PREGS+LEON_REG_CACHECTRL_OFFSET), %g1
254 /* LEON2 Register Base in g1 */
258 /* Set Cache control register */
264 /* Clear LEON2 registers */
265 st %g0, [%g1 + LEON2_ECTRL]
266 st %g0, [%g1 + LEON2_IMASK]
267 st %g0, [%g1 + LEON2_IPEND]
268 st %g0, [%g1 + LEON2_IFORCE]
269 st %g0, [%g1 + LEON2_ICLEAR]
270 st %g0, [%g1 + LEON2_IOREG]
271 st %g0, [%g1 + LEON2_IODIR]
272 st %g0, [%g1 + LEON2_IOICONF]
273 st %g0, [%g1 + LEON2_UCTRL0]
274 st %g0, [%g1 + LEON2_UCTRL1]
277 /* I/O port initialization */
279 st %g2, [%g1 + LEON2_IOREG]
283 /* memory config register 1 */
284 set CONFIG_SYS_GRLIB_MEMCFG1, %g2
288 st %g2, [%g1 + LEON2_MCFG1]
289 set CONFIG_SYS_GRLIB_MEMCFG2, %g2 ! Load memory config register 2
290 #if !( defined(TSIM) || !defined(BZIMAGE))
291 st %g2, [%g1 + LEON2_MCFG2] ! only for prom version, else done by "dumon -i"
293 set CONFIG_SYS_GRLIB_MEMCFG3, %g2 ! Init FT register
294 st %g2, [%g1 + LEON2_ECTRL]
295 ld [%g1 + LEON2_ECTRL], %g2
299 mov %g0, %asr16 ! clear err_reg
314 set CONFIG_SYS_INIT_SP_OFFSET, %fp
322 /* un relocated start address of monitor */
323 #define TEXT_START _text
325 /* un relocated end address of monitor */
326 #define DATA_END __init_end
331 set CONFIG_SYS_RELOC_MONITOR_BASE,%g4
348 /* register g4 contain address to start
349 * This means that BSS must be directly after data and code segments
351 * g3 is length of bss = (__bss_end-__bss_start)
356 /* clear bss area (the relocated) */
361 clr %g1 /* std %g0 uses g0 and g1 */
362 /* clearing 16byte a time ==> linker script need to align to 16 byte offset */
371 /* add offsets to GOT table */
376 * new got offset = (old GOT-PTR (read with ld) -
377 * CONFIG_SYS_RELOC_MONITOR_BASE(from define) ) +
378 * Destination Address (from define)
380 set CONFIG_SYS_RELOC_MONITOR_BASE,%g2
386 sub %g2,%g1,%g2 ! prepare register with (new base address) -
389 ld [%g4],%l0 ! load old GOT-PTR
390 add %l0,%g2,%l0 ! increase with (new base address) -
399 set __prom_start, %g2
401 set CONFIG_SYS_PROM_OFFSET, %g4
410 bne prom_relocate_loop
413 /* Trap table has been moved, lets tell CPU about
414 * the new trap table address
417 set CONFIG_SYS_RELOC_MONITOR_BASE, %g2
422 /* Call relocated init functions */
425 set CONFIG_SYS_RELOC_MONITOR_BASE,%o2
432 set CONFIG_SYS_RELOC_MONITOR_BASE,%o2
438 dead: ta 0 ! if call returns...
441 /* Interrupt handler caller,
442 * reg L7: interrupt number
443 * reg L0: psr after interrupt
456 mov %l7, %o0 ! irq level
458 set (CONFIG_SYS_RELOC_MONITOR_BASE-TEXT_BASE), %o2
461 add %sp, SF_REGS_SZ, %o1 ! pt_regs ptr
462 or %l0, PSR_PIL, %g2 ! restore PIL after handler_irq
463 wr %g2, PSR_ET, %psr ! keep ET up
468 !Window overflow trap handler.
469 .global _window_overflow
473 mov %wim, %l3 ! Calculate next WIM
476 sll %l3, (CONFIG_SYS_SPARC_NWINDOWS-1) , %l4
479 save ! Get into window to be saved.
500 restore ! Go back to trap window.
502 jmp %l1 ! Re-execute save.
505 /* Window underflow trap handler. */
507 .global _window_underflow
511 mov %wim, %l3 ! Calculate next WIM
513 srl %l3, (CONFIG_SYS_SPARC_NWINDOWS-1), %l5
517 restore ! Two restores to get into the
518 restore ! window to restore
519 ld [%sp + 0], %l0; ! Restore window from the stack
535 save ! Get back to the trap window.
537 jmp %l1 ! Re-execute restore.
551 b _hwerr ! loop infinite
554 /* Registers to not touch at all. */
555 #define t_psr l0 /* Set by caller */
556 #define t_pc l1 /* Set by caller */
557 #define t_npc l2 /* Set by caller */
558 #define t_wim l3 /* Set by caller */
559 #define t_twinmask l4 /* Set at beginning of this entry routine. */
560 #define t_kstack l5 /* Set right before pt_regs frame is built */
561 #define t_retpc l6 /* If you change this, change winmacro.h header file */
562 #define t_systable l7 /* Never touch this, could be the syscall table ptr. */
563 #define curptr g6 /* Set after pt_regs frame is built */
566 /* build a pt_regs trap frame. */
567 sub %fp, (SF_REGS_SZ + PT_REGS_SZ), %t_kstack
568 PT_STORE_ALL(t_kstack, t_psr, t_pc, t_npc, g2)
570 /* See if we are in the trap window. */
572 sll %t_twinmask, %t_psr, %t_twinmask ! t_twinmask = (1 << psr)
573 andcc %t_twinmask, %t_wim, %g0
574 beq 1f ! in trap window, clean up
577 /*-------------------------------------------------
578 * Spill , adjust %wim and go.
580 srl %t_wim, 0x1, %g2 ! begin computation of new %wim
582 set (CONFIG_SYS_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
584 sll %t_wim, %g3, %t_wim ! NWINDOWS-1
588 save %g0, %g0, %g0 ! get in window to be saved
590 /* Set new %wim value */
593 /* Save the kernel window onto the corresponding stack. */
596 restore %g0, %g0, %g0
597 /*-------------------------------------------------*/
600 /* Trap from kernel with a window available.
603 jmpl %t_retpc + 0x8, %g0 ! return to caller
604 mov %t_kstack, %sp ! jump onto new stack
610 wr %t_psr, 0x0, %psr ! enable nesting again, clear ET
612 /* Will the rett land us in the invalid window? */
616 set CONFIG_SYS_SPARC_NWINDOWS, %g2 !NWINDOWS
622 be 1f ! Nope, just return from the trap
625 /* We have to grab a window before returning. */
626 set (CONFIG_SYS_SPARC_NWINDOWS-1), %g3 !NWINDOWS-1
634 /* Grrr, make sure we load from the right %sp... */
635 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
637 restore %g0, %g0, %g0
642 /* Reload the entire frame in case this is from a
643 * kernel system call or whatever...
646 PT_LOAD_ALL(sp, t_psr, t_pc, t_npc, g1)
656 /* This is called from relocated C-code.
657 * It resets the system by jumping to _start