pmon启动分析(汇编部分)

  • 格式:docx
  • 大小:41.49 KB
  • 文档页数:38

/* $Id: start.S,v 1.1.1.1 2006/09/14 01:59:08 root 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 #include #include #include

#include "pmon/dev/ns16550.h" #include "target/prid.h" #include "target/sbd.h" #include "target/fcr.h" #include "target/via686b.h" #include "target/i8254.h" #include "target/isapnpreg.h" #define DEBUG_LOCORE

#ifndef BOOT_FROM_EJTAG #define BOOT_FROM_EJTAG #endif #undef BOOT_FROM_EJTAG

#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

/* Delay macro */ #define DELAY(count) \ li v0, count; \ 99: \ bnez v0, 99b;\ addiu v0, -1

#define tmpsize s1 #define msize s2 #define bonito s4 #define dbg s5 #define sdCfg s6

#define CP0_CONFIG $16 #define CP0_TAGLO $28 #define CP0_TAGHI $29

/* * Register usage: * * s0 link versus load offset, used to relocate absolute adresses. * s1 free * s2 memory size. * s3 free. * s4 Bonito base address. * s5 dbg. * s6 sdCfg. * s7 rasave. * s8 L3 Cache size. */

.set noreorder .globl _start .globl start .globl __main _start: start: .globl stack /* 栈的大小是16K,从反汇编的地址可以看出,在下面la sp,stack中堆栈指针SP指向的地址是0x8000C000,可以看出sp的指向的位置,并不是指向flash,因此开始的堆栈用的就是sdram,而ld生成代码的text段的起始地址为0x80010000,这是吻合的。

*/ stack = 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 /*禁止中断*/ mtc0 zero, COP_0_CAUSE_REG /*禁止异常处理*/ li t0, SR_BOOT_EXC_VEC /* Exception to Boostrap Location */ mtc0 t0, COP_0_STATUS_REG /* 以上两句中SR_BOOT_EXC_VEC 的值是0x00400000,其目的就是设置协处理器0的状态寄存器status的BEV位为1,使得CPU使用ROM(kseg1空间的异常入口),可见此时的这些代码都是在ROM中运行的。 */ la sp, stack la gp, _gp

// bal uncached /* Switch to uncached address space */ nop

bal locate /* Get current execute address */ nop uncached: or ra, UNCACHED_MEMORY_ADDR j ra nop /* bal locate是一条跳转指令。 先说说bal这条指令。通常bal指令会算出相对于PC寄存器的偏移量,然后把PC+8指令的地址放到ra寄存器里,也就是把uncached:即把or ra,UNCACHED_MEMORY_ADDR这条指令的地址放到ra寄存器中。由于龙芯加电启动时是从0xBFC00000地址开始的,那么此时ra寄存器中的值就是0xBFC0002C,此后程序就跳转到locate这里开始执行。 */ /* 由于龙芯的地址空间决定,当BEV=1时,异常入口地址从0xBFC00200出开始,所以这里的代码不能太长,指令条数是有限的,但并不是上面说的16条(这是我的理解),因为后面紧跟着是其它中断向量的地址。 */ /* * Reboot vector usable from outside pmon. */ /*以下是各种异常*/ .align 9 ext_map_and_reboot: li a0,0x10000000 /*test from 0xbfcxxxxx or 0xff20xxxx */ and a0,ra bnez a0,1f la a0,_start li s0,0xbfc00000 subu s0,a0 1: 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