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