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