TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -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> |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 25 | #include <timestamp.h> |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 26 | #include "version.h" |
| 27 | |
| 28 | #ifndef CONFIG_IDENT_STRING |
| 29 | #define CONFIG_IDENT_STRING "" |
| 30 | #endif |
| 31 | |
| 32 | #define _START _start |
| 33 | #define _FAULT _fault |
| 34 | |
| 35 | #define SAVE_ALL \ |
| 36 | move.w #0x2700,%sr; /* disable intrs */ \ |
| 37 | subl #60,%sp; /* space for 15 regs */ \ |
| 38 | moveml %d0-%d7/%a0-%a6,%sp@; |
| 39 | |
| 40 | #define RESTORE_ALL \ |
| 41 | moveml %sp@,%d0-%d7/%a0-%a6; \ |
| 42 | addl #60,%sp; /* space for 15 regs */ \ |
| 43 | rte; |
| 44 | |
| 45 | .text |
| 46 | /* |
| 47 | * Vector table. This is used for initial platform startup. |
| 48 | * These vectors are to catch any un-intended traps. |
| 49 | */ |
| 50 | _vectors: |
| 51 | |
| 52 | INITSP: .long 0x00000000 /* Initial SP */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 53 | INITPC: .long _START /* Initial PC */ |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 54 | vector02: .long _FAULT /* Access Error */ |
| 55 | vector03: .long _FAULT /* Address Error */ |
| 56 | vector04: .long _FAULT /* Illegal Instruction */ |
| 57 | vector05: .long _FAULT /* Reserved */ |
| 58 | vector06: .long _FAULT /* Reserved */ |
| 59 | vector07: .long _FAULT /* Reserved */ |
| 60 | vector08: .long _FAULT /* Privilege Violation */ |
| 61 | vector09: .long _FAULT /* Trace */ |
| 62 | vector0A: .long _FAULT /* Unimplemented A-Line */ |
| 63 | vector0B: .long _FAULT /* Unimplemented F-Line */ |
| 64 | vector0C: .long _FAULT /* Debug Interrupt */ |
| 65 | vector0D: .long _FAULT /* Reserved */ |
| 66 | vector0E: .long _FAULT /* Format Error */ |
| 67 | vector0F: .long _FAULT /* Unitialized Int. */ |
| 68 | |
| 69 | /* Reserved */ |
| 70 | vector10_17: |
| 71 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 72 | |
| 73 | vector18: .long _FAULT /* Spurious Interrupt */ |
| 74 | vector19: .long _FAULT /* Autovector Level 1 */ |
| 75 | vector1A: .long _FAULT /* Autovector Level 2 */ |
| 76 | vector1B: .long _FAULT /* Autovector Level 3 */ |
| 77 | vector1C: .long _FAULT /* Autovector Level 4 */ |
| 78 | vector1D: .long _FAULT /* Autovector Level 5 */ |
| 79 | vector1E: .long _FAULT /* Autovector Level 6 */ |
| 80 | vector1F: .long _FAULT /* Autovector Level 7 */ |
| 81 | |
| 82 | /* TRAP #0 - #15 */ |
| 83 | vector20_2F: |
| 84 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 85 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 86 | |
| 87 | /* Reserved */ |
| 88 | vector30_3F: |
| 89 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 90 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 91 | |
| 92 | vector64_127: |
| 93 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 94 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 95 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 96 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 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 | |
| 102 | vector128_191: |
| 103 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 104 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 105 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 106 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 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 | |
| 112 | vector192_255: |
| 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 | .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 | |
| 122 | .text |
| 123 | |
| 124 | .globl _start |
| 125 | _start: |
| 126 | nop |
| 127 | nop |
| 128 | move.w #0x2700,%sr /* Mask off Interrupt */ |
| 129 | |
| 130 | /* Set vector base register at the beginning of the Flash */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | move.l #CONFIG_SYS_FLASH_BASE, %d0 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 132 | movec %d0, %VBR |
| 133 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 135 | movec %d0, %RAMBAR1 |
| 136 | |
| 137 | /* invalidate and disable cache */ |
| 138 | move.l #0x01000000, %d0 /* Invalidate cache cmd */ |
| 139 | movec %d0, %CACR /* Invalidate cache */ |
| 140 | nop |
| 141 | move.l #0, %d0 |
| 142 | movec %d0, %ACR0 |
| 143 | movec %d0, %ACR1 |
| 144 | |
| 145 | /* initialize general use internal ram */ |
| 146 | move.l #0, %d0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1 |
| 148 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a2 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 149 | move.l %d0, (%a1) |
| 150 | move.l %d0, (%a2) |
| 151 | |
| 152 | /* set stackpointer to end of internal ram to get some stackspace for the |
| 153 | first c-code */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 155 | clr.l %sp@- |
| 156 | |
| 157 | move.l #__got_start, %a5 /* put relocation table address to a5 */ |
| 158 | |
| 159 | bsr cpu_init_f /* run low-level CPU init code (from flash) */ |
| 160 | bsr board_init_f /* run low-level board init code (from flash) */ |
| 161 | |
| 162 | /* board_init_f() does not return */ |
| 163 | |
| 164 | /*------------------------------------------------------------------------------*/ |
| 165 | |
| 166 | /* |
| 167 | * void relocate_code (addr_sp, gd, addr_moni) |
| 168 | * |
| 169 | * This "function" does not return, instead it continues in RAM |
| 170 | * after relocating the monitor code. |
| 171 | * |
| 172 | * r3 = dest |
| 173 | * r4 = src |
| 174 | * r5 = length in bytes |
| 175 | * r6 = cachelinesize |
| 176 | */ |
| 177 | .globl relocate_code |
| 178 | relocate_code: |
| 179 | link.w %a6,#0 |
| 180 | move.l 8(%a6), %sp /* set new stack pointer */ |
| 181 | |
| 182 | move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ |
| 183 | move.l 16(%a6), %a0 /* Save copy of Destination Address */ |
| 184 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 185 | move.l #CONFIG_SYS_MONITOR_BASE, %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 186 | move.l #__init_end, %a2 |
| 187 | move.l %a0, %a3 |
| 188 | |
| 189 | /* copy the code to RAM */ |
| 190 | 1: |
| 191 | move.l (%a1)+, (%a3)+ |
| 192 | cmp.l %a1,%a2 |
| 193 | bgt.s 1b |
| 194 | |
| 195 | /* |
| 196 | * We are done. Do not return, instead branch to second part of board |
| 197 | * initialization, now running from RAM. |
| 198 | */ |
| 199 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 200 | add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 201 | jmp (%a1) |
| 202 | |
| 203 | in_ram: |
| 204 | |
| 205 | clear_bss: |
| 206 | /* |
| 207 | * Now clear BSS segment |
| 208 | */ |
| 209 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 210 | add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 211 | move.l %a0, %d1 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 212 | add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 213 | 6: |
| 214 | clr.l (%a1)+ |
| 215 | cmp.l %a1,%d1 |
| 216 | bgt.s 6b |
| 217 | |
| 218 | /* |
| 219 | * fix got table in RAM |
| 220 | */ |
| 221 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 222 | add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 223 | move.l %a1,%a5 /* * fix got pointer register a5 */ |
| 224 | |
| 225 | move.l %a0, %a2 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 226 | add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 227 | |
| 228 | 7: |
| 229 | move.l (%a1),%d1 |
| 230 | sub.l #_start,%d1 |
| 231 | add.l %a0,%d1 |
| 232 | move.l %d1,(%a1)+ |
| 233 | cmp.l %a2, %a1 |
| 234 | bne 7b |
| 235 | |
| 236 | /* calculate relative jump to board_init_r in ram */ |
| 237 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 238 | add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 239 | |
| 240 | /* set parameters for board_init_r */ |
| 241 | move.l %a0,-(%sp) /* dest_addr */ |
| 242 | move.l %d0,-(%sp) /* gd */ |
| 243 | jsr (%a1) |
| 244 | |
| 245 | /*------------------------------------------------------------------------------*/ |
| 246 | /* exception code */ |
| 247 | .globl _fault |
| 248 | _fault: |
| 249 | jmp _fault |
| 250 | .globl _exc_handler |
| 251 | |
| 252 | _exc_handler: |
| 253 | SAVE_ALL |
| 254 | movel %sp,%sp@- |
| 255 | bsr exc_handler |
| 256 | addql #4,%sp |
| 257 | RESTORE_ALL |
| 258 | |
| 259 | .globl _int_handler |
| 260 | _int_handler: |
| 261 | SAVE_ALL |
| 262 | movel %sp,%sp@- |
| 263 | bsr int_handler |
| 264 | addql #4,%sp |
| 265 | RESTORE_ALL |
| 266 | |
| 267 | /*------------------------------------------------------------------------------*/ |
| 268 | /* cache functions */ |
| 269 | .globl icache_enable |
| 270 | icache_enable: |
| 271 | move.l #0x01000000, %d0 /* Invalidate cache cmd */ |
| 272 | movec %d0, %CACR /* Invalidate cache */ |
| 273 | nop |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 274 | move.l #(CONFIG_SYS_SDRAM_BASE + 0xc000), %d0 /* Setup cache mask */ |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 275 | movec %d0, %ACR0 /* Enable cache */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 276 | move.l #(CONFIG_SYS_FLASH_BASE + 0xc000), %d0 /* Setup cache mask */ |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 277 | movec %d0, %ACR1 /* Enable cache */ |
| 278 | |
| 279 | move.l #0x80400100, %d0 /* Setup cache mask */ |
| 280 | movec %d0, %CACR /* Enable cache */ |
| 281 | nop |
| 282 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 283 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 284 | moveq #1, %d0 |
| 285 | move.l %d0, (%a1) |
| 286 | rts |
| 287 | |
| 288 | .globl icache_disable |
| 289 | icache_disable: |
| 290 | move.l #0x00000100, %d0 /* Setup cache mask */ |
| 291 | movec %d0, %CACR /* Disable cache */ |
| 292 | clr.l %d0 /* Setup cache mask */ |
| 293 | movec %d0, %ACR0 |
| 294 | movec %d0, %ACR1 |
| 295 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 296 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 297 | moveq #0, %d0 |
| 298 | move.l %d0, (%a1) |
| 299 | rts |
| 300 | |
| 301 | .globl icache_status |
| 302 | icache_status: |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 303 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-8), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 304 | move.l (%a1), %d0 |
| 305 | rts |
| 306 | |
| 307 | .globl icache_invalid |
| 308 | icache_invalid: |
| 309 | move.l #0x80600100, %d0 /* Setup cache mask */ |
| 310 | movec %d0, %CACR /* Enable cache */ |
| 311 | nop |
| 312 | rts |
| 313 | |
| 314 | .globl dcache_enable |
| 315 | dcache_enable: |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 316 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 317 | moveq #1, %d0 |
| 318 | move.l %d0, (%a1) |
| 319 | rts |
| 320 | |
| 321 | /* No dcache, just a dummy function */ |
| 322 | .globl dcache_disable |
| 323 | dcache_disable: |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 324 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 325 | moveq #0, %d0 |
| 326 | move.l %d0, (%a1) |
| 327 | rts |
| 328 | |
| 329 | .globl dcache_status |
| 330 | dcache_status: |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 331 | move.l #(CONFIG_SYS_INIT_RAM_ADDR+CONFIG_SYS_INIT_RAM_END-4), %a1 |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 332 | move.l (%a1), %d0 |
| 333 | rts |
| 334 | |
| 335 | /*------------------------------------------------------------------------------*/ |
| 336 | |
| 337 | .globl version_string |
| 338 | version_string: |
| 339 | .ascii U_BOOT_VERSION |
Peter Tyser | 561858e | 2008-11-03 09:30:59 -0600 | [diff] [blame] | 340 | .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")" |
TsiChungLiew | 4a442d3 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 341 | .ascii CONFIG_IDENT_STRING, "\0" |
TsiChung Liew | 9b46432 | 2008-03-28 08:47:45 -0500 | [diff] [blame] | 342 | .align 4 |