Stefan Kristiansson | 952db94 | 2011-11-26 19:04:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi> |
| 3 | * (C) Copyright 2011, Julius Baxter <julius@opencores.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 18 | * MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <config.h> |
| 22 | #include <asm-offsets.h> |
| 23 | #include <asm/spr-defs.h> |
| 24 | |
| 25 | #define EXCEPTION_STACK_SIZE (128+128) |
| 26 | |
| 27 | #define HANDLE_EXCEPTION \ |
| 28 | l.addi r1, r1, -EXCEPTION_STACK_SIZE ;\ |
| 29 | l.sw 0x1c(r1), r9 ;\ |
| 30 | l.jal _exception_handler ;\ |
| 31 | l.nop ;\ |
| 32 | l.lwz r9, 0x1c(r1) ;\ |
| 33 | l.addi r1, r1, EXCEPTION_STACK_SIZE ;\ |
| 34 | l.rfe ;\ |
| 35 | l.nop |
| 36 | |
| 37 | .section .vectors, "ax" |
| 38 | .global __reset |
| 39 | |
| 40 | /* reset */ |
| 41 | .org 0x100 |
| 42 | __reset: |
| 43 | /* there is no guarantee r0 is hardwired to zero, clear it here */ |
| 44 | l.andi r0, r0, 0 |
| 45 | /* reset stack and frame pointers */ |
| 46 | l.andi r1, r0, 0 |
| 47 | l.andi r2, r0, 0 |
| 48 | |
| 49 | /* set supervisor mode */ |
| 50 | l.ori r3,r0,SPR_SR_SM |
| 51 | l.mtspr r0,r3,SPR_SR |
| 52 | |
| 53 | /* Relocate u-boot */ |
| 54 | l.movhi r3,hi(__start) /* source start address */ |
| 55 | l.ori r3,r3,lo(__start) |
| 56 | l.movhi r4,hi(_stext) /* dest start address */ |
| 57 | l.ori r4,r4,lo(_stext) |
| 58 | l.movhi r5,hi(__end) /* dest end address */ |
| 59 | l.ori r5,r5,lo(__end) |
| 60 | |
| 61 | .L_reloc: |
| 62 | l.lwz r6,0(r3) |
| 63 | l.sw 0(r4),r6 |
| 64 | l.addi r3,r3,4 |
| 65 | l.sfltu r4,r5 |
| 66 | l.bf .L_reloc |
| 67 | l.addi r4,r4,4 /* delay slot */ |
| 68 | |
| 69 | #ifdef CONFIG_SYS_RELOCATE_VECTORS |
| 70 | /* Relocate vectors from 0xf0000000 to 0x00000000 */ |
| 71 | l.movhi r4, 0xf000 /* source */ |
| 72 | l.movhi r5, 0 /* destination */ |
| 73 | l.addi r6, r5, CONFIG_SYS_VECTORS_LEN /* length */ |
| 74 | .L_relocvectors: |
| 75 | l.lwz r7, 0(r4) |
| 76 | l.sw 0(r5), r7 |
| 77 | l.addi r5, r5, 4 |
| 78 | l.sfeq r5,r6 |
| 79 | l.bnf .L_relocvectors |
| 80 | l.addi r4,r4, 4 |
| 81 | #endif |
| 82 | |
| 83 | l.j _start |
| 84 | l.nop |
| 85 | |
| 86 | /* bus error */ |
| 87 | .org 0x200 |
| 88 | HANDLE_EXCEPTION |
| 89 | |
| 90 | /* data page fault */ |
| 91 | .org 0x300 |
| 92 | HANDLE_EXCEPTION |
| 93 | |
| 94 | /* instruction page fault */ |
| 95 | .org 0x400 |
| 96 | HANDLE_EXCEPTION |
| 97 | |
| 98 | /* tick timer */ |
| 99 | .org 0x500 |
| 100 | HANDLE_EXCEPTION |
| 101 | |
| 102 | /* alignment */ |
| 103 | .org 0x600 |
| 104 | HANDLE_EXCEPTION |
| 105 | |
| 106 | /* illegal instruction */ |
| 107 | .org 0x700 |
| 108 | HANDLE_EXCEPTION |
| 109 | |
| 110 | /* external interrupt */ |
| 111 | .org 0x800 |
| 112 | HANDLE_EXCEPTION |
| 113 | |
| 114 | /* D-TLB miss */ |
| 115 | .org 0x900 |
| 116 | HANDLE_EXCEPTION |
| 117 | |
| 118 | /* I-TLB miss */ |
| 119 | .org 0xa00 |
| 120 | HANDLE_EXCEPTION |
| 121 | |
| 122 | /* range */ |
| 123 | .org 0xb00 |
| 124 | HANDLE_EXCEPTION |
| 125 | |
| 126 | /* system call */ |
| 127 | .org 0xc00 |
| 128 | HANDLE_EXCEPTION |
| 129 | |
| 130 | /* floating point */ |
| 131 | .org 0xd00 |
| 132 | HANDLE_EXCEPTION |
| 133 | |
| 134 | /* trap */ |
| 135 | .org 0xe00 |
| 136 | HANDLE_EXCEPTION |
| 137 | |
| 138 | /* reserved */ |
| 139 | .org 0xf00 |
| 140 | HANDLE_EXCEPTION |
| 141 | |
| 142 | /* reserved */ |
| 143 | .org 0x1100 |
| 144 | HANDLE_EXCEPTION |
| 145 | |
| 146 | /* reserved */ |
| 147 | .org 0x1200 |
| 148 | HANDLE_EXCEPTION |
| 149 | |
| 150 | /* reserved */ |
| 151 | .org 0x1300 |
| 152 | HANDLE_EXCEPTION |
| 153 | |
| 154 | /* reserved */ |
| 155 | .org 0x1400 |
| 156 | HANDLE_EXCEPTION |
| 157 | |
| 158 | /* reserved */ |
| 159 | .org 0x1500 |
| 160 | HANDLE_EXCEPTION |
| 161 | |
| 162 | /* reserved */ |
| 163 | .org 0x1600 |
| 164 | HANDLE_EXCEPTION |
| 165 | |
| 166 | /* reserved */ |
| 167 | .org 0x1700 |
| 168 | HANDLE_EXCEPTION |
| 169 | |
| 170 | /* reserved */ |
| 171 | .org 0x1800 |
| 172 | HANDLE_EXCEPTION |
| 173 | |
| 174 | /* reserved */ |
| 175 | .org 0x1900 |
| 176 | HANDLE_EXCEPTION |
| 177 | |
| 178 | /* reserved */ |
| 179 | .org 0x1a00 |
| 180 | HANDLE_EXCEPTION |
| 181 | |
| 182 | /* reserved */ |
| 183 | .org 0x1b00 |
| 184 | HANDLE_EXCEPTION |
| 185 | |
| 186 | /* reserved */ |
| 187 | .org 0x1c00 |
| 188 | HANDLE_EXCEPTION |
| 189 | |
| 190 | /* reserved */ |
| 191 | .org 0x1d00 |
| 192 | HANDLE_EXCEPTION |
| 193 | |
| 194 | /* reserved */ |
| 195 | .org 0x1e00 |
| 196 | HANDLE_EXCEPTION |
| 197 | |
| 198 | /* reserved */ |
| 199 | .org 0x1f00 |
| 200 | HANDLE_EXCEPTION |
| 201 | |
| 202 | /* Startup routine */ |
| 203 | .text |
| 204 | .global _start |
| 205 | _start: |
| 206 | /* Init stack and frame pointers */ |
| 207 | l.movhi r1, hi(CONFIG_SYS_INIT_SP_ADDR) |
| 208 | l.ori r1, r1, lo(CONFIG_SYS_INIT_SP_ADDR) |
| 209 | l.or r2, r0, r1 |
| 210 | |
| 211 | /* clear BSS segments */ |
| 212 | l.movhi r4, hi(_bss_start) |
| 213 | l.ori r4, r4, lo(_bss_start) |
| 214 | l.movhi r5, hi(_bss_end) |
| 215 | l.ori r5, r5, lo(_bss_end) |
| 216 | .L_clear_bss: |
| 217 | l.sw 0(r4), r0 |
| 218 | l.sfltu r4,r5 |
| 219 | l.bf .L_clear_bss |
| 220 | l.addi r4,r4,4 |
| 221 | |
| 222 | /* Reset registers before jumping to board_init */ |
| 223 | l.andi r3, r0, 0 |
| 224 | l.andi r4, r0, 0 |
| 225 | l.andi r5, r0, 0 |
| 226 | l.andi r6, r0, 0 |
| 227 | l.andi r7, r0, 0 |
| 228 | l.andi r8, r0, 0 |
| 229 | l.andi r9, r0, 0 |
| 230 | l.andi r10, r0, 0 |
| 231 | l.andi r11, r0, 0 |
| 232 | l.andi r12, r0, 0 |
| 233 | l.andi r13, r0, 0 |
| 234 | l.andi r14, r0, 0 |
| 235 | l.andi r15, r0, 0 |
| 236 | l.andi r17, r0, 0 |
| 237 | l.andi r18, r0, 0 |
| 238 | l.andi r19, r0, 0 |
| 239 | l.andi r20, r0, 0 |
| 240 | l.andi r21, r0, 0 |
| 241 | l.andi r22, r0, 0 |
| 242 | l.andi r23, r0, 0 |
| 243 | l.andi r24, r0, 0 |
| 244 | l.andi r25, r0, 0 |
| 245 | l.andi r26, r0, 0 |
| 246 | l.andi r27, r0, 0 |
| 247 | l.andi r28, r0, 0 |
| 248 | l.andi r29, r0, 0 |
| 249 | l.andi r30, r0, 0 |
| 250 | l.andi r31, r0, 0 |
| 251 | |
| 252 | l.j board_init |
| 253 | l.nop |
| 254 | |
| 255 | .size _start, .-_start |
| 256 | |
| 257 | /* |
| 258 | * Store state onto stack and call the real exception handler |
| 259 | */ |
| 260 | .section .text |
| 261 | .extern exception_handler |
| 262 | .type _exception_handler,@function |
| 263 | |
| 264 | _exception_handler: |
| 265 | /* Store state (r9 already saved)*/ |
| 266 | l.sw 0x00(r1), r2 |
| 267 | l.sw 0x04(r1), r3 |
| 268 | l.sw 0x08(r1), r4 |
| 269 | l.sw 0x0c(r1), r5 |
| 270 | l.sw 0x10(r1), r6 |
| 271 | l.sw 0x14(r1), r7 |
| 272 | l.sw 0x18(r1), r8 |
| 273 | l.sw 0x20(r1), r10 |
| 274 | l.sw 0x24(r1), r11 |
| 275 | l.sw 0x28(r1), r12 |
| 276 | l.sw 0x2c(r1), r13 |
| 277 | l.sw 0x30(r1), r14 |
| 278 | l.sw 0x34(r1), r15 |
| 279 | l.sw 0x38(r1), r16 |
| 280 | l.sw 0x3c(r1), r17 |
| 281 | l.sw 0x40(r1), r18 |
| 282 | l.sw 0x44(r1), r19 |
| 283 | l.sw 0x48(r1), r20 |
| 284 | l.sw 0x4c(r1), r21 |
| 285 | l.sw 0x50(r1), r22 |
| 286 | l.sw 0x54(r1), r23 |
| 287 | l.sw 0x58(r1), r24 |
| 288 | l.sw 0x5c(r1), r25 |
| 289 | l.sw 0x60(r1), r26 |
| 290 | l.sw 0x64(r1), r27 |
| 291 | l.sw 0x68(r1), r28 |
| 292 | l.sw 0x6c(r1), r29 |
| 293 | l.sw 0x70(r1), r30 |
| 294 | l.sw 0x74(r1), r31 |
| 295 | |
| 296 | /* Save return address */ |
| 297 | l.or r14, r0, r9 |
| 298 | /* Call exception handler with the link address as argument */ |
| 299 | l.jal exception_handler |
| 300 | l.or r3, r0, r14 |
| 301 | /* Load return address */ |
| 302 | l.or r9, r0, r14 |
| 303 | |
| 304 | /* Restore state */ |
| 305 | l.lwz r2, 0x00(r1) |
| 306 | l.lwz r3, 0x04(r1) |
| 307 | l.lwz r4, 0x08(r1) |
| 308 | l.lwz r5, 0x0c(r1) |
| 309 | l.lwz r6, 0x10(r1) |
| 310 | l.lwz r7, 0x14(r1) |
| 311 | l.lwz r8, 0x18(r1) |
| 312 | l.lwz r10, 0x20(r1) |
| 313 | l.lwz r11, 0x24(r1) |
| 314 | l.lwz r12, 0x28(r1) |
| 315 | l.lwz r13, 0x2c(r1) |
| 316 | l.lwz r14, 0x30(r1) |
| 317 | l.lwz r15, 0x34(r1) |
| 318 | l.lwz r16, 0x38(r1) |
| 319 | l.lwz r17, 0x3c(r1) |
| 320 | l.lwz r18, 0x40(r1) |
| 321 | l.lwz r19, 0x44(r1) |
| 322 | l.lwz r20, 0x48(r1) |
| 323 | l.lwz r21, 0x4c(r1) |
| 324 | l.lwz r22, 0x50(r1) |
| 325 | l.lwz r23, 0x54(r1) |
| 326 | l.lwz r24, 0x58(r1) |
| 327 | l.lwz r25, 0x5c(r1) |
| 328 | l.lwz r26, 0x60(r1) |
| 329 | l.lwz r27, 0x64(r1) |
| 330 | l.lwz r28, 0x68(r1) |
| 331 | l.lwz r29, 0x6c(r1) |
| 332 | l.lwz r30, 0x70(r1) |
| 333 | l.lwz r31, 0x74(r1) |
| 334 | l.jr r9 |
| 335 | l.nop |