1a4145534SPeter Tyser/* 2a4145534SPeter Tyser * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de> 3a4145534SPeter Tyser * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com> 4a4145534SPeter Tyser * 5a4145534SPeter Tyser * See file CREDITS for list of people who contributed to this 6a4145534SPeter Tyser * project. 7a4145534SPeter Tyser * 8a4145534SPeter Tyser * This program is free software; you can redistribute it and/or 9a4145534SPeter Tyser * modify it under the terms of the GNU General Public License as 10a4145534SPeter Tyser * published by the Free Software Foundation; either version 2 of 11a4145534SPeter Tyser * the License, or (at your option) any later version. 12a4145534SPeter Tyser * 13a4145534SPeter Tyser * This program is distributed in the hope that it will be useful, 14a4145534SPeter Tyser * but WITHOUT ANY WARRANTY; without even the implied warranty of 15a4145534SPeter Tyser * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16a4145534SPeter Tyser * GNU General Public License for more details. 17a4145534SPeter Tyser * 18a4145534SPeter Tyser * You should have received a copy of the GNU General Public License 19a4145534SPeter Tyser * along with this program; if not, write to the Free Software 20a4145534SPeter Tyser * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21a4145534SPeter Tyser * MA 02111-1307 USA 22a4145534SPeter Tyser */ 23a4145534SPeter Tyser 2425ddd1fbSWolfgang Denk#include <asm-offsets.h> 25a4145534SPeter Tyser#include <config.h> 26a4145534SPeter Tyser#include "version.h" 27a4145534SPeter Tyser#include <asm/cache.h> 28a4145534SPeter Tyser 29a4145534SPeter Tyser#ifndef CONFIG_IDENT_STRING 30a4145534SPeter Tyser#define CONFIG_IDENT_STRING "" 31a4145534SPeter Tyser#endif 32a4145534SPeter Tyser 33a4145534SPeter Tyser#define _START _start 34a4145534SPeter Tyser#define _FAULT _fault 35a4145534SPeter Tyser 36a4145534SPeter Tyser#define SAVE_ALL \ 37a4145534SPeter Tyser move.w #0x2700,%sr; /* disable intrs */ \ 38a4145534SPeter Tyser subl #60,%sp; /* space for 15 regs */ \ 39a4145534SPeter Tyser moveml %d0-%d7/%a0-%a6,%sp@; 40a4145534SPeter Tyser 41a4145534SPeter Tyser#define RESTORE_ALL \ 42a4145534SPeter Tyser moveml %sp@,%d0-%d7/%a0-%a6; \ 43a4145534SPeter Tyser addl #60,%sp; /* space for 15 regs */ \ 44a4145534SPeter Tyser rte; 45a4145534SPeter Tyser 46a4145534SPeter Tyser.text 47a4145534SPeter Tyser/* 48a4145534SPeter Tyser * Vector table. This is used for initial platform startup. 49a4145534SPeter Tyser * These vectors are to catch any un-intended traps. 50a4145534SPeter Tyser */ 51a4145534SPeter Tyser_vectors: 52a4145534SPeter Tyser 53a4145534SPeter TyserINITSP: .long 0x00000000 /* Initial SP */ 54a4145534SPeter TyserINITPC: .long _START /* Initial PC */ 55a4145534SPeter Tyservector02: .long _FAULT /* Access Error */ 56a4145534SPeter Tyservector03: .long _FAULT /* Address Error */ 57a4145534SPeter Tyservector04: .long _FAULT /* Illegal Instruction */ 58a4145534SPeter Tyservector05: .long _FAULT /* Reserved */ 59a4145534SPeter Tyservector06: .long _FAULT /* Reserved */ 60a4145534SPeter Tyservector07: .long _FAULT /* Reserved */ 61a4145534SPeter Tyservector08: .long _FAULT /* Privilege Violation */ 62a4145534SPeter Tyservector09: .long _FAULT /* Trace */ 63a4145534SPeter Tyservector0A: .long _FAULT /* Unimplemented A-Line */ 64a4145534SPeter Tyservector0B: .long _FAULT /* Unimplemented F-Line */ 65a4145534SPeter Tyservector0C: .long _FAULT /* Debug Interrupt */ 66a4145534SPeter Tyservector0D: .long _FAULT /* Reserved */ 67a4145534SPeter Tyservector0E: .long _FAULT /* Format Error */ 68a4145534SPeter Tyservector0F: .long _FAULT /* Unitialized Int. */ 69a4145534SPeter Tyser 70a4145534SPeter Tyser/* Reserved */ 71a4145534SPeter Tyservector10_17: 72a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 73a4145534SPeter Tyser 74a4145534SPeter Tyservector18: .long _FAULT /* Spurious Interrupt */ 75a4145534SPeter Tyservector19: .long _FAULT /* Autovector Level 1 */ 76a4145534SPeter Tyservector1A: .long _FAULT /* Autovector Level 2 */ 77a4145534SPeter Tyservector1B: .long _FAULT /* Autovector Level 3 */ 78a4145534SPeter Tyservector1C: .long _FAULT /* Autovector Level 4 */ 79a4145534SPeter Tyservector1D: .long _FAULT /* Autovector Level 5 */ 80a4145534SPeter Tyservector1E: .long _FAULT /* Autovector Level 6 */ 81a4145534SPeter Tyservector1F: .long _FAULT /* Autovector Level 7 */ 82a4145534SPeter Tyser 83a4145534SPeter Tyser/* TRAP #0 - #15 */ 84a4145534SPeter Tyservector20_2F: 85a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 86a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 87a4145534SPeter Tyser 88a4145534SPeter Tyser/* Reserved */ 89a4145534SPeter Tyservector30_3F: 90a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 91a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 92a4145534SPeter Tyser 93a4145534SPeter Tyservector64_127: 94a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 95a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 96a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 97a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 98a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 99a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 100a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 101a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 102a4145534SPeter Tyser 103a4145534SPeter Tyservector128_191: 104a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 105a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 106a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 107a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 108a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 109a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 110a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 111a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 112a4145534SPeter Tyser 113a4145534SPeter Tyservector192_255: 114a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 115a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 116a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 117a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 118a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 119a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 120a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 121a4145534SPeter Tyser.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 122a4145534SPeter Tyser 123a4145534SPeter Tyser .text 124a4145534SPeter Tyser 125a4145534SPeter Tyser .globl _start 126a4145534SPeter Tyser_start: 127a4145534SPeter Tyser nop 128a4145534SPeter Tyser nop 129a4145534SPeter Tyser move.w #0x2700,%sr /* Mask off Interrupt */ 130a4145534SPeter Tyser 131a4145534SPeter Tyser /* Set vector base register at the beginning of the Flash */ 132a4145534SPeter Tyser move.l #CONFIG_SYS_FLASH_BASE, %d0 133a4145534SPeter Tyser movec %d0, %VBR 134a4145534SPeter Tyser 135a4145534SPeter Tyser move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 136a4145534SPeter Tyser movec %d0, %RAMBAR0 137a4145534SPeter Tyser 138a4145534SPeter Tyser move.l #(CONFIG_SYS_INIT_RAM1_ADDR + CONFIG_SYS_INIT_RAM1_CTRL), %d0 139a4145534SPeter Tyser movec %d0, %RAMBAR1 140a4145534SPeter Tyser 141a4145534SPeter Tyser move.l #CONFIG_SYS_MBAR, %d0 /* set MBAR address */ 142a4145534SPeter Tyser move.c %d0, %MBAR 143a4145534SPeter Tyser 144a4145534SPeter Tyser /* invalidate and disable cache */ 145a4145534SPeter Tyser move.l #0x01040100, %d0 /* Invalidate cache cmd */ 146a4145534SPeter Tyser movec %d0, %CACR /* Invalidate cache */ 147a4145534SPeter Tyser move.l #0, %d0 148a4145534SPeter Tyser movec %d0, %ACR0 149a4145534SPeter Tyser movec %d0, %ACR1 150a4145534SPeter Tyser movec %d0, %ACR2 151a4145534SPeter Tyser movec %d0, %ACR3 152a4145534SPeter Tyser 153a4145534SPeter Tyser /* initialize general use internal ram */ 154a4145534SPeter Tyser move.l #0, %d0 155a4145534SPeter Tyser move.l #(ICACHE_STATUS), %a1 /* icache */ 156a4145534SPeter Tyser move.l #(DCACHE_STATUS), %a2 /* icache */ 157a4145534SPeter Tyser move.l %d0, (%a1) 158a4145534SPeter Tyser move.l %d0, (%a2) 159a4145534SPeter Tyser 160a4145534SPeter Tyser /* set stackpointer to end of internal ram to get some stackspace for the 161a4145534SPeter Tyser first c-code */ 162a4145534SPeter Tyser move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp 163a4145534SPeter Tyser clr.l %sp@- 164a4145534SPeter Tyser 165a4145534SPeter Tyser move.l #__got_start, %a5 /* put relocation table address to a5 */ 166a4145534SPeter Tyser 167a4145534SPeter Tyser bsr cpu_init_f /* run low-level CPU init code (from flash) */ 168a4145534SPeter Tyser bsr board_init_f /* run low-level board init code (from flash) */ 169a4145534SPeter Tyser 170a4145534SPeter Tyser /* board_init_f() does not return */ 171a4145534SPeter Tyser 172a4145534SPeter Tyser/*------------------------------------------------------------------------------*/ 173a4145534SPeter Tyser 174a4145534SPeter Tyser/* 175a4145534SPeter Tyser * void relocate_code (addr_sp, gd, addr_moni) 176a4145534SPeter Tyser * 177a4145534SPeter Tyser * This "function" does not return, instead it continues in RAM 178a4145534SPeter Tyser * after relocating the monitor code. 179a4145534SPeter Tyser * 180a4145534SPeter Tyser * r3 = dest 181a4145534SPeter Tyser * r4 = src 182a4145534SPeter Tyser * r5 = length in bytes 183a4145534SPeter Tyser * r6 = cachelinesize 184a4145534SPeter Tyser */ 185a4145534SPeter Tyser .globl relocate_code 186a4145534SPeter Tyserrelocate_code: 187a4145534SPeter Tyser link.w %a6,#0 188a4145534SPeter Tyser move.l 8(%a6), %sp /* set new stack pointer */ 189a4145534SPeter Tyser 190a4145534SPeter Tyser move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ 191a4145534SPeter Tyser move.l 16(%a6), %a0 /* Save copy of Destination Address */ 192a4145534SPeter Tyser 193a4145534SPeter Tyser move.l #CONFIG_SYS_MONITOR_BASE, %a1 194a4145534SPeter Tyser move.l #__init_end, %a2 195a4145534SPeter Tyser move.l %a0, %a3 196a4145534SPeter Tyser 197a4145534SPeter Tyser /* copy the code to RAM */ 198a4145534SPeter Tyser1: 199a4145534SPeter Tyser move.l (%a1)+, (%a3)+ 200a4145534SPeter Tyser cmp.l %a1,%a2 201a4145534SPeter Tyser bgt.s 1b 202a4145534SPeter Tyser 203a4145534SPeter Tyser/* 204a4145534SPeter Tyser * We are done. Do not return, instead branch to second part of board 205a4145534SPeter Tyser * initialization, now running from RAM. 206a4145534SPeter Tyser */ 207a4145534SPeter Tyser move.l %a0, %a1 208a4145534SPeter Tyser add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 209a4145534SPeter Tyser jmp (%a1) 210a4145534SPeter Tyser 211a4145534SPeter Tyserin_ram: 212a4145534SPeter Tyser 213a4145534SPeter Tyserclear_bss: 214a4145534SPeter Tyser /* 215a4145534SPeter Tyser * Now clear BSS segment 216a4145534SPeter Tyser */ 217a4145534SPeter Tyser move.l %a0, %a1 218a4145534SPeter Tyser add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 219a4145534SPeter Tyser move.l %a0, %d1 220a4145534SPeter Tyser add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 221a4145534SPeter Tyser6: 222a4145534SPeter Tyser clr.l (%a1)+ 223a4145534SPeter Tyser cmp.l %a1,%d1 224a4145534SPeter Tyser bgt.s 6b 225a4145534SPeter Tyser 226a4145534SPeter Tyser /* 227a4145534SPeter Tyser * fix got table in RAM 228a4145534SPeter Tyser */ 229a4145534SPeter Tyser move.l %a0, %a1 230a4145534SPeter Tyser add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 231a4145534SPeter Tyser move.l %a1,%a5 /* * fix got pointer register a5 */ 232a4145534SPeter Tyser 233a4145534SPeter Tyser move.l %a0, %a2 234a4145534SPeter Tyser add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 235a4145534SPeter Tyser 236a4145534SPeter Tyser7: 237a4145534SPeter Tyser move.l (%a1),%d1 238a4145534SPeter Tyser sub.l #_start,%d1 239a4145534SPeter Tyser add.l %a0,%d1 240a4145534SPeter Tyser move.l %d1,(%a1)+ 241a4145534SPeter Tyser cmp.l %a2, %a1 242a4145534SPeter Tyser bne 7b 243a4145534SPeter Tyser 244a4145534SPeter Tyser /* calculate relative jump to board_init_r in ram */ 245a4145534SPeter Tyser move.l %a0, %a1 246a4145534SPeter Tyser add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 247a4145534SPeter Tyser 248a4145534SPeter Tyser /* set parameters for board_init_r */ 249a4145534SPeter Tyser move.l %a0,-(%sp) /* dest_addr */ 250a4145534SPeter Tyser move.l %d0,-(%sp) /* gd */ 251a4145534SPeter Tyser jsr (%a1) 252a4145534SPeter Tyser 253a4145534SPeter Tyser/*------------------------------------------------------------------------------*/ 254a4145534SPeter Tyser/* exception code */ 255a4145534SPeter Tyser .globl _fault 256a4145534SPeter Tyser_fault: 257a4145534SPeter Tyser bra _fault 258a4145534SPeter Tyser .globl _exc_handler 259a4145534SPeter Tyser 260a4145534SPeter Tyser_exc_handler: 261a4145534SPeter Tyser SAVE_ALL 262a4145534SPeter Tyser movel %sp,%sp@- 263a4145534SPeter Tyser bsr exc_handler 264a4145534SPeter Tyser addql #4,%sp 265a4145534SPeter Tyser RESTORE_ALL 266a4145534SPeter Tyser 267a4145534SPeter Tyser .globl _int_handler 268a4145534SPeter Tyser_int_handler: 269a4145534SPeter Tyser SAVE_ALL 270a4145534SPeter Tyser movel %sp,%sp@- 271a4145534SPeter Tyser bsr int_handler 272a4145534SPeter Tyser addql #4,%sp 273a4145534SPeter Tyser RESTORE_ALL 274a4145534SPeter Tyser 275a4145534SPeter Tyser/*------------------------------------------------------------------------------*/ 276a4145534SPeter Tyser 277a4145534SPeter Tyser .globl version_string 278a4145534SPeter Tyserversion_string: 279*09c2e90cSAndreas Bießmann .ascii U_BOOT_VERSION_STRING, "\0" 280a4145534SPeter Tyser .align 4 281