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