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