1*4882a593Smuzhiyun/* 2*4882a593Smuzhiyun * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de> 3*4882a593Smuzhiyun * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com> 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ 6*4882a593Smuzhiyun */ 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun#include <asm-offsets.h> 9*4882a593Smuzhiyun#include <config.h> 10*4882a593Smuzhiyun#include "version.h" 11*4882a593Smuzhiyun#include <asm/cache.h> 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun#define _START _start 14*4882a593Smuzhiyun#define _FAULT _fault 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun#define SAVE_ALL \ 17*4882a593Smuzhiyun move.w #0x2700,%sr; /* disable intrs */ \ 18*4882a593Smuzhiyun subl #60,%sp; /* space for 15 regs */ \ 19*4882a593Smuzhiyun moveml %d0-%d7/%a0-%a6,%sp@; 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun#define RESTORE_ALL \ 22*4882a593Smuzhiyun moveml %sp@,%d0-%d7/%a0-%a6; \ 23*4882a593Smuzhiyun addl #60,%sp; /* space for 15 regs */ \ 24*4882a593Smuzhiyun rte; 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun#if defined(CONFIG_CF_SBF) 27*4882a593Smuzhiyun#define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + \ 28*4882a593Smuzhiyun CONFIG_SYS_INIT_RAM_ADDR) 29*4882a593Smuzhiyun#define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + \ 30*4882a593Smuzhiyun CONFIG_SYS_INIT_RAM_ADDR) 31*4882a593Smuzhiyun#endif 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun.text 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun/* 36*4882a593Smuzhiyun * Vector table. This is used for initial platform startup. 37*4882a593Smuzhiyun * These vectors are to catch any un-intended traps. 38*4882a593Smuzhiyun */ 39*4882a593Smuzhiyun_vectors: 40*4882a593Smuzhiyun#if defined(CONFIG_CF_SBF) 41*4882a593SmuzhiyunINITSP: .long 0 /* Initial SP */ 42*4882a593SmuzhiyunINITPC: .long ASM_DRAMINIT /* Initial PC */ 43*4882a593Smuzhiyun#else 44*4882a593SmuzhiyunINITSP: .long 0 /* Initial SP */ 45*4882a593SmuzhiyunINITPC: .long _START /* Initial PC */ 46*4882a593Smuzhiyun#endif 47*4882a593Smuzhiyun 48*4882a593Smuzhiyunvector02_0F: 49*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 50*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun/* Reserved */ 53*4882a593Smuzhiyunvector10_17: 54*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 55*4882a593Smuzhiyun 56*4882a593Smuzhiyunvector18_1F: 57*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun#if !defined(CONFIG_CF_SBF) 60*4882a593Smuzhiyun/* TRAP #0 - #15 */ 61*4882a593Smuzhiyunvector20_2F: 62*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 63*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun/* Reserved */ 66*4882a593Smuzhiyunvector30_3F: 67*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 68*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 69*4882a593Smuzhiyun 70*4882a593Smuzhiyunvector64_127: 71*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 72*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 73*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 74*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 75*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 76*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 77*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 78*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 79*4882a593Smuzhiyun 80*4882a593Smuzhiyunvector128_191: 81*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 82*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 83*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 84*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 85*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 86*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 87*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 88*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 89*4882a593Smuzhiyun 90*4882a593Smuzhiyunvector192_255: 91*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 92*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 93*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 94*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 95*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 96*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 97*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 98*4882a593Smuzhiyun.long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT 99*4882a593Smuzhiyun#endif 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun#if defined(CONFIG_CF_SBF) 102*4882a593Smuzhiyun /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */ 103*4882a593Smuzhiyunasm_sbf_img_hdr: 104*4882a593Smuzhiyun .long 0x00000000 /* checksum, not yet implemented */ 105*4882a593Smuzhiyun .long 0x00020000 /* image length */ 106*4882a593Smuzhiyun .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */ 107*4882a593Smuzhiyun 108*4882a593Smuzhiyunasm_dram_init: 109*4882a593Smuzhiyun move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 110*4882a593Smuzhiyun movec %d0, %RAMBAR1 /* init Rambar */ 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp 113*4882a593Smuzhiyun clr.l %sp@- 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun /* Must disable global address */ 116*4882a593Smuzhiyun move.l #0xFC008000, %a1 117*4882a593Smuzhiyun move.l #(CONFIG_SYS_CS0_BASE), (%a1) 118*4882a593Smuzhiyun move.l #0xFC008008, %a1 119*4882a593Smuzhiyun move.l #(CONFIG_SYS_CS0_CTRL), (%a1) 120*4882a593Smuzhiyun move.l #0xFC008004, %a1 121*4882a593Smuzhiyun move.l #(CONFIG_SYS_CS0_MASK), (%a1) 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun /* 124*4882a593Smuzhiyun * Dram Initialization 125*4882a593Smuzhiyun * a1, a2, and d0 126*4882a593Smuzhiyun */ 127*4882a593Smuzhiyun move.l #0xFC0A4074, %a1 128*4882a593Smuzhiyun move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1) 129*4882a593Smuzhiyun nop 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun /* SDRAM Chip 0 and 1 */ 132*4882a593Smuzhiyun move.l #0xFC0B8110, %a1 133*4882a593Smuzhiyun move.l #0xFC0B8114, %a2 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun /* calculate the size */ 136*4882a593Smuzhiyun move.l #0x13, %d1 137*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_SIZE), %d2 138*4882a593Smuzhiyun#ifdef CONFIG_SYS_SDRAM_BASE1 139*4882a593Smuzhiyun lsr.l #1, %d2 140*4882a593Smuzhiyun#endif 141*4882a593Smuzhiyun 142*4882a593Smuzhiyundramsz_loop: 143*4882a593Smuzhiyun lsr.l #1, %d2 144*4882a593Smuzhiyun add.l #1, %d1 145*4882a593Smuzhiyun cmp.l #1, %d2 146*4882a593Smuzhiyun bne dramsz_loop 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun /* SDRAM Chip 0 and 1 */ 149*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_BASE), (%a1) 150*4882a593Smuzhiyun or.l %d1, (%a1) 151*4882a593Smuzhiyun#ifdef CONFIG_SYS_SDRAM_BASE1 152*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2) 153*4882a593Smuzhiyun or.l %d1, (%a2) 154*4882a593Smuzhiyun#endif 155*4882a593Smuzhiyun nop 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun /* dram cfg1 and cfg2 */ 158*4882a593Smuzhiyun move.l #0xFC0B8008, %a1 159*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1) 160*4882a593Smuzhiyun nop 161*4882a593Smuzhiyun move.l #0xFC0B800C, %a2 162*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2) 163*4882a593Smuzhiyun nop 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun move.l #0xFC0B8000, %a1 /* Mode */ 166*4882a593Smuzhiyun move.l #0xFC0B8004, %a2 /* Ctrl */ 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun /* Issue PALL */ 169*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2) 170*4882a593Smuzhiyun nop 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun /* Issue LEMR */ 173*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_MODE), (%a1) 174*4882a593Smuzhiyun nop 175*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1) 176*4882a593Smuzhiyun nop 177*4882a593Smuzhiyun 178*4882a593Smuzhiyun move.l #1000, %d0 179*4882a593Smuzhiyunwait1000: 180*4882a593Smuzhiyun nop 181*4882a593Smuzhiyun subq.l #1, %d0 182*4882a593Smuzhiyun bne wait1000 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun /* Issue PALL */ 185*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2) 186*4882a593Smuzhiyun nop 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun /* Perform two refresh cycles */ 189*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0 190*4882a593Smuzhiyun nop 191*4882a593Smuzhiyun move.l %d0, (%a2) 192*4882a593Smuzhiyun move.l %d0, (%a2) 193*4882a593Smuzhiyun nop 194*4882a593Smuzhiyun 195*4882a593Smuzhiyun move.l #(CONFIG_SYS_SDRAM_CTRL), %d0 196*4882a593Smuzhiyun and.l #0x7FFFFFFF, %d0 197*4882a593Smuzhiyun or.l #0x10000c00, %d0 198*4882a593Smuzhiyun move.l %d0, (%a2) 199*4882a593Smuzhiyun nop 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun /* 202*4882a593Smuzhiyun * DSPI Initialization 203*4882a593Smuzhiyun * a0 - general, sram - 0x80008000 - 32, see M52277EVB.h 204*4882a593Smuzhiyun * a1 - dspi status 205*4882a593Smuzhiyun * a2 - dtfr 206*4882a593Smuzhiyun * a3 - drfr 207*4882a593Smuzhiyun * a4 - Dst addr 208*4882a593Smuzhiyun */ 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun /* Enable pins for DSPI mode - chip-selects are enabled later */ 211*4882a593Smuzhiyun move.l #0xFC0A4036, %a0 212*4882a593Smuzhiyun move.b #0x3F, %d0 213*4882a593Smuzhiyun move.b %d0, (%a0) 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun /* DSPI CS */ 216*4882a593Smuzhiyun#ifdef CONFIG_SYS_DSPI_CS0 217*4882a593Smuzhiyun move.b (%a0), %d0 218*4882a593Smuzhiyun or.l #0xC0, %d0 219*4882a593Smuzhiyun move.b %d0, (%a0) 220*4882a593Smuzhiyun#endif 221*4882a593Smuzhiyun#ifdef CONFIG_SYS_DSPI_CS2 222*4882a593Smuzhiyun move.l #0xFC0A4037, %a0 223*4882a593Smuzhiyun move.b (%a0), %d0 224*4882a593Smuzhiyun or.l #0x10, %d0 225*4882a593Smuzhiyun move.b %d0, (%a0) 226*4882a593Smuzhiyun#endif 227*4882a593Smuzhiyun nop 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun /* Configure DSPI module */ 230*4882a593Smuzhiyun move.l #0xFC05C000, %a0 231*4882a593Smuzhiyun move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */ 232*4882a593Smuzhiyun 233*4882a593Smuzhiyun move.l #0xFC05C00C, %a0 234*4882a593Smuzhiyun move.l #0x3E000011, (%a0) 235*4882a593Smuzhiyun 236*4882a593Smuzhiyun move.l #0xFC05C034, %a2 /* dtfr */ 237*4882a593Smuzhiyun move.l #0xFC05C03B, %a3 /* drfr */ 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun move.l #(ASM_SBF_IMG_HDR + 4), %a1 240*4882a593Smuzhiyun move.l (%a1)+, %d5 241*4882a593Smuzhiyun move.l (%a1), %a4 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0 244*4882a593Smuzhiyun move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun move.l #0xFC05C02C, %a1 /* dspi status */ 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun /* Issue commands and address */ 249*4882a593Smuzhiyun move.l #0x8004000B, %d2 /* Fast Read Cmd */ 250*4882a593Smuzhiyun jsr asm_dspi_wr_status 251*4882a593Smuzhiyun jsr asm_dspi_rd_status 252*4882a593Smuzhiyun 253*4882a593Smuzhiyun move.l #0x80040000, %d2 /* Address byte 2 */ 254*4882a593Smuzhiyun jsr asm_dspi_wr_status 255*4882a593Smuzhiyun jsr asm_dspi_rd_status 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun move.l #0x80040000, %d2 /* Address byte 1 */ 258*4882a593Smuzhiyun jsr asm_dspi_wr_status 259*4882a593Smuzhiyun jsr asm_dspi_rd_status 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun move.l #0x80040000, %d2 /* Address byte 0 */ 262*4882a593Smuzhiyun jsr asm_dspi_wr_status 263*4882a593Smuzhiyun jsr asm_dspi_rd_status 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun move.l #0x80040000, %d2 /* Dummy Wr and Rd */ 266*4882a593Smuzhiyun jsr asm_dspi_wr_status 267*4882a593Smuzhiyun jsr asm_dspi_rd_status 268*4882a593Smuzhiyun 269*4882a593Smuzhiyun /* Transfer serial boot header to sram */ 270*4882a593Smuzhiyunasm_dspi_rd_loop1: 271*4882a593Smuzhiyun move.l #0x80040000, %d2 272*4882a593Smuzhiyun jsr asm_dspi_wr_status 273*4882a593Smuzhiyun jsr asm_dspi_rd_status 274*4882a593Smuzhiyun 275*4882a593Smuzhiyun move.b %d1, (%a0) /* read, copy to dst */ 276*4882a593Smuzhiyun 277*4882a593Smuzhiyun add.l #1, %a0 /* inc dst by 1 */ 278*4882a593Smuzhiyun sub.l #1, %d4 /* dec cnt by 1 */ 279*4882a593Smuzhiyun bne asm_dspi_rd_loop1 280*4882a593Smuzhiyun 281*4882a593Smuzhiyun /* Transfer u-boot from serial flash to memory */ 282*4882a593Smuzhiyunasm_dspi_rd_loop2: 283*4882a593Smuzhiyun move.l #0x80040000, %d2 284*4882a593Smuzhiyun jsr asm_dspi_wr_status 285*4882a593Smuzhiyun jsr asm_dspi_rd_status 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun move.b %d1, (%a4) /* read, copy to dst */ 288*4882a593Smuzhiyun 289*4882a593Smuzhiyun add.l #1, %a4 /* inc dst by 1 */ 290*4882a593Smuzhiyun sub.l #1, %d5 /* dec cnt by 1 */ 291*4882a593Smuzhiyun bne asm_dspi_rd_loop2 292*4882a593Smuzhiyun 293*4882a593Smuzhiyun move.l #0x00040000, %d2 /* Terminate */ 294*4882a593Smuzhiyun jsr asm_dspi_wr_status 295*4882a593Smuzhiyun jsr asm_dspi_rd_status 296*4882a593Smuzhiyun 297*4882a593Smuzhiyun /* jump to memory and execute */ 298*4882a593Smuzhiyun move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0 299*4882a593Smuzhiyun move.l %a0, (%a1) 300*4882a593Smuzhiyun jmp (%a0) 301*4882a593Smuzhiyun 302*4882a593Smuzhiyunasm_dspi_wr_status: 303*4882a593Smuzhiyun move.l (%a1), %d0 /* status */ 304*4882a593Smuzhiyun and.l #0x0000F000, %d0 305*4882a593Smuzhiyun cmp.l #0x00003000, %d0 306*4882a593Smuzhiyun bgt asm_dspi_wr_status 307*4882a593Smuzhiyun 308*4882a593Smuzhiyun move.l %d2, (%a2) 309*4882a593Smuzhiyun rts 310*4882a593Smuzhiyun 311*4882a593Smuzhiyunasm_dspi_rd_status: 312*4882a593Smuzhiyun move.l (%a1), %d0 /* status */ 313*4882a593Smuzhiyun and.l #0x000000F0, %d0 314*4882a593Smuzhiyun lsr.l #4, %d0 315*4882a593Smuzhiyun cmp.l #0, %d0 316*4882a593Smuzhiyun beq asm_dspi_rd_status 317*4882a593Smuzhiyun 318*4882a593Smuzhiyun move.b (%a3), %d1 319*4882a593Smuzhiyun rts 320*4882a593Smuzhiyun#endif /* CONFIG_CF_SBF */ 321*4882a593Smuzhiyun 322*4882a593Smuzhiyun.text 323*4882a593Smuzhiyun . = 0x400 324*4882a593Smuzhiyun.globl _start 325*4882a593Smuzhiyun_start: 326*4882a593Smuzhiyun nop 327*4882a593Smuzhiyun nop 328*4882a593Smuzhiyun move.w #0x2700,%sr /* Mask off Interrupt */ 329*4882a593Smuzhiyun 330*4882a593Smuzhiyun /* Set vector base register at the beginning of the Flash */ 331*4882a593Smuzhiyun#if defined(CONFIG_CF_SBF) 332*4882a593Smuzhiyun move.l #CONFIG_SYS_TEXT_BASE, %d0 333*4882a593Smuzhiyun movec %d0, %VBR 334*4882a593Smuzhiyun#else 335*4882a593Smuzhiyun move.l #CONFIG_SYS_FLASH_BASE, %d0 336*4882a593Smuzhiyun movec %d0, %VBR 337*4882a593Smuzhiyun 338*4882a593Smuzhiyun move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0 339*4882a593Smuzhiyun movec %d0, %RAMBAR1 340*4882a593Smuzhiyun#endif 341*4882a593Smuzhiyun 342*4882a593Smuzhiyun /* invalidate and disable cache */ 343*4882a593Smuzhiyun move.l #CF_CACR_CINV, %d0 /* Invalidate cache cmd */ 344*4882a593Smuzhiyun movec %d0, %CACR /* Invalidate cache */ 345*4882a593Smuzhiyun move.l #0, %d0 346*4882a593Smuzhiyun movec %d0, %ACR0 347*4882a593Smuzhiyun movec %d0, %ACR1 348*4882a593Smuzhiyun 349*4882a593Smuzhiyun /* initialize general use internal ram */ 350*4882a593Smuzhiyun move.l #0, %d0 351*4882a593Smuzhiyun move.l #(ICACHE_STATUS), %a1 /* icache */ 352*4882a593Smuzhiyun move.l #(DCACHE_STATUS), %a2 /* icache */ 353*4882a593Smuzhiyun move.l %d0, (%a1) 354*4882a593Smuzhiyun move.l %d0, (%a2) 355*4882a593Smuzhiyun 356*4882a593Smuzhiyun /* put relocation table address to a5 */ 357*4882a593Smuzhiyun move.l #__got_start, %a5 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun /* setup stack initially on top of internal static ram */ 360*4882a593Smuzhiyun move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun /* 363*4882a593Smuzhiyun * if configured, malloc_f arena will be reserved first, 364*4882a593Smuzhiyun * then (and always) gd struct space will be reserved 365*4882a593Smuzhiyun */ 366*4882a593Smuzhiyun move.l %sp, -(%sp) 367*4882a593Smuzhiyun bsr board_init_f_alloc_reserve 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun /* update stack and frame-pointers */ 370*4882a593Smuzhiyun move.l %d0, %sp 371*4882a593Smuzhiyun move.l %sp, %fp 372*4882a593Smuzhiyun 373*4882a593Smuzhiyun /* initialize reserved area */ 374*4882a593Smuzhiyun move.l %d0, -(%sp) 375*4882a593Smuzhiyun bsr board_init_f_init_reserve 376*4882a593Smuzhiyun 377*4882a593Smuzhiyun /* run low-level CPU init code (from flash) */ 378*4882a593Smuzhiyun bsr cpu_init_f 379*4882a593Smuzhiyun clr.l %sp@- 380*4882a593Smuzhiyun 381*4882a593Smuzhiyun /* run low-level board init code (from flash) */ 382*4882a593Smuzhiyun bsr board_init_f 383*4882a593Smuzhiyun 384*4882a593Smuzhiyun /* board_init_f() does not return */ 385*4882a593Smuzhiyun 386*4882a593Smuzhiyun/******************************************************************************/ 387*4882a593Smuzhiyun 388*4882a593Smuzhiyun/* 389*4882a593Smuzhiyun * void relocate_code (addr_sp, gd, addr_moni) 390*4882a593Smuzhiyun * 391*4882a593Smuzhiyun * This "function" does not return, instead it continues in RAM 392*4882a593Smuzhiyun * after relocating the monitor code. 393*4882a593Smuzhiyun * 394*4882a593Smuzhiyun * r3 = dest 395*4882a593Smuzhiyun * r4 = src 396*4882a593Smuzhiyun * r5 = length in bytes 397*4882a593Smuzhiyun * r6 = cachelinesize 398*4882a593Smuzhiyun */ 399*4882a593Smuzhiyun.globl relocate_code 400*4882a593Smuzhiyunrelocate_code: 401*4882a593Smuzhiyun link.w %a6,#0 402*4882a593Smuzhiyun move.l 8(%a6), %sp /* set new stack pointer */ 403*4882a593Smuzhiyun 404*4882a593Smuzhiyun move.l 12(%a6), %d0 /* Save copy of Global Data pointer */ 405*4882a593Smuzhiyun move.l 16(%a6), %a0 /* Save copy of Destination Address */ 406*4882a593Smuzhiyun 407*4882a593Smuzhiyun move.l #CONFIG_SYS_MONITOR_BASE, %a1 408*4882a593Smuzhiyun move.l #__init_end, %a2 409*4882a593Smuzhiyun move.l %a0, %a3 410*4882a593Smuzhiyun 411*4882a593Smuzhiyun /* copy the code to RAM */ 412*4882a593Smuzhiyun1: 413*4882a593Smuzhiyun move.l (%a1)+, (%a3)+ 414*4882a593Smuzhiyun cmp.l %a1,%a2 415*4882a593Smuzhiyun bgt.s 1b 416*4882a593Smuzhiyun 417*4882a593Smuzhiyun/* 418*4882a593Smuzhiyun * We are done. Do not return, instead branch to second part of board 419*4882a593Smuzhiyun * initialization, now running from RAM. 420*4882a593Smuzhiyun */ 421*4882a593Smuzhiyun move.l %a0, %a1 422*4882a593Smuzhiyun add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1 423*4882a593Smuzhiyun jmp (%a1) 424*4882a593Smuzhiyun 425*4882a593Smuzhiyunin_ram: 426*4882a593Smuzhiyun 427*4882a593Smuzhiyunclear_bss: 428*4882a593Smuzhiyun /* 429*4882a593Smuzhiyun * Now clear BSS segment 430*4882a593Smuzhiyun */ 431*4882a593Smuzhiyun move.l %a0, %a1 432*4882a593Smuzhiyun add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1 433*4882a593Smuzhiyun move.l %a0, %d1 434*4882a593Smuzhiyun add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1 435*4882a593Smuzhiyun6: 436*4882a593Smuzhiyun clr.l (%a1)+ 437*4882a593Smuzhiyun cmp.l %a1,%d1 438*4882a593Smuzhiyun bgt.s 6b 439*4882a593Smuzhiyun 440*4882a593Smuzhiyun /* 441*4882a593Smuzhiyun * fix got table in RAM 442*4882a593Smuzhiyun */ 443*4882a593Smuzhiyun move.l %a0, %a1 444*4882a593Smuzhiyun add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1 445*4882a593Smuzhiyun move.l %a1,%a5 /* fix got pointer register a5 */ 446*4882a593Smuzhiyun 447*4882a593Smuzhiyun move.l %a0, %a2 448*4882a593Smuzhiyun add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2 449*4882a593Smuzhiyun 450*4882a593Smuzhiyun7: 451*4882a593Smuzhiyun move.l (%a1),%d1 452*4882a593Smuzhiyun sub.l #_start,%d1 453*4882a593Smuzhiyun add.l %a0,%d1 454*4882a593Smuzhiyun move.l %d1,(%a1)+ 455*4882a593Smuzhiyun cmp.l %a2, %a1 456*4882a593Smuzhiyun bne 7b 457*4882a593Smuzhiyun 458*4882a593Smuzhiyun /* calculate relative jump to board_init_r in ram */ 459*4882a593Smuzhiyun move.l %a0, %a1 460*4882a593Smuzhiyun add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1 461*4882a593Smuzhiyun 462*4882a593Smuzhiyun /* set parameters for board_init_r */ 463*4882a593Smuzhiyun move.l %a0,-(%sp) /* dest_addr */ 464*4882a593Smuzhiyun move.l %d0,-(%sp) /* gd */ 465*4882a593Smuzhiyun jsr (%a1) 466*4882a593Smuzhiyun 467*4882a593Smuzhiyun/******************************************************************************/ 468*4882a593Smuzhiyun 469*4882a593Smuzhiyun/* exception code */ 470*4882a593Smuzhiyun.globl _fault 471*4882a593Smuzhiyun_fault: 472*4882a593Smuzhiyun bra _fault 473*4882a593Smuzhiyun 474*4882a593Smuzhiyun.globl _exc_handler 475*4882a593Smuzhiyun_exc_handler: 476*4882a593Smuzhiyun SAVE_ALL 477*4882a593Smuzhiyun movel %sp,%sp@- 478*4882a593Smuzhiyun bsr exc_handler 479*4882a593Smuzhiyun addql #4,%sp 480*4882a593Smuzhiyun RESTORE_ALL 481*4882a593Smuzhiyun 482*4882a593Smuzhiyun.globl _int_handler 483*4882a593Smuzhiyun_int_handler: 484*4882a593Smuzhiyun SAVE_ALL 485*4882a593Smuzhiyun movel %sp,%sp@- 486*4882a593Smuzhiyun bsr int_handler 487*4882a593Smuzhiyun addql #4,%sp 488*4882a593Smuzhiyun RESTORE_ALL 489*4882a593Smuzhiyun 490*4882a593Smuzhiyun/******************************************************************************/ 491*4882a593Smuzhiyun 492*4882a593Smuzhiyun.globl version_string 493*4882a593Smuzhiyunversion_string: 494*4882a593Smuzhiyun.ascii U_BOOT_VERSION_STRING, "\0" 495*4882a593Smuzhiyun.align 4 496