1*83d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */ 2a4145534SPeter Tyser/* 3a4145534SPeter Tyser * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de> 4a4145534SPeter Tyser * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com> 5a4145534SPeter Tyser */ 6a4145534SPeter Tyser 725ddd1fbSWolfgang Denk#include <asm-offsets.h> 8a4145534SPeter Tyser#include <config.h> 9a4145534SPeter Tyser#include "version.h" 10a4145534SPeter Tyser#include <asm/cache.h> 11a4145534SPeter Tyser 12a4145534SPeter Tyser#define _START _start 13a4145534SPeter Tyser#define _FAULT _fault 14a4145534SPeter Tyser 15a4145534SPeter Tyser#define SAVE_ALL \ 16a4145534SPeter Tyser move.w #0x2700,%sr; /* disable intrs */ \ 17a4145534SPeter Tyser subl #60,%sp; /* space for 15 regs */ \ 18a4145534SPeter Tyser moveml %d0-%d7/%a0-%a6,%sp@; 19a4145534SPeter Tyser 20a4145534SPeter Tyser#define RESTORE_ALL \ 21a4145534SPeter Tyser moveml %sp@,%d0-%d7/%a0-%a6; \ 22a4145534SPeter Tyser addl #60,%sp; /* space for 15 regs */ \ 23a4145534SPeter Tyser rte; 24a4145534SPeter Tyser 25a4145534SPeter Tyser.text 265c928d02SAngelo Dureghello 27a4145534SPeter Tyser/* 28a4145534SPeter Tyser * Vector table. This is used for initial platform startup. 29a4145534SPeter Tyser * These vectors are to catch any un-intended traps. 30a4145534SPeter Tyser */ 31a4145534SPeter Tyser_vectors: 32a4145534SPeter TyserINITSP: .long 0x00000000 /* Initial SP */ 33a4145534SPeter TyserINITPC: .long _START /* Initial PC */ 345c928d02SAngelo Dureghello 355c928d02SAngelo Dureghellovector02_0F: 365c928d02SAngelo Dureghello.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 375c928d02SAngelo Dureghello.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 38a4145534SPeter Tyser 39a4145534SPeter Tyser/* Reserved */ 40a4145534SPeter Tyservector10_17: 41a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 42a4145534SPeter Tyser 435c928d02SAngelo Dureghellovector18_1F: 445c928d02SAngelo Dureghello.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 45a4145534SPeter Tyser 46a4145534SPeter Tyser/* TRAP #0 - #15 */ 47a4145534SPeter Tyservector20_2F: 48a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 49a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 50a4145534SPeter Tyser 51a4145534SPeter Tyser/* Reserved */ 52a4145534SPeter Tyservector30_3F: 53a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 54a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 55a4145534SPeter Tyser 56a4145534SPeter Tyservector64_127: 57a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 58a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 59a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 60a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 61a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 62a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 63a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 64a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 65a4145534SPeter Tyser 66a4145534SPeter Tyservector128_191: 67a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 68a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 69a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 70a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 71a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 72a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 73a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 74a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 75a4145534SPeter Tyser 76a4145534SPeter Tyservector192_255: 77a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 78a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 79a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 80a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 81a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 82a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 83a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 84a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 85a4145534SPeter Tyser 86a4145534SPeter Tyser.text 87a4145534SPeter Tyser 88a4145534SPeter Tyser.globl _start 89a4145534SPeter Tyser_start: 90a4145534SPeter Tyser nop 91a4145534SPeter Tyser nop 92a4145534SPeter Tyser move.w #0x2700,%sr /* Mask off Interrupt */ 93a4145534SPeter Tyser 94a4145534SPeter Tyser /* Set vector base register at the beginning of the Flash */ 95a4145534SPeter Tyser move.l #CONFIG_SYS_FLASH_BASE, %d0 96a4145534SPeter Tyser movec %d0, %VBR 97a4145534SPeter Tyser 98a4145534SPeter Tyser move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 99a4145534SPeter Tyser movec %d0, %RAMBAR0 100a4145534SPeter Tyser 101a4145534SPeter Tyser move.l #(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0 102a4145534SPeter Tyser movec %d0, %RAMBAR1 103a4145534SPeter Tyser 104a4145534SPeter Tyser move.l #CONFIG_SYS_MBAR, %d0 /* set MBAR address */ 105a4145534SPeter Tyser move.c %d0, %MBAR 106a4145534SPeter Tyser 107a4145534SPeter Tyser /* invalidate and disable cache */ 108a4145534SPeter Tyser move.l #0x01040100, %d0 /* Invalidate cache cmd */ 109a4145534SPeter Tyser movec %d0, %CACR /* Invalidate cache */ 110a4145534SPeter Tyser move.l #0, %d0 111a4145534SPeter Tyser movec %d0, %ACR0 112a4145534SPeter Tyser movec %d0, %ACR1 113a4145534SPeter Tyser movec %d0, %ACR2 114a4145534SPeter Tyser movec %d0, %ACR3 115a4145534SPeter Tyser 116a4145534SPeter Tyser /* initialize general use internal ram */ 117a4145534SPeter Tyser move.l #0, %d0 118a4145534SPeter Tyser move.l #(ICACHE_STATUS), %a1 /* icache */ 119a4145534SPeter Tyser move.l #(DCACHE_STATUS), %a2 /* icache */ 120a4145534SPeter Tyser move.l %d0, (%a1) 121a4145534SPeter Tyser move.l %d0, (%a2) 122a4145534SPeter Tyser 1235044c9ccSangelo@sysam.it /* put relocation table address to a5 */ 1245044c9ccSangelo@sysam.it move.l #__got_start, %a5 125a4145534SPeter Tyser 1265044c9ccSangelo@sysam.it /* setup stack initially on top of internal static ram */ 1275044c9ccSangelo@sysam.it move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp 1285044c9ccSangelo@sysam.it 1295044c9ccSangelo@sysam.it /* 1305044c9ccSangelo@sysam.it * if configured, malloc_f arena will be reserved first, 1315044c9ccSangelo@sysam.it * then (and always) gd struct space will be reserved 1325044c9ccSangelo@sysam.it */ 1335044c9ccSangelo@sysam.it move.l %sp, -(%sp) 1345044c9ccSangelo@sysam.it bsr board_init_f_alloc_reserve 1355044c9ccSangelo@sysam.it 1365044c9ccSangelo@sysam.it /* update stack and frame-pointers */ 1375044c9ccSangelo@sysam.it move.l %d0, %sp 1385044c9ccSangelo@sysam.it move.l %sp, %fp 1395044c9ccSangelo@sysam.it 1405044c9ccSangelo@sysam.it /* initialize reserved area */ 1415044c9ccSangelo@sysam.it move.l %d0, -(%sp) 1425044c9ccSangelo@sysam.it bsr board_init_f_init_reserve 143a4145534SPeter Tyser 1445c928d02SAngelo Dureghello /* run low-level CPU init code (from flash) */ 1455c928d02SAngelo Dureghello jbsr cpu_init_f 1465c928d02SAngelo Dureghello 1475c928d02SAngelo Dureghello /* run low-level board init code (from flash) */ 1485044c9ccSangelo@sysam.it clr.l %sp@- 1495c928d02SAngelo Dureghello jbsr board_init_f 150a4145534SPeter Tyser 151a4145534SPeter Tyser /* board_init_f() does not return */ 152a4145534SPeter Tyser 1535c928d02SAngelo Dureghello/******************************************************************************/ 154a4145534SPeter Tyser 155a4145534SPeter Tyser/* 156a4145534SPeter Tyser * void relocate_code (addr_sp, gd, addr_moni) 157a4145534SPeter Tyser * 158a4145534SPeter Tyser * This "function" does not return, instead it continues in RAM 159a4145534SPeter Tyser * after relocating the monitor code. 160a4145534SPeter Tyser * 161a4145534SPeter Tyser * r3 = dest 162a4145534SPeter Tyser * r4 = src 163a4145534SPeter Tyser * r5 = length in bytes 164a4145534SPeter Tyser * r6 = cachelinesize 165a4145534SPeter Tyser */ 166a4145534SPeter Tyser.globl relocate_code 167a4145534SPeter Tyserrelocate_code: 168a4145534SPeter Tyser link.w %a6,#0 169a4145534SPeter Tyser move.l 8(%a6), %sp /* set new stack pointer */ 170a4145534SPeter Tyser 171a4145534SPeter Tyser move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ 172a4145534SPeter Tyser move.l 16(%a6), %a0 /* Save copy of Destination Address */ 173a4145534SPeter Tyser 174a4145534SPeter Tyser move.l #CONFIG_SYS_MONITOR_BASE, %a1 175a4145534SPeter Tyser move.l #__init_end, %a2 176a4145534SPeter Tyser move.l %a0, %a3 177a4145534SPeter Tyser 178a4145534SPeter Tyser /* copy the code to RAM */ 179a4145534SPeter Tyser1: 180a4145534SPeter Tyser move.l (%a1)+, (%a3)+ 181a4145534SPeter Tyser cmp.l %a1,%a2 182a4145534SPeter Tyser bgt.s 1b 183a4145534SPeter Tyser 184a4145534SPeter Tyser/* 185a4145534SPeter Tyser * We are done. Do not return, instead branch to second part of board 186a4145534SPeter Tyser * initialization, now running from RAM. 187a4145534SPeter Tyser */ 188a4145534SPeter Tyser move.l %a0, %a1 189a4145534SPeter Tyser add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 190a4145534SPeter Tyser jmp (%a1) 191a4145534SPeter Tyser 192a4145534SPeter Tyserin_ram: 193a4145534SPeter Tyser 194a4145534SPeter Tyserclear_bss: 195a4145534SPeter Tyser /* 196a4145534SPeter Tyser * Now clear BSS segment 197a4145534SPeter Tyser */ 198a4145534SPeter Tyser move.l %a0, %a1 199a4145534SPeter Tyser add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 200a4145534SPeter Tyser move.l %a0, %d1 201a4145534SPeter Tyser add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 202a4145534SPeter Tyser6: 203a4145534SPeter Tyser clr.l (%a1)+ 204a4145534SPeter Tyser cmp.l %a1,%d1 205a4145534SPeter Tyser bgt.s 6b 206a4145534SPeter Tyser 207a4145534SPeter Tyser /* 208a4145534SPeter Tyser * fix got table in RAM 209a4145534SPeter Tyser */ 210a4145534SPeter Tyser move.l %a0, %a1 211a4145534SPeter Tyser add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 2125c928d02SAngelo Dureghello move.l %a1,%a5 /* fix got pointer register a5 */ 213a4145534SPeter Tyser 214a4145534SPeter Tyser move.l %a0, %a2 215a4145534SPeter Tyser add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 216a4145534SPeter Tyser 217a4145534SPeter Tyser7: 218a4145534SPeter Tyser move.l (%a1),%d1 219a4145534SPeter Tyser sub.l #_start,%d1 220a4145534SPeter Tyser add.l %a0,%d1 221a4145534SPeter Tyser move.l %d1,(%a1)+ 222a4145534SPeter Tyser cmp.l %a2, %a1 223a4145534SPeter Tyser bne 7b 224a4145534SPeter Tyser 225a4145534SPeter Tyser /* calculate relative jump to board_init_r in ram */ 226a4145534SPeter Tyser move.l %a0, %a1 227a4145534SPeter Tyser add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 228a4145534SPeter Tyser 229a4145534SPeter Tyser /* set parameters for board_init_r */ 230a4145534SPeter Tyser move.l %a0,-(%sp) /* dest_addr */ 231a4145534SPeter Tyser move.l %d0,-(%sp) /* gd */ 232a4145534SPeter Tyser jsr (%a1) 233a4145534SPeter Tyser 2345c928d02SAngelo Dureghello/******************************************************************************/ 2355c928d02SAngelo Dureghello 236a4145534SPeter Tyser/* exception code */ 237a4145534SPeter Tyser.globl _fault 238a4145534SPeter Tyser_fault: 239a4145534SPeter Tyser bra _fault 240a4145534SPeter Tyser 2415c928d02SAngelo Dureghello.globl _exc_handler 242a4145534SPeter Tyser_exc_handler: 243a4145534SPeter Tyser SAVE_ALL 244a4145534SPeter Tyser movel %sp,%sp@- 245a4145534SPeter Tyser bsr exc_handler 246a4145534SPeter Tyser addql #4,%sp 247a4145534SPeter Tyser RESTORE_ALL 248a4145534SPeter Tyser 249a4145534SPeter Tyser.globl _int_handler 250a4145534SPeter Tyser_int_handler: 251a4145534SPeter Tyser SAVE_ALL 252a4145534SPeter Tyser movel %sp,%sp@- 253a4145534SPeter Tyser bsr int_handler 254a4145534SPeter Tyser addql #4,%sp 255a4145534SPeter Tyser RESTORE_ALL 256a4145534SPeter Tyser 2575c928d02SAngelo Dureghello/******************************************************************************/ 258a4145534SPeter Tyser 259a4145534SPeter Tyser.globl version_string 260a4145534SPeter Tyserversion_string: 26109c2e90cSAndreas Bießmann.ascii U_BOOT_VERSION_STRING, "\0" 262a4145534SPeter Tyser.align 4 263