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