wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 2 | * Copyright 2004, 2007 Freescale Semiconductor. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003 Motorola,Inc. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards |
| 25 | * |
| 26 | * The processor starts at 0xfffffffc and the code is first executed in the |
| 27 | * last 4K page(0xfffff000-0xffffffff) in flash/rom. |
| 28 | * |
| 29 | */ |
| 30 | |
| 31 | #include <config.h> |
| 32 | #include <mpc85xx.h> |
| 33 | #include <version.h> |
| 34 | |
| 35 | #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */ |
| 36 | |
| 37 | #include <ppc_asm.tmpl> |
| 38 | #include <ppc_defs.h> |
| 39 | |
| 40 | #include <asm/cache.h> |
| 41 | #include <asm/mmu.h> |
| 42 | |
| 43 | #ifndef CONFIG_IDENT_STRING |
| 44 | #define CONFIG_IDENT_STRING "" |
| 45 | #endif |
| 46 | |
| 47 | #undef MSR_KERNEL |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 48 | #define MSR_KERNEL ( MSR_ME ) /* Machine Check */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Set up GOT: Global Offset Table |
| 52 | * |
| 53 | * Use r14 to access the GOT |
| 54 | */ |
| 55 | START_GOT |
| 56 | GOT_ENTRY(_GOT2_TABLE_) |
| 57 | GOT_ENTRY(_FIXUP_TABLE_) |
| 58 | |
| 59 | GOT_ENTRY(_start) |
| 60 | GOT_ENTRY(_start_of_vectors) |
| 61 | GOT_ENTRY(_end_of_vectors) |
| 62 | GOT_ENTRY(transfer_to_handler) |
| 63 | |
| 64 | GOT_ENTRY(__init_end) |
| 65 | GOT_ENTRY(_end) |
| 66 | GOT_ENTRY(__bss_start) |
| 67 | END_GOT |
| 68 | |
| 69 | /* |
| 70 | * e500 Startup -- after reset only the last 4KB of the effective |
| 71 | * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg |
| 72 | * section is located at THIS LAST page and basically does three |
| 73 | * things: clear some registers, set up exception tables and |
| 74 | * add more TLB entries for 'larger spaces'(e.g. the boot rom) to |
| 75 | * continue the boot procedure. |
| 76 | |
| 77 | * Once the boot rom is mapped by TLB entries we can proceed |
| 78 | * with normal startup. |
| 79 | * |
| 80 | */ |
| 81 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 82 | .section .bootpg,"ax" |
| 83 | .globl _start_e500 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 84 | |
| 85 | _start_e500: |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 86 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 87 | /* clear registers/arrays not reset by hardware */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 88 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 89 | /* L1 */ |
| 90 | li r0,2 |
| 91 | mtspr L1CSR0,r0 /* invalidate d-cache */ |
| 92 | mtspr L1CSR1,r0 /* invalidate i-cache */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 93 | |
| 94 | mfspr r1,DBSR |
| 95 | mtspr DBSR,r1 /* Clear all valid bits */ |
| 96 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 97 | /* |
| 98 | * Enable L1 Caches early |
| 99 | * |
| 100 | */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 101 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 102 | lis r2,L1CSR0_CPE@H /* enable parity */ |
| 103 | ori r2,r2,L1CSR0_DCE |
| 104 | mtspr L1CSR0,r2 /* enable L1 Dcache */ |
| 105 | isync |
| 106 | mtspr L1CSR1,r2 /* enable L1 Icache */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 107 | isync |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 108 | msync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 109 | |
| 110 | /* Setup interrupt vectors */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 111 | lis r1,TEXT_BASE@h |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 112 | mtspr IVPR,r1 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 113 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 114 | li r1,0x0100 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 115 | mtspr IVOR0,r1 /* 0: Critical input */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 116 | li r1,0x0200 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 117 | mtspr IVOR1,r1 /* 1: Machine check */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 118 | li r1,0x0300 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 119 | mtspr IVOR2,r1 /* 2: Data storage */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 120 | li r1,0x0400 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 121 | mtspr IVOR3,r1 /* 3: Instruction storage */ |
| 122 | li r1,0x0500 |
| 123 | mtspr IVOR4,r1 /* 4: External interrupt */ |
| 124 | li r1,0x0600 |
| 125 | mtspr IVOR5,r1 /* 5: Alignment */ |
| 126 | li r1,0x0700 |
| 127 | mtspr IVOR6,r1 /* 6: Program check */ |
| 128 | li r1,0x0800 |
| 129 | mtspr IVOR7,r1 /* 7: floating point unavailable */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 130 | li r1,0x0900 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 131 | mtspr IVOR8,r1 /* 8: System call */ |
| 132 | /* 9: Auxiliary processor unavailable(unsupported) */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 133 | li r1,0x0a00 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 134 | mtspr IVOR10,r1 /* 10: Decrementer */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 135 | li r1,0x0b00 |
| 136 | mtspr IVOR11,r1 /* 11: Interval timer */ |
| 137 | li r1,0x0c00 |
Wolfgang Denk | c94dea2 | 2005-08-04 01:24:19 +0200 | [diff] [blame] | 138 | mtspr IVOR12,r1 /* 12: Watchdog timer */ |
| 139 | li r1,0x0d00 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 140 | mtspr IVOR13,r1 /* 13: Data TLB error */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 141 | li r1,0x0e00 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 142 | mtspr IVOR14,r1 /* 14: Instruction TLB error */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 143 | li r1,0x0f00 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 144 | mtspr IVOR15,r1 /* 15: Debug */ |
| 145 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 146 | |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 147 | /* |
wdenk | 492b9e7 | 2004-08-01 23:02:45 +0000 | [diff] [blame] | 148 | * After reset, CCSRBAR is located at CFG_CCSRBAR_DEFAULT, i.e. |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 149 | * 0xff700000-0xff800000. We need add a TLB1 entry for this 1MB |
| 150 | * region before we can access any CCSR registers such as L2 |
| 151 | * registers, Local Access Registers,etc. We will also re-allocate |
| 152 | * CFG_CCSRBAR_DEFAULT to CFG_CCSRBAR immediately after TLB1 setup. |
| 153 | * |
| 154 | * Please refer to board-specif directory for TLB1 entry configuration. |
| 155 | * (e.g. board/<yourboard>/init.S) |
| 156 | * |
| 157 | */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 158 | bl tlb1_entry |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 159 | mr r5,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 160 | lwzu r4,0(r5) /* how many TLB1 entries we actually use */ |
Zang Roy-r61911 | 077fb1a | 2006-12-20 11:01:00 +0800 | [diff] [blame] | 161 | mtctr r4 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 162 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 163 | 0: lwzu r6,4(r5) |
| 164 | lwzu r7,4(r5) |
| 165 | lwzu r8,4(r5) |
| 166 | lwzu r9,4(r5) |
| 167 | mtspr MAS0,r6 |
| 168 | mtspr MAS1,r7 |
| 169 | mtspr MAS2,r8 |
| 170 | mtspr MAS3,r9 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 171 | isync |
| 172 | msync |
| 173 | tlbwe |
| 174 | isync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 175 | bdnz 0b |
| 176 | |
| 177 | 1: |
| 178 | #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR) |
| 179 | /* Special sequence needed to update CCSRBAR itself */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 180 | lis r4,CFG_CCSRBAR_DEFAULT@h |
| 181 | ori r4,r4,CFG_CCSRBAR_DEFAULT@l |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 182 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 183 | lis r5,CFG_CCSRBAR@h |
| 184 | ori r5,r5,CFG_CCSRBAR@l |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 185 | srwi r6,r5,12 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 186 | stw r6,0(r4) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 187 | isync |
| 188 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 189 | lis r5,0xffff |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 190 | ori r5,r5,0xf000 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 191 | lwz r5,0(r5) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 192 | isync |
| 193 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 194 | lis r3,CFG_CCSRBAR@h |
| 195 | lwz r5,CFG_CCSRBAR@l(r3) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 196 | isync |
| 197 | #endif |
| 198 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 199 | |
| 200 | /* set up local access windows, defined at board/<boardname>/init.S */ |
| 201 | lis r7,CFG_CCSRBAR@h |
| 202 | ori r7,r7,CFG_CCSRBAR@l |
| 203 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 204 | bl law_entry |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 205 | mr r6,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 206 | lwzu r5,0(r6) /* how many windows we actually use */ |
Zang Roy-r61911 | 077fb1a | 2006-12-20 11:01:00 +0800 | [diff] [blame] | 207 | mtctr r5 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 208 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 209 | li r2,0x0c28 /* the first pair is reserved for */ |
| 210 | li r1,0x0c30 /* boot-over-rio-or-pci */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 211 | |
Zang Roy-r61911 | 077fb1a | 2006-12-20 11:01:00 +0800 | [diff] [blame] | 212 | 0: lwzu r4,4(r6) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 213 | lwzu r3,4(r6) |
| 214 | stwx r4,r7,r2 |
| 215 | stwx r3,r7,r1 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 216 | addi r2,r2,0x0020 |
| 217 | addi r1,r1,0x0020 |
| 218 | bdnz 0b |
| 219 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 220 | /* Clear and set up some registers. */ |
| 221 | li r0,0x0000 |
| 222 | lis r1,0xffff |
| 223 | mtspr DEC,r0 /* prevent dec exceptions */ |
| 224 | mttbl r0 /* prevent fit & wdt exceptions */ |
| 225 | mttbu r0 |
| 226 | mtspr TSR,r1 /* clear all timer exception status */ |
| 227 | mtspr TCR,r0 /* disable all */ |
| 228 | mtspr ESR,r0 /* clear exception syndrome register */ |
| 229 | mtspr MCSR,r0 /* machine check syndrome register */ |
| 230 | mtxer r0 /* clear integer exception register */ |
| 231 | lis r1,0x0002 /* set CE bit (Critical Exceptions) */ |
| 232 | ori r1,r1,0x1200 /* set ME/DE bit */ |
| 233 | mtmsr r1 /* change MSR */ |
| 234 | isync |
| 235 | |
| 236 | /* Enable Time Base and Select Time Base Clock */ |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 237 | lis r0,HID0_EMCP@h /* Enable machine check */ |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 238 | #if defined(CONFIG_ENABLE_36BIT_PHYS) |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 239 | ori r0,r0,(HID0_TBEN|HID0_ENMAS7)@l /* Enable Timebase & MAS7 */ |
| 240 | #else |
| 241 | ori r0,r0,HID0_TBEN@l /* enable Timebase */ |
Jon Loeliger | 77a4f6e | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 242 | #endif |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 243 | mtspr HID0,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 244 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 245 | li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 246 | mtspr HID1,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 247 | |
| 248 | /* Enable Branch Prediction */ |
| 249 | #if defined(CONFIG_BTB) |
| 250 | li r0,0x201 /* BBFI = 1, BPEN = 1 */ |
| 251 | mtspr BUCSR,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 252 | #endif |
| 253 | |
| 254 | #if defined(CFG_INIT_DBCR) |
| 255 | lis r1,0xffff |
| 256 | ori r1,r1,0xffff |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 257 | mtspr DBSR,r1 /* Clear all status bits */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 258 | lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */ |
| 259 | ori r0,r0,CFG_INIT_DBCR@l |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 260 | mtspr DBCR0,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 261 | #endif |
| 262 | |
Kumar Gala | 76e276b | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 263 | /* L1 DCache is used for initial RAM */ |
| 264 | |
| 265 | /* Allocate Initial RAM in data cache. |
| 266 | */ |
| 267 | lis r3,CFG_INIT_RAM_ADDR@h |
| 268 | ori r3,r3,CFG_INIT_RAM_ADDR@l |
| 269 | li r2,512 /* 512*32=16K */ |
| 270 | mtctr r2 |
| 271 | li r0,0 |
| 272 | 1: |
| 273 | dcbz r0,r3 |
| 274 | dcbtls 0,r0,r3 |
| 275 | addi r3,r3,32 |
| 276 | bdnz 1b |
| 277 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 278 | /* Jump out the last 4K page and continue to 'normal' start */ |
Kumar Gala | 76e276b | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 279 | #ifdef CFG_RAMBOOT |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 280 | bl 3f |
| 281 | b _start_cont |
Kumar Gala | 76e276b | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 282 | #else |
| 283 | /* Calculate absolute address in FLASH and jump there */ |
| 284 | /*--------------------------------------------------------------*/ |
| 285 | lis r3,CFG_MONITOR_BASE@h |
| 286 | ori r3,r3,CFG_MONITOR_BASE@l |
| 287 | addi r3,r3,_start_cont - _start + _START_OFFSET |
| 288 | mtlr r3 |
| 289 | #endif |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 290 | |
| 291 | 3: li r0,0 |
| 292 | mtspr SRR1,r0 /* Keep things disabled for now */ |
| 293 | mflr r1 |
| 294 | mtspr SRR0,r1 |
| 295 | rfi |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 296 | isync |
| 297 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 298 | .text |
| 299 | .globl _start |
| 300 | _start: |
| 301 | .long 0x27051956 /* U-BOOT Magic Number */ |
| 302 | .globl version_string |
| 303 | version_string: |
| 304 | .ascii U_BOOT_VERSION |
| 305 | .ascii " (", __DATE__, " - ", __TIME__, ")" |
| 306 | .ascii CONFIG_IDENT_STRING, "\0" |
| 307 | |
| 308 | .align 4 |
| 309 | .globl _start_cont |
| 310 | _start_cont: |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 311 | /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/ |
| 312 | lis r1,CFG_INIT_RAM_ADDR@h |
| 313 | ori r1,r1,CFG_INIT_SP_OFFSET@l |
| 314 | |
| 315 | li r0,0 |
| 316 | stwu r0,-4(r1) |
| 317 | stwu r0,-4(r1) /* Terminate call chain */ |
| 318 | |
| 319 | stwu r1,-8(r1) /* Save back chain and move SP */ |
| 320 | lis r0,RESET_VECTOR@h /* Address of reset vector */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 321 | ori r0,r0,RESET_VECTOR@l |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 322 | stwu r1,-8(r1) /* Save back chain and move SP */ |
| 323 | stw r0,+12(r1) /* Save return addr (underflow vect) */ |
| 324 | |
| 325 | GET_GOT |
| 326 | bl cpu_init_f |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 327 | bl board_init_f |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 328 | isync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 329 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 330 | . = EXC_OFF_SYS_RESET |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 331 | .globl _start_of_vectors |
| 332 | _start_of_vectors: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 333 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 334 | /* Critical input. */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 335 | CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException) |
| 336 | |
| 337 | /* Machine check */ |
| 338 | MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 339 | |
| 340 | /* Data Storage exception. */ |
| 341 | STD_EXCEPTION(0x0300, DataStorage, UnknownException) |
| 342 | |
| 343 | /* Instruction Storage exception. */ |
| 344 | STD_EXCEPTION(0x0400, InstStorage, UnknownException) |
| 345 | |
| 346 | /* External Interrupt exception. */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 347 | STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 348 | |
| 349 | /* Alignment exception. */ |
| 350 | . = 0x0600 |
| 351 | Alignment: |
Rafal Jaworowski | 06244e4 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 352 | EXCEPTION_PROLOG(SRR0, SRR1) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 353 | mfspr r4,DAR |
| 354 | stw r4,_DAR(r21) |
| 355 | mfspr r5,DSISR |
| 356 | stw r5,_DSISR(r21) |
| 357 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 358 | li r20,MSR_KERNEL |
| 359 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 360 | lwz r6,GOT(transfer_to_handler) |
| 361 | mtlr r6 |
| 362 | blrl |
| 363 | .L_Alignment: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 364 | .long AlignmentException - _start + _START_OFFSET |
| 365 | .long int_return - _start + _START_OFFSET |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 366 | |
| 367 | /* Program check exception */ |
| 368 | . = 0x0700 |
| 369 | ProgramCheck: |
Rafal Jaworowski | 06244e4 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 370 | EXCEPTION_PROLOG(SRR0, SRR1) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 371 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 372 | li r20,MSR_KERNEL |
| 373 | rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */ |
| 374 | lwz r6,GOT(transfer_to_handler) |
| 375 | mtlr r6 |
| 376 | blrl |
| 377 | .L_ProgramCheck: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 378 | .long ProgramCheckException - _start + _START_OFFSET |
| 379 | .long int_return - _start + _START_OFFSET |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 380 | |
| 381 | /* No FPU on MPC85xx. This exception is not supposed to happen. |
| 382 | */ |
| 383 | STD_EXCEPTION(0x0800, FPUnavailable, UnknownException) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 384 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 385 | . = 0x0900 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 386 | /* |
| 387 | * r0 - SYSCALL number |
| 388 | * r3-... arguments |
| 389 | */ |
| 390 | SystemCall: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 391 | addis r11,r0,0 /* get functions table addr */ |
| 392 | ori r11,r11,0 /* Note: this code is patched in trap_init */ |
| 393 | addis r12,r0,0 /* get number of functions */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 394 | ori r12,r12,0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 395 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 396 | cmplw 0,r0,r12 |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 397 | bge 1f |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 398 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 399 | rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 400 | add r11,r11,r0 |
| 401 | lwz r11,0(r11) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 402 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 403 | li r20,0xd00-4 /* Get stack pointer */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 404 | lwz r12,0(r20) |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 405 | subi r12,r12,12 /* Adjust stack pointer */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 406 | li r0,0xc00+_end_back-SystemCall |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 407 | cmplw 0,r0,r12 /* Check stack overflow */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 408 | bgt 1f |
| 409 | stw r12,0(r20) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 410 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 411 | mflr r0 |
| 412 | stw r0,0(r12) |
| 413 | mfspr r0,SRR0 |
| 414 | stw r0,4(r12) |
| 415 | mfspr r0,SRR1 |
| 416 | stw r0,8(r12) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 417 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 418 | li r12,0xc00+_back-SystemCall |
| 419 | mtlr r12 |
| 420 | mtspr SRR0,r11 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 421 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 422 | 1: SYNC |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 423 | rfi |
| 424 | _back: |
| 425 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 426 | mfmsr r11 /* Disable interrupts */ |
| 427 | li r12,0 |
| 428 | ori r12,r12,MSR_EE |
| 429 | andc r11,r11,r12 |
| 430 | SYNC /* Some chip revs need this... */ |
| 431 | mtmsr r11 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 432 | SYNC |
| 433 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 434 | li r12,0xd00-4 /* restore regs */ |
| 435 | lwz r12,0(r12) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 436 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 437 | lwz r11,0(r12) |
| 438 | mtlr r11 |
| 439 | lwz r11,4(r12) |
| 440 | mtspr SRR0,r11 |
| 441 | lwz r11,8(r12) |
| 442 | mtspr SRR1,r11 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 443 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 444 | addi r12,r12,12 /* Adjust stack pointer */ |
| 445 | li r20,0xd00-4 |
| 446 | stw r12,0(r20) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 447 | |
| 448 | SYNC |
| 449 | rfi |
| 450 | _end_back: |
| 451 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 452 | STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt) |
| 453 | STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException) |
| 454 | STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 455 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 456 | STD_EXCEPTION(0x0d00, DataTLBError, UnknownException) |
| 457 | STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 458 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 459 | CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException ) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 460 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 461 | .globl _end_of_vectors |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 462 | _end_of_vectors: |
| 463 | |
| 464 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 465 | . = . + (0x100 - ( . & 0xff )) /* align for debug */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 466 | |
| 467 | /* |
| 468 | * This code finishes saving the registers to the exception frame |
| 469 | * and jumps to the appropriate handler for the exception. |
| 470 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 471 | */ |
| 472 | .globl transfer_to_handler |
| 473 | transfer_to_handler: |
| 474 | stw r22,_NIP(r21) |
| 475 | lis r22,MSR_POW@h |
| 476 | andc r23,r23,r22 |
| 477 | stw r23,_MSR(r21) |
| 478 | SAVE_GPR(7, r21) |
| 479 | SAVE_4GPRS(8, r21) |
| 480 | SAVE_8GPRS(12, r21) |
| 481 | SAVE_8GPRS(24, r21) |
| 482 | |
| 483 | mflr r23 |
| 484 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 485 | stw r24,TRAP(r21) |
| 486 | li r22,0 |
| 487 | stw r22,RESULT(r21) |
| 488 | mtspr SPRG2,r22 /* r1 is now kernel sp */ |
| 489 | |
| 490 | lwz r24,0(r23) /* virtual address of handler */ |
| 491 | lwz r23,4(r23) /* where to go when done */ |
| 492 | mtspr SRR0,r24 |
| 493 | mtspr SRR1,r20 |
| 494 | mtlr r23 |
| 495 | SYNC |
| 496 | rfi /* jump to handler, enable MMU */ |
| 497 | |
| 498 | int_return: |
| 499 | mfmsr r28 /* Disable interrupts */ |
| 500 | li r4,0 |
| 501 | ori r4,r4,MSR_EE |
| 502 | andc r28,r28,r4 |
| 503 | SYNC /* Some chip revs need this... */ |
| 504 | mtmsr r28 |
| 505 | SYNC |
| 506 | lwz r2,_CTR(r1) |
| 507 | lwz r0,_LINK(r1) |
| 508 | mtctr r2 |
| 509 | mtlr r0 |
| 510 | lwz r2,_XER(r1) |
| 511 | lwz r0,_CCR(r1) |
| 512 | mtspr XER,r2 |
| 513 | mtcrf 0xFF,r0 |
| 514 | REST_10GPRS(3, r1) |
| 515 | REST_10GPRS(13, r1) |
| 516 | REST_8GPRS(23, r1) |
| 517 | REST_GPR(31, r1) |
| 518 | lwz r2,_NIP(r1) /* Restore environment */ |
| 519 | lwz r0,_MSR(r1) |
| 520 | mtspr SRR0,r2 |
| 521 | mtspr SRR1,r0 |
| 522 | lwz r0,GPR0(r1) |
| 523 | lwz r2,GPR2(r1) |
| 524 | lwz r1,GPR1(r1) |
| 525 | SYNC |
| 526 | rfi |
| 527 | |
| 528 | crit_return: |
| 529 | mfmsr r28 /* Disable interrupts */ |
| 530 | li r4,0 |
| 531 | ori r4,r4,MSR_EE |
| 532 | andc r28,r28,r4 |
| 533 | SYNC /* Some chip revs need this... */ |
| 534 | mtmsr r28 |
| 535 | SYNC |
| 536 | lwz r2,_CTR(r1) |
| 537 | lwz r0,_LINK(r1) |
| 538 | mtctr r2 |
| 539 | mtlr r0 |
| 540 | lwz r2,_XER(r1) |
| 541 | lwz r0,_CCR(r1) |
| 542 | mtspr XER,r2 |
| 543 | mtcrf 0xFF,r0 |
| 544 | REST_10GPRS(3, r1) |
| 545 | REST_10GPRS(13, r1) |
| 546 | REST_8GPRS(23, r1) |
| 547 | REST_GPR(31, r1) |
| 548 | lwz r2,_NIP(r1) /* Restore environment */ |
| 549 | lwz r0,_MSR(r1) |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 550 | mtspr SPRN_CSRR0,r2 |
| 551 | mtspr SPRN_CSRR1,r0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 552 | lwz r0,GPR0(r1) |
| 553 | lwz r2,GPR2(r1) |
| 554 | lwz r1,GPR1(r1) |
| 555 | SYNC |
| 556 | rfci |
| 557 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 558 | mck_return: |
| 559 | mfmsr r28 /* Disable interrupts */ |
| 560 | li r4,0 |
| 561 | ori r4,r4,MSR_EE |
| 562 | andc r28,r28,r4 |
| 563 | SYNC /* Some chip revs need this... */ |
| 564 | mtmsr r28 |
| 565 | SYNC |
| 566 | lwz r2,_CTR(r1) |
| 567 | lwz r0,_LINK(r1) |
| 568 | mtctr r2 |
| 569 | mtlr r0 |
| 570 | lwz r2,_XER(r1) |
| 571 | lwz r0,_CCR(r1) |
| 572 | mtspr XER,r2 |
| 573 | mtcrf 0xFF,r0 |
| 574 | REST_10GPRS(3, r1) |
| 575 | REST_10GPRS(13, r1) |
| 576 | REST_8GPRS(23, r1) |
| 577 | REST_GPR(31, r1) |
| 578 | lwz r2,_NIP(r1) /* Restore environment */ |
| 579 | lwz r0,_MSR(r1) |
| 580 | mtspr SPRN_MCSRR0,r2 |
| 581 | mtspr SPRN_MCSRR1,r0 |
| 582 | lwz r0,GPR0(r1) |
| 583 | lwz r2,GPR2(r1) |
| 584 | lwz r1,GPR1(r1) |
| 585 | SYNC |
| 586 | rfmci |
| 587 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 588 | /* Cache functions. |
| 589 | */ |
| 590 | invalidate_icache: |
| 591 | mfspr r0,L1CSR1 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 592 | ori r0,r0,L1CSR1_ICFI |
| 593 | msync |
| 594 | isync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 595 | mtspr L1CSR1,r0 |
| 596 | isync |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 597 | blr /* entire I cache */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 598 | |
| 599 | invalidate_dcache: |
| 600 | mfspr r0,L1CSR0 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 601 | ori r0,r0,L1CSR0_DCFI |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 602 | msync |
| 603 | isync |
| 604 | mtspr L1CSR0,r0 |
| 605 | isync |
| 606 | blr |
| 607 | |
| 608 | .globl icache_enable |
| 609 | icache_enable: |
| 610 | mflr r8 |
| 611 | bl invalidate_icache |
| 612 | mtlr r8 |
| 613 | isync |
| 614 | mfspr r4,L1CSR1 |
| 615 | ori r4,r4,0x0001 |
| 616 | oris r4,r4,0x0001 |
| 617 | mtspr L1CSR1,r4 |
| 618 | isync |
| 619 | blr |
| 620 | |
| 621 | .globl icache_disable |
| 622 | icache_disable: |
| 623 | mfspr r0,L1CSR1 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 624 | lis r3,0 |
| 625 | ori r3,r3,L1CSR1_ICE |
| 626 | andc r0,r0,r3 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 627 | mtspr L1CSR1,r0 |
| 628 | isync |
| 629 | blr |
| 630 | |
| 631 | .globl icache_status |
| 632 | icache_status: |
| 633 | mfspr r3,L1CSR1 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 634 | andi. r3,r3,L1CSR1_ICE |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 635 | blr |
| 636 | |
| 637 | .globl dcache_enable |
| 638 | dcache_enable: |
| 639 | mflr r8 |
| 640 | bl invalidate_dcache |
| 641 | mtlr r8 |
| 642 | isync |
| 643 | mfspr r0,L1CSR0 |
| 644 | ori r0,r0,0x0001 |
| 645 | oris r0,r0,0x0001 |
| 646 | msync |
| 647 | isync |
| 648 | mtspr L1CSR0,r0 |
| 649 | isync |
| 650 | blr |
| 651 | |
| 652 | .globl dcache_disable |
| 653 | dcache_disable: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 654 | mfspr r3,L1CSR0 |
| 655 | lis r4,0 |
| 656 | ori r4,r4,L1CSR0_DCE |
| 657 | andc r3,r3,r4 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 658 | mtspr L1CSR0,r0 |
| 659 | isync |
| 660 | blr |
| 661 | |
| 662 | .globl dcache_status |
| 663 | dcache_status: |
| 664 | mfspr r3,L1CSR0 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 665 | andi. r3,r3,L1CSR0_DCE |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 666 | blr |
| 667 | |
| 668 | .globl get_pir |
| 669 | get_pir: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 670 | mfspr r3,PIR |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 671 | blr |
| 672 | |
| 673 | .globl get_pvr |
| 674 | get_pvr: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 675 | mfspr r3,PVR |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 676 | blr |
| 677 | |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 678 | .globl get_svr |
| 679 | get_svr: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 680 | mfspr r3,SVR |
wdenk | a445ddf | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 681 | blr |
| 682 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 683 | .globl wr_tcr |
| 684 | wr_tcr: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 685 | mtspr TCR,r3 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 686 | blr |
| 687 | |
| 688 | /*------------------------------------------------------------------------------- */ |
| 689 | /* Function: in8 */ |
| 690 | /* Description: Input 8 bits */ |
| 691 | /*------------------------------------------------------------------------------- */ |
| 692 | .globl in8 |
| 693 | in8: |
| 694 | lbz r3,0x0000(r3) |
| 695 | blr |
| 696 | |
| 697 | /*------------------------------------------------------------------------------- */ |
| 698 | /* Function: out8 */ |
| 699 | /* Description: Output 8 bits */ |
| 700 | /*------------------------------------------------------------------------------- */ |
| 701 | .globl out8 |
| 702 | out8: |
| 703 | stb r4,0x0000(r3) |
Ed Swarthout | 7d6be30 | 2007-09-26 16:35:54 -0500 | [diff] [blame^] | 704 | sync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 705 | blr |
| 706 | |
| 707 | /*------------------------------------------------------------------------------- */ |
| 708 | /* Function: out16 */ |
| 709 | /* Description: Output 16 bits */ |
| 710 | /*------------------------------------------------------------------------------- */ |
| 711 | .globl out16 |
| 712 | out16: |
| 713 | sth r4,0x0000(r3) |
Ed Swarthout | 7d6be30 | 2007-09-26 16:35:54 -0500 | [diff] [blame^] | 714 | sync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 715 | blr |
| 716 | |
| 717 | /*------------------------------------------------------------------------------- */ |
| 718 | /* Function: out16r */ |
| 719 | /* Description: Byte reverse and output 16 bits */ |
| 720 | /*------------------------------------------------------------------------------- */ |
| 721 | .globl out16r |
| 722 | out16r: |
| 723 | sthbrx r4,r0,r3 |
Ed Swarthout | 7d6be30 | 2007-09-26 16:35:54 -0500 | [diff] [blame^] | 724 | sync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 725 | blr |
| 726 | |
| 727 | /*------------------------------------------------------------------------------- */ |
| 728 | /* Function: out32 */ |
| 729 | /* Description: Output 32 bits */ |
| 730 | /*------------------------------------------------------------------------------- */ |
| 731 | .globl out32 |
| 732 | out32: |
| 733 | stw r4,0x0000(r3) |
Ed Swarthout | 7d6be30 | 2007-09-26 16:35:54 -0500 | [diff] [blame^] | 734 | sync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 735 | blr |
| 736 | |
| 737 | /*------------------------------------------------------------------------------- */ |
| 738 | /* Function: out32r */ |
| 739 | /* Description: Byte reverse and output 32 bits */ |
| 740 | /*------------------------------------------------------------------------------- */ |
| 741 | .globl out32r |
| 742 | out32r: |
| 743 | stwbrx r4,r0,r3 |
Ed Swarthout | 7d6be30 | 2007-09-26 16:35:54 -0500 | [diff] [blame^] | 744 | sync |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 745 | blr |
| 746 | |
| 747 | /*------------------------------------------------------------------------------- */ |
| 748 | /* Function: in16 */ |
| 749 | /* Description: Input 16 bits */ |
| 750 | /*------------------------------------------------------------------------------- */ |
| 751 | .globl in16 |
| 752 | in16: |
| 753 | lhz r3,0x0000(r3) |
| 754 | blr |
| 755 | |
| 756 | /*------------------------------------------------------------------------------- */ |
| 757 | /* Function: in16r */ |
| 758 | /* Description: Input 16 bits and byte reverse */ |
| 759 | /*------------------------------------------------------------------------------- */ |
| 760 | .globl in16r |
| 761 | in16r: |
| 762 | lhbrx r3,r0,r3 |
| 763 | blr |
| 764 | |
| 765 | /*------------------------------------------------------------------------------- */ |
| 766 | /* Function: in32 */ |
| 767 | /* Description: Input 32 bits */ |
| 768 | /*------------------------------------------------------------------------------- */ |
| 769 | .globl in32 |
| 770 | in32: |
| 771 | lwz 3,0x0000(3) |
| 772 | blr |
| 773 | |
| 774 | /*------------------------------------------------------------------------------- */ |
| 775 | /* Function: in32r */ |
| 776 | /* Description: Input 32 bits and byte reverse */ |
| 777 | /*------------------------------------------------------------------------------- */ |
| 778 | .globl in32r |
| 779 | in32r: |
| 780 | lwbrx r3,r0,r3 |
| 781 | blr |
| 782 | |
| 783 | /*------------------------------------------------------------------------------- */ |
| 784 | /* Function: ppcDcbf */ |
| 785 | /* Description: Data Cache block flush */ |
| 786 | /* Input: r3 = effective address */ |
| 787 | /* Output: none. */ |
| 788 | /*------------------------------------------------------------------------------- */ |
| 789 | .globl ppcDcbf |
| 790 | ppcDcbf: |
| 791 | dcbf r0,r3 |
| 792 | blr |
| 793 | |
| 794 | /*------------------------------------------------------------------------------- */ |
| 795 | /* Function: ppcDcbi */ |
| 796 | /* Description: Data Cache block Invalidate */ |
| 797 | /* Input: r3 = effective address */ |
| 798 | /* Output: none. */ |
| 799 | /*------------------------------------------------------------------------------- */ |
| 800 | .globl ppcDcbi |
| 801 | ppcDcbi: |
| 802 | dcbi r0,r3 |
| 803 | blr |
| 804 | |
wdenk | 13eb221 | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 805 | /*-------------------------------------------------------------------------- |
| 806 | * Function: ppcDcbz |
| 807 | * Description: Data Cache block zero. |
| 808 | * Input: r3 = effective address |
| 809 | * Output: none. |
| 810 | *-------------------------------------------------------------------------- */ |
| 811 | |
| 812 | .globl ppcDcbz |
| 813 | ppcDcbz: |
| 814 | dcbz r0,r3 |
| 815 | blr |
| 816 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 817 | /*------------------------------------------------------------------------------- */ |
| 818 | /* Function: ppcSync */ |
| 819 | /* Description: Processor Synchronize */ |
| 820 | /* Input: none. */ |
| 821 | /* Output: none. */ |
| 822 | /*------------------------------------------------------------------------------- */ |
| 823 | .globl ppcSync |
| 824 | ppcSync: |
| 825 | sync |
| 826 | blr |
| 827 | |
| 828 | /*------------------------------------------------------------------------------*/ |
| 829 | |
| 830 | /* |
| 831 | * void relocate_code (addr_sp, gd, addr_moni) |
| 832 | * |
| 833 | * This "function" does not return, instead it continues in RAM |
| 834 | * after relocating the monitor code. |
| 835 | * |
| 836 | * r3 = dest |
| 837 | * r4 = src |
| 838 | * r5 = length in bytes |
| 839 | * r6 = cachelinesize |
| 840 | */ |
| 841 | .globl relocate_code |
| 842 | relocate_code: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 843 | mr r1,r3 /* Set new stack pointer */ |
| 844 | mr r9,r4 /* Save copy of Init Data pointer */ |
| 845 | mr r10,r5 /* Save copy of Destination Address */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 846 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 847 | mr r3,r5 /* Destination Address */ |
| 848 | lis r4,CFG_MONITOR_BASE@h /* Source Address */ |
| 849 | ori r4,r4,CFG_MONITOR_BASE@l |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 850 | lwz r5,GOT(__init_end) |
| 851 | sub r5,r5,r4 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 852 | li r6,CFG_CACHELINE_SIZE /* Cache Line Size */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 853 | |
| 854 | /* |
| 855 | * Fix GOT pointer: |
| 856 | * |
| 857 | * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address |
| 858 | * |
| 859 | * Offset: |
| 860 | */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 861 | sub r15,r10,r4 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 862 | |
| 863 | /* First our own GOT */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 864 | add r14,r14,r15 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 865 | /* the the one used by the C code */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 866 | add r30,r30,r15 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 867 | |
| 868 | /* |
| 869 | * Now relocate code |
| 870 | */ |
| 871 | |
| 872 | cmplw cr1,r3,r4 |
| 873 | addi r0,r5,3 |
| 874 | srwi. r0,r0,2 |
| 875 | beq cr1,4f /* In place copy is not necessary */ |
| 876 | beq 7f /* Protect against 0 count */ |
| 877 | mtctr r0 |
| 878 | bge cr1,2f |
| 879 | |
| 880 | la r8,-4(r4) |
| 881 | la r7,-4(r3) |
| 882 | 1: lwzu r0,4(r8) |
| 883 | stwu r0,4(r7) |
| 884 | bdnz 1b |
| 885 | b 4f |
| 886 | |
| 887 | 2: slwi r0,r0,2 |
| 888 | add r8,r4,r0 |
| 889 | add r7,r3,r0 |
| 890 | 3: lwzu r0,-4(r8) |
| 891 | stwu r0,-4(r7) |
| 892 | bdnz 3b |
| 893 | |
| 894 | /* |
| 895 | * Now flush the cache: note that we must start from a cache aligned |
| 896 | * address. Otherwise we might miss one cache line. |
| 897 | */ |
| 898 | 4: cmpwi r6,0 |
| 899 | add r5,r3,r5 |
| 900 | beq 7f /* Always flush prefetch queue in any case */ |
| 901 | subi r0,r6,1 |
| 902 | andc r3,r3,r0 |
| 903 | mr r4,r3 |
| 904 | 5: dcbst 0,r4 |
| 905 | add r4,r4,r6 |
| 906 | cmplw r4,r5 |
| 907 | blt 5b |
| 908 | sync /* Wait for all dcbst to complete on bus */ |
| 909 | mr r4,r3 |
| 910 | 6: icbi 0,r4 |
| 911 | add r4,r4,r6 |
| 912 | cmplw r4,r5 |
| 913 | blt 6b |
| 914 | 7: sync /* Wait for all icbi to complete on bus */ |
| 915 | isync |
| 916 | |
Wolfgang Denk | 29dcbd4 | 2005-10-05 00:00:54 +0200 | [diff] [blame] | 917 | /* |
| 918 | * Re-point the IVPR at RAM |
| 919 | */ |
| 920 | mtspr IVPR,r10 |
Wolfgang Denk | 9da240c | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 921 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 922 | /* |
| 923 | * We are done. Do not return, instead branch to second part of board |
| 924 | * initialization, now running from RAM. |
| 925 | */ |
| 926 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 927 | addi r0,r10,in_ram - _start + _START_OFFSET |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 928 | mtlr r0 |
| 929 | blr /* NEVER RETURNS! */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 930 | .globl in_ram |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 931 | in_ram: |
| 932 | |
| 933 | /* |
| 934 | * Relocation Function, r14 point to got2+0x8000 |
| 935 | * |
| 936 | * Adjust got2 pointers, no need to check for 0, this code |
| 937 | * already puts a few entries in the table. |
| 938 | */ |
| 939 | li r0,__got2_entries@sectoff@l |
| 940 | la r3,GOT(_GOT2_TABLE_) |
| 941 | lwz r11,GOT(_GOT2_TABLE_) |
| 942 | mtctr r0 |
| 943 | sub r11,r3,r11 |
| 944 | addi r3,r3,-4 |
| 945 | 1: lwzu r0,4(r3) |
| 946 | add r0,r0,r11 |
| 947 | stw r0,0(r3) |
| 948 | bdnz 1b |
| 949 | |
| 950 | /* |
| 951 | * Now adjust the fixups and the pointers to the fixups |
| 952 | * in case we need to move ourselves again. |
| 953 | */ |
| 954 | 2: li r0,__fixup_entries@sectoff@l |
| 955 | lwz r3,GOT(_FIXUP_TABLE_) |
| 956 | cmpwi r0,0 |
| 957 | mtctr r0 |
| 958 | addi r3,r3,-4 |
| 959 | beq 4f |
| 960 | 3: lwzu r4,4(r3) |
| 961 | lwzux r0,r4,r11 |
| 962 | add r0,r0,r11 |
| 963 | stw r10,0(r3) |
| 964 | stw r0,0(r4) |
| 965 | bdnz 3b |
| 966 | 4: |
| 967 | clear_bss: |
| 968 | /* |
| 969 | * Now clear BSS segment |
| 970 | */ |
| 971 | lwz r3,GOT(__bss_start) |
| 972 | lwz r4,GOT(_end) |
| 973 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 974 | cmplw 0,r3,r4 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 975 | beq 6f |
| 976 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 977 | li r0,0 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 978 | 5: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 979 | stw r0,0(r3) |
| 980 | addi r3,r3,4 |
| 981 | cmplw 0,r3,r4 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 982 | bne 5b |
| 983 | 6: |
| 984 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 985 | mr r3,r9 /* Init Data pointer */ |
| 986 | mr r4,r10 /* Destination Address */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 987 | bl board_init_r |
| 988 | |
| 989 | /* |
| 990 | * Copy exception vector code to low memory |
| 991 | * |
| 992 | * r3: dest_addr |
| 993 | * r7: source address, r8: end address, r9: target address |
| 994 | */ |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 995 | .globl trap_init |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 996 | trap_init: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 997 | lwz r7,GOT(_start_of_vectors) |
| 998 | lwz r8,GOT(_end_of_vectors) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 999 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1000 | li r9,0x100 /* reset vector always at 0x100 */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1001 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1002 | cmplw 0,r7,r8 |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1003 | bgelr /* return if r7>=r8 - just in case */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1004 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1005 | mflr r4 /* save link register */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1006 | 1: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1007 | lwz r0,0(r7) |
| 1008 | stw r0,0(r9) |
| 1009 | addi r7,r7,4 |
| 1010 | addi r9,r9,4 |
| 1011 | cmplw 0,r7,r8 |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1012 | bne 1b |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1013 | |
| 1014 | /* |
| 1015 | * relocate `hdlr' and `int_return' entries |
| 1016 | */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1017 | li r7,.L_CriticalInput - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1018 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1019 | li r7,.L_MachineCheck - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1020 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1021 | li r7,.L_DataStorage - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1022 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1023 | li r7,.L_InstStorage - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1024 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1025 | li r7,.L_ExtInterrupt - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1026 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1027 | li r7,.L_Alignment - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1028 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1029 | li r7,.L_ProgramCheck - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1030 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1031 | li r7,.L_FPUnavailable - _start + _START_OFFSET |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1032 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1033 | li r7,.L_Decrementer - _start + _START_OFFSET |
| 1034 | bl trap_reloc |
| 1035 | li r7,.L_IntervalTimer - _start + _START_OFFSET |
| 1036 | li r8,_end_of_vectors - _start + _START_OFFSET |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1037 | 2: |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1038 | bl trap_reloc |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1039 | addi r7,r7,0x100 /* next exception vector */ |
| 1040 | cmplw 0,r7,r8 |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1041 | blt 2b |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1042 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1043 | lis r7,0x0 |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1044 | mtspr IVPR,r7 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1045 | |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1046 | mtlr r4 /* restore link register */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1047 | blr |
| 1048 | |
| 1049 | /* |
| 1050 | * Function: relocate entries for one exception vector |
| 1051 | */ |
| 1052 | trap_reloc: |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1053 | lwz r0,0(r7) /* hdlr ... */ |
| 1054 | add r0,r0,r3 /* ... += dest_addr */ |
| 1055 | stw r0,0(r7) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1056 | |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1057 | lwz r0,4(r7) /* int_return ... */ |
| 1058 | add r0,r0,r3 /* ... += dest_addr */ |
| 1059 | stw r0,4(r7) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1060 | |
| 1061 | blr |
| 1062 | |
| 1063 | #ifdef CFG_INIT_RAM_LOCK |
| 1064 | .globl unlock_ram_in_cache |
| 1065 | unlock_ram_in_cache: |
| 1066 | /* invalidate the INIT_RAM section */ |
Andy Fleming | f08233c | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1067 | lis r3,(CFG_INIT_RAM_ADDR & ~31)@h |
| 1068 | ori r3,r3,(CFG_INIT_RAM_ADDR & ~31)@l |
| 1069 | li r4,512 |
| 1070 | mtctr r4 |
| 1071 | 1: icbi r0,r3 |
| 1072 | dcbi r0,r3 |
| 1073 | addi r3,r3,32 |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1074 | bdnz 1b |
wdenk | f3da7cc | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1075 | sync /* Wait for all icbi to complete on bus */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1076 | isync |
| 1077 | blr |
| 1078 | #endif |