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