wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
Prabhakar Kushwaha | a4107f8 | 2012-02-14 22:49:29 +0000 | [diff] [blame] | 2 | * Copyright 2004, 2007-2012 Freescale Semiconductor, Inc. |
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 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 31 | #include <asm-offsets.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 32 | #include <config.h> |
| 33 | #include <mpc85xx.h> |
| 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 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 44 | #undef MSR_KERNEL |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 45 | #define MSR_KERNEL ( MSR_ME ) /* Machine Check */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Set up GOT: Global Offset Table |
| 49 | * |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 50 | * Use r12 to access the GOT |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 51 | */ |
| 52 | START_GOT |
| 53 | GOT_ENTRY(_GOT2_TABLE_) |
| 54 | GOT_ENTRY(_FIXUP_TABLE_) |
| 55 | |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 56 | #ifndef CONFIG_NAND_SPL |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 57 | GOT_ENTRY(_start) |
| 58 | GOT_ENTRY(_start_of_vectors) |
| 59 | GOT_ENTRY(_end_of_vectors) |
| 60 | GOT_ENTRY(transfer_to_handler) |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 61 | #endif |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 62 | |
| 63 | GOT_ENTRY(__init_end) |
Po-Yu Chuang | 44c6e65 | 2011-03-01 22:59:59 +0000 | [diff] [blame] | 64 | GOT_ENTRY(__bss_end__) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 65 | GOT_ENTRY(__bss_start) |
| 66 | END_GOT |
| 67 | |
| 68 | /* |
| 69 | * e500 Startup -- after reset only the last 4KB of the effective |
| 70 | * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg |
| 71 | * section is located at THIS LAST page and basically does three |
| 72 | * things: clear some registers, set up exception tables and |
| 73 | * add more TLB entries for 'larger spaces'(e.g. the boot rom) to |
| 74 | * continue the boot procedure. |
| 75 | |
| 76 | * Once the boot rom is mapped by TLB entries we can proceed |
| 77 | * with normal startup. |
| 78 | * |
| 79 | */ |
| 80 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 81 | .section .bootpg,"ax" |
| 82 | .globl _start_e500 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 83 | |
| 84 | _start_e500: |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 85 | |
Ruchika Gupta | 7065b7d | 2010-12-15 17:02:08 +0000 | [diff] [blame] | 86 | #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC) |
| 87 | /* ISBC uses L2 as stack. |
| 88 | * Disable L2 cache here so that u-boot can enable it later |
| 89 | * as part of it's normal flow |
| 90 | */ |
| 91 | |
| 92 | /* Check if L2 is enabled */ |
| 93 | mfspr r3, SPRN_L2CSR0 |
| 94 | lis r2, L2CSR0_L2E@h |
| 95 | ori r2, r2, L2CSR0_L2E@l |
| 96 | and. r4, r3, r2 |
| 97 | beq l2_disabled |
| 98 | |
| 99 | mfspr r3, SPRN_L2CSR0 |
| 100 | /* Flush L2 cache */ |
| 101 | lis r2,(L2CSR0_L2FL)@h |
| 102 | ori r2, r2, (L2CSR0_L2FL)@l |
| 103 | or r3, r2, r3 |
| 104 | sync |
| 105 | isync |
| 106 | mtspr SPRN_L2CSR0,r3 |
| 107 | isync |
| 108 | 1: |
| 109 | mfspr r3, SPRN_L2CSR0 |
| 110 | and. r1, r3, r2 |
| 111 | bne 1b |
| 112 | |
| 113 | mfspr r3, SPRN_L2CSR0 |
| 114 | lis r2, L2CSR0_L2E@h |
| 115 | ori r2, r2, L2CSR0_L2E@l |
| 116 | andc r4, r3, r2 |
| 117 | sync |
| 118 | isync |
| 119 | mtspr SPRN_L2CSR0,r4 |
| 120 | isync |
| 121 | |
| 122 | l2_disabled: |
| 123 | #endif |
| 124 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 125 | /* clear registers/arrays not reset by hardware */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 126 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 127 | /* L1 */ |
| 128 | li r0,2 |
| 129 | mtspr L1CSR0,r0 /* invalidate d-cache */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 130 | mtspr L1CSR1,r0 /* invalidate i-cache */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 131 | |
| 132 | mfspr r1,DBSR |
| 133 | mtspr DBSR,r1 /* Clear all valid bits */ |
| 134 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 135 | /* |
| 136 | * Enable L1 Caches early |
| 137 | * |
| 138 | */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 139 | |
Kumar Gala | 82fd1f8 | 2009-03-19 02:53:01 -0500 | [diff] [blame] | 140 | #if defined(CONFIG_E500MC) && defined(CONFIG_SYS_CACHE_STASHING) |
| 141 | /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */ |
| 142 | li r2,(32 + 0) |
| 143 | mtspr L1CSR2,r2 |
| 144 | #endif |
| 145 | |
Kumar Gala | 33f57bd | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 146 | /* Enable/invalidate the I-Cache */ |
| 147 | lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h |
| 148 | ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l |
| 149 | mtspr SPRN_L1CSR1,r2 |
| 150 | 1: |
| 151 | mfspr r3,SPRN_L1CSR1 |
| 152 | and. r1,r3,r2 |
| 153 | bne 1b |
| 154 | |
| 155 | lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h |
| 156 | ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l |
| 157 | mtspr SPRN_L1CSR1,r3 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 158 | isync |
Kumar Gala | 33f57bd | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 159 | 2: |
| 160 | mfspr r3,SPRN_L1CSR1 |
| 161 | andi. r1,r3,L1CSR1_ICE@l |
| 162 | beq 2b |
| 163 | |
| 164 | /* Enable/invalidate the D-Cache */ |
| 165 | lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h |
| 166 | ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l |
| 167 | mtspr SPRN_L1CSR0,r2 |
| 168 | 1: |
| 169 | mfspr r3,SPRN_L1CSR0 |
| 170 | and. r1,r3,r2 |
| 171 | bne 1b |
| 172 | |
| 173 | lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h |
| 174 | ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l |
| 175 | mtspr SPRN_L1CSR0,r3 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 176 | isync |
Kumar Gala | 33f57bd | 2010-03-26 15:14:43 -0500 | [diff] [blame] | 177 | 2: |
| 178 | mfspr r3,SPRN_L1CSR0 |
| 179 | andi. r1,r3,L1CSR0_DCE@l |
| 180 | beq 2b |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 181 | |
| 182 | /* Setup interrupt vectors */ |
Haiying Wang | 0635b09 | 2010-11-10 15:37:13 -0500 | [diff] [blame] | 183 | lis r1,CONFIG_SYS_MONITOR_BASE@h |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 184 | mtspr IVPR,r1 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 185 | |
Prabhakar Kushwaha | a4107f8 | 2012-02-14 22:49:29 +0000 | [diff] [blame] | 186 | lis r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@h |
| 187 | ori r3,r3,(CONFIG_SYS_MONITOR_BASE & 0xffff)@l |
| 188 | |
| 189 | addi r4,r3,CriticalInput - _start + _START_OFFSET |
| 190 | mtspr IVOR0,r4 /* 0: Critical input */ |
| 191 | addi r4,r3,MachineCheck - _start + _START_OFFSET |
| 192 | mtspr IVOR1,r4 /* 1: Machine check */ |
| 193 | addi r4,r3,DataStorage - _start + _START_OFFSET |
| 194 | mtspr IVOR2,r4 /* 2: Data storage */ |
| 195 | addi r4,r3,InstStorage - _start + _START_OFFSET |
| 196 | mtspr IVOR3,r4 /* 3: Instruction storage */ |
| 197 | addi r4,r3,ExtInterrupt - _start + _START_OFFSET |
| 198 | mtspr IVOR4,r4 /* 4: External interrupt */ |
| 199 | addi r4,r3,Alignment - _start + _START_OFFSET |
| 200 | mtspr IVOR5,r4 /* 5: Alignment */ |
| 201 | addi r4,r3,ProgramCheck - _start + _START_OFFSET |
| 202 | mtspr IVOR6,r4 /* 6: Program check */ |
| 203 | addi r4,r3,FPUnavailable - _start + _START_OFFSET |
| 204 | mtspr IVOR7,r4 /* 7: floating point unavailable */ |
| 205 | addi r4,r3,SystemCall - _start + _START_OFFSET |
| 206 | mtspr IVOR8,r4 /* 8: System call */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 207 | /* 9: Auxiliary processor unavailable(unsupported) */ |
Prabhakar Kushwaha | a4107f8 | 2012-02-14 22:49:29 +0000 | [diff] [blame] | 208 | addi r4,r3,Decrementer - _start + _START_OFFSET |
| 209 | mtspr IVOR10,r4 /* 10: Decrementer */ |
| 210 | addi r4,r3,IntervalTimer - _start + _START_OFFSET |
| 211 | mtspr IVOR11,r4 /* 11: Interval timer */ |
| 212 | addi r4,r3,WatchdogTimer - _start + _START_OFFSET |
| 213 | mtspr IVOR12,r4 /* 12: Watchdog timer */ |
| 214 | addi r4,r3,DataTLBError - _start + _START_OFFSET |
| 215 | mtspr IVOR13,r4 /* 13: Data TLB error */ |
| 216 | addi r4,r3,InstructionTLBError - _start + _START_OFFSET |
| 217 | mtspr IVOR14,r4 /* 14: Instruction TLB error */ |
| 218 | addi r4,r3,DebugBreakpoint - _start + _START_OFFSET |
| 219 | mtspr IVOR15,r4 /* 15: Debug */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 220 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 221 | /* Clear and set up some registers. */ |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 222 | li r0,0x0000 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 223 | lis r1,0xffff |
| 224 | mtspr DEC,r0 /* prevent dec exceptions */ |
| 225 | mttbl r0 /* prevent fit & wdt exceptions */ |
| 226 | mttbu r0 |
| 227 | mtspr TSR,r1 /* clear all timer exception status */ |
| 228 | mtspr TCR,r0 /* disable all */ |
| 229 | mtspr ESR,r0 /* clear exception syndrome register */ |
| 230 | mtspr MCSR,r0 /* machine check syndrome register */ |
| 231 | mtxer r0 /* clear integer exception register */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 232 | |
Scott Wood | dcc87dd | 2009-08-20 17:45:05 -0500 | [diff] [blame] | 233 | #ifdef CONFIG_SYS_BOOK3E_HV |
| 234 | mtspr MAS8,r0 /* make sure MAS8 is clear */ |
| 235 | #endif |
| 236 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 237 | /* Enable Time Base and Select Time Base Clock */ |
wdenk | 0ac6f8b | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 238 | lis r0,HID0_EMCP@h /* Enable machine check */ |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 239 | #if defined(CONFIG_ENABLE_36BIT_PHYS) |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 240 | ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */ |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 241 | #endif |
Kumar Gala | 1b3e404 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 242 | #ifndef CONFIG_E500MC |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 243 | ori r0,r0,HID0_TBEN@l /* Enable Timebase */ |
Kumar Gala | 1b3e404 | 2009-03-19 09:16:10 -0500 | [diff] [blame] | 244 | #endif |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 245 | mtspr HID0,r0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 246 | |
Kumar Gala | 0f060c3 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 247 | #ifndef CONFIG_E500MC |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 248 | li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */ |
Sandeep Gopalpet | ff8473e | 2010-03-12 10:45:02 +0530 | [diff] [blame] | 249 | mfspr r3,PVR |
| 250 | andi. r3,r3, 0xff |
| 251 | cmpwi r3,0x50@l /* if we are rev 5.0 or greater set MBDD */ |
| 252 | blt 1f |
| 253 | /* Set MBDD bit also */ |
| 254 | ori r0, r0, HID1_MBDD@l |
| 255 | 1: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 256 | mtspr HID1,r0 |
Kumar Gala | 0f060c3 | 2008-10-23 01:47:38 -0500 | [diff] [blame] | 257 | #endif |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 258 | |
Kumar Gala | 43f082b | 2011-11-22 06:51:15 -0600 | [diff] [blame] | 259 | #ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999 |
| 260 | mfspr r3,977 |
| 261 | oris r3,r3,0x0100 |
| 262 | mtspr 977,r3 |
| 263 | #endif |
| 264 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 265 | /* Enable Branch Prediction */ |
| 266 | #if defined(CONFIG_BTB) |
Kumar Gala | 69bcf5b | 2010-03-29 13:50:31 -0500 | [diff] [blame] | 267 | lis r0,BUCSR_ENABLE@h |
| 268 | ori r0,r0,BUCSR_ENABLE@l |
| 269 | mtspr SPRN_BUCSR,r0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 270 | #endif |
| 271 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 272 | #if defined(CONFIG_SYS_INIT_DBCR) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 273 | lis r1,0xffff |
| 274 | ori r1,r1,0xffff |
wdenk | 0ac6f8b | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 275 | mtspr DBSR,r1 /* Clear all status bits */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 276 | lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */ |
| 277 | ori r0,r0,CONFIG_SYS_INIT_DBCR@l |
wdenk | 0ac6f8b | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 278 | mtspr DBCR0,r0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 279 | #endif |
| 280 | |
Haiying Wang | 22b6dbc | 2009-03-27 17:02:44 -0400 | [diff] [blame] | 281 | #ifdef CONFIG_MPC8569 |
| 282 | #define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000) |
| 283 | #define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0) |
| 284 | |
| 285 | /* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to |
| 286 | * use address space which is more than 12bits, and it must be done in |
| 287 | * the 4K boot page. So we set this bit here. |
| 288 | */ |
| 289 | |
| 290 | /* create a temp mapping TLB0[0] for LBCR */ |
| 291 | lis r6,FSL_BOOKE_MAS0(0, 0, 0)@h |
| 292 | ori r6,r6,FSL_BOOKE_MAS0(0, 0, 0)@l |
| 293 | |
| 294 | lis r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h |
| 295 | ori r7,r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l |
| 296 | |
| 297 | lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@h |
| 298 | ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@l |
| 299 | |
| 300 | lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0, |
| 301 | (MAS3_SX|MAS3_SW|MAS3_SR))@h |
| 302 | ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0, |
| 303 | (MAS3_SX|MAS3_SW|MAS3_SR))@l |
| 304 | |
| 305 | mtspr MAS0,r6 |
| 306 | mtspr MAS1,r7 |
| 307 | mtspr MAS2,r8 |
| 308 | mtspr MAS3,r9 |
| 309 | isync |
| 310 | msync |
| 311 | tlbwe |
| 312 | |
| 313 | /* Set LBCR register */ |
| 314 | lis r4,CONFIG_SYS_LBCR_ADDR@h |
| 315 | ori r4,r4,CONFIG_SYS_LBCR_ADDR@l |
| 316 | |
| 317 | lis r5,CONFIG_SYS_LBC_LBCR@h |
| 318 | ori r5,r5,CONFIG_SYS_LBC_LBCR@l |
| 319 | stw r5,0(r4) |
| 320 | isync |
| 321 | |
| 322 | /* invalidate this temp TLB */ |
| 323 | lis r4,CONFIG_SYS_LBC_ADDR@h |
| 324 | ori r4,r4,CONFIG_SYS_LBC_ADDR@l |
| 325 | tlbivax 0,r4 |
| 326 | isync |
| 327 | |
| 328 | #endif /* CONFIG_MPC8569 */ |
| 329 | |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 330 | /* |
Timur Tabi | 72243c0 | 2011-10-31 13:30:45 -0500 | [diff] [blame] | 331 | * Search for the TLB that covers the code we're executing, and shrink it |
| 332 | * so that it covers only this 4K page. That will ensure that any other |
| 333 | * TLB we create won't interfere with it. We assume that the TLB exists, |
| 334 | * which is why we don't check the Valid bit of MAS1. |
| 335 | * |
| 336 | * This is necessary, for example, when booting from the on-chip ROM, |
| 337 | * which (oddly) creates a single 4GB TLB that covers CCSR and DDR. |
| 338 | * If we don't shrink this TLB now, then we'll accidentally delete it |
| 339 | * in "purge_old_ccsr_tlb" below. |
| 340 | */ |
| 341 | bl nexti /* Find our address */ |
| 342 | nexti: mflr r1 /* R1 = our PC */ |
| 343 | li r2, 0 |
| 344 | mtspr MAS6, r2 /* Assume the current PID and AS are 0 */ |
| 345 | isync |
| 346 | msync |
| 347 | tlbsx 0, r1 /* This must succeed */ |
| 348 | |
| 349 | /* Set the size of the TLB to 4KB */ |
| 350 | mfspr r3, MAS1 |
| 351 | li r2, 0xF00 |
| 352 | andc r3, r3, r2 /* Clear the TSIZE bits */ |
| 353 | ori r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l |
| 354 | mtspr MAS1, r3 |
| 355 | |
| 356 | /* |
| 357 | * Set the base address of the TLB to our PC. We assume that |
| 358 | * virtual == physical. We also assume that MAS2_EPN == MAS3_RPN. |
| 359 | */ |
| 360 | lis r3, MAS2_EPN@h |
| 361 | ori r3, r3, MAS2_EPN@l /* R3 = MAS2_EPN */ |
| 362 | |
| 363 | and r1, r1, r3 /* Our PC, rounded down to the nearest page */ |
| 364 | |
| 365 | mfspr r2, MAS2 |
| 366 | andc r2, r2, r3 |
| 367 | or r2, r2, r1 |
| 368 | mtspr MAS2, r2 /* Set the EPN to our PC base address */ |
| 369 | |
| 370 | mfspr r2, MAS3 |
| 371 | andc r2, r2, r3 |
| 372 | or r2, r2, r1 |
| 373 | mtspr MAS3, r2 /* Set the RPN to our PC base address */ |
| 374 | |
| 375 | isync |
| 376 | msync |
| 377 | tlbwe |
| 378 | |
| 379 | /* |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 380 | * Relocate CCSR, if necessary. We relocate CCSR if (obviously) the default |
| 381 | * location is not where we want it. This typically happens on a 36-bit |
| 382 | * system, where we want to move CCSR to near the top of 36-bit address space. |
| 383 | * |
| 384 | * To move CCSR, we create two temporary TLBs, one for the old location, and |
| 385 | * another for the new location. On CoreNet systems, we also need to create |
| 386 | * a special, temporary LAW. |
| 387 | * |
| 388 | * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for |
| 389 | * long-term TLBs, so we use TLB0 here. |
| 390 | */ |
| 391 | #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) |
| 392 | |
| 393 | #if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW) |
| 394 | #error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined." |
| 395 | #endif |
| 396 | |
| 397 | purge_old_ccsr_tlb: |
| 398 | lis r8, CONFIG_SYS_CCSRBAR@h |
| 399 | ori r8, r8, CONFIG_SYS_CCSRBAR@l |
| 400 | lis r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h |
| 401 | ori r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l |
| 402 | |
| 403 | /* |
| 404 | * In a multi-stage boot (e.g. NAND boot), a previous stage may have |
| 405 | * created a TLB for CCSR, which will interfere with our relocation |
| 406 | * code. Since we're going to create a new TLB for CCSR anyway, |
| 407 | * it should be safe to delete this old TLB here. We have to search |
| 408 | * for it, though. |
| 409 | */ |
| 410 | |
| 411 | li r1, 0 |
| 412 | mtspr MAS6, r1 /* Search the current address space and PID */ |
Timur Tabi | 452ad61 | 2011-10-31 13:30:43 -0500 | [diff] [blame] | 413 | isync |
| 414 | msync |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 415 | tlbsx 0, r8 |
| 416 | mfspr r1, MAS1 |
| 417 | andis. r2, r1, MAS1_VALID@h /* Check for the Valid bit */ |
| 418 | beq 1f /* Skip if no TLB found */ |
| 419 | |
| 420 | rlwinm r1, r1, 0, 1, 31 /* Clear Valid bit */ |
| 421 | mtspr MAS1, r1 |
Timur Tabi | 452ad61 | 2011-10-31 13:30:43 -0500 | [diff] [blame] | 422 | isync |
| 423 | msync |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 424 | tlbwe |
| 425 | 1: |
| 426 | |
| 427 | create_ccsr_new_tlb: |
| 428 | /* |
| 429 | * Create a TLB for the new location of CCSR. Register R8 is reserved |
| 430 | * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR). |
| 431 | */ |
| 432 | lis r0, FSL_BOOKE_MAS0(0, 0, 0)@h |
| 433 | ori r0, r0, FSL_BOOKE_MAS0(0, 0, 0)@l |
| 434 | lis r1, FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h |
| 435 | ori r1, r1, FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l |
| 436 | lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@h |
| 437 | ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@l |
| 438 | lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h |
| 439 | ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l |
| 440 | lis r7, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h |
| 441 | ori r7, r7, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l |
| 442 | mtspr MAS0, r0 |
| 443 | mtspr MAS1, r1 |
| 444 | mtspr MAS2, r2 |
| 445 | mtspr MAS3, r3 |
| 446 | mtspr MAS7, r7 |
| 447 | isync |
| 448 | msync |
| 449 | tlbwe |
| 450 | |
| 451 | /* |
Timur Tabi | c2efa0a | 2011-10-31 13:30:42 -0500 | [diff] [blame] | 452 | * Create a TLB for the current location of CCSR. Register R9 is reserved |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 453 | * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000). |
| 454 | */ |
| 455 | create_ccsr_old_tlb: |
| 456 | lis r0, FSL_BOOKE_MAS0(0, 1, 0)@h |
| 457 | ori r0, r0, FSL_BOOKE_MAS0(0, 1, 0)@l |
| 458 | lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@h |
| 459 | ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@l |
| 460 | lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_DEFAULT, 0, (MAS3_SW|MAS3_SR))@h |
| 461 | ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_DEFAULT, 0, (MAS3_SW|MAS3_SR))@l |
| 462 | li r7, 0 /* The default CCSR address is always a 32-bit number */ |
| 463 | mtspr MAS0, r0 |
| 464 | /* MAS1 is the same as above */ |
| 465 | mtspr MAS2, r2 |
| 466 | mtspr MAS3, r3 |
| 467 | mtspr MAS7, r7 |
| 468 | isync |
| 469 | msync |
| 470 | tlbwe |
| 471 | |
Timur Tabi | 19e4384 | 2011-10-31 13:30:44 -0500 | [diff] [blame] | 472 | /* |
| 473 | * We have a TLB for what we think is the current (old) CCSR. Let's |
| 474 | * verify that, otherwise we won't be able to move it. |
| 475 | * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only |
| 476 | * need to compare the lower 32 bits of CCSRBAR on CoreNet systems. |
| 477 | */ |
| 478 | verify_old_ccsr: |
| 479 | lis r0, CONFIG_SYS_CCSRBAR_DEFAULT@h |
| 480 | ori r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l |
| 481 | #ifdef CONFIG_FSL_CORENET |
| 482 | lwz r1, 4(r9) /* CCSRBARL */ |
| 483 | #else |
| 484 | lwz r1, 0(r9) /* CCSRBAR, shifted right by 12 */ |
| 485 | slwi r1, r1, 12 |
| 486 | #endif |
| 487 | |
| 488 | cmpl 0, r0, r1 |
| 489 | |
| 490 | /* |
| 491 | * If the value we read from CCSRBARL is not what we expect, then |
| 492 | * enter an infinite loop. This will at least allow a debugger to |
| 493 | * halt execution and examine TLBs, etc. There's no point in going |
| 494 | * on. |
| 495 | */ |
| 496 | infinite_debug_loop: |
| 497 | bne infinite_debug_loop |
| 498 | |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 499 | #ifdef CONFIG_FSL_CORENET |
| 500 | |
| 501 | #define CCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000) |
| 502 | #define LAW_EN 0x80000000 |
| 503 | #define LAW_SIZE_4K 0xb |
| 504 | #define CCSRBAR_LAWAR (LAW_EN | (0x1e << 20) | LAW_SIZE_4K) |
| 505 | #define CCSRAR_C 0x80000000 /* Commit */ |
| 506 | |
| 507 | create_temp_law: |
| 508 | /* |
| 509 | * On CoreNet systems, we create the temporary LAW using a special LAW |
| 510 | * target ID of 0x1e. LAWBARH is at offset 0xc00 in CCSR. |
| 511 | */ |
| 512 | lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h |
| 513 | ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l |
| 514 | lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h |
| 515 | ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l |
| 516 | lis r2, CCSRBAR_LAWAR@h |
| 517 | ori r2, r2, CCSRBAR_LAWAR@l |
| 518 | |
| 519 | stw r0, 0xc00(r9) /* LAWBARH0 */ |
| 520 | stw r1, 0xc04(r9) /* LAWBARL0 */ |
| 521 | sync |
| 522 | stw r2, 0xc08(r9) /* LAWAR0 */ |
| 523 | |
| 524 | /* |
| 525 | * Read back from LAWAR to ensure the update is complete. e500mc |
| 526 | * cores also require an isync. |
| 527 | */ |
| 528 | lwz r0, 0xc08(r9) /* LAWAR0 */ |
| 529 | isync |
| 530 | |
| 531 | /* |
| 532 | * Read the current CCSRBARH and CCSRBARL using load word instructions. |
| 533 | * Follow this with an isync instruction. This forces any outstanding |
| 534 | * accesses to configuration space to completion. |
| 535 | */ |
| 536 | read_old_ccsrbar: |
| 537 | lwz r0, 0(r9) /* CCSRBARH */ |
Timur Tabi | c2efa0a | 2011-10-31 13:30:42 -0500 | [diff] [blame] | 538 | lwz r0, 4(r9) /* CCSRBARL */ |
Timur Tabi | 6ca88b0 | 2011-08-03 16:30:10 -0500 | [diff] [blame] | 539 | isync |
| 540 | |
| 541 | /* |
| 542 | * Write the new values for CCSRBARH and CCSRBARL to their old |
| 543 | * locations. The CCSRBARH has a shadow register. When the CCSRBARH |
| 544 | * has a new value written it loads a CCSRBARH shadow register. When |
| 545 | * the CCSRBARL is written, the CCSRBARH shadow register contents |
| 546 | * along with the CCSRBARL value are loaded into the CCSRBARH and |
| 547 | * CCSRBARL registers, respectively. Follow this with a sync |
| 548 | * instruction. |
| 549 | */ |
| 550 | write_new_ccsrbar: |
| 551 | lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h |
| 552 | ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l |
| 553 | lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h |
| 554 | ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l |
| 555 | lis r2, CCSRAR_C@h |
| 556 | ori r2, r2, CCSRAR_C@l |
| 557 | |
| 558 | stw r0, 0(r9) /* Write to CCSRBARH */ |
| 559 | sync /* Make sure we write to CCSRBARH first */ |
| 560 | stw r1, 4(r9) /* Write to CCSRBARL */ |
| 561 | sync |
| 562 | |
| 563 | /* |
| 564 | * Write a 1 to the commit bit (C) of CCSRAR at the old location. |
| 565 | * Follow this with a sync instruction. |
| 566 | */ |
| 567 | stw r2, 8(r9) |
| 568 | sync |
| 569 | |
| 570 | /* Delete the temporary LAW */ |
| 571 | delete_temp_law: |
| 572 | li r1, 0 |
| 573 | stw r1, 0xc08(r8) |
| 574 | sync |
| 575 | stw r1, 0xc00(r8) |
| 576 | stw r1, 0xc04(r8) |
| 577 | sync |
| 578 | |
| 579 | #else /* #ifdef CONFIG_FSL_CORENET */ |
| 580 | |
| 581 | write_new_ccsrbar: |
| 582 | /* |
| 583 | * Read the current value of CCSRBAR using a load word instruction |
| 584 | * followed by an isync. This forces all accesses to configuration |
| 585 | * space to complete. |
| 586 | */ |
| 587 | sync |
| 588 | lwz r0, 0(r9) |
| 589 | isync |
| 590 | |
| 591 | /* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */ |
| 592 | #define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \ |
| 593 | (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12)) |
| 594 | |
| 595 | /* Write the new value to CCSRBAR. */ |
| 596 | lis r0, CCSRBAR_PHYS_RS12@h |
| 597 | ori r0, r0, CCSRBAR_PHYS_RS12@l |
| 598 | stw r0, 0(r9) |
| 599 | sync |
| 600 | |
| 601 | /* |
| 602 | * The manual says to perform a load of an address that does not |
| 603 | * access configuration space or the on-chip SRAM using an existing TLB, |
| 604 | * but that doesn't appear to be necessary. We will do the isync, |
| 605 | * though. |
| 606 | */ |
| 607 | isync |
| 608 | |
| 609 | /* |
| 610 | * Read the contents of CCSRBAR from its new location, followed by |
| 611 | * another isync. |
| 612 | */ |
| 613 | lwz r0, 0(r8) |
| 614 | isync |
| 615 | |
| 616 | #endif /* #ifdef CONFIG_FSL_CORENET */ |
| 617 | |
| 618 | /* Delete the temporary TLBs */ |
| 619 | delete_temp_tlbs: |
| 620 | lis r0, FSL_BOOKE_MAS0(0, 0, 0)@h |
| 621 | ori r0, r0, FSL_BOOKE_MAS0(0, 0, 0)@l |
| 622 | li r1, 0 |
| 623 | lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@h |
| 624 | ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@l |
| 625 | mtspr MAS0, r0 |
| 626 | mtspr MAS1, r1 |
| 627 | mtspr MAS2, r2 |
| 628 | isync |
| 629 | msync |
| 630 | tlbwe |
| 631 | |
| 632 | lis r0, FSL_BOOKE_MAS0(0, 1, 0)@h |
| 633 | ori r0, r0, FSL_BOOKE_MAS0(0, 1, 0)@l |
| 634 | lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@h |
| 635 | ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@l |
| 636 | mtspr MAS0, r0 |
| 637 | mtspr MAS2, r2 |
| 638 | isync |
| 639 | msync |
| 640 | tlbwe |
| 641 | #endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */ |
| 642 | |
| 643 | create_init_ram_area: |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 644 | lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h |
| 645 | ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l |
| 646 | |
Ruchika Gupta | 7065b7d | 2010-12-15 17:02:08 +0000 | [diff] [blame] | 647 | #if !defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SECURE_BOOT) |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 648 | /* create a temp mapping in AS=1 to the 4M boot window */ |
Dave Liu | f51f07e | 2008-12-16 12:09:27 +0800 | [diff] [blame] | 649 | lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@h |
| 650 | 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] | 651 | |
Haiying Wang | 0635b09 | 2010-11-10 15:37:13 -0500 | [diff] [blame] | 652 | lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE & 0xffc00000, (MAS2_I|MAS2_G))@h |
| 653 | ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE & 0xffc00000, (MAS2_I|MAS2_G))@l |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 654 | |
Dave Liu | f51f07e | 2008-12-16 12:09:27 +0800 | [diff] [blame] | 655 | /* The 85xx has the default boot window 0xff800000 - 0xffffffff */ |
| 656 | lis r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h |
| 657 | ori r9,r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l |
Ruchika Gupta | 7065b7d | 2010-12-15 17:02:08 +0000 | [diff] [blame] | 658 | #elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT) |
| 659 | /* create a temp mapping in AS = 1 for Flash mapping |
| 660 | * created by PBL for ISBC code |
| 661 | */ |
| 662 | lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h |
| 663 | ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l |
| 664 | |
| 665 | lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@h |
| 666 | ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@l |
| 667 | |
| 668 | lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_PBI_FLASH_WINDOW, 0, |
| 669 | (MAS3_SX|MAS3_SW|MAS3_SR))@h |
| 670 | ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_PBI_FLASH_WINDOW, 0, |
| 671 | (MAS3_SX|MAS3_SW|MAS3_SR))@l |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 672 | #else |
| 673 | /* |
Haiying Wang | 0635b09 | 2010-11-10 15:37:13 -0500 | [diff] [blame] | 674 | * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main |
| 675 | * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage. |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 676 | */ |
| 677 | lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h |
| 678 | ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l |
| 679 | |
Haiying Wang | 0635b09 | 2010-11-10 15:37:13 -0500 | [diff] [blame] | 680 | lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@h |
| 681 | ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@l |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 682 | |
Haiying Wang | 0635b09 | 2010-11-10 15:37:13 -0500 | [diff] [blame] | 683 | lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_MONITOR_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h |
| 684 | ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_MONITOR_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 685 | #endif |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 686 | |
| 687 | mtspr MAS0,r6 |
| 688 | mtspr MAS1,r7 |
| 689 | mtspr MAS2,r8 |
| 690 | mtspr MAS3,r9 |
| 691 | isync |
| 692 | msync |
| 693 | tlbwe |
| 694 | |
| 695 | /* create a temp mapping in AS=1 to the stack */ |
| 696 | lis r6,FSL_BOOKE_MAS0(1, 14, 0)@h |
| 697 | ori r6,r6,FSL_BOOKE_MAS0(1, 14, 0)@l |
| 698 | |
| 699 | lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@h |
| 700 | ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@l |
| 701 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 702 | lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@h |
| 703 | 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] | 704 | |
york | a3f1852 | 2010-07-02 22:25:57 +0000 | [diff] [blame] | 705 | #if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \ |
| 706 | defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH) |
| 707 | lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0, |
| 708 | (MAS3_SX|MAS3_SW|MAS3_SR))@h |
| 709 | ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0, |
| 710 | (MAS3_SX|MAS3_SW|MAS3_SR))@l |
| 711 | li r10,CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH |
| 712 | mtspr MAS7,r10 |
| 713 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 714 | lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h |
| 715 | ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l |
york | a3f1852 | 2010-07-02 22:25:57 +0000 | [diff] [blame] | 716 | #endif |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 717 | |
| 718 | mtspr MAS0,r6 |
| 719 | mtspr MAS1,r7 |
| 720 | mtspr MAS2,r8 |
| 721 | mtspr MAS3,r9 |
| 722 | isync |
| 723 | msync |
| 724 | tlbwe |
| 725 | |
Scott Wood | 1b72dbe | 2009-08-20 17:44:20 -0500 | [diff] [blame] | 726 | lis r6,MSR_IS|MSR_DS@h |
| 727 | ori r6,r6,MSR_IS|MSR_DS@l |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 728 | lis r7,switch_as@h |
| 729 | ori r7,r7,switch_as@l |
| 730 | |
| 731 | mtspr SPRN_SRR0,r7 |
| 732 | mtspr SPRN_SRR1,r6 |
| 733 | rfi |
| 734 | |
| 735 | switch_as: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 736 | /* L1 DCache is used for initial RAM */ |
| 737 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 738 | /* Allocate Initial RAM in data cache. |
| 739 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 740 | lis r3,CONFIG_SYS_INIT_RAM_ADDR@h |
| 741 | ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l |
Kumar Gala | b009f3e | 2008-01-08 01:22:21 -0600 | [diff] [blame] | 742 | mfspr r2, L1CFG0 |
| 743 | andi. r2, r2, 0x1ff |
| 744 | /* cache size * 1024 / (2 * L1 line size) */ |
| 745 | slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT) |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 746 | mtctr r2 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 747 | li r0,0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 748 | 1: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 749 | dcbz r0,r3 |
| 750 | dcbtls 0,r0,r3 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 751 | addi r3,r3,CONFIG_SYS_CACHELINE_SIZE |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 752 | bdnz 1b |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 753 | |
Kumar Gala | 3db0bef | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 754 | /* 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] | 755 | #ifdef CONFIG_SYS_RAMBOOT |
Kumar Gala | 3db0bef | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 756 | b _start_cont |
| 757 | #else |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 758 | /* Calculate absolute address in FLASH and jump there */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 759 | /*--------------------------------------------------------------*/ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 760 | lis r3,CONFIG_SYS_MONITOR_BASE@h |
| 761 | ori r3,r3,CONFIG_SYS_MONITOR_BASE@l |
Kumar Gala | 3db0bef | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 762 | addi r3,r3,_start_cont - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 763 | mtlr r3 |
urwithsughosh@gmail.com | 1e701e7 | 2007-09-24 13:36:01 -0400 | [diff] [blame] | 764 | blr |
Kumar Gala | 3db0bef | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 765 | #endif |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 766 | |
Kumar Gala | 3db0bef | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 767 | .text |
| 768 | .globl _start |
| 769 | _start: |
| 770 | .long 0x27051956 /* U-BOOT Magic Number */ |
| 771 | .globl version_string |
| 772 | version_string: |
Andreas Bießmann | 09c2e90 | 2011-07-18 20:24:04 +0200 | [diff] [blame] | 773 | .ascii U_BOOT_VERSION_STRING, "\0" |
Kumar Gala | 3db0bef | 2007-08-07 18:07:27 -0500 | [diff] [blame] | 774 | |
| 775 | .align 4 |
| 776 | .globl _start_cont |
| 777 | _start_cont: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 778 | /* 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] | 779 | lis r1,CONFIG_SYS_INIT_RAM_ADDR@h |
| 780 | ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 781 | |
| 782 | li r0,0 |
| 783 | stwu r0,-4(r1) |
| 784 | stwu r0,-4(r1) /* Terminate call chain */ |
| 785 | |
| 786 | stwu r1,-8(r1) /* Save back chain and move SP */ |
| 787 | lis r0,RESET_VECTOR@h /* Address of reset vector */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 788 | ori r0,r0,RESET_VECTOR@l |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 789 | stwu r1,-8(r1) /* Save back chain and move SP */ |
| 790 | stw r0,+12(r1) /* Save return addr (underflow vect) */ |
| 791 | |
| 792 | GET_GOT |
Kumar Gala | 8716318 | 2008-01-16 22:38:34 -0600 | [diff] [blame] | 793 | bl cpu_init_early_f |
| 794 | |
| 795 | /* switch back to AS = 0 */ |
| 796 | lis r3,(MSR_CE|MSR_ME|MSR_DE)@h |
| 797 | ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l |
| 798 | mtmsr r3 |
| 799 | isync |
| 800 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 801 | bl cpu_init_f |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 802 | bl board_init_f |
wdenk | 0ac6f8b | 2004-07-09 23:27:13 +0000 | [diff] [blame] | 803 | isync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 804 | |
Peter Tyser | 52ebd9c | 2010-09-14 19:13:53 -0500 | [diff] [blame] | 805 | /* NOTREACHED - board_init_f() does not return */ |
| 806 | |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 807 | #ifndef CONFIG_NAND_SPL |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 808 | . = EXC_OFF_SYS_RESET |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 809 | .globl _start_of_vectors |
| 810 | _start_of_vectors: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 811 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 812 | /* Critical input. */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 813 | CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException) |
| 814 | |
| 815 | /* Machine check */ |
| 816 | MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 817 | |
| 818 | /* Data Storage exception. */ |
| 819 | STD_EXCEPTION(0x0300, DataStorage, UnknownException) |
| 820 | |
| 821 | /* Instruction Storage exception. */ |
| 822 | STD_EXCEPTION(0x0400, InstStorage, UnknownException) |
| 823 | |
| 824 | /* External Interrupt exception. */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 825 | STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 826 | |
| 827 | /* Alignment exception. */ |
| 828 | . = 0x0600 |
| 829 | Alignment: |
Rafal Jaworowski | 02032e8 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 830 | EXCEPTION_PROLOG(SRR0, SRR1) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 831 | mfspr r4,DAR |
| 832 | stw r4,_DAR(r21) |
| 833 | mfspr r5,DSISR |
| 834 | stw r5,_DSISR(r21) |
| 835 | addi r3,r1,STACK_FRAME_OVERHEAD |
Joakim Tjernlund | fc4e188 | 2010-01-19 14:41:55 +0100 | [diff] [blame] | 836 | EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 837 | |
| 838 | /* Program check exception */ |
| 839 | . = 0x0700 |
| 840 | ProgramCheck: |
Rafal Jaworowski | 02032e8 | 2007-06-22 14:58:04 +0200 | [diff] [blame] | 841 | EXCEPTION_PROLOG(SRR0, SRR1) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 842 | addi r3,r1,STACK_FRAME_OVERHEAD |
Joakim Tjernlund | fc4e188 | 2010-01-19 14:41:55 +0100 | [diff] [blame] | 843 | EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException, |
| 844 | MSR_KERNEL, COPY_EE) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 845 | |
| 846 | /* No FPU on MPC85xx. This exception is not supposed to happen. |
| 847 | */ |
| 848 | STD_EXCEPTION(0x0800, FPUnavailable, UnknownException) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 849 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 850 | . = 0x0900 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 851 | /* |
| 852 | * r0 - SYSCALL number |
| 853 | * r3-... arguments |
| 854 | */ |
| 855 | SystemCall: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 856 | addis r11,r0,0 /* get functions table addr */ |
| 857 | ori r11,r11,0 /* Note: this code is patched in trap_init */ |
| 858 | addis r12,r0,0 /* get number of functions */ |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 859 | ori r12,r12,0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 860 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 861 | cmplw 0,r0,r12 |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 862 | bge 1f |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 863 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 864 | rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */ |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 865 | add r11,r11,r0 |
| 866 | lwz r11,0(r11) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 867 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 868 | li r20,0xd00-4 /* Get stack pointer */ |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 869 | lwz r12,0(r20) |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 870 | subi r12,r12,12 /* Adjust stack pointer */ |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 871 | li r0,0xc00+_end_back-SystemCall |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 872 | cmplw 0,r0,r12 /* Check stack overflow */ |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 873 | bgt 1f |
| 874 | stw r12,0(r20) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 875 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 876 | mflr r0 |
| 877 | stw r0,0(r12) |
| 878 | mfspr r0,SRR0 |
| 879 | stw r0,4(r12) |
| 880 | mfspr r0,SRR1 |
| 881 | stw r0,8(r12) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 882 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 883 | li r12,0xc00+_back-SystemCall |
| 884 | mtlr r12 |
| 885 | mtspr SRR0,r11 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 886 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 887 | 1: SYNC |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 888 | rfi |
| 889 | _back: |
| 890 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 891 | mfmsr r11 /* Disable interrupts */ |
| 892 | li r12,0 |
| 893 | ori r12,r12,MSR_EE |
| 894 | andc r11,r11,r12 |
| 895 | SYNC /* Some chip revs need this... */ |
| 896 | mtmsr r11 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 897 | SYNC |
| 898 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 899 | li r12,0xd00-4 /* restore regs */ |
| 900 | lwz r12,0(r12) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 901 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 902 | lwz r11,0(r12) |
| 903 | mtlr r11 |
| 904 | lwz r11,4(r12) |
| 905 | mtspr SRR0,r11 |
| 906 | lwz r11,8(r12) |
| 907 | mtspr SRR1,r11 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 908 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 909 | addi r12,r12,12 /* Adjust stack pointer */ |
| 910 | li r20,0xd00-4 |
| 911 | stw r12,0(r20) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 912 | |
| 913 | SYNC |
| 914 | rfi |
| 915 | _end_back: |
| 916 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 917 | STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt) |
| 918 | STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException) |
| 919 | STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 920 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 921 | STD_EXCEPTION(0x0d00, DataTLBError, UnknownException) |
| 922 | STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 923 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 924 | CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException ) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 925 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 926 | .globl _end_of_vectors |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 927 | _end_of_vectors: |
| 928 | |
| 929 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 930 | . = . + (0x100 - ( . & 0xff )) /* align for debug */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 931 | |
| 932 | /* |
| 933 | * This code finishes saving the registers to the exception frame |
| 934 | * and jumps to the appropriate handler for the exception. |
| 935 | * Register r21 is pointer into trap frame, r1 has new stack pointer. |
| 936 | */ |
| 937 | .globl transfer_to_handler |
| 938 | transfer_to_handler: |
| 939 | stw r22,_NIP(r21) |
| 940 | lis r22,MSR_POW@h |
| 941 | andc r23,r23,r22 |
| 942 | stw r23,_MSR(r21) |
| 943 | SAVE_GPR(7, r21) |
| 944 | SAVE_4GPRS(8, r21) |
| 945 | SAVE_8GPRS(12, r21) |
| 946 | SAVE_8GPRS(24, r21) |
| 947 | |
| 948 | mflr r23 |
| 949 | andi. r24,r23,0x3f00 /* get vector offset */ |
| 950 | stw r24,TRAP(r21) |
| 951 | li r22,0 |
| 952 | stw r22,RESULT(r21) |
| 953 | mtspr SPRG2,r22 /* r1 is now kernel sp */ |
| 954 | |
| 955 | lwz r24,0(r23) /* virtual address of handler */ |
| 956 | lwz r23,4(r23) /* where to go when done */ |
| 957 | mtspr SRR0,r24 |
| 958 | mtspr SRR1,r20 |
| 959 | mtlr r23 |
| 960 | SYNC |
| 961 | rfi /* jump to handler, enable MMU */ |
| 962 | |
| 963 | int_return: |
| 964 | mfmsr r28 /* Disable interrupts */ |
| 965 | li r4,0 |
| 966 | ori r4,r4,MSR_EE |
| 967 | andc r28,r28,r4 |
| 968 | SYNC /* Some chip revs need this... */ |
| 969 | mtmsr r28 |
| 970 | SYNC |
| 971 | lwz r2,_CTR(r1) |
| 972 | lwz r0,_LINK(r1) |
| 973 | mtctr r2 |
| 974 | mtlr r0 |
| 975 | lwz r2,_XER(r1) |
| 976 | lwz r0,_CCR(r1) |
| 977 | mtspr XER,r2 |
| 978 | mtcrf 0xFF,r0 |
| 979 | REST_10GPRS(3, r1) |
| 980 | REST_10GPRS(13, r1) |
| 981 | REST_8GPRS(23, r1) |
| 982 | REST_GPR(31, r1) |
| 983 | lwz r2,_NIP(r1) /* Restore environment */ |
| 984 | lwz r0,_MSR(r1) |
| 985 | mtspr SRR0,r2 |
| 986 | mtspr SRR1,r0 |
| 987 | lwz r0,GPR0(r1) |
| 988 | lwz r2,GPR2(r1) |
| 989 | lwz r1,GPR1(r1) |
| 990 | SYNC |
| 991 | rfi |
| 992 | |
| 993 | crit_return: |
| 994 | mfmsr r28 /* Disable interrupts */ |
| 995 | li r4,0 |
| 996 | ori r4,r4,MSR_EE |
| 997 | andc r28,r28,r4 |
| 998 | SYNC /* Some chip revs need this... */ |
| 999 | mtmsr r28 |
| 1000 | SYNC |
| 1001 | lwz r2,_CTR(r1) |
| 1002 | lwz r0,_LINK(r1) |
| 1003 | mtctr r2 |
| 1004 | mtlr r0 |
| 1005 | lwz r2,_XER(r1) |
| 1006 | lwz r0,_CCR(r1) |
| 1007 | mtspr XER,r2 |
| 1008 | mtcrf 0xFF,r0 |
| 1009 | REST_10GPRS(3, r1) |
| 1010 | REST_10GPRS(13, r1) |
| 1011 | REST_8GPRS(23, r1) |
| 1012 | REST_GPR(31, r1) |
| 1013 | lwz r2,_NIP(r1) /* Restore environment */ |
| 1014 | lwz r0,_MSR(r1) |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1015 | mtspr SPRN_CSRR0,r2 |
| 1016 | mtspr SPRN_CSRR1,r0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1017 | lwz r0,GPR0(r1) |
| 1018 | lwz r2,GPR2(r1) |
| 1019 | lwz r1,GPR1(r1) |
| 1020 | SYNC |
| 1021 | rfci |
| 1022 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1023 | mck_return: |
| 1024 | mfmsr r28 /* Disable interrupts */ |
| 1025 | li r4,0 |
| 1026 | ori r4,r4,MSR_EE |
| 1027 | andc r28,r28,r4 |
| 1028 | SYNC /* Some chip revs need this... */ |
| 1029 | mtmsr r28 |
| 1030 | SYNC |
| 1031 | lwz r2,_CTR(r1) |
| 1032 | lwz r0,_LINK(r1) |
| 1033 | mtctr r2 |
| 1034 | mtlr r0 |
| 1035 | lwz r2,_XER(r1) |
| 1036 | lwz r0,_CCR(r1) |
| 1037 | mtspr XER,r2 |
| 1038 | mtcrf 0xFF,r0 |
| 1039 | REST_10GPRS(3, r1) |
| 1040 | REST_10GPRS(13, r1) |
| 1041 | REST_8GPRS(23, r1) |
| 1042 | REST_GPR(31, r1) |
| 1043 | lwz r2,_NIP(r1) /* Restore environment */ |
| 1044 | lwz r0,_MSR(r1) |
| 1045 | mtspr SPRN_MCSRR0,r2 |
| 1046 | mtspr SPRN_MCSRR1,r0 |
| 1047 | lwz r0,GPR0(r1) |
| 1048 | lwz r2,GPR2(r1) |
| 1049 | lwz r1,GPR1(r1) |
| 1050 | SYNC |
| 1051 | rfmci |
| 1052 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1053 | /* Cache functions. |
| 1054 | */ |
Matthew McClintock | 0a9fe8e | 2011-05-23 08:38:53 +0000 | [diff] [blame] | 1055 | .globl flush_icache |
| 1056 | flush_icache: |
Kumar Gala | 54e091d | 2008-09-22 14:11:10 -0500 | [diff] [blame] | 1057 | .globl invalidate_icache |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1058 | invalidate_icache: |
| 1059 | mfspr r0,L1CSR1 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1060 | ori r0,r0,L1CSR1_ICFI |
| 1061 | msync |
| 1062 | isync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1063 | mtspr L1CSR1,r0 |
| 1064 | isync |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1065 | blr /* entire I cache */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1066 | |
Kumar Gala | 54e091d | 2008-09-22 14:11:10 -0500 | [diff] [blame] | 1067 | .globl invalidate_dcache |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1068 | invalidate_dcache: |
| 1069 | mfspr r0,L1CSR0 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1070 | ori r0,r0,L1CSR0_DCFI |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1071 | msync |
| 1072 | isync |
| 1073 | mtspr L1CSR0,r0 |
| 1074 | isync |
| 1075 | blr |
| 1076 | |
| 1077 | .globl icache_enable |
| 1078 | icache_enable: |
| 1079 | mflr r8 |
| 1080 | bl invalidate_icache |
| 1081 | mtlr r8 |
| 1082 | isync |
| 1083 | mfspr r4,L1CSR1 |
| 1084 | ori r4,r4,0x0001 |
| 1085 | oris r4,r4,0x0001 |
| 1086 | mtspr L1CSR1,r4 |
| 1087 | isync |
| 1088 | blr |
| 1089 | |
| 1090 | .globl icache_disable |
| 1091 | icache_disable: |
| 1092 | mfspr r0,L1CSR1 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1093 | lis r3,0 |
| 1094 | ori r3,r3,L1CSR1_ICE |
| 1095 | andc r0,r0,r3 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1096 | mtspr L1CSR1,r0 |
| 1097 | isync |
| 1098 | blr |
| 1099 | |
| 1100 | .globl icache_status |
| 1101 | icache_status: |
| 1102 | mfspr r3,L1CSR1 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1103 | andi. r3,r3,L1CSR1_ICE |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1104 | blr |
| 1105 | |
| 1106 | .globl dcache_enable |
| 1107 | dcache_enable: |
| 1108 | mflr r8 |
| 1109 | bl invalidate_dcache |
| 1110 | mtlr r8 |
| 1111 | isync |
| 1112 | mfspr r0,L1CSR0 |
| 1113 | ori r0,r0,0x0001 |
| 1114 | oris r0,r0,0x0001 |
| 1115 | msync |
| 1116 | isync |
| 1117 | mtspr L1CSR0,r0 |
| 1118 | isync |
| 1119 | blr |
| 1120 | |
| 1121 | .globl dcache_disable |
| 1122 | dcache_disable: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1123 | mfspr r3,L1CSR0 |
| 1124 | lis r4,0 |
| 1125 | ori r4,r4,L1CSR0_DCE |
| 1126 | andc r3,r3,r4 |
Kumar Gala | 45a6813 | 2011-01-05 10:33:46 -0600 | [diff] [blame] | 1127 | mtspr L1CSR0,r3 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1128 | isync |
| 1129 | blr |
| 1130 | |
| 1131 | .globl dcache_status |
| 1132 | dcache_status: |
| 1133 | mfspr r3,L1CSR0 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1134 | andi. r3,r3,L1CSR0_DCE |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1135 | blr |
| 1136 | |
| 1137 | .globl get_pir |
| 1138 | get_pir: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1139 | mfspr r3,PIR |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1140 | blr |
| 1141 | |
| 1142 | .globl get_pvr |
| 1143 | get_pvr: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1144 | mfspr r3,PVR |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1145 | blr |
| 1146 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1147 | .globl get_svr |
| 1148 | get_svr: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1149 | mfspr r3,SVR |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1150 | blr |
| 1151 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1152 | .globl wr_tcr |
| 1153 | wr_tcr: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1154 | mtspr TCR,r3 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1155 | blr |
| 1156 | |
| 1157 | /*------------------------------------------------------------------------------- */ |
| 1158 | /* Function: in8 */ |
| 1159 | /* Description: Input 8 bits */ |
| 1160 | /*------------------------------------------------------------------------------- */ |
| 1161 | .globl in8 |
| 1162 | in8: |
| 1163 | lbz r3,0x0000(r3) |
| 1164 | blr |
| 1165 | |
| 1166 | /*------------------------------------------------------------------------------- */ |
| 1167 | /* Function: out8 */ |
| 1168 | /* Description: Output 8 bits */ |
| 1169 | /*------------------------------------------------------------------------------- */ |
| 1170 | .globl out8 |
| 1171 | out8: |
| 1172 | stb r4,0x0000(r3) |
Ed Swarthout | 1487adb | 2007-09-26 16:35:54 -0500 | [diff] [blame] | 1173 | sync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1174 | blr |
| 1175 | |
| 1176 | /*------------------------------------------------------------------------------- */ |
| 1177 | /* Function: out16 */ |
| 1178 | /* Description: Output 16 bits */ |
| 1179 | /*------------------------------------------------------------------------------- */ |
| 1180 | .globl out16 |
| 1181 | out16: |
| 1182 | sth r4,0x0000(r3) |
Ed Swarthout | 1487adb | 2007-09-26 16:35:54 -0500 | [diff] [blame] | 1183 | sync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1184 | blr |
| 1185 | |
| 1186 | /*------------------------------------------------------------------------------- */ |
| 1187 | /* Function: out16r */ |
| 1188 | /* Description: Byte reverse and output 16 bits */ |
| 1189 | /*------------------------------------------------------------------------------- */ |
| 1190 | .globl out16r |
| 1191 | out16r: |
| 1192 | sthbrx r4,r0,r3 |
Ed Swarthout | 1487adb | 2007-09-26 16:35:54 -0500 | [diff] [blame] | 1193 | sync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1194 | blr |
| 1195 | |
| 1196 | /*------------------------------------------------------------------------------- */ |
| 1197 | /* Function: out32 */ |
| 1198 | /* Description: Output 32 bits */ |
| 1199 | /*------------------------------------------------------------------------------- */ |
| 1200 | .globl out32 |
| 1201 | out32: |
| 1202 | stw r4,0x0000(r3) |
Ed Swarthout | 1487adb | 2007-09-26 16:35:54 -0500 | [diff] [blame] | 1203 | sync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1204 | blr |
| 1205 | |
| 1206 | /*------------------------------------------------------------------------------- */ |
| 1207 | /* Function: out32r */ |
| 1208 | /* Description: Byte reverse and output 32 bits */ |
| 1209 | /*------------------------------------------------------------------------------- */ |
| 1210 | .globl out32r |
| 1211 | out32r: |
| 1212 | stwbrx r4,r0,r3 |
Ed Swarthout | 1487adb | 2007-09-26 16:35:54 -0500 | [diff] [blame] | 1213 | sync |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1214 | blr |
| 1215 | |
| 1216 | /*------------------------------------------------------------------------------- */ |
| 1217 | /* Function: in16 */ |
| 1218 | /* Description: Input 16 bits */ |
| 1219 | /*------------------------------------------------------------------------------- */ |
| 1220 | .globl in16 |
| 1221 | in16: |
| 1222 | lhz r3,0x0000(r3) |
| 1223 | blr |
| 1224 | |
| 1225 | /*------------------------------------------------------------------------------- */ |
| 1226 | /* Function: in16r */ |
| 1227 | /* Description: Input 16 bits and byte reverse */ |
| 1228 | /*------------------------------------------------------------------------------- */ |
| 1229 | .globl in16r |
| 1230 | in16r: |
| 1231 | lhbrx r3,r0,r3 |
| 1232 | blr |
| 1233 | |
| 1234 | /*------------------------------------------------------------------------------- */ |
| 1235 | /* Function: in32 */ |
| 1236 | /* Description: Input 32 bits */ |
| 1237 | /*------------------------------------------------------------------------------- */ |
| 1238 | .globl in32 |
| 1239 | in32: |
| 1240 | lwz 3,0x0000(3) |
| 1241 | blr |
| 1242 | |
| 1243 | /*------------------------------------------------------------------------------- */ |
| 1244 | /* Function: in32r */ |
| 1245 | /* Description: Input 32 bits and byte reverse */ |
| 1246 | /*------------------------------------------------------------------------------- */ |
| 1247 | .globl in32r |
| 1248 | in32r: |
| 1249 | lwbrx r3,r0,r3 |
| 1250 | blr |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 1251 | #endif /* !CONFIG_NAND_SPL */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1252 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1253 | /*------------------------------------------------------------------------------*/ |
| 1254 | |
| 1255 | /* |
Kumar Gala | d30f904 | 2009-09-11 11:27:00 -0500 | [diff] [blame] | 1256 | * void write_tlb(mas0, mas1, mas2, mas3, mas7) |
| 1257 | */ |
| 1258 | .globl write_tlb |
| 1259 | write_tlb: |
| 1260 | mtspr MAS0,r3 |
| 1261 | mtspr MAS1,r4 |
| 1262 | mtspr MAS2,r5 |
| 1263 | mtspr MAS3,r6 |
| 1264 | #ifdef CONFIG_ENABLE_36BIT_PHYS |
| 1265 | mtspr MAS7,r7 |
| 1266 | #endif |
| 1267 | li r3,0 |
| 1268 | #ifdef CONFIG_SYS_BOOK3E_HV |
| 1269 | mtspr MAS8,r3 |
| 1270 | #endif |
| 1271 | isync |
| 1272 | tlbwe |
| 1273 | msync |
| 1274 | isync |
| 1275 | blr |
| 1276 | |
| 1277 | /* |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1278 | * void relocate_code (addr_sp, gd, addr_moni) |
| 1279 | * |
| 1280 | * This "function" does not return, instead it continues in RAM |
| 1281 | * after relocating the monitor code. |
| 1282 | * |
| 1283 | * r3 = dest |
| 1284 | * r4 = src |
| 1285 | * r5 = length in bytes |
| 1286 | * r6 = cachelinesize |
| 1287 | */ |
| 1288 | .globl relocate_code |
| 1289 | relocate_code: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1290 | mr r1,r3 /* Set new stack pointer */ |
| 1291 | mr r9,r4 /* Save copy of Init Data pointer */ |
| 1292 | mr r10,r5 /* Save copy of Destination Address */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1293 | |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 1294 | GET_GOT |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1295 | mr r3,r5 /* Destination Address */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1296 | lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */ |
| 1297 | ori r4,r4,CONFIG_SYS_MONITOR_BASE@l |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1298 | lwz r5,GOT(__init_end) |
| 1299 | sub r5,r5,r4 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1300 | li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1301 | |
| 1302 | /* |
| 1303 | * Fix GOT pointer: |
| 1304 | * |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1305 | * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1306 | * |
| 1307 | * Offset: |
| 1308 | */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1309 | sub r15,r10,r4 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1310 | |
| 1311 | /* First our own GOT */ |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 1312 | add r12,r12,r15 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1313 | /* the the one used by the C code */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1314 | add r30,r30,r15 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1315 | |
| 1316 | /* |
| 1317 | * Now relocate code |
| 1318 | */ |
| 1319 | |
| 1320 | cmplw cr1,r3,r4 |
| 1321 | addi r0,r5,3 |
| 1322 | srwi. r0,r0,2 |
| 1323 | beq cr1,4f /* In place copy is not necessary */ |
| 1324 | beq 7f /* Protect against 0 count */ |
| 1325 | mtctr r0 |
| 1326 | bge cr1,2f |
| 1327 | |
| 1328 | la r8,-4(r4) |
| 1329 | la r7,-4(r3) |
| 1330 | 1: lwzu r0,4(r8) |
| 1331 | stwu r0,4(r7) |
| 1332 | bdnz 1b |
| 1333 | b 4f |
| 1334 | |
| 1335 | 2: slwi r0,r0,2 |
| 1336 | add r8,r4,r0 |
| 1337 | add r7,r3,r0 |
| 1338 | 3: lwzu r0,-4(r8) |
| 1339 | stwu r0,-4(r7) |
| 1340 | bdnz 3b |
| 1341 | |
| 1342 | /* |
| 1343 | * Now flush the cache: note that we must start from a cache aligned |
| 1344 | * address. Otherwise we might miss one cache line. |
| 1345 | */ |
| 1346 | 4: cmpwi r6,0 |
| 1347 | add r5,r3,r5 |
| 1348 | beq 7f /* Always flush prefetch queue in any case */ |
| 1349 | subi r0,r6,1 |
| 1350 | andc r3,r3,r0 |
| 1351 | mr r4,r3 |
| 1352 | 5: dcbst 0,r4 |
| 1353 | add r4,r4,r6 |
| 1354 | cmplw r4,r5 |
| 1355 | blt 5b |
| 1356 | sync /* Wait for all dcbst to complete on bus */ |
| 1357 | mr r4,r3 |
| 1358 | 6: icbi 0,r4 |
| 1359 | add r4,r4,r6 |
| 1360 | cmplw r4,r5 |
| 1361 | blt 6b |
| 1362 | 7: sync /* Wait for all icbi to complete on bus */ |
| 1363 | isync |
| 1364 | |
Wolfgang Denk | 7d31499 | 2005-10-05 00:00:54 +0200 | [diff] [blame] | 1365 | /* |
| 1366 | * Re-point the IVPR at RAM |
| 1367 | */ |
| 1368 | mtspr IVPR,r10 |
Wolfgang Denk | 99b0d28 | 2005-10-05 00:19:34 +0200 | [diff] [blame] | 1369 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1370 | /* |
| 1371 | * We are done. Do not return, instead branch to second part of board |
| 1372 | * initialization, now running from RAM. |
| 1373 | */ |
| 1374 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1375 | addi r0,r10,in_ram - _start + _START_OFFSET |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1376 | mtlr r0 |
| 1377 | blr /* NEVER RETURNS! */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1378 | .globl in_ram |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1379 | in_ram: |
| 1380 | |
| 1381 | /* |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 1382 | * Relocation Function, r12 point to got2+0x8000 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1383 | * |
| 1384 | * Adjust got2 pointers, no need to check for 0, this code |
| 1385 | * already puts a few entries in the table. |
| 1386 | */ |
| 1387 | li r0,__got2_entries@sectoff@l |
| 1388 | la r3,GOT(_GOT2_TABLE_) |
| 1389 | lwz r11,GOT(_GOT2_TABLE_) |
| 1390 | mtctr r0 |
| 1391 | sub r11,r3,r11 |
| 1392 | addi r3,r3,-4 |
| 1393 | 1: lwzu r0,4(r3) |
Joakim Tjernlund | afc3ba0 | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 1394 | cmpwi r0,0 |
| 1395 | beq- 2f |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1396 | add r0,r0,r11 |
| 1397 | stw r0,0(r3) |
Joakim Tjernlund | afc3ba0 | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 1398 | 2: bdnz 1b |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1399 | |
| 1400 | /* |
| 1401 | * Now adjust the fixups and the pointers to the fixups |
| 1402 | * in case we need to move ourselves again. |
| 1403 | */ |
Joakim Tjernlund | afc3ba0 | 2009-10-08 02:03:51 +0200 | [diff] [blame] | 1404 | li r0,__fixup_entries@sectoff@l |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1405 | lwz r3,GOT(_FIXUP_TABLE_) |
| 1406 | cmpwi r0,0 |
| 1407 | mtctr r0 |
| 1408 | addi r3,r3,-4 |
| 1409 | beq 4f |
| 1410 | 3: lwzu r4,4(r3) |
| 1411 | lwzux r0,r4,r11 |
Joakim Tjernlund | d1e0b10 | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 1412 | cmpwi r0,0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1413 | add r0,r0,r11 |
Joakim Tjernlund | 34bbf61 | 2010-11-04 19:02:00 +0100 | [diff] [blame] | 1414 | stw r4,0(r3) |
Joakim Tjernlund | d1e0b10 | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 1415 | beq- 5f |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1416 | stw r0,0(r4) |
Joakim Tjernlund | d1e0b10 | 2010-10-14 11:51:44 +0200 | [diff] [blame] | 1417 | 5: bdnz 3b |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1418 | 4: |
| 1419 | clear_bss: |
| 1420 | /* |
| 1421 | * Now clear BSS segment |
| 1422 | */ |
| 1423 | lwz r3,GOT(__bss_start) |
Po-Yu Chuang | 44c6e65 | 2011-03-01 22:59:59 +0000 | [diff] [blame] | 1424 | lwz r4,GOT(__bss_end__) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1425 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1426 | cmplw 0,r3,r4 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1427 | beq 6f |
| 1428 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1429 | li r0,0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1430 | 5: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1431 | stw r0,0(r3) |
| 1432 | addi r3,r3,4 |
| 1433 | cmplw 0,r3,r4 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1434 | bne 5b |
| 1435 | 6: |
| 1436 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1437 | mr r3,r9 /* Init Data pointer */ |
| 1438 | mr r4,r10 /* Destination Address */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1439 | bl board_init_r |
| 1440 | |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 1441 | #ifndef CONFIG_NAND_SPL |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1442 | /* |
| 1443 | * Copy exception vector code to low memory |
| 1444 | * |
| 1445 | * r3: dest_addr |
| 1446 | * r7: source address, r8: end address, r9: target address |
| 1447 | */ |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1448 | .globl trap_init |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1449 | trap_init: |
Joakim Tjernlund | 0f8aa15 | 2010-01-19 14:41:56 +0100 | [diff] [blame] | 1450 | mflr r4 /* save link register */ |
| 1451 | GET_GOT |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1452 | lwz r7,GOT(_start_of_vectors) |
| 1453 | lwz r8,GOT(_end_of_vectors) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1454 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1455 | li r9,0x100 /* reset vector always at 0x100 */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1456 | |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1457 | cmplw 0,r7,r8 |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1458 | bgelr /* return if r7>=r8 - just in case */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1459 | 1: |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1460 | lwz r0,0(r7) |
| 1461 | stw r0,0(r9) |
| 1462 | addi r7,r7,4 |
| 1463 | addi r9,r9,4 |
| 1464 | cmplw 0,r7,r8 |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1465 | bne 1b |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1466 | |
| 1467 | /* |
| 1468 | * relocate `hdlr' and `int_return' entries |
| 1469 | */ |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1470 | li r7,.L_CriticalInput - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1471 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1472 | li r7,.L_MachineCheck - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1473 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1474 | li r7,.L_DataStorage - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1475 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1476 | li r7,.L_InstStorage - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1477 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1478 | li r7,.L_ExtInterrupt - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1479 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1480 | li r7,.L_Alignment - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1481 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1482 | li r7,.L_ProgramCheck - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1483 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1484 | li r7,.L_FPUnavailable - _start + _START_OFFSET |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1485 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1486 | li r7,.L_Decrementer - _start + _START_OFFSET |
| 1487 | bl trap_reloc |
| 1488 | li r7,.L_IntervalTimer - _start + _START_OFFSET |
| 1489 | li r8,_end_of_vectors - _start + _START_OFFSET |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1490 | 2: |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1491 | bl trap_reloc |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1492 | addi r7,r7,0x100 /* next exception vector */ |
| 1493 | cmplw 0,r7,r8 |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1494 | blt 2b |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1495 | |
Prabhakar Kushwaha | 64829ba | 2012-02-14 22:49:49 +0000 | [diff] [blame^] | 1496 | /* Update IVORs as per relocated vector table address */ |
| 1497 | li r7,0x0100 |
| 1498 | mtspr IVOR0,r7 /* 0: Critical input */ |
| 1499 | li r7,0x0200 |
| 1500 | mtspr IVOR1,r7 /* 1: Machine check */ |
| 1501 | li r7,0x0300 |
| 1502 | mtspr IVOR2,r7 /* 2: Data storage */ |
| 1503 | li r7,0x0400 |
| 1504 | mtspr IVOR3,r7 /* 3: Instruction storage */ |
| 1505 | li r7,0x0500 |
| 1506 | mtspr IVOR4,r7 /* 4: External interrupt */ |
| 1507 | li r7,0x0600 |
| 1508 | mtspr IVOR5,r7 /* 5: Alignment */ |
| 1509 | li r7,0x0700 |
| 1510 | mtspr IVOR6,r7 /* 6: Program check */ |
| 1511 | li r7,0x0800 |
| 1512 | mtspr IVOR7,r7 /* 7: floating point unavailable */ |
| 1513 | li r7,0x0900 |
| 1514 | mtspr IVOR8,r7 /* 8: System call */ |
| 1515 | /* 9: Auxiliary processor unavailable(unsupported) */ |
| 1516 | li r7,0x0a00 |
| 1517 | mtspr IVOR10,r7 /* 10: Decrementer */ |
| 1518 | li r7,0x0b00 |
| 1519 | mtspr IVOR11,r7 /* 11: Interval timer */ |
| 1520 | li r7,0x0c00 |
| 1521 | mtspr IVOR12,r7 /* 12: Watchdog timer */ |
| 1522 | li r7,0x0d00 |
| 1523 | mtspr IVOR13,r7 /* 13: Data TLB error */ |
| 1524 | li r7,0x0e00 |
| 1525 | mtspr IVOR14,r7 /* 14: Instruction TLB error */ |
| 1526 | li r7,0x0f00 |
| 1527 | mtspr IVOR15,r7 /* 15: Debug */ |
| 1528 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1529 | lis r7,0x0 |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1530 | mtspr IVPR,r7 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1531 | |
wdenk | 343117b | 2005-05-13 22:49:36 +0000 | [diff] [blame] | 1532 | mtlr r4 /* restore link register */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1533 | blr |
| 1534 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1535 | .globl unlock_ram_in_cache |
| 1536 | unlock_ram_in_cache: |
| 1537 | /* invalidate the INIT_RAM section */ |
Kumar Gala | a38a5b6 | 2008-10-23 01:47:37 -0500 | [diff] [blame] | 1538 | lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h |
| 1539 | 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] | 1540 | mfspr r4,L1CFG0 |
| 1541 | andi. r4,r4,0x1ff |
| 1542 | slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT) |
Andy Fleming | 61a21e9 | 2007-08-14 01:34:21 -0500 | [diff] [blame] | 1543 | mtctr r4 |
Kumar Gala | 2b22fa4 | 2008-02-27 16:30:47 -0600 | [diff] [blame] | 1544 | 1: dcbi r0,r3 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1545 | addi r3,r3,CONFIG_SYS_CACHELINE_SIZE |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1546 | bdnz 1b |
Kumar Gala | 2b22fa4 | 2008-02-27 16:30:47 -0600 | [diff] [blame] | 1547 | sync |
Andy Fleming | 21fae8b | 2008-02-27 14:29:58 -0600 | [diff] [blame] | 1548 | |
| 1549 | /* Invalidate the TLB entries for the cache */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1550 | lis r3,CONFIG_SYS_INIT_RAM_ADDR@h |
| 1551 | ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l |
Andy Fleming | 21fae8b | 2008-02-27 14:29:58 -0600 | [diff] [blame] | 1552 | tlbivax 0,r3 |
| 1553 | addi r3,r3,0x1000 |
| 1554 | tlbivax 0,r3 |
| 1555 | addi r3,r3,0x1000 |
| 1556 | tlbivax 0,r3 |
| 1557 | addi r3,r3,0x1000 |
| 1558 | tlbivax 0,r3 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1559 | isync |
| 1560 | blr |
Kumar Gala | 54e091d | 2008-09-22 14:11:10 -0500 | [diff] [blame] | 1561 | |
| 1562 | .globl flush_dcache |
| 1563 | flush_dcache: |
| 1564 | mfspr r3,SPRN_L1CFG0 |
| 1565 | |
| 1566 | rlwinm r5,r3,9,3 /* Extract cache block size */ |
| 1567 | twlgti r5,1 /* Only 32 and 64 byte cache blocks |
| 1568 | * are currently defined. |
| 1569 | */ |
| 1570 | li r4,32 |
| 1571 | subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) - |
| 1572 | * log2(number of ways) |
| 1573 | */ |
| 1574 | slw r5,r4,r5 /* r5 = cache block size */ |
| 1575 | |
| 1576 | rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */ |
| 1577 | mulli r7,r7,13 /* An 8-way cache will require 13 |
| 1578 | * loads per set. |
| 1579 | */ |
| 1580 | slw r7,r7,r6 |
| 1581 | |
| 1582 | /* save off HID0 and set DCFA */ |
| 1583 | mfspr r8,SPRN_HID0 |
| 1584 | ori r9,r8,HID0_DCFA@l |
| 1585 | mtspr SPRN_HID0,r9 |
| 1586 | isync |
| 1587 | |
| 1588 | lis r4,0 |
| 1589 | mtctr r7 |
| 1590 | |
| 1591 | 1: lwz r3,0(r4) /* Load... */ |
| 1592 | add r4,r4,r5 |
| 1593 | bdnz 1b |
| 1594 | |
| 1595 | msync |
| 1596 | lis r4,0 |
| 1597 | mtctr r7 |
| 1598 | |
| 1599 | 1: dcbf 0,r4 /* ...and flush. */ |
| 1600 | add r4,r4,r5 |
| 1601 | bdnz 1b |
| 1602 | |
| 1603 | /* restore HID0 */ |
| 1604 | mtspr SPRN_HID0,r8 |
| 1605 | isync |
| 1606 | |
| 1607 | blr |
Kumar Gala | 26f4cdba | 2009-08-14 13:37:54 -0500 | [diff] [blame] | 1608 | |
| 1609 | .globl setup_ivors |
| 1610 | setup_ivors: |
| 1611 | |
| 1612 | #include "fixed_ivor.S" |
| 1613 | blr |
Mingkai Hu | 7da5335 | 2009-09-11 14:19:10 +0800 | [diff] [blame] | 1614 | #endif /* !CONFIG_NAND_SPL */ |