⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 starto.s.b1

📁 国产CPU-龙芯(loongson)BIOS源代码
💻 B1
📖 第 1 页 / 共 2 页
字号:
/*	$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/it8172.h"#include "pmon/dev/ns16550.h"#ifdef GODSONEV2A#	define SKIPDIMM#	define SDRAM_MODE_FIX#else#	undef SKIPDIMM#	undef SDRAM_MODE_FIX#endif#define DEBUG_LOCORE#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/* *   Register usage: * *	s0	link versus load offset, used to relocate absolute adresses. *	s1	free *	s2	base address to ITE 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! */	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/* * gpio function define          */#define GPIO_LOOP       10000#define MK_LAT(v)\        li              t0, (v);        \9:      subu    t0, 1;          \        bne             t0, 0, 9b;      \        nop;#if 1#define FLASH_GPIO(a)   \        li      a0, (a)         ;\        bal     __flash_gpio    ;\        nop#else#define FLASH_GPIO(a)   \        li      t1, 0xb4013802;\        li      t0, 0x550       ;\        sh      t0, (t1)        ;\        subu    t1, t1, 2;\        li      t0, (a)         ;\        sll     t0, 2           ;\        sb      t0, (t1);       \        MK_LAT(GPIO_LOOP);#endif/*  * LED       */    #define FLASH_LED(a)    \        li      a0, (a)         ;\        bal     __led_display   ;\        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 */#define CFG_IB		0x00000020#define CFG_DB		0x00000010#define	CFG_C_WBACK	3#define CFG_BE		0x00008000#define	FG_BE 		0x00008000#define	CFG_EPMASK	0x0f000000#define	CFG_EPD		0x00000000#define	CFG_AD		0x00800000/* * Initialize Configuration for board */       	mfc0	   t1, COP_0_CONFIG                  # Get Config Reg	nop	and             t1, ~0x3f               # Set Config Reg bits 5..0 only        or              t1, CFG_IB \                          | CFG_DB \                          | CFG_C_WBACK         # Set Cache Mode related bits in Config Reg        and             t1, ~CFG_BE             # Clean Big Endian bit in Config Reg        /* set DDDD rate for CPUs that aren't hardware configured */        and             t1, ~CFG_EPMASK         # Set EP 4 bits to 0 in Config Reg        or              t1, CFG_EPD             # Set EP DataPattern 0        and             t1, ~CFG_AD                             # ???        mtc0    t1, COP_0_CONFIG           # Re-Set Config Reg bits	nop        mfc0    t1, COP_0_STATUS_REG           	nop        mtc0    zero, COP_0_CAUSE_REG          	nop        and             t1, SR_SOFT_RESET       #        or              t1, SR_BOOT_EXC_VEC      # Should be omited because it has been done before        mtc0    t1, COP_0_STATUS_REG           # Set STATUS Reg        nop	FLASH_GPIO(1)/* * Read Memory Capacity and Update IT8172 related Register */	li	t1, 0x1b	sw      t1, ( IT_MC_SDTYPE + IT8172_BASE + KSEG1 )	nop	FLASH_GPIO(2)        li      t9, 0x0300              # 4mA        sh      t9, (UNCACHED_MEMORY_ADDR + IT8172_BASE + IT_PCDCR)        nop        li      t9, 0x803B              # cas=3, burst length=8        sh      t9, (UNCACHED_MEMORY_ADDR + IT8172_BASE + IT_MC_SDRMR)        nop        li      t9, 0x01ff        sh      t9, (UNCACHED_MEMORY_ADDR + IT8172_BASE + IT_MC_SDRTR)        nop        li      t9, 0x1                 # open board        sh      t9, (UNCACHED_MEMORY_ADDR + IT8172_BASE + IT_CMFPCR)    # change IT_CMFPCR        nop        FLASH_GPIO(0x03)                # GPD 2..4 => 0001/* *  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        FLASH_GPIO(0x04)                # GPD 2..4 => 0001        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");/* *  Reset and initialize caches to a known state. */#define IndexStoreTagI	0x08#define IndexStoreTagD	0x09#define IndexStoreTagS	0x0b#define IndexStoreTagT	0x0a#define FillI		0x14#if 1 	TTYDBG("Testing memory...\r\n")	li	t7, 10tmem:	li	t0, 0xa0000000+1*1024*1024	li	t1, 0xa0000000	li	t2, 0xffffffff1:	sw	t2, 0(t1)	lw	t3, 0(t1)	bne	t3, t2, 1f	nop	not	t2	sw	t2, 0(t1)	lw	t3, 0(t1)	bne	t3, t2, 1f	nop	not t2	addu	t2, 1	addu	t1, 4	beq	t1, t0, 2f	nop	and	t4, t1, 0x000fffff	bnez	t4, skipdot	li	a0, '.'	bal	tgt_putchar	nopskipdot:	b	1b	nop1:	TTYDBG("Memory test failed at ");	move	a0,	t1	bal	hexserial	nop	TTYDBG("\r\nWrite=");	move	a0, t2	bal	hexserial	nop	TTYDBG("\r\nRead=");	move	a0, t3	bal	hexserial	nop1:	b	1b	nop2:	TTYDBG("Testing ok...\r\n");	sub	t7,1	beqz	t7, 1f	nop	b	tmem	nop1:		b	1b	nop#endif/* *  Clean out and initialize the TLB */	bal	CPU_TLBClear	nop	li	a0, 0xc0000000	li	a1, 0x40000000	bal	CPU_TLBInit	nop/* *  At this point all memory controller setup should have been done *  and we should be able to function 'normally' and C code can be *  used freely from this point. */	TTYDBG("Copy PMON to execute location...\r\n")#ifdef DEBUG_LOCORE	TTYDBG("start = ")	la	a0, start	bal	hexserial	nop	TTYDBG("\r\ns0 = ")	move	a0, s0	bal	hexserial	nop	TTYDBG("\r\n")#endif	la	a0, start	li	a1, 0xbfc00000	la	a2, _edata	subu	t1, a2, a0	srl t1, t1, 2	/* copy text section */	li	t0, 01:	lw	v0, 0(a1)	nop	sw	v0, 0(a0)	addu	a0, 4	bne a2, a0, 1b	addu	a1, 4		/* Clear BSS */	la	a0, _edata	la	a2, _end2:	sw	zero, 0(a0)	bne a2, a0, 2b	addu	a0, 4#if 0	la	a1, start	/* RAM start address */	la	v0, copytoram	addu	v0, s0		/* Compute ROM address of 'copytoram' */	jal	v0	add	a0, a1, s0	/* ROM start address */	beqz	v0, 1f	nop	move	s3, v0	PRINTSTR("\r\nPANIC! Copy to memory failed at 0x")	move	a0, s3	bal	hexserial	nop	PRINTSTR(".\r\n")	b	stuck	nop#endif1:	TTYDBG("Copy PMON to execute location done.\r\n")1:	li	a0,0x04000000 /* 64Mb */	move	t0,a0	TTYDBG("memsize=");	bal	hexserial	move	a0,t0	move	a0,t0#ifdef SKIPDIMM	li	a0,	256#endif        FLASH_GPIO(0x06)               	la	v0, initmips	jalr	v0	nopstuck:#ifdef DEBUG_LOCORE	TTYDBG("Dumping IT8172 setup.\r\n")	TTYDBG("offset----data------------------------.\r\n")	li	s3, 01:	move	a0, s3	bal	hexserial	nop	TTYDBG(": ")2:	add	a0, s3, s2	lw	a0, 0(a0)	bal	hexserial	addiu	s3, 4	TTYDBG(" ")	li	a0, 0xfff	and	a0, s3	beqz	a0, 3f	li	a0, 0x01f	and	a0, s3	bnez	a0, 2b	TTYDBG("\r\n")	b	1b	nop3:	b	3b	nop

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -