Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Angelo Dureghello <angelo@sysam.it> |
| 4 | * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com> |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <asm-offsets.h> |
| 8 | #include <config.h> |
| 9 | #include "version.h" |
| 10 | #include <asm/cache.h> |
| 11 | |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 12 | #define _START _start |
| 13 | #define _FAULT _fault |
| 14 | |
| 15 | |
| 16 | .macro SAVE_ALL |
| 17 | move.w #0x2700,%sr; /* disable intrs */ |
| 18 | subl #60,%sp; /* space for 15 regs */ |
| 19 | moveml %d0-%d7/%a0-%a6,%sp@ |
| 20 | .endm |
| 21 | |
| 22 | .macro RESTORE_ALL |
| 23 | moveml %sp@,%d0-%d7/%a0-%a6; |
| 24 | addl #60,%sp; /* space for 15 regs */ |
| 25 | rte |
| 26 | .endm |
| 27 | |
| 28 | /* If we come from a pre-loader we don't need an initial exception |
| 29 | * table. |
| 30 | */ |
| 31 | #if !defined(CONFIG_MONITOR_IS_IN_RAM) |
| 32 | |
| 33 | .text |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 34 | |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 35 | /* |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 36 | * Vector table. This is used for initial platform startup. |
| 37 | * These vectors are to catch any un-intended traps. |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 38 | */ |
| 39 | _vectors: |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 40 | /* Flash offset is 0 until we setup CS0 */ |
| 41 | .long 0x00000000 |
| 42 | #if defined(CONFIG_M5307) && \ |
| 43 | (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) |
| 44 | .long _start - CONFIG_SYS_TEXT_BASE |
| 45 | #else |
| 46 | .long _START |
| 47 | #endif |
| 48 | |
| 49 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 50 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 51 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 52 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 53 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 54 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 55 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 56 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 57 | |
| 58 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 59 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 60 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 61 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 62 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 63 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 64 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 65 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 66 | |
| 67 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 68 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 69 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 70 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 71 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 72 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 73 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 74 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 75 | |
| 76 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 77 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 78 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 79 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 80 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 81 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 82 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 83 | .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT |
| 84 | |
| 85 | #endif |
| 86 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 87 | .text |
| 88 | |
| 89 | .globl _start |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 90 | _start: |
| 91 | nop |
| 92 | nop |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 93 | move.w #0x2700,%sr |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 94 | |
| 95 | /* set MBAR address + valid flag */ |
| 96 | move.l #(CONFIG_SYS_MBAR + 1), %d0 |
| 97 | move.c %d0, %MBAR |
| 98 | |
| 99 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0 |
| 100 | move.c %d0, %RAMBAR |
| 101 | |
| 102 | /* DS 4.8.2 (Cache Organization) invalidate and disable cache */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 103 | move.l #CF_CACR_CINVA, %d0 |
| 104 | movec %d0, %CACR |
| 105 | move.l #0, %d0 |
| 106 | movec %d0, %ACR0 |
| 107 | movec %d0, %ACR1 |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * if we come from a pre-loader we have no exception table and |
| 111 | * therefore no VBR to set |
| 112 | */ |
| 113 | #if !defined(CONFIG_MONITOR_IS_IN_RAM) |
| 114 | move.l #CONFIG_SYS_FLASH_BASE, %d0 |
| 115 | movec %d0, %VBR |
| 116 | #endif |
| 117 | |
| 118 | /* initialize general use internal ram */ |
| 119 | move.l #0, %d0 |
| 120 | move.l #(ICACHE_STATUS), %a1 /* icache */ |
| 121 | move.l #(DCACHE_STATUS), %a2 /* dcache */ |
| 122 | move.l %d0, (%a1) |
| 123 | move.l %d0, (%a2) |
| 124 | |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 125 | /* put relocation table address to a5 */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 126 | move.l #__got_start, %a5 |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 127 | |
| 128 | /* setup stack initially on top of internal static ram */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 129 | move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 130 | |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 131 | /* |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 132 | * if configured, malloc_f arena will be reserved first, |
| 133 | * then (and always) gd struct space will be reserved |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 134 | */ |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 135 | move.l %sp, -(%sp) |
| 136 | bsr board_init_f_alloc_reserve |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 137 | |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 138 | /* update stack and frame-pointers */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 139 | move.l %d0, %sp |
| 140 | move.l %sp, %fp |
angelo@sysam.it | ef9707c | 2016-04-27 21:50:44 +0200 | [diff] [blame] | 141 | |
| 142 | /* initialize reserved area */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 143 | move.l %d0, -(%sp) |
| 144 | bsr board_init_f_init_reserve |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 145 | |
| 146 | /* run low-level CPU init code (from flash) */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 147 | bsr cpu_init_f |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 148 | |
| 149 | /* run low-level board init code (from flash) */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 150 | clr.l %sp@- |
| 151 | bsr board_init_f |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 152 | |
| 153 | /* board_init_f() does not return */ |
| 154 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 155 | /******************************************************************************/ |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 156 | |
| 157 | /* |
Simon Glass | 284f71b | 2019-12-28 10:44:45 -0700 | [diff] [blame] | 158 | * void relocate_code(addr_sp, gd, addr_moni) |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 159 | * |
| 160 | * This "function" does not return, instead it continues in RAM |
| 161 | * after relocating the monitor code. |
| 162 | * |
| 163 | */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 164 | .globl relocate_code |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 165 | relocate_code: |
| 166 | link.w %a6,#0 |
| 167 | move.l 8(%a6), %sp /* set new stack pointer */ |
| 168 | move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ |
| 169 | move.l 16(%a6), %a0 /* Save copy of Destination Address */ |
| 170 | |
| 171 | move.l #CONFIG_SYS_MONITOR_BASE, %a1 |
| 172 | move.l #__init_end, %a2 |
| 173 | move.l %a0, %a3 |
| 174 | /* copy the code to RAM */ |
| 175 | 1: |
| 176 | move.l (%a1)+, (%a3)+ |
| 177 | cmp.l %a1,%a2 |
| 178 | bgt.s 1b |
| 179 | |
| 180 | /* |
| 181 | * We are done. Do not return, instead branch to second part of board |
| 182 | * initialization, now running from RAM. |
| 183 | */ |
| 184 | move.l %a0, %a1 |
| 185 | add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 |
| 186 | jmp (%a1) |
| 187 | |
| 188 | in_ram: |
| 189 | |
| 190 | clear_bss: |
| 191 | /* |
| 192 | * Now clear BSS segment |
| 193 | */ |
| 194 | move.l %a0, %a1 |
| 195 | add.l #(_sbss - CONFIG_SYS_MONITOR_BASE), %a1 |
| 196 | move.l %a0, %d1 |
| 197 | add.l #(_ebss - CONFIG_SYS_MONITOR_BASE), %d1 |
| 198 | 6: |
| 199 | clr.l (%a1)+ |
| 200 | cmp.l %a1,%d1 |
| 201 | bgt.s 6b |
| 202 | |
| 203 | /* |
| 204 | * fix got table in RAM |
| 205 | */ |
| 206 | move.l %a0, %a1 |
| 207 | add.l #(__got_start - CONFIG_SYS_MONITOR_BASE), %a1 |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 208 | |
| 209 | /* fix got pointer register a5 */ |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 210 | move.l %a1,%a5 |
| 211 | |
| 212 | move.l %a0, %a2 |
| 213 | add.l #(__got_end - CONFIG_SYS_MONITOR_BASE), %a2 |
| 214 | |
| 215 | 7: |
| 216 | move.l (%a1),%d1 |
| 217 | sub.l #_start, %d1 |
| 218 | add.l %a0,%d1 |
| 219 | move.l %d1,(%a1)+ |
| 220 | cmp.l %a2, %a1 |
| 221 | bne 7b |
| 222 | |
| 223 | /* calculate relative jump to board_init_r in ram */ |
| 224 | move.l %a0, %a1 |
| 225 | add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 |
| 226 | |
| 227 | /* set parameters for board_init_r */ |
| 228 | move.l %a0,-(%sp) /* dest_addr */ |
| 229 | move.l %d0,-(%sp) /* gd */ |
| 230 | #if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE!=CONFIG_SYS_INT_FLASH_BASE) && \ |
| 231 | defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP) |
| 232 | halt |
| 233 | #endif |
| 234 | jsr (%a1) |
| 235 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 236 | /******************************************************************************/ |
| 237 | |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 238 | /* exception code */ |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 239 | .globl _fault |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 240 | _fault: |
| 241 | bra _fault |
| 242 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 243 | .globl _exc_handler |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 244 | _exc_handler: |
| 245 | SAVE_ALL |
| 246 | movel %sp,%sp@- |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 247 | bsr exc_handler |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 248 | addql #4,%sp |
| 249 | RESTORE_ALL |
| 250 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 251 | .globl _int_handler |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 252 | _int_handler: |
| 253 | SAVE_ALL |
| 254 | movel %sp,%sp@- |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 255 | bsr int_handler |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 256 | addql #4,%sp |
| 257 | RESTORE_ALL |
| 258 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 259 | /******************************************************************************/ |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 260 | |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 261 | .globl version_string |
angelo@sysam.it | bb4ba2c | 2015-02-12 01:40:00 +0100 | [diff] [blame] | 262 | version_string: |
Angelo Dureghello | 65d5991 | 2016-05-22 00:14:29 +0200 | [diff] [blame] | 263 | .ascii U_BOOT_VERSION |
| 264 | .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")" |
| 265 | .ascii CONFIG_IDENT_STRING, "\0" |
| 266 | .align 4 |