TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de> |
| 3 | * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com> |
| 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 | #include <config.h> |
| 25 | #include "version.h" |
| 26 | |
| 27 | #ifndef CONFIG_IDENT_STRING |
| 28 | #define CONFIG_IDENT_STRING "" |
| 29 | #endif |
| 30 | |
| 31 | /* last three long word reserved for cache status */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | #define ICACHE_STATUS (CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END- 4) |
| 33 | #define DCACHE_STATUS (CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END- 8) |
| 34 | #define CACR_STATUS (CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-12) |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 35 | |
| 36 | #define _START _start |
| 37 | #define _FAULT _fault |
| 38 | |
| 39 | #define SAVE_ALL \ |
| 40 | move.w #0x2700,%sr; /* disable intrs */ \ |
| 41 | subl #60,%sp; /* space for 15 regs */ \ |
| 42 | moveml %d0-%d7/%a0-%a6,%sp@; |
| 43 | |
| 44 | #define RESTORE_ALL \ |
| 45 | moveml %sp@,%d0-%d7/%a0-%a6; \ |
| 46 | addl #60,%sp; /* space for 15 regs */ \ |
| 47 | rte; |
| 48 | |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 49 | #if defined(CONFIG_CF_SBF) |
| 50 | #define ASM_DRAMINIT (asm_dram_init - TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR) |
| 51 | #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR) |
| 52 | #endif |
| 53 | |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 54 | .text |
| 55 | /* |
| 56 | * Vector table. This is used for initial platform startup. |
| 57 | * These vectors are to catch any un-intended traps. |
| 58 | */ |
| 59 | _vectors: |
| 60 | |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 61 | #if defined(CONFIG_CF_SBF) |
| 62 | INITSP: .long 0 /* Initial SP */ |
| 63 | INITPC: .long ASM_DRAMINIT /* Initial PC */ |
| 64 | #else |
| 65 | INITSP: .long 0 /* Initial SP */ |
| 66 | INITPC: .long _START /* Initial PC */ |
| 67 | #endif |
| 68 | |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 69 | vector02: .long _FAULT /* Access Error */ |
| 70 | vector03: .long _FAULT /* Address Error */ |
| 71 | vector04: .long _FAULT /* Illegal Instruction */ |
| 72 | vector05: .long _FAULT /* Reserved */ |
| 73 | vector06: .long _FAULT /* Reserved */ |
| 74 | vector07: .long _FAULT /* Reserved */ |
| 75 | vector08: .long _FAULT /* Privilege Violation */ |
| 76 | vector09: .long _FAULT /* Trace */ |
| 77 | vector0A: .long _FAULT /* Unimplemented A-Line */ |
| 78 | vector0B: .long _FAULT /* Unimplemented F-Line */ |
| 79 | vector0C: .long _FAULT /* Debug Interrupt */ |
| 80 | vector0D: .long _FAULT /* Reserved */ |
| 81 | vector0E: .long _FAULT /* Format Error */ |
| 82 | vector0F: .long _FAULT /* Unitialized Int. */ |
| 83 | |
| 84 | /* Reserved */ |
| 85 | vector10_17: |
| 86 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 87 | |
| 88 | vector18: .long _FAULT /* Spurious Interrupt */ |
| 89 | vector19: .long _FAULT /* Autovector Level 1 */ |
| 90 | vector1A: .long _FAULT /* Autovector Level 2 */ |
| 91 | vector1B: .long _FAULT /* Autovector Level 3 */ |
| 92 | vector1C: .long _FAULT /* Autovector Level 4 */ |
| 93 | vector1D: .long _FAULT /* Autovector Level 5 */ |
| 94 | vector1E: .long _FAULT /* Autovector Level 6 */ |
| 95 | vector1F: .long _FAULT /* Autovector Level 7 */ |
| 96 | |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 97 | #if !defined(CONFIG_CF_SBF) |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 98 | /* TRAP #0 - #15 */ |
| 99 | vector20_2F: |
| 100 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 101 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 102 | |
| 103 | /* Reserved */ |
| 104 | vector30_3F: |
| 105 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 106 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 107 | |
| 108 | vector64_127: |
| 109 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 110 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 111 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 112 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 113 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 114 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 115 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 116 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 117 | |
| 118 | vector128_191: |
| 119 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 120 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 121 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 122 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 123 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 124 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 125 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 126 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 127 | |
| 128 | vector192_255: |
| 129 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 130 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 131 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 132 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 133 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 134 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 135 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 136 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 137 | #endif |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 138 | |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 139 | #if defined(CONFIG_CF_SBF) |
| 140 | /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */ |
| 141 | asm_sbf_img_hdr: |
| 142 | .long 0x00000000 /* checksum, not yet implemented */ |
| 143 | .long 0x00020000 /* image length */ |
| 144 | .long TEXT_BASE /* image to be relocated at */ |
| 145 | |
| 146 | asm_dram_init: |
| 147 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 |
| 148 | movec %d0, %RAMBAR1 /* init Rambar */ |
| 149 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp |
| 150 | clr.l %sp@- |
| 151 | |
| 152 | /* Must disable global address */ |
| 153 | move.l #0xFC008000, %a1 |
| 154 | move.l #(CONFIG_SYS_CS0_BASE), (%a1) |
| 155 | move.l #0xFC008008, %a1 |
| 156 | move.l #(CONFIG_SYS_CS0_CTRL), (%a1) |
| 157 | move.l #0xFC008004, %a1 |
| 158 | move.l #(CONFIG_SYS_CS0_MASK), (%a1) |
| 159 | |
| 160 | /* |
| 161 | * Dram Initialization |
| 162 | * a1, a2, and d0 |
| 163 | */ |
| 164 | /* mscr sdram */ |
| 165 | move.l #0xFC0A4074, %a1 |
| 166 | move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1) |
| 167 | nop |
| 168 | |
| 169 | /* SDRAM Chip 0 and 1 */ |
| 170 | move.l #0xFC0B8110, %a1 |
| 171 | move.l #0xFC0B8114, %a2 |
| 172 | |
| 173 | /* calculate the size */ |
| 174 | move.l #0x13, %d1 |
| 175 | move.l #(CONFIG_SYS_SDRAM_SIZE), %d2 |
| 176 | #ifdef CONFIG_SYS_SDRAM_BASE1 |
| 177 | lsr.l #1, %d2 |
| 178 | #endif |
| 179 | |
| 180 | dramsz_loop: |
| 181 | lsr.l #1, %d2 |
| 182 | add.l #1, %d1 |
| 183 | cmp.l #1, %d2 |
| 184 | bne dramsz_loop |
| 185 | |
| 186 | /* SDRAM Chip 0 and 1 */ |
| 187 | move.l #(CONFIG_SYS_SDRAM_BASE), (%a1) |
| 188 | or.l %d1, (%a1) |
| 189 | #ifdef CONFIG_SYS_SDRAM_BASE1 |
| 190 | move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2) |
| 191 | or.l %d1, (%a2) |
| 192 | #endif |
| 193 | nop |
| 194 | |
| 195 | /* dram cfg1 and cfg2 */ |
| 196 | move.l #0xFC0B8008, %a1 |
| 197 | move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1) |
| 198 | nop |
| 199 | move.l #0xFC0B800C, %a2 |
| 200 | move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2) |
| 201 | nop |
| 202 | |
| 203 | move.l #0xFC0B8000, %a1 /* Mode */ |
| 204 | move.l #0xFC0B8004, %a2 /* Ctrl */ |
| 205 | |
| 206 | /* Issue PALL */ |
| 207 | move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2) |
| 208 | nop |
| 209 | |
| 210 | /* Issue LEMR */ |
| 211 | move.l #(CONFIG_SYS_SDRAM_MODE), (%a1) |
| 212 | nop |
| 213 | move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1) |
| 214 | nop |
| 215 | |
| 216 | move.l #1000, %d0 |
| 217 | wait1000: |
| 218 | nop |
| 219 | subq.l #1, %d0 |
| 220 | bne wait1000 |
| 221 | |
| 222 | /* Issue PALL */ |
| 223 | move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2) |
| 224 | nop |
| 225 | |
| 226 | /* Perform two refresh cycles */ |
| 227 | move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0 |
| 228 | nop |
| 229 | move.l %d0, (%a2) |
| 230 | move.l %d0, (%a2) |
| 231 | nop |
| 232 | |
| 233 | move.l #(CONFIG_SYS_SDRAM_CTRL), %d0 |
| 234 | and.l #0x7FFFFFFF, %d0 |
| 235 | or.l #0x10000c00, %d0 |
| 236 | move.l %d0, (%a2) |
| 237 | nop |
| 238 | |
| 239 | /* |
| 240 | * DSPI Initialization |
| 241 | * a0 - general, sram - 0x80008000 - 32, see M52277EVB.h |
| 242 | * a1 - dspi status |
| 243 | * a2 - dtfr |
| 244 | * a3 - drfr |
| 245 | * a4 - Dst addr |
| 246 | */ |
| 247 | |
| 248 | /* Enable pins for DSPI mode - chip-selects are enabled later */ |
| 249 | move.l #0xFC0A4036, %a0 |
| 250 | move.b #0x3F, %d0 |
| 251 | move.b %d0, (%a0) |
| 252 | |
| 253 | /* DSPI CS */ |
| 254 | #ifdef CONFIG_SYS_DSPI_CS0 |
| 255 | move.b (%a0), %d0 |
| 256 | or.l #0xC0, %d0 |
| 257 | move.b %d0, (%a0) |
| 258 | #endif |
| 259 | #ifdef CONFIG_SYS_DSPI_CS2 |
| 260 | move.l #0xFC0A4037, %a0 |
| 261 | move.b (%a0), %d0 |
| 262 | or.l #0x10, %d0 |
| 263 | move.b %d0, (%a0) |
| 264 | #endif |
| 265 | nop |
| 266 | |
| 267 | /* Configure DSPI module */ |
| 268 | move.l #0xFC05C000, %a0 |
| 269 | move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */ |
| 270 | |
| 271 | move.l #0xFC05C00C, %a0 |
| 272 | move.l #0x3E000011, (%a0) |
| 273 | |
| 274 | move.l #0xFC05C034, %a2 /* dtfr */ |
| 275 | move.l #0xFC05C03B, %a3 /* drfr */ |
| 276 | |
| 277 | move.l #(ASM_SBF_IMG_HDR + 4), %a1 |
| 278 | move.l (%a1)+, %d5 |
| 279 | move.l (%a1), %a4 |
| 280 | |
| 281 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0 |
| 282 | move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4 |
| 283 | |
| 284 | move.l #0xFC05C02C, %a1 /* dspi status */ |
| 285 | |
| 286 | /* Issue commands and address */ |
| 287 | move.l #0x8004000B, %d2 /* Fast Read Cmd */ |
| 288 | jsr asm_dspi_wr_status |
| 289 | jsr asm_dspi_rd_status |
| 290 | |
| 291 | move.l #0x80040000, %d2 /* Address byte 2 */ |
| 292 | jsr asm_dspi_wr_status |
| 293 | jsr asm_dspi_rd_status |
| 294 | |
| 295 | move.l #0x80040000, %d2 /* Address byte 1 */ |
| 296 | jsr asm_dspi_wr_status |
| 297 | jsr asm_dspi_rd_status |
| 298 | |
| 299 | move.l #0x80040000, %d2 /* Address byte 0 */ |
| 300 | jsr asm_dspi_wr_status |
| 301 | jsr asm_dspi_rd_status |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 302 | |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 303 | move.l #0x80040000, %d2 /* Dummy Wr and Rd */ |
| 304 | jsr asm_dspi_wr_status |
| 305 | jsr asm_dspi_rd_status |
| 306 | |
| 307 | /* Transfer serial boot header to sram */ |
| 308 | asm_dspi_rd_loop1: |
| 309 | move.l #0x80040000, %d2 |
| 310 | jsr asm_dspi_wr_status |
| 311 | jsr asm_dspi_rd_status |
| 312 | |
| 313 | move.b %d1, (%a0) /* read, copy to dst */ |
| 314 | |
| 315 | add.l #1, %a0 /* inc dst by 1 */ |
| 316 | sub.l #1, %d4 /* dec cnt by 1 */ |
| 317 | bne asm_dspi_rd_loop1 |
| 318 | |
| 319 | /* Transfer u-boot from serial flash to memory */ |
| 320 | asm_dspi_rd_loop2: |
| 321 | move.l #0x80040000, %d2 |
| 322 | jsr asm_dspi_wr_status |
| 323 | jsr asm_dspi_rd_status |
| 324 | |
| 325 | move.b %d1, (%a4) /* read, copy to dst */ |
| 326 | |
| 327 | add.l #1, %a4 /* inc dst by 1 */ |
| 328 | sub.l #1, %d5 /* dec cnt by 1 */ |
| 329 | bne asm_dspi_rd_loop2 |
| 330 | |
| 331 | move.l #0x00040000, %d2 /* Terminate */ |
| 332 | jsr asm_dspi_wr_status |
| 333 | jsr asm_dspi_rd_status |
| 334 | |
| 335 | /* jump to memory and execute */ |
| 336 | move.l #(TEXT_BASE + 0x400), %a0 |
| 337 | move.l %a0, (%a1) |
| 338 | jmp (%a0) |
| 339 | |
| 340 | asm_dspi_wr_status: |
| 341 | move.l (%a1), %d0 /* status */ |
| 342 | and.l #0x0000F000, %d0 |
| 343 | cmp.l #0x00003000, %d0 |
| 344 | bgt asm_dspi_wr_status |
| 345 | |
| 346 | move.l %d2, (%a2) |
| 347 | rts |
| 348 | |
| 349 | asm_dspi_rd_status: |
| 350 | move.l (%a1), %d0 /* status */ |
| 351 | and.l #0x000000F0, %d0 |
| 352 | lsr.l #4, %d0 |
| 353 | cmp.l #0, %d0 |
| 354 | beq asm_dspi_rd_status |
| 355 | |
| 356 | move.b (%a3), %d1 |
| 357 | rts |
| 358 | #endif /* CONFIG_CF_SBF */ |
| 359 | |
| 360 | .text |
| 361 | . = 0x400 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 362 | .globl _start |
| 363 | _start: |
| 364 | nop |
| 365 | nop |
| 366 | move.w #0x2700,%sr /* Mask off Interrupt */ |
| 367 | |
| 368 | /* Set vector base register at the beginning of the Flash */ |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 369 | #if defined(CONFIG_CF_SBF) |
| 370 | move.l #TEXT_BASE, %d0 |
| 371 | movec %d0, %VBR |
| 372 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 373 | move.l #CONFIG_SYS_FLASH_BASE, %d0 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 374 | movec %d0, %VBR |
| 375 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 376 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 377 | movec %d0, %RAMBAR1 |
TsiChung Liew | 39966e3 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 378 | #endif |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 379 | |
| 380 | /* initialize general use internal ram */ |
| 381 | move.l #0, %d0 |
| 382 | move.l #(ICACHE_STATUS), %a1 /* icache */ |
| 383 | move.l #(DCACHE_STATUS), %a2 /* icache */ |
| 384 | move.l #(CACR_STATUS), %a3 /* CACR */ |
| 385 | move.l %d0, (%a1) |
| 386 | move.l %d0, (%a2) |
| 387 | move.l %d0, (%a3) |
| 388 | |
| 389 | /* invalidate and disable cache */ |
| 390 | move.l #0x01000000, %d0 /* Invalidate cache cmd */ |
| 391 | movec %d0, %CACR /* Invalidate cache */ |
| 392 | move.l #0, %d0 |
| 393 | movec %d0, %ACR0 |
| 394 | movec %d0, %ACR1 |
| 395 | |
| 396 | /* set stackpointer to end of internal ram to get some stackspace for |
| 397 | the first c-code */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 398 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 399 | clr.l %sp@- |
| 400 | |
| 401 | move.l #__got_start, %a5 /* put relocation table address to a5 */ |
| 402 | |
| 403 | bsr cpu_init_f /* run low-level CPU init code (from flash) */ |
| 404 | bsr board_init_f /* run low-level board init code (from flash) */ |
| 405 | |
| 406 | /* board_init_f() does not return */ |
| 407 | |
| 408 | /*------------------------------------------------------------------------------*/ |
| 409 | |
| 410 | /* |
| 411 | * void relocate_code (addr_sp, gd, addr_moni) |
| 412 | * |
| 413 | * This "function" does not return, instead it continues in RAM |
| 414 | * after relocating the monitor code. |
| 415 | * |
| 416 | * r3 = dest |
| 417 | * r4 = src |
| 418 | * r5 = length in bytes |
| 419 | * r6 = cachelinesize |
| 420 | */ |
| 421 | .globl relocate_code |
| 422 | relocate_code: |
| 423 | link.w %a6,#0 |
| 424 | move.l 8(%a6), %sp /* set new stack pointer */ |
| 425 | |
| 426 | move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ |
| 427 | move.l 16(%a6), %a0 /* Save copy of Destination Address */ |
| 428 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 429 | move.l #CONFIG_SYS_MONITOR_BASE, %a1 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 430 | move.l #__init_end, %a2 |
| 431 | move.l %a0, %a3 |
| 432 | |
| 433 | /* copy the code to RAM */ |
| 434 | 1: |
| 435 | move.l (%a1)+, (%a3)+ |
| 436 | cmp.l %a1,%a2 |
| 437 | bgt.s 1b |
| 438 | |
| 439 | /* |
| 440 | * We are done. Do not return, instead branch to second part of board |
| 441 | * initialization, now running from RAM. |
| 442 | */ |
| 443 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 444 | add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 445 | jmp (%a1) |
| 446 | |
| 447 | in_ram: |
| 448 | |
| 449 | clear_bss: |
| 450 | /* |
| 451 | * Now clear BSS segment |
| 452 | */ |
| 453 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 454 | add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 455 | move.l %a0, %d1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 456 | add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 457 | 6: |
| 458 | clr.l (%a1)+ |
| 459 | cmp.l %a1,%d1 |
| 460 | bgt.s 6b |
| 461 | |
| 462 | /* |
| 463 | * fix got table in RAM |
| 464 | */ |
| 465 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 466 | add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 467 | move.l %a1,%a5 /* * fix got pointer register a5 */ |
| 468 | |
| 469 | move.l %a0, %a2 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 470 | add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 471 | |
| 472 | 7: |
| 473 | move.l (%a1),%d1 |
| 474 | sub.l #_start,%d1 |
| 475 | add.l %a0,%d1 |
| 476 | move.l %d1,(%a1)+ |
| 477 | cmp.l %a2, %a1 |
| 478 | bne 7b |
| 479 | |
| 480 | /* calculate relative jump to board_init_r in ram */ |
| 481 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 482 | add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 483 | |
| 484 | /* set parameters for board_init_r */ |
| 485 | move.l %a0,-(%sp) /* dest_addr */ |
| 486 | move.l %d0,-(%sp) /* gd */ |
| 487 | jsr (%a1) |
| 488 | |
| 489 | /*------------------------------------------------------------------------------*/ |
| 490 | /* exception code */ |
| 491 | .globl _fault |
| 492 | _fault: |
| 493 | jmp _fault |
| 494 | .globl _exc_handler |
| 495 | |
| 496 | _exc_handler: |
| 497 | SAVE_ALL |
| 498 | movel %sp,%sp@- |
| 499 | bsr exc_handler |
| 500 | addql #4,%sp |
| 501 | RESTORE_ALL |
| 502 | |
| 503 | .globl _int_handler |
| 504 | _int_handler: |
| 505 | SAVE_ALL |
| 506 | movel %sp,%sp@- |
| 507 | bsr int_handler |
| 508 | addql #4,%sp |
| 509 | RESTORE_ALL |
| 510 | |
| 511 | /*------------------------------------------------------------------------------*/ |
| 512 | /* cache functions */ |
| 513 | .globl icache_enable |
| 514 | icache_enable: |
| 515 | move.l #0x01200000, %d0 /* Invalid cache */ |
| 516 | movec %d0, %CACR |
| 517 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 518 | move.l #(CONFIG_SYS_SDRAM_BASE + 0x1c000), %d0 |
TsiChungLiew | ae831cd | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 519 | movec %d0, %ACR0 |
| 520 | |
| 521 | move.l #0x81600610, %d0 /* Enable cache */ |
| 522 | movec %d0, %CACR |
| 523 | |
| 524 | move.l #(ICACHE_STATUS), %a1 |
| 525 | moveq #1, %d0 |
| 526 | move.l %d0, (%a1) |
| 527 | rts |
| 528 | |
| 529 | .globl icache_disable |
| 530 | icache_disable: |
| 531 | move.l #0x01F00000, %d0 /* Setup cache mask */ |
| 532 | movec %d0, %CACR /* Invalidate icache */ |
| 533 | clr.l %d0 |
| 534 | movec %d0, %ACR0 |
| 535 | movec %d0, %ACR1 |
| 536 | |
| 537 | move.l #(ICACHE_STATUS), %a1 |
| 538 | moveq #0, %d0 |
| 539 | move.l %d0, (%a1) |
| 540 | rts |
| 541 | |
| 542 | .globl icache_status |
| 543 | icache_status: |
| 544 | move.l #(ICACHE_STATUS), %a1 |
| 545 | move.l (%a1), %d0 |
| 546 | rts |
| 547 | |
| 548 | .globl icache_invalid |
| 549 | icache_invalid: |
| 550 | move.l #0x80600610, %d0 /* Invalidate icache */ |
| 551 | movec %d0, %CACR /* Enable and invalidate cache */ |
| 552 | rts |
| 553 | |
| 554 | .globl dcache_enable |
| 555 | dcache_enable: |
| 556 | move.l #0x01200000, %d0 /* Invalid cache */ |
| 557 | movec %d0, %CACR |
| 558 | |
| 559 | move.l #0x81300610, %d0 |
| 560 | movec %d0, %CACR |
| 561 | |
| 562 | move.l #(DCACHE_STATUS), %a1 |
| 563 | moveq #1, %d0 |
| 564 | move.l %d0, (%a1) |
| 565 | rts |
| 566 | |
| 567 | .globl dcache_disable |
| 568 | dcache_disable: |
| 569 | move.l #0x81600610, %d0 /* Setup cache mask */ |
| 570 | movec %d0, %CACR /* Invalidate icache */ |
| 571 | |
| 572 | move.l #(DCACHE_STATUS), %a1 |
| 573 | moveq #0, %d0 |
| 574 | move.l %d0, (%a1) |
| 575 | rts |
| 576 | |
| 577 | .globl dcache_invalid |
| 578 | dcache_invalid: |
| 579 | move.l #0x81100610, %d0 /* Setup cache mask */ |
| 580 | movec %d0, %CACR /* Enable and invalidate cache */ |
| 581 | rts |
| 582 | |
| 583 | .globl dcache_status |
| 584 | dcache_status: |
| 585 | move.l #(DCACHE_STATUS), %a1 |
| 586 | move.l (%a1), %d0 |
| 587 | rts |
| 588 | |
| 589 | /*------------------------------------------------------------------------------*/ |
| 590 | |
| 591 | .globl version_string |
| 592 | version_string: |
| 593 | .ascii U_BOOT_VERSION |
| 594 | .ascii " (", __DATE__, " - ", __TIME__, ")" |
| 595 | .ascii CONFIG_IDENT_STRING, "\0" |
TsiChung Liew | 9d636e9 | 2008-03-28 08:47:45 -0500 | [diff] [blame] | 596 | .align 4 |