1/* SPDX-License-Identifier: GPL-2.0+ */ 2/* 3 * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de> 4 * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com> 5 */ 6 7#include <asm-offsets.h> 8#include <config.h> 9#include <asm/cache.h> 10 11#define _START _start 12#define _FAULT _fault 13 14 15#define 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 20#define RESTORE_ALL \ 21 moveml %sp@,%d0-%d7/%a0-%a6; \ 22 addl #60,%sp; /* space for 15 regs */ \ 23 rte 24 25/* If we come from a pre-loader we don't need an initial exception 26 * table. 27 */ 28#if !defined(CONFIG_MONITOR_IS_IN_RAM) 29 30.text 31 32/* 33 * Vector table. This is used for initial platform startup. 34 * These vectors are to catch any un-intended traps. 35 */ 36_vectors: 37.long 0x00000000 /* Flash offset is 0 until we setup CS0 */ 38#if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) 39.long _start - CONFIG_SYS_TEXT_BASE 40#else 41.long _START 42#endif 43 44.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 45.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 46.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 47.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 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 52 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, _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 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.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 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.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 80#endif 81 82.text 83 84#if defined(CONFIG_SYS_INT_FLASH_BASE) && \ 85 (defined(CONFIG_M5282) || defined(CONFIG_M5281)) 86#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) 87.long 0x55AA55AA,0xAA55AA55 /* CFM Backdoorkey */ 88.long 0xFFFFFFFF /* all sectors protected */ 89.long 0x00000000 /* supervisor/User restriction */ 90.long 0x00000000 /* programm/data space restriction */ 91.long 0x00000000 /* Flash security */ 92#endif 93#endif 94 95.globl _start 96_start: 97 nop 98 nop 99 move.w #0x2700,%sr 100 101#if defined(CONFIG_M5208) 102 /* Initialize RAMBAR: locate SRAM and validate it */ 103 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 104 movec %d0, %RAMBAR1 105#endif 106 107#if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5253) 108 /* set MBAR address + valid flag */ 109 move.l #(CONFIG_SYS_MBAR + 1), %d0 110 move.c %d0, %MBAR 111 112 /*** The 5249 has MBAR2 as well ***/ 113#ifdef CONFIG_SYS_MBAR2 114 /* Get MBAR2 address */ 115 move.l #(CONFIG_SYS_MBAR2 + 1), %d0 116 /* Set MBAR2 */ 117 movec %d0, #0xc0e 118#endif 119 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 1), %d0 120 movec %d0, %RAMBAR0 121#endif /* CONFIG_M5272 || CONFIG_M5249 || CONFIG_M5253 */ 122 123#if defined(CONFIG_M5282) || defined(CONFIG_M5271) 124 /* set MBAR address + valid flag */ 125 move.l #(CONFIG_SYS_MBAR + 1), %d0 126 move.l %d0, 0x40000000 127 128 /* Initialize RAMBAR1: locate SRAM and validate it */ 129 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0 130 movec %d0, %RAMBAR1 131 132#if defined(CONFIG_M5282) 133#if (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) 134 /* 135 * Setup code in SRAM to initialize FLASHBAR, 136 * if start from internal Flash 137 */ 138 move.l #(_flashbar_setup-CONFIG_SYS_INT_FLASH_BASE), %a0 139 move.l #(_flashbar_setup_end-CONFIG_SYS_INT_FLASH_BASE), %a1 140 move.l #(CONFIG_SYS_INIT_RAM_ADDR), %a2 141_copy_flash: 142 move.l (%a0)+, (%a2)+ 143 cmp.l %a0, %a1 144 bgt.s _copy_flash 145 jmp CONFIG_SYS_INIT_RAM_ADDR 146 147_flashbar_setup: 148 /* Initialize FLASHBAR: locate internal Flash and validate it */ 149 move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0 150 movec %d0, %FLASHBAR 151 jmp _after_flashbar_copy.L /* Force jump to absolute address */ 152_flashbar_setup_end: 153 nop 154_after_flashbar_copy: 155#else 156 /* Setup code to initialize FLASHBAR, if start from external Memory */ 157 move.l #(CONFIG_SYS_INT_FLASH_BASE + CONFIG_SYS_INT_FLASH_ENABLE), %d0 158 movec %d0, %FLASHBAR 159#endif /* (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) */ 160 161#endif 162#endif 163 /* 164 * if we come from a pre-loader we have no exception table and 165 * therefore no VBR to set 166 */ 167#if !defined(CONFIG_MONITOR_IS_IN_RAM) 168#if defined(CONFIG_M5282) && (CONFIG_SYS_TEXT_BASE == CONFIG_SYS_INT_FLASH_BASE) 169 move.l #CONFIG_SYS_INT_FLASH_BASE, %d0 170#else 171 move.l #CONFIG_SYS_FLASH_BASE, %d0 172#endif 173 movec %d0, %VBR 174#endif 175 176#ifdef CONFIG_M5275 177 /* set MBAR address + valid flag */ 178 move.l #(CONFIG_SYS_MBAR + 1), %d0 179 move.l %d0, 0x40000000 180/* movec %d0, %MBAR */ 181 182 /* Initialize RAMBAR: locate SRAM and validate it */ 183 move.l #(CONFIG_SYS_INIT_RAM_ADDR + 0x21), %d0 184 movec %d0, %RAMBAR1 185#endif 186 187 /* initialize general use internal ram */ 188 move.l #0, %d0 189 move.l #(ICACHE_STATUS), %a1 /* icache */ 190 move.l #(DCACHE_STATUS), %a2 /* icache */ 191 move.l %d0, (%a1) 192 move.l %d0, (%a2) 193 194 /* put relocation table address to a5 */ 195 move.l #__got_start, %a5 196 197 /* setup stack initially on top of internal static ram */ 198 move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp 199 200 /* 201 * if configured, malloc_f arena will be reserved first, 202 * then (and always) gd struct space will be reserved 203 */ 204 move.l %sp, -(%sp) 205 move.l #board_init_f_alloc_reserve, %a1 206 jsr (%a1) 207 208 /* update stack and frame-pointers */ 209 move.l %d0, %sp 210 move.l %sp, %fp 211 212 /* initialize reserved area */ 213 move.l %d0, -(%sp) 214 move.l #board_init_f_init_reserve, %a1 215 jsr (%a1) 216 217 /* run low-level CPU init code (from flash) */ 218 move.l #cpu_init_f, %a1 219 jsr (%a1) 220 221 /* run low-level board init code (from flash) */ 222 clr.l %sp@- 223 move.l #board_init_f, %a1 224 jsr (%a1) 225 226 /* board_init_f() does not return */ 227 228/******************************************************************************/ 229 230/* 231 * void relocate_code(addr_sp, gd, addr_moni) 232 * 233 * This "function" does not return, instead it continues in RAM 234 * after relocating the monitor code. 235 * 236 * r3 = dest 237 * r4 = src 238 * r5 = length in bytes 239 * r6 = cachelinesize 240 */ 241.globl relocate_code 242relocate_code: 243 link.w %a6,#0 244 move.l 8(%a6), %sp /* set new stack pointer */ 245 246 move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ 247 move.l 16(%a6), %a0 /* Save copy of Destination Address */ 248 249 move.l #CONFIG_SYS_MONITOR_BASE, %a1 250 move.l #__init_end, %a2 251 move.l %a0, %a3 252 /* copy the code to RAM */ 2531: 254 move.l (%a1)+, (%a3)+ 255 cmp.l %a1,%a2 256 bgt.s 1b 257 258/* 259 * We are done. Do not return, instead branch to second part of board 260 * initialization, now running from RAM. 261 */ 262 move.l %a0, %a1 263 add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 264 jmp (%a1) 265 266in_ram: 267 268clear_bss: 269 /* 270 * Now clear BSS segment 271 */ 272 move.l %a0, %a1 273 add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 274 move.l %a0, %d1 275 add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 2766: 277 clr.l (%a1)+ 278 cmp.l %a1,%d1 279 bgt.s 6b 280 281 /* 282 * fix got table in RAM 283 */ 284 move.l %a0, %a1 285 add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 286 move.l %a1,%a5 /* fix got pointer register a5 */ 287 288 move.l %a0, %a2 289 add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 290 2917: 292 move.l (%a1),%d1 293 sub.l #_start,%d1 294 add.l %a0,%d1 295 move.l %d1,(%a1)+ 296 cmp.l %a2, %a1 297 bne 7b 298 299 /* calculate relative jump to board_init_r in ram */ 300 move.l %a0, %a1 301 add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 302 303 /* set parameters for board_init_r */ 304 move.l %a0,-(%sp) /* dest_addr */ 305 move.l %d0,-(%sp) /* gd */ 306#if defined(DEBUG) && (CONFIG_SYS_TEXT_BASE != CONFIG_SYS_INT_FLASH_BASE) && \ 307 defined(CONFIG_SYS_HALT_BEFOR_RAM_JUMP) 308 halt 309#endif 310 jsr (%a1) 311 312/******************************************************************************/ 313 314/* exception code */ 315.globl _fault 316_fault: 317 bra _fault 318 319.globl _exc_handler 320_exc_handler: 321 SAVE_ALL 322 movel %sp,%sp@- 323 bsr exc_handler 324 addql #4,%sp 325 RESTORE_ALL 326 327.globl _int_handler 328_int_handler: 329 SAVE_ALL 330 movel %sp,%sp@- 331 bsr int_handler 332 addql #4,%sp 333 RESTORE_ALL 334 335/******************************************************************************/ 336 337.align 4 338