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