TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [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 */ |
| 32 | #define CACR_STATUS (CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END-12) |
| 33 | #define ICACHE_STATUS (CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END- 8) |
| 34 | #define DCACHE_STATUS (CFG_INIT_RAM_ADDR+CFG_INIT_RAM_END- 4) |
| 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 | |
| 49 | .text |
| 50 | /* |
| 51 | * Vector table. This is used for initial platform startup. |
| 52 | * These vectors are to catch any un-intended traps. |
| 53 | */ |
| 54 | _vectors: |
| 55 | |
| 56 | INITSP: .long 0x00000000 /* Initial SP */ |
| 57 | INITPC: .long _START /* Initial PC */ |
| 58 | vector02: .long _FAULT /* Access Error */ |
| 59 | vector03: .long _FAULT /* Address Error */ |
| 60 | vector04: .long _FAULT /* Illegal Instruction */ |
| 61 | vector05: .long _FAULT /* Reserved */ |
| 62 | vector06: .long _FAULT /* Reserved */ |
| 63 | vector07: .long _FAULT /* Reserved */ |
| 64 | vector08: .long _FAULT /* Privilege Violation */ |
| 65 | vector09: .long _FAULT /* Trace */ |
| 66 | vector0A: .long _FAULT /* Unimplemented A-Line */ |
| 67 | vector0B: .long _FAULT /* Unimplemented F-Line */ |
| 68 | vector0C: .long _FAULT /* Debug Interrupt */ |
| 69 | vector0D: .long _FAULT /* Reserved */ |
| 70 | vector0E: .long _FAULT /* Format Error */ |
| 71 | vector0F: .long _FAULT /* Unitialized Int. */ |
| 72 | |
| 73 | /* Reserved */ |
| 74 | vector10_17: |
| 75 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 76 | |
| 77 | vector18: .long _FAULT /* Spurious Interrupt */ |
| 78 | vector19: .long _FAULT /* Autovector Level 1 */ |
| 79 | vector1A: .long _FAULT /* Autovector Level 2 */ |
| 80 | vector1B: .long _FAULT /* Autovector Level 3 */ |
| 81 | vector1C: .long _FAULT /* Autovector Level 4 */ |
| 82 | vector1D: .long _FAULT /* Autovector Level 5 */ |
| 83 | vector1E: .long _FAULT /* Autovector Level 6 */ |
| 84 | vector1F: .long _FAULT /* Autovector Level 7 */ |
| 85 | |
| 86 | /* TRAP #0 - #15 */ |
| 87 | vector20_2F: |
| 88 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 89 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 90 | |
| 91 | /* Reserved */ |
| 92 | vector30_3F: |
| 93 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 94 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 95 | |
| 96 | vector64_127: |
| 97 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 98 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 99 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 100 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 101 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 102 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 103 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 104 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 105 | |
| 106 | vector128_191: |
| 107 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 108 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 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 | |
| 116 | vector192_255: |
| 117 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 118 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 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 | |
| 126 | .text |
| 127 | |
| 128 | .globl _start |
| 129 | _start: |
| 130 | nop |
| 131 | nop |
| 132 | move.w #0x2700,%sr /* Mask off Interrupt */ |
| 133 | |
| 134 | /* Set vector base register at the beginning of the Flash */ |
| 135 | move.l #CFG_FLASH_BASE, %d0 |
| 136 | movec %d0, %VBR |
| 137 | |
| 138 | move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_RAM_CTRL), %d0 |
TsiChungLiew | 0573a7a | 2007-11-07 18:00:54 -0600 | [diff] [blame^] | 139 | movec %d0, %RAMBAR1 |
TsiChungLiew | fc3ca3b | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 140 | |
| 141 | /* initialize general use internal ram */ |
| 142 | move.l #0, %d0 |
| 143 | move.l #(CACR_STATUS), %a1 /* CACR */ |
| 144 | move.l #(ICACHE_STATUS), %a2 /* icache */ |
| 145 | move.l #(DCACHE_STATUS), %a3 /* dcache */ |
| 146 | move.l %d0, (%a1) |
| 147 | move.l %d0, (%a2) |
| 148 | move.l %d0, (%a3) |
| 149 | |
| 150 | /* invalidate and disable cache */ |
| 151 | move.l #0x01004100, %d0 /* Invalidate cache cmd */ |
| 152 | movec %d0, %CACR /* Invalidate cache */ |
| 153 | move.l #0, %d0 |
| 154 | movec %d0, %ACR0 |
| 155 | movec %d0, %ACR1 |
| 156 | movec %d0, %ACR2 |
| 157 | movec %d0, %ACR3 |
| 158 | |
| 159 | /* set stackpointer to end of internal ram to get some stackspace for |
| 160 | the first c-code */ |
| 161 | move.l #(CFG_INIT_RAM_ADDR + CFG_INIT_SP_OFFSET), %sp |
| 162 | clr.l %sp@- |
| 163 | |
| 164 | move.l #__got_start, %a5 /* put relocation table address to a5 */ |
| 165 | |
| 166 | bsr cpu_init_f /* run low-level CPU init code (from flash) */ |
| 167 | bsr board_init_f /* run low-level board init code (from flash) */ |
| 168 | |
| 169 | /* board_init_f() does not return */ |
| 170 | |
| 171 | /*------------------------------------------------------------------------------*/ |
| 172 | |
| 173 | /* |
| 174 | * void relocate_code (addr_sp, gd, addr_moni) |
| 175 | * |
| 176 | * This "function" does not return, instead it continues in RAM |
| 177 | * after relocating the monitor code. |
| 178 | * |
| 179 | * r3 = dest |
| 180 | * r4 = src |
| 181 | * r5 = length in bytes |
| 182 | * r6 = cachelinesize |
| 183 | */ |
| 184 | .globl relocate_code |
| 185 | relocate_code: |
| 186 | link.w %a6,#0 |
| 187 | move.l 8(%a6), %sp /* set new stack pointer */ |
| 188 | |
| 189 | move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ |
| 190 | move.l 16(%a6), %a0 /* Save copy of Destination Address */ |
| 191 | |
| 192 | move.l #CFG_MONITOR_BASE, %a1 |
| 193 | move.l #__init_end, %a2 |
| 194 | move.l %a0, %a3 |
| 195 | |
| 196 | /* copy the code to RAM */ |
| 197 | 1: |
| 198 | move.l (%a1)+, (%a3)+ |
| 199 | cmp.l %a1,%a2 |
| 200 | bgt.s 1b |
| 201 | |
| 202 | /* |
| 203 | * We are done. Do not return, instead branch to second part of board |
| 204 | * initialization, now running from RAM. |
| 205 | */ |
| 206 | move.l %a0, %a1 |
| 207 | add.l #(in_ram - CFG_MONITOR_BASE), %a1 |
| 208 | jmp (%a1) |
| 209 | |
| 210 | in_ram: |
| 211 | |
| 212 | clear_bss: |
| 213 | /* |
| 214 | * Now clear BSS segment |
| 215 | */ |
| 216 | move.l %a0, %a1 |
| 217 | add.l #(_sbss - CFG_MONITOR_BASE),%a1 |
| 218 | move.l %a0, %d1 |
| 219 | add.l #(_ebss - CFG_MONITOR_BASE),%d1 |
| 220 | 6: |
| 221 | clr.l (%a1)+ |
| 222 | cmp.l %a1,%d1 |
| 223 | bgt.s 6b |
| 224 | |
| 225 | /* |
| 226 | * fix got table in RAM |
| 227 | */ |
| 228 | move.l %a0, %a1 |
| 229 | add.l #(__got_start - CFG_MONITOR_BASE),%a1 |
| 230 | move.l %a1,%a5 /* * fix got pointer register a5 */ |
| 231 | |
| 232 | move.l %a0, %a2 |
| 233 | add.l #(__got_end - CFG_MONITOR_BASE),%a2 |
| 234 | |
| 235 | 7: |
| 236 | move.l (%a1),%d1 |
| 237 | sub.l #_start,%d1 |
| 238 | add.l %a0,%d1 |
| 239 | move.l %d1,(%a1)+ |
| 240 | cmp.l %a2, %a1 |
| 241 | bne 7b |
| 242 | |
| 243 | /* calculate relative jump to board_init_r in ram */ |
| 244 | move.l %a0, %a1 |
| 245 | add.l #(board_init_r - CFG_MONITOR_BASE), %a1 |
| 246 | |
| 247 | /* set parameters for board_init_r */ |
| 248 | move.l %a0,-(%sp) /* dest_addr */ |
| 249 | move.l %d0,-(%sp) /* gd */ |
| 250 | jsr (%a1) |
| 251 | |
| 252 | /*------------------------------------------------------------------------------*/ |
| 253 | /* exception code */ |
| 254 | .globl _fault |
| 255 | _fault: |
| 256 | jmp _fault |
| 257 | .globl _exc_handler |
| 258 | |
| 259 | _exc_handler: |
| 260 | SAVE_ALL |
| 261 | movel %sp,%sp@- |
| 262 | bsr exc_handler |
| 263 | addql #4,%sp |
| 264 | RESTORE_ALL |
| 265 | |
| 266 | .globl _int_handler |
| 267 | _int_handler: |
| 268 | SAVE_ALL |
| 269 | movel %sp,%sp@- |
| 270 | bsr int_handler |
| 271 | addql #4,%sp |
| 272 | RESTORE_ALL |
| 273 | |
| 274 | /*------------------------------------------------------------------------------*/ |
| 275 | /* cache functions */ |
| 276 | .globl icache_enable |
| 277 | icache_enable: |
| 278 | move.l #(CACR_STATUS), %a1 /* read CACR Status */ |
| 279 | move.l (%a1), %d1 |
| 280 | |
| 281 | move.l #0x00040100, %d0 /* Invalidate icache */ |
| 282 | or.l %d1, %d0 |
| 283 | movec %d0, %CACR |
| 284 | |
| 285 | move.l #(CFG_SDRAM_BASE + 0xc000), %d0 /* Setup icache */ |
| 286 | movec %d0, %ACR2 |
| 287 | |
| 288 | or.l #0x00088400, %d1 /* Enable bcache and icache */ |
| 289 | movec %d1, %CACR |
| 290 | |
| 291 | move.l #(ICACHE_STATUS), %a1 |
| 292 | moveq #1, %d0 |
| 293 | move.l %d0, (%a1) |
| 294 | rts |
| 295 | |
| 296 | .globl icache_disable |
| 297 | icache_disable: |
| 298 | move.l #(CACR_STATUS), %a1 /* read CACR Status */ |
| 299 | move.l (%a1), %d0 |
| 300 | |
| 301 | and.l #0xFFF77BFF, %d0 |
| 302 | or.l #0x00040100, %d0 /* Setup cache mask */ |
| 303 | movec %d0, %CACR /* Invalidate icache */ |
| 304 | clr.l %d0 |
| 305 | movec %d0, %ACR2 |
| 306 | movec %d0, %ACR3 |
| 307 | |
| 308 | move.l #(ICACHE_STATUS), %a1 |
| 309 | moveq #0, %d0 |
| 310 | move.l %d0, (%a1) |
| 311 | rts |
| 312 | |
| 313 | .globl icache_status |
| 314 | icache_status: |
| 315 | move.l #(ICACHE_STATUS), %a1 |
| 316 | move.l (%a1), %d0 |
| 317 | rts |
| 318 | |
| 319 | .globl icache_invalid |
| 320 | icache_invalid: |
| 321 | move.l #(CACR_STATUS), %a1 /* read CACR Status */ |
| 322 | move.l (%a1), %d0 |
| 323 | |
| 324 | or.l #0x00040100, %d0 /* Invalidate icache */ |
| 325 | movec %d0, %CACR /* Enable and invalidate cache */ |
| 326 | rts |
| 327 | |
| 328 | .globl dcache_enable |
| 329 | dcache_enable: |
| 330 | move.l #(CACR_STATUS), %a1 /* read CACR Status */ |
| 331 | move.l (%a1), %d1 |
| 332 | |
| 333 | move.l #0x01000000, %d0 |
| 334 | or.l %d1, %d0 |
| 335 | movec %d0, %CACR /* Invalidate dcache */ |
| 336 | |
| 337 | move.l #(CFG_SDRAM_BASE + 0xc000), %d0 |
| 338 | movec %d0, %ACR0 |
| 339 | move.l #0, %d0 |
| 340 | movec %d0, %ACR1 |
| 341 | |
| 342 | or.l #0x80000000, %d1 /* Enable bcache and icache */ |
| 343 | movec %d1, %CACR |
| 344 | |
| 345 | move.l #(DCACHE_STATUS), %a1 |
| 346 | moveq #1, %d0 |
| 347 | move.l %d0, (%a1) |
| 348 | rts |
| 349 | |
| 350 | .globl dcache_disable |
| 351 | dcache_disable: |
| 352 | move.l #(CACR_STATUS), %a1 /* read CACR Status */ |
| 353 | move.l (%a1), %d0 |
| 354 | |
| 355 | and.l #0x7FFFFFFF, %d0 |
| 356 | or.l #0x01000000, %d0 /* Setup cache mask */ |
| 357 | movec %d0, %CACR /* Disable dcache */ |
| 358 | clr.l %d0 |
| 359 | movec %d0, %ACR0 |
| 360 | movec %d0, %ACR1 |
| 361 | |
| 362 | move.l #(DCACHE_STATUS), %a1 |
| 363 | moveq #0, %d0 |
| 364 | move.l %d0, (%a1) |
| 365 | rts |
| 366 | |
| 367 | .globl dcache_invalid |
| 368 | dcache_invalid: |
| 369 | move.l #(CACR_STATUS), %a1 /* read CACR Status */ |
| 370 | move.l (%a1), %d0 |
| 371 | |
| 372 | or.l #0x01000000, %d0 /* Setup cache mask */ |
| 373 | movec %d0, %CACR /* Enable and invalidate cache */ |
| 374 | rts |
| 375 | |
| 376 | .globl dcache_status |
| 377 | dcache_status: |
| 378 | move.l #(DCACHE_STATUS), %a1 |
| 379 | move.l (%a1), %d0 |
| 380 | rts |
| 381 | |
| 382 | /*------------------------------------------------------------------------------*/ |
| 383 | |
| 384 | .globl version_string |
| 385 | version_string: |
| 386 | .ascii U_BOOT_VERSION |
| 387 | .ascii " (", __DATE__, " - ", __TIME__, ")" |
| 388 | .ascii CONFIG_IDENT_STRING, "\0" |