starto.s
来自「国产CPU-龙芯(loongson)BIOS源代码」· S 代码 · 共 2,687 行 · 第 1/4 页
S
2,687 行
/* $Id: starto.S,v 1.7 2004/05/27 04:14:49 wlin Exp $ *//* * Copyright (c) 2001 Opsycon AB (www.opsycon.se) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Opsycon AB, Sweden. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#ifndef _KERNEL#define _KERNEL#endif#include <asm.h>#include <regnum.h>#include <cpu.h>#include <pte.h>#include "target/ev64240.h"#include "pmon/dev/ns16550.h"#include "pmon/dev/gt64240reg.h"#ifdef GODSONEV2A# define SKIPDIMM# define SDRAM_MODE_FIX#else# undef SKIPDIMM# undef SDRAM_MODE_FIX#endif#define RUN_SDRAM_FAST#define DEBUG_LOCORE 1#ifdef DEBUG_LOCORE#define TTYDBG(x) \ .rdata;98: .asciz x; .text; la a0, 98b; bal stringserial; nop#else#define TTYDBG(x)#endif#define PRINTSTR(x) \ .rdata;98: .asciz x; .text; la a0, 98b; bal stringserial; nop#define GTINIT(offset, value) \ .word GT_BASE_ADDR+(offset), HTOLE32(value)#define HIGHMEM_BASE 0x20000000/* * Register usage: * * s0 link versus load offset, used to relocate absolute adresses. * s1 free * s2 base address to Galileo chip. * s3 L1 I cache size. * s4 L1 I cache line size. * s5 L1 D cache size. * s6 L1 D cache line size. * s7 L2 Cache size. * s8 L3 Cache size. */ .set noreorder .globl _start .globl start .globl __main_start:start: .globl stackstack = start - 0x4000 /* Place PMON stack below PMON start in RAM *//* NOTE!! Not more that 16 instructions here!!! Right now it's FULL! */ mtc0 zero, COP_0_STATUS_REG#if 0 li t0, SR_BOOT_EXC_VEC /* Exception to Boostrap Location */ mtc0 t0, COP_0_STATUS_REG#endif lui a0,0x3000 li a1,SR_BOOT_EXC_VEC or a0,a0,a1 mtc0 a0, COP_0_STATUS_REG mtc0 zero, COP_0_CAUSE_REG la sp, stack la gp, _gp bal uncached /* Switch to uncached address space */ nop bal locate /* Get current execute address */ nopuncached: or ra, UNCACHED_MEMORY_ADDR j ra nop/* * Reboot vector usable from outside pmon. */ .align 8ext_map_and_reboot: bal CPU_TLBClear nop li a0, 0xc0000000 li a1, 0x40000000 bal CPU_TLBInit nop la v0, tgt_reboot la v1, start subu v0, v1 lui v1, 0xffc0 addu v0, v1 jr v0 nop/* * Exception vectors here for rom, before we are up and running. Catch * whatever comes up before we have a fully fledged exception handler. */ .align 9 /* bfc00200 */ la a0, v200_msg bal stringserial nop b exc_common .align 7 /* bfc00280 */ la a0, v280_msg bal stringserial nop b exc_common/* Cache error */ .align 8 /* bfc00300 */ PRINTSTR("\r\nPANIC! Unexpected Cache Error exception! ") mfc0 a0, COP_0_CACHE_ERR bal hexserial nop b exc_common/* General exception */ .align 7 /* bfc00380 *//* make keg0 uncached to make sure prints works! */#if 0 mfc0 a0,COP_0_CONFIG and a0,a0,0xfffffff8 or a0,a0,0x2 mtc0 a0,COP_0_CONFIG#endif#if 1 lui a1, 0xa040 nop mfc0 a0, COP_0_EXC_PC nop sw a0, (a1) nop mfc0 a0, COP_0_CAUSE_REG nop sw a0, (a1) nop dmfc0 a0, $8 nop dsrl a0,a0,32 nop sw a0, (a1) nop mfc0 a0, $8 nop sw a0, (a1) nop mfc0 a0, COP_0_EXC_PC nop lw a0, (a0) nop sw a0, (a1) nop#endif la a0, v380_msg bal stringserial nop b exc_common .align 8 /* bfc00400 */ la a0, v400_msg bal stringserial nopexc_common: PRINTSTR("\r\nERRORPC=") mfc0 a0, COP_0_ERROR_PC bal hexserial nop PRINTSTR("\r\nEPC=") mfc0 a0, COP_0_EXC_PC bal hexserial nop PRINTSTR("\r\n(EPC)=") mfc0 a0, COP_0_EXC_PC lw a0, (a0) bal hexserial nop PRINTSTR("\r\nSTATUS=") mfc0 a0, COP_0_STATUS_REG bal hexserial nop PRINTSTR("\r\nCAUSE=") mfc0 a0, COP_0_CAUSE_REG bal hexserial nop PRINTSTR("\r\nBADVADDR=") dmfc0 a0, $8 dsrl a0,a0,32 bal hexserial nop dmfc0 a0, $8 bal hexserial nop PRINTSTR("\r\nDERR0=") cfc0 a0, COP_0_DERR_0 bal hexserial nop PRINTSTR("\r\nDERR1=") cfc0 a0, COP_0_DERR_1 bal hexserial nop 1: b 1b nop // b ext_map_and_reboot nop/* * We get here from executing a bal to get the PC value of the current execute * location into ra. Check to see if we run from ROM or if this is ramloaded. */ .align 8 /*bfc00500*/ .word read .word write .word open .word close .word nullfunction .word printf .word vsprintf .word nullfunction .word nullfunction .word getenv .word nullfunction .word nullfunction .word nullfunction .word nullfunction locate: bal init_regs nop la s0, start /* RA set from BAL above! */ subu s0, ra, s0 /* s0 is now load vs. link offset */ and s0, 0xffff0000 /* Mask off lower bits *//* * Clean out and initialize the TLB */ bal CPU_TLBClear nop li a0, 0xc0000000 li a1, 0x40000000 bal CPU_TLBInit nop/* * Turn off all high decoders to avoid address conflicts. */ la s2, GT_BASE_ADDR_DEFAULT li t0, HTOLE32(0x00000fff) sw t0, PCI_0I_O_LOW_DECODE_ADDRESS(s2) sw t0, PCI_0MEMORY0_LOW_DECODE_ADDRESS(s2) sw t0, PCI_0MEMORY1_LOW_DECODE_ADDRESS(s2) sw t0, PCI_0MEMORY2_LOW_DECODE_ADDRESS(s2) sw t0, PCI_0MEMORY3_LOW_DECODE_ADDRESS(s2) sw zero, PCI_0I_O_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_0MEMORY0_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_0MEMORY1_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_0MEMORY2_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_0MEMORY3_HIGH_DECODE_ADDRESS(s2) sw t0, PCI_1I_O_LOW_DECODE_ADDRESS(s2) sw t0, PCI_1MEMORY0_LOW_DECODE_ADDRESS(s2) sw t0, PCI_1MEMORY1_LOW_DECODE_ADDRESS(s2) sw t0, PCI_1MEMORY2_LOW_DECODE_ADDRESS(s2) sw t0, PCI_1MEMORY3_LOW_DECODE_ADDRESS(s2) sw zero, PCI_1I_O_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_1MEMORY0_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_1MEMORY1_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_1MEMORY2_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_1MEMORY3_HIGH_DECODE_ADDRESS(s2)#if 1 li t0, HTOLE32(0x00000101) sw t0, PCI_1I_O_LOW_DECODE_ADDRESS(s2) li t0, HTOLE32(0x00000101) sw t0, PCI_1I_O_HIGH_DECODE_ADDRESS(s2) sw zero, PCI_1I_O_ADDRESS_REMAP(s2) li t0, HTOLE32(0x80000004) sw t0, PCI_1CONFIGURATION_ADDRESS(s2) lw t1, PCI_1CONFIGURATION_DATA_VIRTUAL_REGISTER(s2) ori t1, 0x02|0x04 sw t0, PCI_1CONFIGURATION_ADDRESS(s2) sw t1, PCI_1CONFIGURATION_DATA_VIRTUAL_REGISTER(s2) lw t0, PCI_0ARBITER_CONTROL(s2) or t0, t0, HTOLE32(0x80000000) sw t0, PCI_0ARBITER_CONTROL(s2) lw t0, PCI_1ARBITER_CONTROL(s2) or t0, t0, HTOLE32(0x80000000) sw t0, PCI_1ARBITER_CONTROL(s2)#endif/* * Relocate the Galileo to HIGH memory. */ li t0, HTOLE32((UNCACHED_TO_PHYS(GT_BASE_ADDR) >> 20) | 0x01000000) sw t0, INTERNAL_SPACE_DECODE(s2) li t0, 0x100 /* Need a small delay here */1: bnez t0, 1b addiu t0, -1 la s2, GT_BASE_ADDR /* From now this is the GT base */// bal tgt_setpar125mhz /* Set bus timing for 125MHz */ bal tgt_setpar100mhz /* Set bus timing for 100MHz */ nop /* Changed later if 100Mhz bus */ lw t0, CPU_CONFIG(s2) /* Turn off automatic retries */ li t1, HTOLE32(0x00020000) or t0, t0, t1 sw t0, CPU_CONFIG(s2)/* * Set up I/O decoders to point correctly. */ bal 2f /* Load address to init table */ nop GTINIT(CS_0_LOW_DECODE_ADDRESS, UNCACHED_TO_PHYS(SRAM_BASE) >> 20) GTINIT(CS_0_HIGH_DECODE_ADDRESS, (UNCACHED_TO_PHYS(SRAM_BASE) + SRAM_SIZE - 1) >> 20) GTINIT(CS_1_LOW_DECODE_ADDRESS, UNCACHED_TO_PHYS(RTC_BASE) >> 20) GTINIT(CS_1_HIGH_DECODE_ADDRESS, (UNCACHED_TO_PHYS(RTC_BASE) + RTC_SIZE - 1) >> 20) GTINIT(CS_2_LOW_DECODE_ADDRESS, UNCACHED_TO_PHYS(UART_BASE) >> 20) GTINIT(CS_2_HIGH_DECODE_ADDRESS, (UNCACHED_TO_PHYS(UART_BASE) + UART_SIZE - 1) >> 20) GTINIT(CS_3_LOW_DECODE_ADDRESS, UNCACHED_TO_PHYS(FLASH_BASE) >> 20) GTINIT(CS_3_HIGH_DECODE_ADDRESS, (UNCACHED_TO_PHYS(FLASH_BASE) + FLASH_SIZE - 1) >> 20) /* end mark */ .word 0, 01: sw v1, 0(v0)2: lw v0, 0(ra) /* Address */ lw v1, 4(ra) /* Data */ bnez v0, 1b addiu ra, 8/* * BOOT rom. Read width bits to check boot width size to set up flash CS * "correctly". Bootwidth sticks with straps but for clarity we retain it * Also it should be correct to use the same timing for both flashes since * they can be swapped, although they may have different characteristics. */ lw t0, DEVICE_BOOT_BANK_PARAMETERS(s2) li t1, HTOLE32(GT_DEVPAR_TurnOff(2) | GT_DEVPAR_AccToFirst(15) | \ GT_DEVPAR_AccToNext(15) | GT_DEVPAR_ALEtoWr(5) | \ GT_DEVPAR_WrActive(7) | GT_DEVPAR_WrHigh(5) | \ GT_DEVPAR_Reserved) and t0, HTOLE32(GT_DEVPAR_DevWidthMASK) or t1, t0 /* DevWidth value */ li t2, HTOLE32(GT_DEVPAR_DevWidth32) beqz t0, bootis32 nop// sw t1, DEVICE_BOOT_BANK_PARAMETERS(s2) li t2, HTOLE32(GT_DEVPAR_DevWidth8)bootis32: lw t0, DEVICE_BANK3PARAMETERS(s2) /* Flash Disk */ and t0, HTOLE32(GT_DEVPAR_ReservedMASK) or t0, t2 li t1, HTOLE32(GT_DEVPAR_TurnOff(2) | GT_DEVPAR_AccToFirst(17) | \ GT_DEVPAR_AccToNext(17) | GT_DEVPAR_ALEtoWr(5) | \ GT_DEVPAR_WrActive(7) | GT_DEVPAR_WrHigh(7)) or t0, t1 sw t0, DEVICE_BANK3PARAMETERS(s2)/* * Init serial I/O for diagnostic output. */ bal initserial nop PRINTSTR("\r\nPMON2000 MIPS Initializing. Standby...\r\n") PRINTSTR("ERRORPC=") mfc0 a0, COP_0_ERROR_PC bal hexserial nop PRINTSTR(" CONFIG=") mfc0 a0, COP_0_CONFIG bal hexserial nop PRINTSTR("\r\n") la s0, start /* RA set from BAL above! */ subu s0, ra, s0 /* s0 is now load vs. link offset */ and s0, 0xffff0000 /* Mask off lower bits */ TTYDBG("Setting up SDRAM controller\r\n"); /* Read the SPD info and get DRAM Configuration */ bal doinit nop GTINIT(SCS_0_LOW_DECODE_ADDRESS, 0xfff) GTINIT(SCS_0_HIGH_DECODE_ADDRESS, 0x000) GTINIT(SCS_1_LOW_DECODE_ADDRESS, 0xfff) GTINIT(SCS_1_HIGH_DECODE_ADDRESS, 0x000) GTINIT(SCS_2_LOW_DECODE_ADDRESS, 0xfff) GTINIT(SCS_2_HIGH_DECODE_ADDRESS, 0x000) GTINIT(SCS_3_LOW_DECODE_ADDRESS, 0xfff) GTINIT(SCS_3_HIGH_DECODE_ADDRESS, 0x000)#ifdef RUN_SDRAM_FAST GTINIT(SDRAM_TIMING_PARAMETERS, 0x00004515)#else GTINIT(SDRAM_TIMING_PARAMETERS, 0x0000072a)#endif .word 0, 0doinit: li v0, 0xb0000000 /* ra is set from previous bal */ bgtu v0, ra, in_ram /* if pc is lower than rom space.. */ nop b 2f nop1: sw v1, 0(v0)2: lw v0, 0(ra) /* Address */ lw v1, 4(ra) /* Data */ bnez v0, 1b addiu ra, 8/* * We are executing in ROM space so start do the setup work. * * Initialize SDRAM. * * NOTE!!! We can't complete address mapping at this point * because we cant't move the bootrom mapping until we are * executing out of SDRAM. We start by setting both banks * to 128MB and then once running from SDRAM we change the * decoding to map the actual memory. */#ifdef SKIPDIMM b skipdimm nop#endif bal boot_i2c_init nop TTYDBG("Probing DIMM...\r\nDIMM0="); bal probe_sdram_size li a0, 0x600 move t2, v0 bal hexserial move a0,v0 TTYDBG("\r\n"); beqz t2,sdram_slot1_config move s1,zero bal boot_i2c_read li a0, 0x61f li t0,HTOLE32(0x8000) li v1,0x10 beq v0,v1,1f li v1,0x20 beq v0,v1,1f li t0,HTOLE32(0xc000) li v1,0x40 beq v0,v1,1f li v1,0x80 beq v0,v1,1f nop bal boot_i2c_read li a0,0x604 li t0,HTOLE32(0x4000) li v1,0x10 beq v0,v1,1f nop li t0,HTOLE32(0x8000)1:#ifdef RUN_SDRAM_FAST or t0,0xF0000#endif sw t0,SDRAM_BANK0PARAMETERS(s2) sw t0,SDRAM_BANK1PARAMETERS(s2) bal boot_i2c_read li a0, 0x605 beq v0, 2, sdram_slot0_2bank nop TTYDBG("DIMM0: 1 side\r\n"); bgtu t2, 0x10000000, panic_dimm0_too_big nop li t0, 0 sw t0, SCS_0_LOW_DECODE_ADDRESS(s2) srl t0, t2, 20 sub t0, 1 sw t0, SCS_0_HIGH_DECODE_ADDRESS(s2) b sdram_slot1_config move s1,t2 sdram_slot0_2bank: TTYDBG("DIMM0: 2 sides\r\n"); bgtu t2, 0x20000000, panic_dimm0_too_big nop bgtu t2, 0x10000000,1f nop li t0, 0 sw t0, SCS_0_LOW_DECODE_ADDRESS(s2) srl t0, t2, 21 sw t0, SCS_1_LOW_DECODE_ADDRESS(s2) sub t0, 1 sw t0, SCS_0_HIGH_DECODE_ADDRESS(s2) srl t0, t2, 20 sub t0, 1 sw t0, SCS_1_HIGH_DECODE_ADDRESS(s2) b sdram_slot1_config move s1,t21: li t0,0 sw t0, SCS_0_LOW_DECODE_ADDRESS(s2) srl t0,t2,21 sub t0,1 sw t0, SCS_0_HIGH_DECODE_ADDRESS(s2) li t0,HIGHMEM_BASE srl t1,t2,1 sw t0, SCS_1_LOW_DECODE_ADDRESS(s2) addu t1,t1,t0 move s1,t1 srl t1,20 sub t1,1 sw t1, SCS_1_HIGH_DECODE_ADDRESS(s2) sdram_slot1_config: TTYDBG("\r\nDIMM1="); bal probe_sdram_size li a0, 0x400 move t3, v0 bal hexserial move a0, v0 TTYDBG("\r\n"); beqz t3,done_dens nop bal boot_i2c_read li a0, 0x41f li t0,HTOLE32(0x8000) li v1,0x10 beq v0,v1,1f li v1,0x20 beq v0,v1,1f li t0,HTOLE32(0xc000) li v1,0x40 beq v0,v1,1f li v1,0x80 beq v0,v1,1f nop bal boot_i2c_read li a0,0x404 li t0,HTOLE32(0x4000) li v1,0x10 beq v0,v1,1f nop li t0,HTOLE32(0x8000)1:#ifdef RUN_SDRAM_FAST or t0,0xF0000#endif sw t0,SDRAM_BANK2PARAMETERS(s2) sw t0,SDRAM_BANK3PARAMETERS(s2) bal boot_i2c_read li a0, 0x405 beq v0, 2, sdram_slot1_2bank nop TTYDBG("DIMM1: 1 side\r\n"); TTYDBG("s1="); bal hexserial move a0,s1 TTYDBG("\r\n"); bnez s1,1f nop bgtu t3,0x10000000,panic_dimm1_too_big nop sw zero,SCS_2_LOW_DECODE_ADDRESS(s2)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?