📄 start.s
字号:
/*** start.S -- startup file for Mongoose V BSP based upon crt0.S from** newlib-1.8.2/libgloss/mips and adapted for RTEMS.**** crt0.S -- startup file for MIPS.**** Copyright (c) 1995, 1996, 1997 Cygnus Support**** The authors hereby grant permission to use, copy, modify, distribute,** and license this software and its documentation for any purpose, provided** that existing copyright notices are retained in all copies and that this** notice is included verbatim in any distributions. No written agreement,** license, or royalty fee is required for any of the authorized uses.** Modifications to this software may be copyrighted by their authors** and need not follow the licensing terms described here, provided that** the new terms are clearly indicated on the first page of each file where** they apply.****** Modification History:** 01/XX/01 Joel Sherrill, OAR Corp,** Modified for Mongoose V BSP for NASA/GSFC Code 582.**** 06/XX/01 Greg Menke, Raytheon, Code 582** Debug modifications. Removed R4000 dependencies.** Added HACKED_PMON defines to facilitate startup.** Added DEFAULT_EXIT_RETURN_TO_MONITOR option.**** 11/14/01 A.Ferrer, NASA/GSFC, Code 582** Cleanup for ST5 mission.**** 11/27/01 A.Ferrer, NASA/GSFC, Code 582** Added cache flush routines.*/#ifndef LANGUAGE_ASSEMBLY#define LANGUAGE_ASSEMBLY#endif#include <asm.h>#include "regs.S"#include "mg5.h" #ifdef __mips16 /* This file contains 32 bit assembly code. */ .set nomips16#endif/*** defined by linkcmds, pointing to the start of the relocation target** memory, referenced in this way so we can avoid defining it** multiply*/ .bss .word 0 .text .align 2/************************************************************************** Function: _start*/ /* Without the following nop, GDB thinks _start is a data variable. ** This is probably a bug in GDB in handling a symbol that is at the ** start of the .text section. */ nop .globl _start .ent _start .globl putch_rom_start: .set noreorder $LF1 = . + 8 /* ** Get the address of start into $5 in a position independent fashion. ** This lets us know whether we have been relocated or not. */ bal $LF1 nop_branch: move a1, ra /* save return address from the jump above */ /* ensure we're sane before doing anything */ li t0, SR_CU0|SR_PE mtc0 t0, C0_SR nop li t0, 0 mtc0 t0, C0_DCIC nop mtc0 t0, C0_CAUSE nop /* ** Call cpuinit. Masking used to call EEPROM address of _cpuinit. Label is RAM label. */ move t2,a1 and t2,0xffff0000 la t0,_cpuinit and t0,0x0000ffff or t0,t2 jal t0 nop /* ** Configure UART */ move t2,a1 and t2,0xffff0000 la t0,config_uart and t0,0x0000ffff or t0,t2 jal t0 nop /* ** Print 'b'. Show that we started. */ move t2,a1 and t2,0xffff0000 li a0,'b' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop li k0,0 li k1,0 move t1,a1 nop li t2,0xa0000000 /* lower limit of kseg1 */ li t3,0xbfffffff /* upper limit of kseg1 */ subu t0,t1,t2 srl t0,31 /* shift high bit down to bit 0 */ bnez t0,1f /* booting from below kseg1 */ subu t0,t3,t1 srl t0,31 /* shift high bit down to bit 0 */ bnez t0,1f /* booting from above kseg1 */ /* ** Call IcacheFlush. Masking used to call EEPROM address of IcacheFlush. Label is RAM label. */ move t2,a1 and t2,0xffff0000 la t0,IcacheFlush and t0,0x0000ffff or t0,t2 move k0,t0 /* save cache flush in-prom address */ jal t0 nop /* ** Print 'I'. Show that we flushed I cache. */ move t2,a1 and t2,0xffff0000 li a0,'I' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop /* ** Call DcacheFlush. Masking used to call EEPROM address of DcacheFlush. Label is RAM label. */ move t2,a1 and t2,0xffff0000 la t0,DcacheFlush and t0,0x0000ffff or t0,t2 jal t0 nop /* ** Print 'D'. Show that we flushed D cache. */ move t2,a1 and t2,0xffff0000 li a0,'D' la t0,putch_rom and t0,0x0000ffff or t0,t2 move k1,t0 /* save cache flush in-prom address */ jal t0 nop1: /* ** Print ' RTEMS b'. Show that we are booting. */ move t2,a1 and t2,0xffff0000 li a0,' ' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,'R' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,'T' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,'E' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,'M' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,'S' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,' ' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop move t2,a1 and t2,0xffff0000 li a0,'b' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop /* ** get the address of the _branch label above as it would appear in ** the relocated code */ la a2, _branch /* relocation destination */ beq a1, a2, _start_in_ram /* skip relocating if we're already there */ nop /* relocate the code from EEPROM to RAM */ /* ** Print 'r' */ move t2,a1 and t2,0xffff0000 li a0,'r' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop la a3, _edatarelocate: lw t0, (a1) /* load from EEPROM */ addu a1, 4 sw t0, (a2) /* store to RAM */ addu a2, 4 bne a2, a3, relocate /* copied all the way to edata? */ nop /* ** Print 'R' */ li a0,'R' la t0,putch_rom and t0,0x0000ffff or t0,t2 jal t0 nop la a2, _start_in_ram jr a2 nop .end _start/************************************************************************** Function: _start_in_ram*/ .globl _start_in_ram .ent _start_in_ram_start_in_ram: /* ** Print 'S'. Already in RAM no need to reference EEPROM address. */ li a0,'S' jal putch_rom nop la gp, _gp /* set the global data pointer */ .end _start_in_ram/************************************************************************** Function: zerobss*/ .globl __memsize .globl zerobss .ent zerobsszerobss: /* ** Print 'z'. Starting to zero out bss. */ li a0,'z' jal putch_rom nop la v0, _fbss la v1, _end3: sw zero,0(v0) bltu v0,v1,3b addiu v0,v0,4 /* executed in delay slot */ la t0, _stack_init /* initialize stack so we */ /* ** We must subtract 24 bytes for the 3 8 byte arguments to main, in ** case main wants to write them back to the stack. The caller is ** supposed to allocate stack space for parameters in registers in ** the old MIPS ABIs. We must do this even though we aren't passing ** arguments, because main might be declared to have them. ** ** Some ports need a larger alignment for the stack, so we subtract ** 32, which satisifes the stack for the arguments and keeps the ** stack pointer better aligned. */ subu t0,t0,32 move sp,t0 /* set stack pointer */ nop /* ** Print 'Z'. Finished zeroing bss. */ li a0,'Z' jal putch_rom nop .end zerobss/************************************************************************** Function: _init*/ .globl exit .text .globl _initialize_rtems .ent _initialize_rtems_initialize_rtems: /* ** Print 'i'. Starting to initialize RTEMS. */ li a0, 'i' jal putch_rom nop /* ** Save the boot-time addresses of the I & D cache flush routines. ** Note, if we're running from RAM, we cannot manipulate the cache ** so we just disable the cache flush functions. */ la a0,_promIcache sw k0,0(a0) nop la a0,_promDcache sw k1,0(a0) nop move a0,zero /* set argc to 0 */ jal boot_card /* call the program start function */ nop /* ** fall through to the "exit" routine */ jal _sys_exit nop .end _initialize_rtems/************************************************************************** Function: _sys_exit**** Exit from the application by jumping to PMON address in EEPROM.*/ .globl _sys_exit .ent _sys_exit_sys_exit: la t0, PMON_ADDRESS jal t0 .end _sys_exit/************************************************************************** function: putch** input : ASCII character in A0** registers used: ra, a0, t0, t1***/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -