wdenk | 0442ed8 | 2002-11-03 10:24:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 1998 Dan Malek <dmalek@jlc.net> |
| 3 | * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> |
| 4 | * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | /*------------------------------------------------------------------------------+ */ |
| 25 | /* */ |
| 26 | /* This source code has been made available to you by IBM on an AS-IS */ |
| 27 | /* basis. Anyone receiving this source is licensed under IBM */ |
| 28 | /* copyrights to use it in any way he or she deems fit, including */ |
| 29 | /* copying it, modifying it, compiling it, and redistributing it either */ |
| 30 | /* with or without modifications. No license under IBM patents or */ |
| 31 | /* patent applications is to be implied by the copyright license. */ |
| 32 | /* */ |
| 33 | /* Any user of this software should understand that IBM cannot provide */ |
| 34 | /* technical support for this software and will not be responsible for */ |
| 35 | /* any consequences resulting from the use of this software. */ |
| 36 | /* */ |
| 37 | /* Any person who transfers this source code or any derivative work */ |
| 38 | /* must include the IBM copyright notice, this paragraph, and the */ |
| 39 | /* preceding two paragraphs in the transferred software. */ |
| 40 | /* */ |
| 41 | /* COPYRIGHT I B M CORPORATION 1995 */ |
| 42 | /* LICENSED MATERIAL - PROGRAM PROPERTY OF I B M */ |
| 43 | /*------------------------------------------------------------------------------- */ |
| 44 | |
| 45 | /* U-Boot - Startup Code for IBM 4xx PowerPC based Embedded Boards |
| 46 | * |
| 47 | * |
| 48 | * The processor starts at 0xfffffffc and the code is executed |
| 49 | * from flash/rom. |
| 50 | * in memory, but as long we don't jump around before relocating. |
| 51 | * board_init lies at a quite high address and when the cpu has |
| 52 | * jumped there, everything is ok. |
| 53 | * This works because the cpu gives the FLASH (CS0) the whole |
| 54 | * address space at startup, and board_init lies as a echo of |
| 55 | * the flash somewhere up there in the memorymap. |
| 56 | * |
| 57 | * board_init will change CS0 to be positioned at the correct |
| 58 | * address and (s)dram will be positioned at address 0 |
| 59 | */ |
| 60 | #include <config.h> |
| 61 | #include <mpc8xx.h> |
| 62 | #include <ppc4xx.h> |
| 63 | #include <version.h> |
| 64 | |
| 65 | #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */ |
| 66 | |
| 67 | #include <ppc_asm.tmpl> |
| 68 | #include <ppc_defs.h> |
| 69 | |
| 70 | #include <asm/cache.h> |
| 71 | #include <asm/mmu.h> |
| 72 | |
| 73 | #ifndef CONFIG_IDENT_STRING |
| 74 | #define CONFIG_IDENT_STRING "" |
| 75 | #endif |
| 76 | |
| 77 | #ifdef CFG_INIT_DCACHE_CS |
| 78 | # if (CFG_INIT_DCACHE_CS == 0) |
| 79 | # define PBxAP pb0ap |
| 80 | # define PBxCR pb0cr |
| 81 | # endif |
| 82 | # if (CFG_INIT_DCACHE_CS == 1) |
| 83 | # define PBxAP pb1ap |
| 84 | # define PBxCR pb1cr |
| 85 | # endif |
| 86 | # if (CFG_INIT_DCACHE_CS == 2) |
| 87 | # define PBxAP pb2ap |
| 88 | # define PBxCR pb2cr |
| 89 | # endif |
| 90 | # if (CFG_INIT_DCACHE_CS == 3) |
| 91 | # define PBxAP pb3ap |
| 92 | # define PBxCR pb3cr |
| 93 | # endif |
| 94 | # if (CFG_INIT_DCACHE_CS == 4) |
| 95 | # define PBxAP pb4ap |
| 96 | # define PBxCR pb4cr |
| 97 | # endif |
| 98 | # if (CFG_INIT_DCACHE_CS == 5) |
| 99 | # define PBxAP pb5ap |
| 100 | # define PBxCR pb5cr |
| 101 | # endif |
| 102 | # if (CFG_INIT_DCACHE_CS == 6) |
| 103 | # define PBxAP pb6ap |
| 104 | # define PBxCR pb6cr |
| 105 | # endif |
| 106 | # if (CFG_INIT_DCACHE_CS == 7) |
| 107 | # define PBxAP pb7ap |
| 108 | # define PBxCR pb7cr |
| 109 | # endif |
| 110 | #endif /* CFG_INIT_DCACHE_CS */ |
| 111 | |
| 112 | /* We don't want the MMU yet. |
| 113 | */ |
| 114 | #undef MSR_KERNEL |
| 115 | #define MSR_KERNEL ( MSR_ME ) /* Machine Check */ |
| 116 | |
| 117 | |
| 118 | .extern ext_bus_cntlr_init |
| 119 | .extern sdram_init |
| 120 | |
| 121 | /* |
| 122 | * Set up GOT: Global Offset Table |
| 123 | * |
| 124 | * Use r14 to access the GOT |
| 125 | */ |
| 126 | START_GOT |
| 127 | GOT_ENTRY(_GOT2_TABLE_) |
| 128 | GOT_ENTRY(_FIXUP_TABLE_) |
| 129 | |
| 130 | GOT_ENTRY(_start) |
| 131 | GOT_ENTRY(_start_of_vectors) |
| 132 | GOT_ENTRY(_end_of_vectors) |
| 133 | GOT_ENTRY(transfer_to_handler) |
| 134 | |
| 135 | GOT_ENTRY(_end) |
| 136 | GOT_ENTRY(.bss) |
| 137 | END_GOT |
| 138 | |
| 139 | /* |
| 140 | * 440 Startup -- on reset only the top 4k of the effective |
| 141 | * address space is mapped in by an entry in the instruction |
| 142 | * and data shadow TLB. The .bootpg section is located in the |
| 143 | * top 4k & does only what's necessary to map in the the rest |
| 144 | * of the boot rom. Once the boot rom is mapped in we can |
| 145 | * proceed with normal startup. |
| 146 | * |
| 147 | * NOTE: CS0 only covers the top 2MB of the effective address |
| 148 | * space after reset. |
| 149 | */ |
| 150 | |
| 151 | #if defined(CONFIG_440) |
| 152 | .section .bootpg,"ax" |
| 153 | .globl _start_440 |
| 154 | |
| 155 | /**************************************************************************/ |
| 156 | _start_440: |
| 157 | /*----------------------------------------------------------------*/ |
| 158 | /* Clear and set up some registers. */ |
| 159 | /*----------------------------------------------------------------*/ |
| 160 | iccci r0,r0 /* NOTE: operands not used for 440 */ |
| 161 | dccci r0,r0 /* NOTE: operands not used for 440 */ |
| 162 | sync |
| 163 | li r0,0 |
| 164 | mtspr srr0,r0 |
| 165 | mtspr srr1,r0 |
| 166 | mtspr csrr0,r0 |
| 167 | mtspr csrr1,r0 |
| 168 | |
| 169 | /*----------------------------------------------------------------*/ |
| 170 | /* Initialize debug */ |
| 171 | /*----------------------------------------------------------------*/ |
| 172 | mtspr dbcr0,r0 |
| 173 | mtspr dbcr1,r0 |
| 174 | mtspr dbcr2,r0 |
| 175 | mtspr iac1,r0 |
| 176 | mtspr iac2,r0 |
| 177 | mtspr iac3,r0 |
| 178 | mtspr dac1,r0 |
| 179 | mtspr dac2,r0 |
| 180 | mtspr dvc1,r0 |
| 181 | mtspr dvc2,r0 |
| 182 | |
| 183 | mfspr r1,dbsr |
| 184 | mtspr dbsr,r1 /* Clear all valid bits */ |
| 185 | |
| 186 | /*----------------------------------------------------------------*/ |
| 187 | /* CCR0 init */ |
| 188 | /*----------------------------------------------------------------*/ |
| 189 | /* Disable store gathering & broadcast, guarantee inst/data |
| 190 | * cache block touch, force load/store alignment |
| 191 | * (see errata 1.12: 440_33) |
| 192 | */ |
| 193 | lis r1,0x0030 /* store gathering & broadcast disable */ |
| 194 | ori r1,r1,0x6000 /* cache touch */ |
| 195 | mtspr ccr0,r1 |
| 196 | |
| 197 | /*----------------------------------------------------------------*/ |
| 198 | /* Setup interrupt vectors */ |
| 199 | /*----------------------------------------------------------------*/ |
| 200 | mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */ |
| 201 | li r1,0x0100 |
| 202 | mtspr ivor0,r1 /* Critical input */ |
| 203 | li r1,0x0200 |
| 204 | mtspr ivor1,r1 /* Machine check */ |
| 205 | li r1,0x0300 |
| 206 | mtspr ivor2,r1 /* Data storage */ |
| 207 | li r1,0x0400 |
| 208 | mtspr ivor3,r1 /* Instruction storage */ |
| 209 | li r1,0x0500 |
| 210 | mtspr ivor4,r1 /* External interrupt */ |
| 211 | li r1,0x0600 |
| 212 | mtspr ivor5,r1 /* Alignment */ |
| 213 | li r1,0x0700 |
| 214 | mtspr ivor6,r1 /* Program check */ |
| 215 | li r1,0x0800 |
| 216 | mtspr ivor7,r1 /* Floating point unavailable */ |
| 217 | li r1,0x0c00 |
| 218 | mtspr ivor8,r1 /* System call */ |
| 219 | li r1,0x1000 |
| 220 | mtspr ivor10,r1 /* Decrementer (PIT for 440) */ |
| 221 | li r1,0x1400 |
| 222 | mtspr ivor13,r1 /* Data TLB error */ |
| 223 | li r1,0x1300 |
| 224 | mtspr ivor14,r1 /* Instr TLB error */ |
| 225 | li r1,0x2000 |
| 226 | mtspr ivor15,r1 /* Debug */ |
| 227 | |
| 228 | /*----------------------------------------------------------------*/ |
| 229 | /* Configure cache regions */ |
| 230 | /*----------------------------------------------------------------*/ |
| 231 | mtspr inv0,r0 |
| 232 | mtspr inv1,r0 |
| 233 | mtspr inv2,r0 |
| 234 | mtspr inv3,r0 |
| 235 | mtspr dnv0,r0 |
| 236 | mtspr dnv1,r0 |
| 237 | mtspr dnv2,r0 |
| 238 | mtspr dnv3,r0 |
| 239 | mtspr itv0,r0 |
| 240 | mtspr itv1,r0 |
| 241 | mtspr itv2,r0 |
| 242 | mtspr itv3,r0 |
| 243 | mtspr dtv0,r0 |
| 244 | mtspr dtv1,r0 |
| 245 | mtspr dtv2,r0 |
| 246 | mtspr dtv3,r0 |
| 247 | |
| 248 | /*----------------------------------------------------------------*/ |
| 249 | /* Cache victim limits */ |
| 250 | /*----------------------------------------------------------------*/ |
| 251 | /* floors 0, ceiling max to use the entire cache -- nothing locked |
| 252 | */ |
| 253 | lis r1,0x0001 |
| 254 | ori r1,r1,0xf800 |
| 255 | mtspr ivlim,r1 |
| 256 | mtspr dvlim,r1 |
| 257 | |
| 258 | /*----------------------------------------------------------------*/ |
| 259 | /* Clear all TLB entries -- TID = 0, TS = 0 */ |
| 260 | /*----------------------------------------------------------------*/ |
| 261 | mtspr mmucr,r0 |
| 262 | li r1,0x003f /* 64 TLB entries */ |
| 263 | mtctr r1 |
| 264 | 0: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/ |
| 265 | subi r1,r1,0x0001 |
| 266 | bdnz 0b |
| 267 | |
| 268 | /*----------------------------------------------------------------*/ |
| 269 | /* TLB entry setup -- step thru tlbtab */ |
| 270 | /*----------------------------------------------------------------*/ |
| 271 | bl tlbtab /* Get tlbtab pointer */ |
| 272 | mr r5,r0 |
| 273 | li r1,0x003f /* 64 TLB entries max */ |
| 274 | mtctr r1 |
| 275 | li r4,0 /* TLB # */ |
| 276 | |
| 277 | addi r5,r5,-4 |
| 278 | 1: lwzu r0,4(r5) |
| 279 | cmpwi r0,0 |
| 280 | beq 2f /* 0 marks end */ |
| 281 | lwzu r1,4(r5) |
| 282 | lwzu r2,4(r5) |
| 283 | tlbwe r0,r4,0 /* TLB Word 0 */ |
| 284 | tlbwe r1,r4,1 /* TLB Word 1 */ |
| 285 | tlbwe r2,r4,2 /* TLB Word 2 */ |
| 286 | addi r4,r4,1 /* Next TLB */ |
| 287 | bdnz 1b |
| 288 | |
| 289 | /*----------------------------------------------------------------*/ |
| 290 | /* Continue from 'normal' start */ |
| 291 | /*----------------------------------------------------------------*/ |
| 292 | 2: bl 3f |
| 293 | b _start |
| 294 | |
| 295 | 3: li r0,0 |
| 296 | mtspr srr1,r0 /* Keep things disabled for now */ |
| 297 | mflr r1 |
| 298 | mtspr srr0,r1 |
| 299 | rfi |
| 300 | #endif |
| 301 | |
| 302 | /* |
| 303 | * r3 - 1st arg to board_init(): IMMP pointer |
| 304 | * r4 - 2nd arg to board_init(): boot flag |
| 305 | */ |
| 306 | .text |
| 307 | .long 0x27051956 /* U-Boot Magic Number */ |
| 308 | .globl version_string |
| 309 | version_string: |
| 310 | .ascii U_BOOT_VERSION |
| 311 | .ascii " (", __DATE__, " - ", __TIME__, ")" |
| 312 | .ascii CONFIG_IDENT_STRING, "\0" |
| 313 | |
| 314 | /* |
| 315 | * Maybe this should be moved somewhere else because the current |
| 316 | * location (0x100) is where the CriticalInput Execption should be. |
| 317 | */ |
| 318 | . = EXC_OFF_SYS_RESET |
| 319 | .globl _start |
| 320 | _start: |
| 321 | |
| 322 | /*****************************************************************************/ |
| 323 | #if defined(CONFIG_440) |
| 324 | |
| 325 | /*----------------------------------------------------------------*/ |
| 326 | /* Clear and set up some registers. */ |
| 327 | /*----------------------------------------------------------------*/ |
| 328 | li r0,0x0000 |
| 329 | lis r1,0xffff |
| 330 | mtspr dec,r0 /* prevent dec exceptions */ |
| 331 | mtspr tbl,r0 /* prevent fit & wdt exceptions */ |
| 332 | mtspr tbu,r0 |
| 333 | mtspr tsr,r1 /* clear all timer exception status */ |
| 334 | mtspr tcr,r0 /* disable all */ |
| 335 | mtspr esr,r0 /* clear exception syndrome register */ |
| 336 | mtxer r0 /* clear integer exception register */ |
| 337 | lis r1,0x0002 /* set CE bit (Critical Exceptions) */ |
| 338 | ori r1,r1,0x1000 /* set ME bit (Machine Exceptions) */ |
| 339 | mtmsr r1 /* change MSR */ |
| 340 | |
| 341 | /*----------------------------------------------------------------*/ |
| 342 | /* Debug setup -- some (not very good) ice's need an event*/ |
| 343 | /* to establish control :-( Define CFG_INIT_DBCR to the dbsr */ |
| 344 | /* value you need in this case 0x8cff 0000 should do the trick */ |
| 345 | /*----------------------------------------------------------------*/ |
| 346 | #if defined(CFG_INIT_DBCR) |
| 347 | lis r1,0xffff |
| 348 | ori r1,r1,0xffff |
| 349 | mtspr dbsr,r1 /* Clear all status bits */ |
| 350 | lis r0,CFG_INIT_DBCR@h |
| 351 | ori r0,r0,CFG_INIT_DBCR@l |
| 352 | mtspr dbcr0,r0 |
| 353 | isync |
| 354 | #endif |
| 355 | |
| 356 | /*----------------------------------------------------------------*/ |
| 357 | /* Setup the internal SRAM */ |
| 358 | /*----------------------------------------------------------------*/ |
| 359 | li r0,0 |
| 360 | mtdcr isram0_sb1cr,r0 /* Disable bank 1 */ |
| 361 | |
| 362 | li r2,0x7fff |
| 363 | ori r2,r2,0xffff |
| 364 | mfdcr r1,isram0_dpc |
| 365 | and r1,r1,r2 /* Disable parity check */ |
| 366 | mtdcr isram0_dpc,r1 |
| 367 | mfdcr r1,isram0_pmeg |
| 368 | andis. r1,r1,r2 /* Disable pwr mgmt */ |
| 369 | mtdcr isram0_pmeg,r1 |
| 370 | |
| 371 | lis r1,0x8000 /* BAS = 8000_0000 */ |
| 372 | ori r1,r1,0x0380 /* 8k rw */ |
| 373 | mtdcr isram0_sb0cr,r1 |
| 374 | |
| 375 | /*----------------------------------------------------------------*/ |
| 376 | /* Setup the stack in internal SRAM */ |
| 377 | /*----------------------------------------------------------------*/ |
| 378 | lis r1,CFG_INIT_RAM_ADDR@h |
| 379 | ori r1,r1,CFG_INIT_SP_OFFSET@l |
| 380 | |
| 381 | li r0,0 |
| 382 | stwu r0,-4(r1) |
| 383 | stwu r0,-4(r1) /* Terminate call chain */ |
| 384 | |
| 385 | stwu r1,-8(r1) /* Save back chain and move SP */ |
| 386 | lis r0,RESET_VECTOR@h /* Address of reset vector */ |
| 387 | ori r0,r0, RESET_VECTOR@l |
| 388 | stwu r1,-8(r1) /* Save back chain and move SP */ |
| 389 | stw r0,+12(r1) /* Save return addr (underflow vect) */ |
| 390 | |
| 391 | GET_GOT |
| 392 | bl board_init_f |
| 393 | |
| 394 | #endif /* CONFIG_440 */ |
| 395 | |
| 396 | /*****************************************************************************/ |
| 397 | #ifdef CONFIG_IOP480 |
| 398 | /*----------------------------------------------------------------------- */ |
| 399 | /* Set up some machine state registers. */ |
| 400 | /*----------------------------------------------------------------------- */ |
| 401 | addi r0,r0,0x0000 /* initialize r0 to zero */ |
| 402 | mtspr esr,r0 /* clear Exception Syndrome Reg */ |
| 403 | mttcr r0 /* timer control register */ |
| 404 | mtexier r0 /* disable all interrupts */ |
| 405 | addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */ |
| 406 | oris r4,r4,0x2 /* set CE bit (Critical Exceptions) */ |
| 407 | mtmsr r4 /* change MSR */ |
| 408 | addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */ |
| 409 | ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */ |
| 410 | mtdbsr r4 /* clear/reset the dbsr */ |
| 411 | mtexisr r4 /* clear all pending interrupts */ |
| 412 | addis r4,r0,0x8000 |
| 413 | mtexier r4 /* enable critical exceptions */ |
| 414 | addis r4,r0,0x0000 /* assume 403GCX - enable core clk */ |
| 415 | ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */ |
| 416 | mtiocr r4 /* since bit not used) & DRC to latch */ |
| 417 | /* data bus on rising edge of CAS */ |
| 418 | /*----------------------------------------------------------------------- */ |
| 419 | /* Clear XER. */ |
| 420 | /*----------------------------------------------------------------------- */ |
| 421 | mtxer r0 |
| 422 | /*----------------------------------------------------------------------- */ |
| 423 | /* Invalidate i-cache and d-cache TAG arrays. */ |
| 424 | /*----------------------------------------------------------------------- */ |
| 425 | addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */ |
| 426 | addi r4,0,1024 /* 1/4 of I-cache */ |
| 427 | ..cloop: |
| 428 | iccci 0,r3 |
| 429 | iccci r4,r3 |
| 430 | dccci 0,r3 |
| 431 | addic. r3,r3,-16 /* move back one cache line */ |
| 432 | bne ..cloop /* loop back to do rest until r3 = 0 */ |
| 433 | |
| 434 | /* */ |
| 435 | /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */ |
| 436 | /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */ |
| 437 | /* */ |
| 438 | |
| 439 | /* first copy IOP480 register base address into r3 */ |
| 440 | addis r3,0,0x5000 /* IOP480 register base address hi */ |
| 441 | /* ori r3,r3,0x0000 / IOP480 register base address lo */ |
| 442 | |
| 443 | #ifdef CONFIG_ADCIOP |
| 444 | /* use r4 as the working variable */ |
| 445 | /* turn on CS3 (LOCCTL.7) */ |
| 446 | lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */ |
| 447 | andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */ |
| 448 | stw r4,0x84(r3) /* LOCTL is at offset 0x84 */ |
| 449 | #endif |
| 450 | |
| 451 | #ifdef CONFIG_DASA_SIM |
| 452 | /* use r4 as the working variable */ |
| 453 | /* turn on MA17 (LOCCTL.7) */ |
| 454 | lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */ |
| 455 | ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */ |
| 456 | stw r4,0x84(r3) /* LOCTL is at offset 0x84 */ |
| 457 | #endif |
| 458 | |
| 459 | /* turn on MA16..13 (LCS0BRD.12 = 0) */ |
| 460 | lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */ |
| 461 | andi. r4,r4,0xefff /* make bit 12 = 0 */ |
| 462 | stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */ |
| 463 | |
| 464 | /* make sure above stores all comlete before going on */ |
| 465 | sync |
| 466 | |
| 467 | /* last thing, set local init status done bit (DEVINIT.31) */ |
| 468 | lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */ |
| 469 | oris r4,r4,0x8000 /* make bit 31 = 1 */ |
| 470 | stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */ |
| 471 | |
| 472 | /* clear all pending interrupts and disable all interrupts */ |
| 473 | li r4,-1 /* set p1 to 0xffffffff */ |
| 474 | stw r4,0x1b0(r3) /* clear all pending interrupts */ |
| 475 | stw r4,0x1b8(r3) /* clear all pending interrupts */ |
| 476 | li r4,0 /* set r4 to 0 */ |
| 477 | stw r4,0x1b4(r3) /* disable all interrupts */ |
| 478 | stw r4,0x1bc(r3) /* disable all interrupts */ |
| 479 | |
| 480 | /* make sure above stores all comlete before going on */ |
| 481 | sync |
| 482 | |
| 483 | /*----------------------------------------------------------------------- */ |
| 484 | /* Enable two 128MB cachable regions. */ |
| 485 | /*----------------------------------------------------------------------- */ |
| 486 | addis r1,r0,0x8000 |
| 487 | addi r1,r1,0x0001 |
| 488 | mticcr r1 /* instruction cache */ |
| 489 | |
| 490 | addis r1,r0,0x0000 |
| 491 | addi r1,r1,0x0000 |
| 492 | mtdccr r1 /* data cache */ |
| 493 | |
| 494 | addis r1,r0,CFG_INIT_RAM_ADDR@h |
| 495 | ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack to SDRAM */ |
| 496 | li r0, 0 /* Make room for stack frame header and */ |
| 497 | stwu r0, -4(r1) /* clear final stack frame so that */ |
| 498 | stwu r0, -4(r1) /* stack backtraces terminate cleanly */ |
| 499 | |
| 500 | GET_GOT /* initialize GOT access */ |
| 501 | |
| 502 | bl board_init_f /* run first part of init code (from Flash) */ |
| 503 | |
| 504 | #endif /* CONFIG_IOP480 */ |
| 505 | |
| 506 | /*****************************************************************************/ |
| 507 | #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405) |
| 508 | /*----------------------------------------------------------------------- */ |
| 509 | /* Clear and set up some registers. */ |
| 510 | /*----------------------------------------------------------------------- */ |
| 511 | addi r4,r0,0x0000 |
| 512 | mtspr sgr,r4 |
| 513 | mtspr dcwr,r4 |
| 514 | mtesr r4 /* clear Exception Syndrome Reg */ |
| 515 | mttcr r4 /* clear Timer Control Reg */ |
| 516 | mtxer r4 /* clear Fixed-Point Exception Reg */ |
| 517 | mtevpr r4 /* clear Exception Vector Prefix Reg */ |
| 518 | addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */ |
| 519 | oris r4,r4,0x0002 /* set CE bit (Critical Exceptions) */ |
| 520 | mtmsr r4 /* change MSR */ |
| 521 | addi r4,r0,(0xFFFF-0x10000) /* set r4 to 0xFFFFFFFF (status in the */ |
| 522 | /* dbsr is cleared by setting bits to 1) */ |
| 523 | mtdbsr r4 /* clear/reset the dbsr */ |
| 524 | |
| 525 | /*----------------------------------------------------------------------- */ |
| 526 | /* Invalidate I and D caches. Enable I cache for defined memory regions */ |
| 527 | /* to speed things up. Leave the D cache disabled for now. It will be */ |
| 528 | /* enabled/left disabled later based on user selected menu options. */ |
| 529 | /* Be aware that the I cache may be disabled later based on the menu */ |
| 530 | /* options as well. See miscLib/main.c. */ |
| 531 | /*----------------------------------------------------------------------- */ |
| 532 | bl invalidate_icache |
| 533 | bl invalidate_dcache |
| 534 | |
| 535 | /*----------------------------------------------------------------------- */ |
| 536 | /* Enable two 128MB cachable regions. */ |
| 537 | /*----------------------------------------------------------------------- */ |
| 538 | addis r4,r0,0x8000 |
| 539 | addi r4,r4,0x0001 |
| 540 | mticcr r4 /* instruction cache */ |
| 541 | isync |
| 542 | |
| 543 | addis r4,r0,0x0000 |
| 544 | addi r4,r4,0x0000 |
| 545 | mtdccr r4 /* data cache */ |
| 546 | |
| 547 | #if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR)) |
| 548 | /*----------------------------------------------------------------------- */ |
| 549 | /* Tune the speed and size for flash CS0 */ |
| 550 | /*----------------------------------------------------------------------- */ |
| 551 | bl ext_bus_cntlr_init |
| 552 | #endif |
| 553 | |
| 554 | #if defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE) |
| 555 | /******************************************************************** |
| 556 | * Setup OCM - On Chip Memory |
| 557 | *******************************************************************/ |
| 558 | /* Setup OCM */ |
| 559 | lis r0, 0x7FFF |
| 560 | ori r0, r0, 0xFFFF |
| 561 | mfdcr r3, ocmiscntl /* get instr-side IRAM config */ |
| 562 | mfdcr r4, ocmdscntl /* get data-side IRAM config */ |
| 563 | and r3, r3, r0 /* disable data-side IRAM */ |
| 564 | and r4, r4, r0 /* disable data-side IRAM */ |
| 565 | mtdcr ocmiscntl, r3 /* set instr-side IRAM config */ |
| 566 | mtdcr ocmdscntl, r4 /* set data-side IRAM config */ |
| 567 | isync |
| 568 | |
| 569 | addis r3, 0, CFG_OCM_DATA_ADDR@h /* OCM location */ |
| 570 | mtdcr ocmdsarc, r3 |
| 571 | addis r4, 0, 0xC000 /* OCM data area enabled */ |
| 572 | mtdcr ocmdscntl, r4 |
| 573 | isync |
| 574 | #endif |
| 575 | |
| 576 | /*----------------------------------------------------------------------- */ |
| 577 | /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */ |
| 578 | /*----------------------------------------------------------------------- */ |
| 579 | #ifdef CFG_INIT_DCACHE_CS |
| 580 | /*----------------------------------------------------------------------- */ |
| 581 | /* Memory Bank x (nothingness) initialization 1GB+64MEG */ |
| 582 | /* used as temporary stack pointer for stage0 */ |
| 583 | /*----------------------------------------------------------------------- */ |
| 584 | li r4,PBxAP |
| 585 | mtdcr ebccfga,r4 |
| 586 | lis r4,0x0380 |
| 587 | ori r4,r4,0x0480 |
| 588 | mtdcr ebccfgd,r4 |
| 589 | |
| 590 | addi r4,0,PBxCR |
| 591 | mtdcr ebccfga,r4 |
| 592 | lis r4,0x400D |
| 593 | ori r4,r4,0xa000 |
| 594 | mtdcr ebccfgd,r4 |
| 595 | |
| 596 | /* turn on data chache for this region */ |
| 597 | lis r4,0x0080 |
| 598 | mtdccr r4 |
| 599 | |
| 600 | /* set stack pointer and clear stack to known value */ |
| 601 | |
| 602 | lis r1,CFG_INIT_RAM_ADDR@h |
| 603 | ori r1,r1,CFG_INIT_SP_OFFSET@l |
| 604 | |
| 605 | li r4,2048 /* we store 2048 words to stack */ |
| 606 | mtctr r4 |
| 607 | |
| 608 | lis r2,CFG_INIT_RAM_ADDR@h /* we also clear data area */ |
| 609 | ori r2,r2,CFG_INIT_RAM_END@l /* so cant copy value from r1 */ |
| 610 | |
| 611 | lis r4,0xdead /* we store 0xdeaddead in the stack */ |
| 612 | ori r4,r4,0xdead |
| 613 | |
| 614 | ..stackloop: |
| 615 | stwu r4,-4(r2) |
| 616 | bdnz ..stackloop |
| 617 | |
| 618 | li r0, 0 /* Make room for stack frame header and */ |
| 619 | stwu r0, -4(r1) /* clear final stack frame so that */ |
| 620 | stwu r0, -4(r1) /* stack backtraces terminate cleanly */ |
| 621 | /* |
| 622 | * Set up a dummy frame to store reset vector as return address. |
| 623 | * this causes stack underflow to reset board. |
| 624 | */ |
| 625 | stwu r1, -8(r1) /* Save back chain and move SP */ |
| 626 | addis r0, 0, RESET_VECTOR@h /* Address of reset vector */ |
| 627 | ori r0, r0, RESET_VECTOR@l |
| 628 | stwu r1, -8(r1) /* Save back chain and move SP */ |
| 629 | stw r0, +12(r1) /* Save return addr (underflow vect) */ |
| 630 | |
| 631 | #elif defined(CFG_TEMP_STACK_OCM) && \ |
| 632 | (defined(CFG_OCM_DATA_ADDR) && defined(CFG_OCM_DATA_SIZE)) |
| 633 | /* |
| 634 | * Stack in OCM. |
| 635 | */ |
| 636 | |
| 637 | /* Set up Stack at top of OCM */ |
| 638 | lis r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@h |
| 639 | ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET)@l |
| 640 | |
| 641 | /* Set up a zeroized stack frame so that backtrace works right */ |
| 642 | li r0, 0 |
| 643 | stwu r0, -4(r1) |
| 644 | stwu r0, -4(r1) |
| 645 | |
| 646 | /* |
| 647 | * Set up a dummy frame to store reset vector as return address. |
| 648 | * this causes stack underflow to reset board. |
| 649 | */ |
| 650 | stwu r1, -8(r1) /* Save back chain and move SP */ |
| 651 | lis r0, RESET_VECTOR@h /* Address of reset vector */ |
| 652 | ori r0, r0, RESET_VECTOR@l |
| 653 | stwu r1, -8(r1) /* Save back chain and move SP */ |
| 654 | stw r0, +12(r1) /* Save return addr (underflow vect) */ |
| 655 | #endif /* CFG_INIT_DCACHE_CS */ |
| 656 | |
| 657 | /*----------------------------------------------------------------------- */ |
| 658 | /* Initialize SDRAM Controller */ |
| 659 | /*----------------------------------------------------------------------- */ |
| 660 | bl sdram_init |
| 661 | |
| 662 | /* |
| 663 | * Setup temporary stack pointer only for boards |
| 664 | * that do not use SDRAM SPD I2C stuff since it |
| 665 | * is already initialized to use DCACHE or OCM |
| 666 | * stacks. |
| 667 | */ |
| 668 | #if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM)) |
| 669 | lis r1, CFG_INIT_RAM_ADDR@h |
| 670 | ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */ |
| 671 | |
| 672 | li r0, 0 /* Make room for stack frame header and */ |
| 673 | stwu r0, -4(r1) /* clear final stack frame so that */ |
| 674 | stwu r0, -4(r1) /* stack backtraces terminate cleanly */ |
| 675 | /* |
| 676 | * Set up a dummy frame to store reset vector as return address. |
| 677 | * this causes stack underflow to reset board. |
| 678 | */ |
| 679 | stwu r1, -8(r1) /* Save back chain and move SP */ |
| 680 | lis r0, RESET_VECTOR@h /* Address of reset vector */ |
| 681 | ori r0, r0, RESET_VECTOR@l |
| 682 | stwu r1, -8(r1) /* Save back chain and move SP */ |
| 683 | stw r0, +12(r1) /* Save return addr (underflow vect) */ |
| 684 | #endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */ |
| 685 | |
| 686 | GET_GOT /* initialize GOT access */ |
| 687 | |
| 688 | bl cpu_init_f /* run low-level CPU init code (from Flash) */ |
| 689 | |
| 690 | /* NEVER RETURNS! */ |
| 691 | bl board_init_f /* run first part of init code (from Flash) */ |
| 692 | |
| 693 | #endif /* CONFIG_405GP || CONFIG_405CR */ |
| 694 | |
| 695 | |
| 696 | .globl _start_of_vectors |
| 697 | _start_of_vectors: |
| 698 | |
| 699 | #if 0 |
| 700 | /*TODO Fixup _start above so we can do this*/ |
| 701 | /* Critical input. */ |
| 702 | CRIT_EXCEPTION(0x100, CritcalInput, CritcalInputException) |
| 703 | #endif |
| 704 | |
| 705 | /* Machine check */ |
| 706 | STD_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
| 707 | |
| 708 | /* Data Storage exception. */ |
| 709 | STD_EXCEPTION(0x300, DataStorage, UnknownException) |
| 710 | |
| 711 | /* Instruction Storage exception. */ |
| 712 | STD_EXCEPTION(0x400, InstStorage, UnknownException) |
| 713 | |
| 714 | /* External Interrupt exception. */ |
| 715 | STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt) |
| 716 | |
| 717 | /* Alignment exception. */ |
| 718 | . = 0x600 |
| 719 | Alignment: |
| 720 | EXCEPTION_PROLOG |
| 721 | mfspr r4,DAR |
| 722 | stw r4,_DAR(r21) |
| 723 | mfspr r5,DSISR |
| 724 | stw r5,_DSISR(r21) |
| 725 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 726 | li r20,MSR_KERNEL |
| 727 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 728 | lwz r6,GOT(transfer_to_handler) |
| 729 | mtlr r6 |
| 730 | blrl |
| 731 | .L_Alignment: |
| 732 | .long AlignmentException - _start + EXC_OFF_SYS_RESET |
| 733 | .long int_return - _start + EXC_OFF_SYS_RESET |
| 734 | |
| 735 | /* Program check exception */ |
| 736 | . = 0x700 |
| 737 | ProgramCheck: |
| 738 | EXCEPTION_PROLOG |
| 739 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 740 | li r20,MSR_KERNEL |
| 741 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 742 | lwz r6,GOT(transfer_to_handler) |
| 743 | mtlr r6 |
| 744 | blrl |
| 745 | .L_ProgramCheck: |
| 746 | .long ProgramCheckException - _start + EXC_OFF_SYS_RESET |
| 747 | .long int_return - _start + EXC_OFF_SYS_RESET |
| 748 | |
| 749 | /* No FPU on MPC8xx. This exception is not supposed to happen. |
| 750 | */ |
| 751 | STD_EXCEPTION(0x800, FPUnavailable, UnknownException) |
| 752 | |
| 753 | /* I guess we could implement decrementer, and may have |
| 754 | * to someday for timekeeping. |
| 755 | */ |
| 756 | STD_EXCEPTION(0x900, Decrementer, timer_interrupt) |
| 757 | STD_EXCEPTION(0xa00, Trap_0a, UnknownException) |
| 758 | STD_EXCEPTION(0xb00, Trap_0b, UnknownException) |
| 759 | |
| 760 | . = 0xc00 |
| 761 | /* |
| 762 | * r0 - SYSCALL number |
| 763 | * r3-... arguments |
| 764 | */ |
| 765 | SystemCall: |
| 766 | addis r11,r0,0 /* get functions table addr */ |
| 767 | ori r11,r11,0 /* Note: this code is patched in trap_init */ |
| 768 | addis r12,r0,0 /* get number of functions */ |
| 769 | ori r12,r12,0 |
| 770 | |
| 771 | cmplw 0, r0, r12 |
| 772 | bge 1f |
| 773 | |
| 774 | rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */ |
| 775 | add r11,r11,r0 |
| 776 | lwz r11,0(r11) |
| 777 | |
| 778 | li r12,0xd00-4*3 /* save LR & SRRx */ |
| 779 | mflr r0 |
| 780 | stw r0,0(r12) |
| 781 | mfspr r0,SRR0 |
| 782 | stw r0,4(r12) |
| 783 | mfspr r0,SRR1 |
| 784 | stw r0,8(r12) |
| 785 | |
| 786 | li r12,0xc00+_back-SystemCall |
| 787 | mtlr r12 |
| 788 | mtspr SRR0,r11 |
| 789 | |
| 790 | 1: SYNC |
| 791 | rfi |
| 792 | |
| 793 | _back: |
| 794 | |
| 795 | mfmsr r11 /* Disable interrupts */ |
| 796 | li r12,0 |
| 797 | ori r12,r12,MSR_EE |
| 798 | andc r11,r11,r12 |
| 799 | SYNC /* Some chip revs need this... */ |
| 800 | mtmsr r11 |
| 801 | SYNC |
| 802 | |
| 803 | li r12,0xd00-4*3 /* restore regs */ |
| 804 | lwz r11,0(r12) |
| 805 | mtlr r11 |
| 806 | lwz r11,4(r12) |
| 807 | mtspr SRR0,r11 |
| 808 | lwz r11,8(r12) |
| 809 | mtspr SRR1,r11 |
| 810 | |
| 811 | SYNC |
| 812 | rfi |
| 813 | |
| 814 | STD_EXCEPTION(0xd00, SingleStep, UnknownException) |
| 815 | |
| 816 | STD_EXCEPTION(0xe00, Trap_0e, UnknownException) |
| 817 | STD_EXCEPTION(0xf00, Trap_0f, UnknownException) |
| 818 | |
| 819 | /* On the MPC8xx, this is a software emulation interrupt. It occurs |
| 820 | * for all unimplemented and illegal instructions. |
| 821 | */ |
| 822 | STD_EXCEPTION(0x1000, PIT, PITException) |
| 823 | |
| 824 | STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException) |
| 825 | STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException) |
| 826 | STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException) |
| 827 | STD_EXCEPTION(0x1400, DataTLBError, UnknownException) |
| 828 | |
| 829 | STD_EXCEPTION(0x1500, Reserved5, UnknownException) |
| 830 | STD_EXCEPTION(0x1600, Reserved6, UnknownException) |
| 831 | STD_EXCEPTION(0x1700, Reserved7, UnknownException) |
| 832 | STD_EXCEPTION(0x1800, Reserved8, UnknownException) |
| 833 | STD_EXCEPTION(0x1900, Reserved9, UnknownException) |
| 834 | STD_EXCEPTION(0x1a00, ReservedA, UnknownException) |
| 835 | STD_EXCEPTION(0x1b00, ReservedB, UnknownException) |
| 836 | |
| 837 | STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException) |
| 838 | STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException) |
| 839 | STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException) |
| 840 | STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException) |
| 841 | |
| 842 | CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException ) |
| 843 | |
| 844 | .globl _end_of_vectors |
| 845 | _end_of_vectors: |
| 846 | |
| 847 | |
| 848 | . = 0x2100 |
| 849 | |
| 850 | /* |
| 851 | * This code finishes saving the registers to the exception frame |
| 852 | * and jumps to the appropriate handler for the exception. |
| 853 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 854 | */ |
| 855 | .globl transfer_to_handler |
| 856 | transfer_to_handler: |
| 857 | stw r22,_NIP(r21) |
| 858 | lis r22,MSR_POW@h |
| 859 | andc r23,r23,r22 |
| 860 | stw r23,_MSR(r21) |
| 861 | SAVE_GPR(7, r21) |
| 862 | SAVE_4GPRS(8, r21) |
| 863 | SAVE_8GPRS(12, r21) |
| 864 | SAVE_8GPRS(24, r21) |
| 865 | #if 0 |
| 866 | andi. r23,r23,MSR_PR |
| 867 | mfspr r23,SPRG3 /* if from user, fix up tss.regs */ |
| 868 | beq 2f |
| 869 | addi r24,r1,STACK_FRAME_OVERHEAD |
| 870 | stw r24,PT_REGS(r23) |
| 871 | 2: addi r2,r23,-TSS /* set r2 to current */ |
| 872 | tovirt(r2,r2,r23) |
| 873 | #endif |
| 874 | mflr r23 |
| 875 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 876 | stw r24,TRAP(r21) |
| 877 | li r22,0 |
| 878 | stw r22,RESULT(r21) |
| 879 | mtspr SPRG2,r22 /* r1 is now kernel sp */ |
| 880 | #if 0 |
| 881 | addi r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */ |
| 882 | cmplw 0,r1,r2 |
| 883 | cmplw 1,r1,r24 |
| 884 | crand 1,1,4 |
| 885 | bgt stack_ovf /* if r2 < r1 < r2+TASK_STRUCT_SIZE */ |
| 886 | #endif |
| 887 | lwz r24,0(r23) /* virtual address of handler */ |
| 888 | lwz r23,4(r23) /* where to go when done */ |
| 889 | mtspr SRR0,r24 |
| 890 | mtspr SRR1,r20 |
| 891 | mtlr r23 |
| 892 | SYNC |
| 893 | rfi /* jump to handler, enable MMU */ |
| 894 | |
| 895 | int_return: |
| 896 | mfmsr r28 /* Disable interrupts */ |
| 897 | li r4,0 |
| 898 | ori r4,r4,MSR_EE |
| 899 | andc r28,r28,r4 |
| 900 | SYNC /* Some chip revs need this... */ |
| 901 | mtmsr r28 |
| 902 | SYNC |
| 903 | lwz r2,_CTR(r1) |
| 904 | lwz r0,_LINK(r1) |
| 905 | mtctr r2 |
| 906 | mtlr r0 |
| 907 | lwz r2,_XER(r1) |
| 908 | lwz r0,_CCR(r1) |
| 909 | mtspr XER,r2 |
| 910 | mtcrf 0xFF,r0 |
| 911 | REST_10GPRS(3, r1) |
| 912 | REST_10GPRS(13, r1) |
| 913 | REST_8GPRS(23, r1) |
| 914 | REST_GPR(31, r1) |
| 915 | lwz r2,_NIP(r1) /* Restore environment */ |
| 916 | lwz r0,_MSR(r1) |
| 917 | mtspr SRR0,r2 |
| 918 | mtspr SRR1,r0 |
| 919 | lwz r0,GPR0(r1) |
| 920 | lwz r2,GPR2(r1) |
| 921 | lwz r1,GPR1(r1) |
| 922 | SYNC |
| 923 | rfi |
| 924 | |
| 925 | crit_return: |
| 926 | mfmsr r28 /* Disable interrupts */ |
| 927 | li r4,0 |
| 928 | ori r4,r4,MSR_EE |
| 929 | andc r28,r28,r4 |
| 930 | SYNC /* Some chip revs need this... */ |
| 931 | mtmsr r28 |
| 932 | SYNC |
| 933 | lwz r2,_CTR(r1) |
| 934 | lwz r0,_LINK(r1) |
| 935 | mtctr r2 |
| 936 | mtlr r0 |
| 937 | lwz r2,_XER(r1) |
| 938 | lwz r0,_CCR(r1) |
| 939 | mtspr XER,r2 |
| 940 | mtcrf 0xFF,r0 |
| 941 | REST_10GPRS(3, r1) |
| 942 | REST_10GPRS(13, r1) |
| 943 | REST_8GPRS(23, r1) |
| 944 | REST_GPR(31, r1) |
| 945 | lwz r2,_NIP(r1) /* Restore environment */ |
| 946 | lwz r0,_MSR(r1) |
| 947 | mtspr 990,r2 /* SRR2 */ |
| 948 | mtspr 991,r0 /* SRR3 */ |
| 949 | lwz r0,GPR0(r1) |
| 950 | lwz r2,GPR2(r1) |
| 951 | lwz r1,GPR1(r1) |
| 952 | SYNC |
| 953 | rfci |
| 954 | |
| 955 | /* Cache functions. |
| 956 | */ |
| 957 | invalidate_icache: |
| 958 | iccci r0,r0 /* for 405, iccci invalidates the */ |
| 959 | blr /* entire I cache */ |
| 960 | |
| 961 | invalidate_dcache: |
| 962 | addi r6,0,0x0000 /* clear GPR 6 */ |
| 963 | /* Do loop for # of dcache congruence classes. */ |
| 964 | addi r7,r0, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2) |
| 965 | /* NOTE: dccci invalidates both */ |
| 966 | mtctr r7 /* ways in the D cache */ |
| 967 | ..dcloop: |
| 968 | dccci 0,r6 /* invalidate line */ |
| 969 | addi r6,r6, CFG_CACHELINE_SIZE /* bump to next line */ |
| 970 | bdnz ..dcloop |
| 971 | blr |
| 972 | |
| 973 | flush_dcache: |
| 974 | addis r9,r0,0x0002 /* set mask for EE and CE msr bits */ |
| 975 | ori r9,r9,0x8000 |
| 976 | mfmsr r12 /* save msr */ |
| 977 | andc r9,r12,r9 |
| 978 | mtmsr r9 /* disable EE and CE */ |
| 979 | addi r10,r0,0x0001 /* enable data cache for unused memory */ |
| 980 | mfdccr r9 /* region 0xF8000000-0xFFFFFFFF via */ |
| 981 | or r10,r10,r9 /* bit 31 in dccr */ |
| 982 | mtdccr r10 |
| 983 | |
| 984 | /* do loop for # of congruence classes. */ |
| 985 | addi r10,r0,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2) |
| 986 | addi r11,r0,(CFG_DCACHE_SIZE / 2) /* D cache set size - 2 way sets */ |
| 987 | mtctr r10 |
| 988 | addi r10,r0,(0xE000-0x10000) /* start at 0xFFFFE000 */ |
| 989 | add r11,r10,r11 /* add to get to other side of cache line */ |
| 990 | ..flush_dcache_loop: |
| 991 | lwz r3,0(r10) /* least recently used side */ |
| 992 | lwz r3,0(r11) /* the other side */ |
| 993 | dccci r0,r11 /* invalidate both sides */ |
| 994 | addi r10,r10,CFG_CACHELINE_SIZE /* bump to next line */ |
| 995 | addi r11,r11,CFG_CACHELINE_SIZE /* bump to next line */ |
| 996 | bdnz ..flush_dcache_loop |
| 997 | sync /* allow memory access to complete */ |
| 998 | mtdccr r9 /* restore dccr */ |
| 999 | mtmsr r12 /* restore msr */ |
| 1000 | blr |
| 1001 | |
| 1002 | .globl icache_enable |
| 1003 | icache_enable: |
| 1004 | mflr r8 |
| 1005 | bl invalidate_icache |
| 1006 | mtlr r8 |
| 1007 | isync |
| 1008 | addis r3,r0, 0x8000 /* set bit 0 */ |
| 1009 | mticcr r3 |
| 1010 | blr |
| 1011 | |
| 1012 | .globl icache_disable |
| 1013 | icache_disable: |
| 1014 | addis r3,r0, 0x0000 /* clear bit 0 */ |
| 1015 | mticcr r3 |
| 1016 | isync |
| 1017 | blr |
| 1018 | |
| 1019 | .globl icache_status |
| 1020 | icache_status: |
| 1021 | mficcr r3 |
| 1022 | srwi r3, r3, 31 /* >>31 => select bit 0 */ |
| 1023 | blr |
| 1024 | |
| 1025 | .globl dcache_enable |
| 1026 | dcache_enable: |
| 1027 | mflr r8 |
| 1028 | bl invalidate_dcache |
| 1029 | mtlr r8 |
| 1030 | isync |
| 1031 | addis r3,r0, 0x8000 /* set bit 0 */ |
| 1032 | mtdccr r3 |
| 1033 | blr |
| 1034 | |
| 1035 | .globl dcache_disable |
| 1036 | dcache_disable: |
| 1037 | mflr r8 |
| 1038 | bl flush_dcache |
| 1039 | mtlr r8 |
| 1040 | addis r3,r0, 0x0000 /* clear bit 0 */ |
| 1041 | mtdccr r3 |
| 1042 | blr |
| 1043 | |
| 1044 | .globl dcache_status |
| 1045 | dcache_status: |
| 1046 | mfdccr r3 |
| 1047 | srwi r3, r3, 31 /* >>31 => select bit 0 */ |
| 1048 | blr |
| 1049 | |
| 1050 | .globl get_pvr |
| 1051 | get_pvr: |
| 1052 | mfspr r3, PVR |
| 1053 | blr |
| 1054 | |
| 1055 | #if !defined(CONFIG_440) |
| 1056 | .globl wr_pit |
| 1057 | wr_pit: |
| 1058 | mtspr pit, r3 |
| 1059 | blr |
| 1060 | #endif |
| 1061 | |
| 1062 | .globl wr_tcr |
| 1063 | wr_tcr: |
| 1064 | mtspr tcr, r3 |
| 1065 | blr |
| 1066 | |
| 1067 | /*------------------------------------------------------------------------------- */ |
| 1068 | /* Function: in8 */ |
| 1069 | /* Description: Input 8 bits */ |
| 1070 | /*------------------------------------------------------------------------------- */ |
| 1071 | .globl in8 |
| 1072 | in8: |
| 1073 | lbz r3,0x0000(r3) |
| 1074 | blr |
| 1075 | |
| 1076 | /*------------------------------------------------------------------------------- */ |
| 1077 | /* Function: out8 */ |
| 1078 | /* Description: Output 8 bits */ |
| 1079 | /*------------------------------------------------------------------------------- */ |
| 1080 | .globl out8 |
| 1081 | out8: |
| 1082 | stb r4,0x0000(r3) |
| 1083 | blr |
| 1084 | |
| 1085 | /*------------------------------------------------------------------------------- */ |
| 1086 | /* Function: out16 */ |
| 1087 | /* Description: Output 16 bits */ |
| 1088 | /*------------------------------------------------------------------------------- */ |
| 1089 | .globl out16 |
| 1090 | out16: |
| 1091 | sth r4,0x0000(r3) |
| 1092 | blr |
| 1093 | |
| 1094 | /*------------------------------------------------------------------------------- */ |
| 1095 | /* Function: out16r */ |
| 1096 | /* Description: Byte reverse and output 16 bits */ |
| 1097 | /*------------------------------------------------------------------------------- */ |
| 1098 | .globl out16r |
| 1099 | out16r: |
| 1100 | sthbrx r4,r0,r3 |
| 1101 | blr |
| 1102 | |
| 1103 | /*------------------------------------------------------------------------------- */ |
| 1104 | /* Function: out32 */ |
| 1105 | /* Description: Output 32 bits */ |
| 1106 | /*------------------------------------------------------------------------------- */ |
| 1107 | .globl out32 |
| 1108 | out32: |
| 1109 | stw r4,0x0000(r3) |
| 1110 | blr |
| 1111 | |
| 1112 | /*------------------------------------------------------------------------------- */ |
| 1113 | /* Function: out32r */ |
| 1114 | /* Description: Byte reverse and output 32 bits */ |
| 1115 | /*------------------------------------------------------------------------------- */ |
| 1116 | .globl out32r |
| 1117 | out32r: |
| 1118 | stwbrx r4,r0,r3 |
| 1119 | blr |
| 1120 | |
| 1121 | /*------------------------------------------------------------------------------- */ |
| 1122 | /* Function: in16 */ |
| 1123 | /* Description: Input 16 bits */ |
| 1124 | /*------------------------------------------------------------------------------- */ |
| 1125 | .globl in16 |
| 1126 | in16: |
| 1127 | lhz r3,0x0000(r3) |
| 1128 | blr |
| 1129 | |
| 1130 | /*------------------------------------------------------------------------------- */ |
| 1131 | /* Function: in16r */ |
| 1132 | /* Description: Input 16 bits and byte reverse */ |
| 1133 | /*------------------------------------------------------------------------------- */ |
| 1134 | .globl in16r |
| 1135 | in16r: |
| 1136 | lhbrx r3,r0,r3 |
| 1137 | blr |
| 1138 | |
| 1139 | /*------------------------------------------------------------------------------- */ |
| 1140 | /* Function: in32 */ |
| 1141 | /* Description: Input 32 bits */ |
| 1142 | /*------------------------------------------------------------------------------- */ |
| 1143 | .globl in32 |
| 1144 | in32: |
| 1145 | lwz 3,0x0000(3) |
| 1146 | blr |
| 1147 | |
| 1148 | /*------------------------------------------------------------------------------- */ |
| 1149 | /* Function: in32r */ |
| 1150 | /* Description: Input 32 bits and byte reverse */ |
| 1151 | /*------------------------------------------------------------------------------- */ |
| 1152 | .globl in32r |
| 1153 | in32r: |
| 1154 | lwbrx r3,r0,r3 |
| 1155 | blr |
| 1156 | |
| 1157 | /*------------------------------------------------------------------------------- */ |
| 1158 | /* Function: ppcDcbf */ |
| 1159 | /* Description: Data Cache block flush */ |
| 1160 | /* Input: r3 = effective address */ |
| 1161 | /* Output: none. */ |
| 1162 | /*------------------------------------------------------------------------------- */ |
| 1163 | .globl ppcDcbf |
| 1164 | ppcDcbf: |
| 1165 | dcbf r0,r3 |
| 1166 | blr |
| 1167 | |
| 1168 | /*------------------------------------------------------------------------------- */ |
| 1169 | /* Function: ppcDcbi */ |
| 1170 | /* Description: Data Cache block Invalidate */ |
| 1171 | /* Input: r3 = effective address */ |
| 1172 | /* Output: none. */ |
| 1173 | /*------------------------------------------------------------------------------- */ |
| 1174 | .globl ppcDcbi |
| 1175 | ppcDcbi: |
| 1176 | dcbi r0,r3 |
| 1177 | blr |
| 1178 | |
| 1179 | /*------------------------------------------------------------------------------- */ |
| 1180 | /* Function: ppcSync */ |
| 1181 | /* Description: Processor Synchronize */ |
| 1182 | /* Input: none. */ |
| 1183 | /* Output: none. */ |
| 1184 | /*------------------------------------------------------------------------------- */ |
| 1185 | .globl ppcSync |
| 1186 | ppcSync: |
| 1187 | sync |
| 1188 | blr |
| 1189 | |
| 1190 | /*------------------------------------------------------------------------------*/ |
| 1191 | |
| 1192 | /* |
| 1193 | * void relocate_code (addr_sp, gd, addr_moni) |
| 1194 | * |
| 1195 | * This "function" does not return, instead it continues in RAM |
| 1196 | * after relocating the monitor code. |
| 1197 | * |
| 1198 | * r3 = dest |
| 1199 | * r4 = src |
| 1200 | * r5 = length in bytes |
| 1201 | * r6 = cachelinesize |
| 1202 | */ |
| 1203 | .globl relocate_code |
| 1204 | relocate_code: |
| 1205 | mr r1, r3 /* Set new stack pointer */ |
| 1206 | mr r9, r4 /* Save copy of Init Data pointer */ |
| 1207 | mr r10, r5 /* Save copy of Destination Address */ |
| 1208 | |
| 1209 | mr r3, r5 /* Destination Address */ |
| 1210 | lis r4, CFG_MONITOR_BASE@h /* Source Address */ |
| 1211 | ori r4, r4, CFG_MONITOR_BASE@l |
| 1212 | lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */ |
| 1213 | ori r5, r5, CFG_MONITOR_LEN@l |
| 1214 | li r6, CFG_CACHELINE_SIZE /* Cache Line Size */ |
| 1215 | |
| 1216 | /* |
| 1217 | * Fix GOT pointer: |
| 1218 | * |
| 1219 | * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address |
| 1220 | * |
| 1221 | * Offset: |
| 1222 | */ |
| 1223 | sub r15, r10, r4 |
| 1224 | |
| 1225 | /* First our own GOT */ |
| 1226 | add r14, r14, r15 |
| 1227 | /* the the one used by the C code */ |
| 1228 | add r30, r30, r15 |
| 1229 | |
| 1230 | /* |
| 1231 | * Now relocate code |
| 1232 | */ |
| 1233 | |
| 1234 | cmplw cr1,r3,r4 |
| 1235 | addi r0,r5,3 |
| 1236 | srwi. r0,r0,2 |
| 1237 | beq cr1,4f /* In place copy is not necessary */ |
| 1238 | beq 7f /* Protect against 0 count */ |
| 1239 | mtctr r0 |
| 1240 | bge cr1,2f |
| 1241 | |
| 1242 | la r8,-4(r4) |
| 1243 | la r7,-4(r3) |
| 1244 | 1: lwzu r0,4(r8) |
| 1245 | stwu r0,4(r7) |
| 1246 | bdnz 1b |
| 1247 | b 4f |
| 1248 | |
| 1249 | 2: slwi r0,r0,2 |
| 1250 | add r8,r4,r0 |
| 1251 | add r7,r3,r0 |
| 1252 | 3: lwzu r0,-4(r8) |
| 1253 | stwu r0,-4(r7) |
| 1254 | bdnz 3b |
| 1255 | |
| 1256 | /* |
| 1257 | * Now flush the cache: note that we must start from a cache aligned |
| 1258 | * address. Otherwise we might miss one cache line. |
| 1259 | */ |
| 1260 | 4: cmpwi r6,0 |
| 1261 | add r5,r3,r5 |
| 1262 | beq 7f /* Always flush prefetch queue in any case */ |
| 1263 | subi r0,r6,1 |
| 1264 | andc r3,r3,r0 |
| 1265 | mr r4,r3 |
| 1266 | 5: dcbst 0,r4 |
| 1267 | add r4,r4,r6 |
| 1268 | cmplw r4,r5 |
| 1269 | blt 5b |
| 1270 | sync /* Wait for all dcbst to complete on bus */ |
| 1271 | mr r4,r3 |
| 1272 | 6: icbi 0,r4 |
| 1273 | add r4,r4,r6 |
| 1274 | cmplw r4,r5 |
| 1275 | blt 6b |
| 1276 | 7: sync /* Wait for all icbi to complete on bus */ |
| 1277 | isync |
| 1278 | |
| 1279 | /* |
| 1280 | * We are done. Do not return, instead branch to second part of board |
| 1281 | * initialization, now running from RAM. |
| 1282 | */ |
| 1283 | |
| 1284 | addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET |
| 1285 | mtlr r0 |
| 1286 | blr /* NEVER RETURNS! */ |
| 1287 | |
| 1288 | in_ram: |
| 1289 | |
| 1290 | /* |
| 1291 | * Relocation Function, r14 point to got2+0x8000 |
| 1292 | * |
| 1293 | * Adjust got2 pointers, no need to check for 0, this code |
| 1294 | * already puts a few entries in the table. |
| 1295 | */ |
| 1296 | li r0,__got2_entries@sectoff@l |
| 1297 | la r3,GOT(_GOT2_TABLE_) |
| 1298 | lwz r11,GOT(_GOT2_TABLE_) |
| 1299 | mtctr r0 |
| 1300 | sub r11,r3,r11 |
| 1301 | addi r3,r3,-4 |
| 1302 | 1: lwzu r0,4(r3) |
| 1303 | add r0,r0,r11 |
| 1304 | stw r0,0(r3) |
| 1305 | bdnz 1b |
| 1306 | |
| 1307 | /* |
| 1308 | * Now adjust the fixups and the pointers to the fixups |
| 1309 | * in case we need to move ourselves again. |
| 1310 | */ |
| 1311 | 2: li r0,__fixup_entries@sectoff@l |
| 1312 | lwz r3,GOT(_FIXUP_TABLE_) |
| 1313 | cmpwi r0,0 |
| 1314 | mtctr r0 |
| 1315 | addi r3,r3,-4 |
| 1316 | beq 4f |
| 1317 | 3: lwzu r4,4(r3) |
| 1318 | lwzux r0,r4,r11 |
| 1319 | add r0,r0,r11 |
| 1320 | stw r10,0(r3) |
| 1321 | stw r0,0(r4) |
| 1322 | bdnz 3b |
| 1323 | 4: |
| 1324 | clear_bss: |
| 1325 | /* |
| 1326 | * Now clear BSS segment |
| 1327 | */ |
| 1328 | lwz r3,GOT(.bss) |
| 1329 | lwz r4,GOT(_end) |
| 1330 | |
| 1331 | cmplw 0, r3, r4 |
| 1332 | beq 6f |
| 1333 | |
| 1334 | li r0, 0 |
| 1335 | 5: |
| 1336 | stw r0, 0(r3) |
| 1337 | addi r3, r3, 4 |
| 1338 | cmplw 0, r3, r4 |
| 1339 | bne 5b |
| 1340 | 6: |
| 1341 | |
| 1342 | mr r3, r9 /* Init Data pointer */ |
| 1343 | mr r4, r10 /* Destination Address */ |
| 1344 | bl board_init_r |
| 1345 | |
| 1346 | /* Problems accessing "end" in C, so do it here */ |
| 1347 | .globl get_endaddr |
| 1348 | get_endaddr: |
| 1349 | lwz r3,GOT(_end) |
| 1350 | blr |
| 1351 | |
| 1352 | /* |
| 1353 | * Copy exception vector code to low memory |
| 1354 | * |
| 1355 | * r3: dest_addr |
| 1356 | * r7: source address, r8: end address, r9: target address |
| 1357 | */ |
| 1358 | .globl trap_init |
| 1359 | trap_init: |
| 1360 | lwz r7, GOT(_start) |
| 1361 | lwz r8, GOT(_end_of_vectors) |
| 1362 | |
| 1363 | rlwinm r9, r7, 0, 18, 31 /* _start & 0x3FFF */ |
| 1364 | |
| 1365 | cmplw 0, r7, r8 |
| 1366 | bgelr /* return if r7>=r8 - just in case */ |
| 1367 | |
| 1368 | mflr r4 /* save link register */ |
| 1369 | 1: |
| 1370 | lwz r0, 0(r7) |
| 1371 | stw r0, 0(r9) |
| 1372 | addi r7, r7, 4 |
| 1373 | addi r9, r9, 4 |
| 1374 | cmplw 0, r7, r8 |
| 1375 | bne 1b |
| 1376 | |
| 1377 | /* |
| 1378 | * relocate `hdlr' and `int_return' entries |
| 1379 | */ |
| 1380 | li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET |
| 1381 | li r8, Alignment - _start + EXC_OFF_SYS_RESET |
| 1382 | 2: |
| 1383 | bl trap_reloc |
| 1384 | addi r7, r7, 0x100 /* next exception vector */ |
| 1385 | cmplw 0, r7, r8 |
| 1386 | blt 2b |
| 1387 | |
| 1388 | li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET |
| 1389 | bl trap_reloc |
| 1390 | |
| 1391 | li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET |
| 1392 | bl trap_reloc |
| 1393 | |
| 1394 | li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET |
| 1395 | li r8, SystemCall - _start + EXC_OFF_SYS_RESET |
| 1396 | 3: |
| 1397 | bl trap_reloc |
| 1398 | addi r7, r7, 0x100 /* next exception vector */ |
| 1399 | cmplw 0, r7, r8 |
| 1400 | blt 3b |
| 1401 | |
| 1402 | li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET |
| 1403 | li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET |
| 1404 | 4: |
| 1405 | bl trap_reloc |
| 1406 | addi r7, r7, 0x100 /* next exception vector */ |
| 1407 | cmplw 0, r7, r8 |
| 1408 | blt 4b |
| 1409 | |
| 1410 | mtlr r4 /* restore link register */ |
| 1411 | blr |
| 1412 | |
| 1413 | /* |
| 1414 | * Function: relocate entries for one exception vector |
| 1415 | */ |
| 1416 | trap_reloc: |
| 1417 | lwz r0, 0(r7) /* hdlr ... */ |
| 1418 | add r0, r0, r3 /* ... += dest_addr */ |
| 1419 | stw r0, 0(r7) |
| 1420 | |
| 1421 | lwz r0, 4(r7) /* int_return ... */ |
| 1422 | add r0, r0, r3 /* ... += dest_addr */ |
| 1423 | stw r0, 4(r7) |
| 1424 | |
| 1425 | blr |