📄 start.s
字号:
/* * Copyright (C) 1998 Dan Malek <dmalek@jlc.net> * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de> * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA *//*------------------------------------------------------------------------------+ *//* *//* This source code has been made available to you by IBM on an AS-IS *//* basis. Anyone receiving this source is licensed under IBM *//* copyrights to use it in any way he or she deems fit, including *//* copying it, modifying it, compiling it, and redistributing it either *//* with or without modifications. No license under IBM patents or *//* patent applications is to be implied by the copyright license. *//* *//* Any user of this software should understand that IBM cannot provide *//* technical support for this software and will not be responsible for *//* any consequences resulting from the use of this software. *//* *//* Any person who transfers this source code or any derivative work *//* must include the IBM copyright notice, this paragraph, and the *//* preceding two paragraphs in the transferred software. *//* *//* COPYRIGHT I B M CORPORATION 1995 *//* LICENSED MATERIAL - PROGRAM PROPERTY OF I B M *//*------------------------------------------------------------------------------- *//* U-Boot - Startup Code for IBM 4xx PowerPC based Embedded Boards * * * The processor starts at 0xfffffffc and the code is executed * from flash/rom. * in memory, but as long we don't jump around before relocating. * board_init lies at a quite high address and when the cpu has * jumped there, everything is ok. * This works because the cpu gives the FLASH (CS0) the whole * address space at startup, and board_init lies as a echo of * the flash somewhere up there in the memorymap. * * board_init will change CS0 to be positioned at the correct * address and (s)dram will be positioned at address 0 */#include <config.h>#include <mpc8xx.h>#include <ppc4xx.h>#include <version.h>#define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */#include <ppc_asm.tmpl>#include <ppc_defs.h>#include <asm/cache.h>#include <asm/mmu.h>#ifndef CONFIG_IDENT_STRING#define CONFIG_IDENT_STRING ""#endif#ifdef CFG_INIT_DCACHE_CS# if (CFG_INIT_DCACHE_CS == 0)# define PBxAP pb0ap# define PBxCR pb0cr# endif# if (CFG_INIT_DCACHE_CS == 1)# define PBxAP pb1ap# define PBxCR pb1cr# endif# if (CFG_INIT_DCACHE_CS == 2)# define PBxAP pb2ap# define PBxCR pb2cr# endif# if (CFG_INIT_DCACHE_CS == 3)# define PBxAP pb3ap# define PBxCR pb3cr# endif# if (CFG_INIT_DCACHE_CS == 4)# define PBxAP pb4ap# define PBxCR pb4cr# endif# if (CFG_INIT_DCACHE_CS == 5)# define PBxAP pb5ap# define PBxCR pb5cr# endif# if (CFG_INIT_DCACHE_CS == 6)# define PBxAP pb6ap# define PBxCR pb6cr# endif# if (CFG_INIT_DCACHE_CS == 7)# define PBxAP pb7ap# define PBxCR pb7cr# endif#endif /* CFG_INIT_DCACHE_CS *//* We don't want the MMU yet.*/#undef MSR_KERNEL#define MSR_KERNEL ( MSR_ME ) /* Machine Check */ .extern ext_bus_cntlr_init .extern sdram_init/* * Set up GOT: Global Offset Table * * Use r14 to access the GOT */ START_GOT GOT_ENTRY(_GOT2_TABLE_) GOT_ENTRY(_FIXUP_TABLE_) GOT_ENTRY(_start) GOT_ENTRY(_start_of_vectors) GOT_ENTRY(_end_of_vectors) GOT_ENTRY(transfer_to_handler) GOT_ENTRY(__init_end) GOT_ENTRY(_end) GOT_ENTRY(__bss_start) END_GOT/* * 440 Startup -- on reset only the top 4k of the effective * address space is mapped in by an entry in the instruction * and data shadow TLB. The .bootpg section is located in the * top 4k & does only what's necessary to map in the the rest * of the boot rom. Once the boot rom is mapped in we can * proceed with normal startup. * * NOTE: CS0 only covers the top 2MB of the effective address * space after reset. */#if defined(CONFIG_440) .section .bootpg,"ax" .globl _start_440/**************************************************************************/_start_440: /*----------------------------------------------------------------*/ /* Clear and set up some registers. */ /*----------------------------------------------------------------*/ iccci r0,r0 /* NOTE: operands not used for 440 */ dccci r0,r0 /* NOTE: operands not used for 440 */ sync li r0,0 mtspr srr0,r0 mtspr srr1,r0 mtspr csrr0,r0 mtspr csrr1,r0 /*----------------------------------------------------------------*/ /* Initialize debug */ /*----------------------------------------------------------------*/ mtspr dbcr0,r0 mtspr dbcr1,r0 mtspr dbcr2,r0 mtspr iac1,r0 mtspr iac2,r0 mtspr iac3,r0 mtspr dac1,r0 mtspr dac2,r0 mtspr dvc1,r0 mtspr dvc2,r0 mfspr r1,dbsr mtspr dbsr,r1 /* Clear all valid bits */ /*----------------------------------------------------------------*/ /* CCR0 init */ /*----------------------------------------------------------------*/ /* Disable store gathering & broadcast, guarantee inst/data * cache block touch, force load/store alignment * (see errata 1.12: 440_33) */ lis r1,0x0030 /* store gathering & broadcast disable */ ori r1,r1,0x6000 /* cache touch */ mtspr ccr0,r1 /*----------------------------------------------------------------*/ /* Setup interrupt vectors */ /*----------------------------------------------------------------*/ mtspr ivpr,r0 /* Vectors start at 0x0000_0000 */ li r1,0x0100 mtspr ivor0,r1 /* Critical input */ li r1,0x0200 mtspr ivor1,r1 /* Machine check */ li r1,0x0300 mtspr ivor2,r1 /* Data storage */ li r1,0x0400 mtspr ivor3,r1 /* Instruction storage */ li r1,0x0500 mtspr ivor4,r1 /* External interrupt */ li r1,0x0600 mtspr ivor5,r1 /* Alignment */ li r1,0x0700 mtspr ivor6,r1 /* Program check */ li r1,0x0800 mtspr ivor7,r1 /* Floating point unavailable */ li r1,0x0c00 mtspr ivor8,r1 /* System call */ li r1,0x1000 mtspr ivor10,r1 /* Decrementer (PIT for 440) */ li r1,0x1400 mtspr ivor13,r1 /* Data TLB error */ li r1,0x1300 mtspr ivor14,r1 /* Instr TLB error */ li r1,0x2000 mtspr ivor15,r1 /* Debug */ /*----------------------------------------------------------------*/ /* Configure cache regions */ /*----------------------------------------------------------------*/ mtspr inv0,r0 mtspr inv1,r0 mtspr inv2,r0 mtspr inv3,r0 mtspr dnv0,r0 mtspr dnv1,r0 mtspr dnv2,r0 mtspr dnv3,r0 mtspr itv0,r0 mtspr itv1,r0 mtspr itv2,r0 mtspr itv3,r0 mtspr dtv0,r0 mtspr dtv1,r0 mtspr dtv2,r0 mtspr dtv3,r0 /*----------------------------------------------------------------*/ /* Cache victim limits */ /*----------------------------------------------------------------*/ /* floors 0, ceiling max to use the entire cache -- nothing locked */ lis r1,0x0001 ori r1,r1,0xf800 mtspr ivlim,r1 mtspr dvlim,r1 /*----------------------------------------------------------------*/ /* Clear all TLB entries -- TID = 0, TS = 0 */ /*----------------------------------------------------------------*/ mtspr mmucr,r0 li r1,0x003f /* 64 TLB entries */ mtctr r10: tlbwe r0,r1,0x0000 /* Invalidate all entries (V=0)*/ subi r1,r1,0x0001 bdnz 0b /*----------------------------------------------------------------*/ /* TLB entry setup -- step thru tlbtab */ /*----------------------------------------------------------------*/ bl tlbtab /* Get tlbtab pointer */ mr r5,r0 li r1,0x003f /* 64 TLB entries max */ mtctr r1 li r4,0 /* TLB # */ addi r5,r5,-41: lwzu r0,4(r5) cmpwi r0,0 beq 2f /* 0 marks end */ lwzu r1,4(r5) lwzu r2,4(r5) tlbwe r0,r4,0 /* TLB Word 0 */ tlbwe r1,r4,1 /* TLB Word 1 */ tlbwe r2,r4,2 /* TLB Word 2 */ addi r4,r4,1 /* Next TLB */ bdnz 1b /*----------------------------------------------------------------*/ /* Continue from 'normal' start */ /*----------------------------------------------------------------*/2: bl 3f b _start3: li r0,0 mtspr srr1,r0 /* Keep things disabled for now */ mflr r1 mtspr srr0,r1 rfi#endif /* CONFIG_440 *//* * r3 - 1st arg to board_init(): IMMP pointer * r4 - 2nd arg to board_init(): boot flag */ .text .long 0x27051956 /* U-Boot Magic Number */ .globl version_stringversion_string: .ascii U_BOOT_VERSION .ascii " (", __DATE__, " - ", __TIME__, ")" .ascii CONFIG_IDENT_STRING, "\0"/* * Maybe this should be moved somewhere else because the current * location (0x100) is where the CriticalInput Execption should be. */ . = EXC_OFF_SYS_RESET .globl _start_start:/*****************************************************************************/#if defined(CONFIG_440) /*----------------------------------------------------------------*/ /* Clear and set up some registers. */ /*----------------------------------------------------------------*/ li r0,0x0000 lis r1,0xffff mtspr dec,r0 /* prevent dec exceptions */ mtspr tbl,r0 /* prevent fit & wdt exceptions */ mtspr tbu,r0 mtspr tsr,r1 /* clear all timer exception status */ mtspr tcr,r0 /* disable all */ mtspr esr,r0 /* clear exception syndrome register */ mtxer r0 /* clear integer exception register */ lis r1,0x0002 /* set CE bit (Critical Exceptions) */ ori r1,r1,0x1000 /* set ME bit (Machine Exceptions) */ mtmsr r1 /* change MSR */ /*----------------------------------------------------------------*/ /* Debug setup -- some (not very good) ice's need an event*/ /* to establish control :-( Define CFG_INIT_DBCR to the dbsr */ /* value you need in this case 0x8cff 0000 should do the trick */ /*----------------------------------------------------------------*/#if defined(CFG_INIT_DBCR) lis r1,0xffff ori r1,r1,0xffff mtspr dbsr,r1 /* Clear all status bits */ lis r0,CFG_INIT_DBCR@h ori r0,r0,CFG_INIT_DBCR@l mtspr dbcr0,r0 isync#endif /*----------------------------------------------------------------*/ /* Setup the internal SRAM */ /*----------------------------------------------------------------*/ li r0,0 mtdcr isram0_sb1cr,r0 /* Disable bank 1 */ li r2,0x7fff ori r2,r2,0xffff mfdcr r1,isram0_dpc and r1,r1,r2 /* Disable parity check */ mtdcr isram0_dpc,r1 mfdcr r1,isram0_pmeg andis. r1,r1,r2 /* Disable pwr mgmt */ mtdcr isram0_pmeg,r1 lis r1,0x8000 /* BAS = 8000_0000 */ ori r1,r1,0x0380 /* 8k rw */ mtdcr isram0_sb0cr,r1 /*----------------------------------------------------------------*/ /* Setup the stack in internal SRAM */ /*----------------------------------------------------------------*/ lis r1,CFG_INIT_RAM_ADDR@h ori r1,r1,CFG_INIT_SP_OFFSET@l li r0,0 stwu r0,-4(r1) stwu r0,-4(r1) /* Terminate call chain */ stwu r1,-8(r1) /* Save back chain and move SP */ lis r0,RESET_VECTOR@h /* Address of reset vector */ ori r0,r0, RESET_VECTOR@l stwu r1,-8(r1) /* Save back chain and move SP */ stw r0,+12(r1) /* Save return addr (underflow vect) */ GET_GOT bl board_init_f#endif /* CONFIG_440 *//*****************************************************************************/#ifdef CONFIG_IOP480 /*----------------------------------------------------------------------- */ /* Set up some machine state registers. */ /*----------------------------------------------------------------------- */ addi r0,r0,0x0000 /* initialize r0 to zero */ mtspr esr,r0 /* clear Exception Syndrome Reg */ mttcr r0 /* timer control register */ mtexier r0 /* disable all interrupts */ addi r4,r0,0x1000 /* set ME bit (Machine Exceptions) */ oris r4,r4,0x2 /* set CE bit (Critical Exceptions) */ mtmsr r4 /* change MSR */ addis r4,r0,0xFFFF /* set r4 to 0xFFFFFFFF (status in the */ ori r4,r4,0xFFFF /* dbsr is cleared by setting bits to 1) */ mtdbsr r4 /* clear/reset the dbsr */ mtexisr r4 /* clear all pending interrupts */ addis r4,r0,0x8000 mtexier r4 /* enable critical exceptions */ addis r4,r0,0x0000 /* assume 403GCX - enable core clk */ ori r4,r4,0x4020 /* dbling (no harm done on GA and GC */ mtiocr r4 /* since bit not used) & DRC to latch */ /* data bus on rising edge of CAS */ /*----------------------------------------------------------------------- */ /* Clear XER. */ /*----------------------------------------------------------------------- */ mtxer r0 /*----------------------------------------------------------------------- */ /* Invalidate i-cache and d-cache TAG arrays. */ /*----------------------------------------------------------------------- */ addi r3,0,1024 /* 1/4 of I-cache size, half of D-cache */ addi r4,0,1024 /* 1/4 of I-cache */..cloop: iccci 0,r3 iccci r4,r3 dccci 0,r3 addic. r3,r3,-16 /* move back one cache line */ bne ..cloop /* loop back to do rest until r3 = 0 */ /* */ /* initialize IOP480 so it can read 1 MB code area for SRAM spaces */ /* this requires enabling MA[17..0], by default only MA[12..0] are enabled. */ /* */ /* first copy IOP480 register base address into r3 */ addis r3,0,0x5000 /* IOP480 register base address hi *//* ori r3,r3,0x0000 / IOP480 register base address lo */#ifdef CONFIG_ADCIOP /* use r4 as the working variable */ /* turn on CS3 (LOCCTL.7) */ lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */ andi. r4,r4,0xff7f /* make bit 7 = 0 -- CS3 mode */ stw r4,0x84(r3) /* LOCTL is at offset 0x84 */#endif#ifdef CONFIG_DASA_SIM /* use r4 as the working variable */ /* turn on MA17 (LOCCTL.7) */ lwz r4,0x84(r3) /* LOCTL is at offset 0x84 */ ori r4,r4,0x80 /* make bit 7 = 1 -- MA17 mode */ stw r4,0x84(r3) /* LOCTL is at offset 0x84 */#endif /* turn on MA16..13 (LCS0BRD.12 = 0) */ lwz r4,0x100(r3) /* LCS0BRD is at offset 0x100 */ andi. r4,r4,0xefff /* make bit 12 = 0 */ stw r4,0x100(r3) /* LCS0BRD is at offset 0x100 */ /* make sure above stores all comlete before going on */ sync /* last thing, set local init status done bit (DEVINIT.31) */ lwz r4,0x80(r3) /* DEVINIT is at offset 0x80 */ oris r4,r4,0x8000 /* make bit 31 = 1 */ stw r4,0x80(r3) /* DEVINIT is at offset 0x80 */ /* clear all pending interrupts and disable all interrupts */ li r4,-1 /* set p1 to 0xffffffff */ stw r4,0x1b0(r3) /* clear all pending interrupts */ stw r4,0x1b8(r3) /* clear all pending interrupts */ li r4,0 /* set r4 to 0 */ stw r4,0x1b4(r3) /* disable all interrupts */ stw r4,0x1bc(r3) /* disable all interrupts */ /* make sure above stores all comlete before going on */ sync /*----------------------------------------------------------------------- */ /* Enable two 128MB cachable regions. */ /*----------------------------------------------------------------------- */ addis r1,r0,0x8000 addi r1,r1,0x0001 mticcr r1 /* instruction cache */ addis r1,r0,0x0000 addi r1,r1,0x0000 mtdccr r1 /* data cache */ addis r1,r0,CFG_INIT_RAM_ADDR@h ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack to SDRAM */ li r0, 0 /* Make room for stack frame header and */ stwu r0, -4(r1) /* clear final stack frame so that */ stwu r0, -4(r1) /* stack backtraces terminate cleanly */ GET_GOT /* initialize GOT access */ bl board_init_f /* run first part of init code (from Flash) */#endif /* CONFIG_IOP480 *//*****************************************************************************/#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405) || defined(CONFIG_405EP) /*----------------------------------------------------------------------- */ /* Clear and set up some registers. */ /*----------------------------------------------------------------------- */ addi r4,r0,0x0000 mtspr sgr,r4 mtspr dcwr,r4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -