TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -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 | * |
TsiChung Liew | e7e4fc8 | 2008-10-22 11:38:21 +0000 | [diff] [blame] | 5 | * (C) Copyright 2004-2008 Freescale Semiconductor, Inc. |
| 6 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
| 7 | * |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 27 | #include <asm-offsets.h> |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 28 | #include <config.h> |
| 29 | #include "version.h" |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 30 | #include <asm/cache.h> |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 31 | |
| 32 | #ifndef CONFIG_IDENT_STRING |
| 33 | #define CONFIG_IDENT_STRING "" |
| 34 | #endif |
| 35 | |
| 36 | #define _START _start |
| 37 | #define _FAULT _fault |
| 38 | |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 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 | |
Wolfgang Wegner | ea32ab2 | 2010-03-02 10:59:20 +0100 | [diff] [blame] | 49 | #if !defined(CONFIG_MONITOR_IS_IN_RAM) |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 50 | .text |
| 51 | /* |
| 52 | * Vector table. This is used for initial platform startup. |
| 53 | * These vectors are to catch any un-intended traps. |
| 54 | */ |
| 55 | _vectors: |
| 56 | |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 57 | INITSP: .long 0x00000000 /* Initial SP */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 58 | INITPC: .long _START /* Initial PC */ |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 59 | vector02: .long _FAULT /* Access Error */ |
| 60 | vector03: .long _FAULT /* Address Error */ |
| 61 | vector04: .long _FAULT /* Illegal Instruction */ |
| 62 | vector05: .long _FAULT /* Reserved */ |
| 63 | vector06: .long _FAULT /* Reserved */ |
| 64 | vector07: .long _FAULT /* Reserved */ |
| 65 | vector08: .long _FAULT /* Privilege Violation */ |
| 66 | vector09: .long _FAULT /* Trace */ |
| 67 | vector0A: .long _FAULT /* Unimplemented A-Line */ |
| 68 | vector0B: .long _FAULT /* Unimplemented F-Line */ |
| 69 | vector0C: .long _FAULT /* Debug Interrupt */ |
| 70 | vector0D: .long _FAULT /* Reserved */ |
| 71 | vector0E: .long _FAULT /* Format Error */ |
| 72 | vector0F: .long _FAULT /* Unitialized Int. */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 73 | |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 74 | /* Reserved */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 75 | vector10_17: |
| 76 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 77 | |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 78 | vector18: .long _FAULT /* Spurious Interrupt */ |
| 79 | vector19: .long _FAULT /* Autovector Level 1 */ |
| 80 | vector1A: .long _FAULT /* Autovector Level 2 */ |
| 81 | vector1B: .long _FAULT /* Autovector Level 3 */ |
| 82 | vector1C: .long _FAULT /* Autovector Level 4 */ |
| 83 | vector1D: .long _FAULT /* Autovector Level 5 */ |
| 84 | vector1E: .long _FAULT /* Autovector Level 6 */ |
| 85 | vector1F: .long _FAULT /* Autovector Level 7 */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 86 | |
| 87 | /* TRAP #0 - #15 */ |
| 88 | vector20_2F: |
| 89 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 90 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 91 | |
| 92 | /* Reserved */ |
| 93 | vector30_3F: |
| 94 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 95 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 96 | |
| 97 | vector64_127: |
| 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 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 106 | |
| 107 | vector128_191: |
| 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 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 116 | |
| 117 | vector192_255: |
| 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 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
Wolfgang Wegner | ea32ab2 | 2010-03-02 10:59:20 +0100 | [diff] [blame] | 126 | #endif /* !defined(CONFIG_MONITOR_IS_IN_RAM) */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 127 | |
| 128 | .text |
| 129 | |
| 130 | .globl _start |
| 131 | _start: |
| 132 | nop |
| 133 | nop |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 134 | move.w #0x2700,%sr /* Mask off Interrupt */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 135 | |
Wolfgang Wegner | ea32ab2 | 2010-03-02 10:59:20 +0100 | [diff] [blame] | 136 | #if !defined(CONFIG_MONITOR_IS_IN_RAM) |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 137 | /* Set vector base register at the beginning of the Flash */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 138 | move.l #CONFIG_SYS_FLASH_BASE, %d0 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 139 | movec %d0, %VBR |
Wolfgang Wegner | ea32ab2 | 2010-03-02 10:59:20 +0100 | [diff] [blame] | 140 | #endif |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 141 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 |
TsiChungLiew | 942383d | 2007-10-25 17:12:36 -0500 | [diff] [blame] | 143 | movec %d0, %RAMBAR1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 144 | |
| 145 | /* invalidate and disable cache */ |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 146 | move.l #CF_CACR_CINVA, %d0 /* Invalidate cache cmd */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 147 | movec %d0, %CACR /* Invalidate cache */ |
| 148 | move.l #0, %d0 |
| 149 | movec %d0, %ACR0 |
| 150 | movec %d0, %ACR1 |
| 151 | |
TsiChung Liew | e7e4fc8 | 2008-10-22 11:38:21 +0000 | [diff] [blame] | 152 | #ifdef CONFIG_MCF5301x |
| 153 | move.l #(0xFC0a0010), %a0 |
| 154 | move.w (%a0), %d0 |
| 155 | and.l %d0, 0xEFFF |
| 156 | |
| 157 | move.w %d0, (%a0) |
| 158 | #endif |
| 159 | |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 160 | /* initialize general use internal ram */ |
| 161 | move.l #0, %d0 |
TsiChung Liew | 0ee47d4 | 2010-03-11 22:12:53 -0600 | [diff] [blame] | 162 | move.l #(ICACHE_STATUS), %a1 /* icache */ |
| 163 | move.l #(DCACHE_STATUS), %a2 /* icache */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 164 | move.l %d0, (%a1) |
| 165 | move.l %d0, (%a2) |
| 166 | |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 167 | /* set stackpointer to end of internal ram to get some stackspace for the |
| 168 | first c-code */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 169 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 170 | clr.l %sp@- |
| 171 | |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 172 | move.l #__got_start, %a5 /* put relocation table address to a5 */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 173 | |
TsiChungLiew | 8592cda | 2007-07-05 23:06:55 -0500 | [diff] [blame] | 174 | bsr cpu_init_f /* run low-level CPU init code (from flash) */ |
| 175 | bsr board_init_f /* run low-level board init code (from flash) */ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 176 | |
| 177 | /* board_init_f() does not return */ |
| 178 | |
| 179 | /*------------------------------------------------------------------------------*/ |
| 180 | |
| 181 | /* |
| 182 | * void relocate_code (addr_sp, gd, addr_moni) |
| 183 | * |
| 184 | * This "function" does not return, instead it continues in RAM |
| 185 | * after relocating the monitor code. |
| 186 | * |
| 187 | * r3 = dest |
| 188 | * r4 = src |
| 189 | * r5 = length in bytes |
| 190 | * r6 = cachelinesize |
| 191 | */ |
| 192 | .globl relocate_code |
| 193 | relocate_code: |
| 194 | link.w %a6,#0 |
| 195 | move.l 8(%a6), %sp /* set new stack pointer */ |
| 196 | |
| 197 | move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ |
| 198 | move.l 16(%a6), %a0 /* Save copy of Destination Address */ |
| 199 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 200 | move.l #CONFIG_SYS_MONITOR_BASE, %a1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 201 | move.l #__init_end, %a2 |
| 202 | move.l %a0, %a3 |
| 203 | |
| 204 | /* copy the code to RAM */ |
| 205 | 1: |
| 206 | move.l (%a1)+, (%a3)+ |
| 207 | cmp.l %a1,%a2 |
| 208 | bgt.s 1b |
| 209 | |
| 210 | /* |
| 211 | * We are done. Do not return, instead branch to second part of board |
| 212 | * initialization, now running from RAM. |
| 213 | */ |
| 214 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 215 | add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 216 | jmp (%a1) |
| 217 | |
| 218 | in_ram: |
| 219 | |
| 220 | clear_bss: |
| 221 | /* |
| 222 | * Now clear BSS segment |
| 223 | */ |
| 224 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 226 | move.l %a0, %d1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 227 | add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 228 | 6: |
| 229 | clr.l (%a1)+ |
| 230 | cmp.l %a1,%d1 |
| 231 | bgt.s 6b |
| 232 | |
| 233 | /* |
| 234 | * fix got table in RAM |
| 235 | */ |
| 236 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 237 | add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 238 | move.l %a1,%a5 /* * fix got pointer register a5 */ |
| 239 | |
| 240 | move.l %a0, %a2 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 241 | add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 242 | |
| 243 | 7: |
| 244 | move.l (%a1),%d1 |
| 245 | sub.l #_start,%d1 |
| 246 | add.l %a0,%d1 |
| 247 | move.l %d1,(%a1)+ |
| 248 | cmp.l %a2, %a1 |
| 249 | bne 7b |
| 250 | |
| 251 | /* calculate relative jump to board_init_r in ram */ |
| 252 | move.l %a0, %a1 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 253 | add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 254 | |
| 255 | /* set parameters for board_init_r */ |
| 256 | move.l %a0,-(%sp) /* dest_addr */ |
| 257 | move.l %d0,-(%sp) /* gd */ |
| 258 | jsr (%a1) |
| 259 | |
| 260 | /*------------------------------------------------------------------------------*/ |
| 261 | /* exception code */ |
| 262 | .globl _fault |
| 263 | _fault: |
| 264 | jmp _fault |
| 265 | .globl _exc_handler |
| 266 | |
| 267 | _exc_handler: |
| 268 | SAVE_ALL |
| 269 | movel %sp,%sp@- |
| 270 | bsr exc_handler |
| 271 | addql #4,%sp |
| 272 | RESTORE_ALL |
| 273 | |
| 274 | .globl _int_handler |
| 275 | _int_handler: |
| 276 | SAVE_ALL |
| 277 | movel %sp,%sp@- |
| 278 | bsr int_handler |
| 279 | addql #4,%sp |
| 280 | RESTORE_ALL |
| 281 | |
| 282 | /*------------------------------------------------------------------------------*/ |
TsiChung Liew | f6afe72 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 283 | .globl version_string |
| 284 | version_string: |
Andreas Bießmann | 61d0195 | 2011-07-18 20:24:04 +0200 | [diff] [blame] | 285 | .ascii U_BOOT_VERSION_STRING, "\0" |
TsiChung Liew | 9d636e9 | 2008-03-28 08:47:45 -0500 | [diff] [blame] | 286 | .align 4 |