URL
https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk
Subversion Repositories openrisc_2011-10-31
[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [libgloss/] [or32/] [crt0.S] - Rev 517
Go to most recent revision | Compare with Previous | Blame | View Log
/* crt0.S. C design runtime startup file.Copyright (C) 2004, Jacob BowerCopyright (C) 2010, Embecosm Limited <info@embecosm.com>Copyright (C) 2011, ORSoC ABContributor Jeremy Bennett <jeremy.bennett@embecosm.com>Contributor Julius Baxter <julius.baxter@orsoc.se>This file is part of Newlib.The original work by Jacob Bower is provided as-is without any kind ofwarranty. Use it at your own risk!All subsequent work is bound by version 3 of the GPL as follows.This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by the FreeSoftware Foundation; either version 3 of the License, or (at your option)any later version.This program is distributed in the hope that it will be useful, but WITHOUTANY WARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License formore details.You should have received a copy of the GNU General Public License alongwith this program. If not, see <http://www.gnu.org/licenses/>. *//* -------------------------------------------------------------------------- *//* This program is commented throughout in a fashion suitable for processingwith Doxygen. *//* -------------------------------------------------------------------------- */#include "spr-defs.h"/* -------------------------------------------------------------------------- *//*!Macro to load a symbol's address into a register.@param[in] gpr General purpose register to load address into.@param[in] symbol Name of symbol to load. *//* -------------------------------------------------------------------------- */#define LOAD_SYMBOL_2_GPR(gpr,symbol) \.global symbol ; \l.movhi gpr, hi(symbol) ; \l.ori gpr, gpr, lo(symbol)/* -------------------------------------------------------------------------- *//*!Macro to handle exceptions.Load NPC into r3, EPCR into r4*//* -------------------------------------------------------------------------- */// Size of redzone + size of space required to store state// This value must match that in _exception_handler.S#define EXCEPTION_STACK_SIZE 128#define CALL_EXCEPTION_HANDLER \l.addi r1, r1, -EXCEPTION_STACK_SIZE; \l.sw 4(r1), r3; \l.sw 8(r1), r4; \l.mfspr r3,r0,SPR_NPC; \l.j or1k_exception_handler; \l.mfspr r4,r0,SPR_EPCR_BASE/* -------------------------------------------------------------------------- *//*!Exception vectors *//* -------------------------------------------------------------------------- */.section .vectors,"ax"/* 0x100: RESET exception */.org 0x100__reset:l.movhi r0, 0l.movhi r1, 0l.movhi r2, 0l.movhi r3, 0l.movhi r4, 0l.movhi r5, 0l.movhi r6, 0l.movhi r7, 0l.movhi r8, 0l.movhi r9, 0l.movhi r10, 0l.movhi r11, 0l.movhi r12, 0l.movhi r13, 0l.movhi r14, 0l.movhi r15, 0l.movhi r16, 0l.movhi r17, 0l.movhi r18, 0l.movhi r19, 0l.movhi r20, 0l.movhi r21, 0l.movhi r22, 0l.movhi r23, 0l.movhi r24, 0l.movhi r25, 0l.movhi r26, 0l.movhi r27, 0l.movhi r28, 0l.movhi r29, 0l.movhi r30, 0l.movhi r31, 0/* Clear status register, set supervisor mode */l.ori r1, r0, SPR_SR_SMl.mtspr r0, r1, SPR_SR/* Clear timer mode register*/l.mtspr r0, r0, SPR_TTMR/* Jump to program initialisation code */LOAD_SYMBOL_2_GPR(r4, _start)l.jr r4l.nop.org 0x200CALL_EXCEPTION_HANDLER/* 0x300: Data Page Fault exception */.org 0x300CALL_EXCEPTION_HANDLER/* 0x400: Insn Page Fault exception */.org 0x400CALL_EXCEPTION_HANDLER/* 0x500: Timer exception */.org 0x500CALL_EXCEPTION_HANDLER/* 0x600: Aligment exception */.org 0x600CALL_EXCEPTION_HANDLER/* 0x700: Illegal insn exception */.org 0x700CALL_EXCEPTION_HANDLER/* 0x800: External interrupt exception */.org 0x800CALL_EXCEPTION_HANDLER/* 0x900: DTLB miss exception */.org 0x900CALL_EXCEPTION_HANDLER/* 0xa00: ITLB miss exception */.org 0xa00CALL_EXCEPTION_HANDLER/* 0xb00: Range exception */.org 0xb00CALL_EXCEPTION_HANDLER/* 0xc00: Syscall exception */.org 0xc00CALL_EXCEPTION_HANDLER/* 0xd00: floating point exception */.org 0xd00CALL_EXCEPTION_HANDLER/* 0xe00: Trap exception */.org 0xe00CALL_EXCEPTION_HANDLER/* 0xf00: Reserved exceptions */.org 0xf00CALL_EXCEPTION_HANDLER.org 0x1000CALL_EXCEPTION_HANDLER.org 0x1100CALL_EXCEPTION_HANDLER.org 0x1200CALL_EXCEPTION_HANDLER.org 0x1300CALL_EXCEPTION_HANDLER.org 0x1400CALL_EXCEPTION_HANDLER.org 0x1500CALL_EXCEPTION_HANDLER.org 0x1600CALL_EXCEPTION_HANDLER.org 0x1700CALL_EXCEPTION_HANDLER.org 0x1800CALL_EXCEPTION_HANDLER.org 0x1900CALL_EXCEPTION_HANDLER.org 0x1a00CALL_EXCEPTION_HANDLER.org 0x1b00CALL_EXCEPTION_HANDLER.org 0x1c00CALL_EXCEPTION_HANDLER.org 0x1d00CALL_EXCEPTION_HANDLER.org 0x1e00CALL_EXCEPTION_HANDLER.org 0x1f00CALL_EXCEPTION_HANDLER/* Pad to the end */.org 0x1ffcl.nop/* -------------------------------------------------------------------------- *//*!Main entry pointWe initialise the stack and frame pointer first, before we set up thecaches, since otherwise we'll need to disable the instruction cache whenpatching the bus error vector code.The remaining tasks are then:- optionally set up instruction and/or data caches- clear BSS- call global and static constructors- set up destructors to be called from exit- jump to the main function- call exit if the main function ever returns.- loop forever (should never get here) *//* -------------------------------------------------------------------------- *//* The stack grows down from the top of writable memory. */.section .data.global stackstack: .space 4,0.section .text.global _start.type _start,@function/* Following externs from board-specific object passed at link time */.extern _board_mem_base.extern _board_mem_size.extern _board_uart_base_start:/* Initialise stack and frame pointer (set to same value) */l.movhi r1,hi(_board_mem_base)l.ori r1,r1,lo(_board_mem_base)l.lwz r1,0(r1)l.movhi r2,hi(_board_mem_size)l.ori r2,r2,lo(_board_mem_size)l.lwz r2,0(r2)l.add r1,r1,r2l.or r2,r1,r1/* Store stack address in stack variable */l.movhi r3,hi(stack)l.ori r3,r3,lo(stack)l.sw 0(r3),r1/* Initialise cache *//* TODO - potentially make this optional for simulation targets to savetime during startup */l.jal or1k_cache_initl.nop/* Clear BSS */.L10: l.movhi r3,hi(__bss_start)l.ori r3,r3,lo(__bss_start)l.movhi r4,hi(end)l.ori r4,r4,lo(end).L1: l.sw (0)(r3),r0l.sfltu r3,r4l.bf .L1l.addi r3,r3,4 /* Delay slot *//* Call global and static constructors */l.jal __initl.nop/* Set up destructors to be called from exit if main ever returns */l.movhi r3,hi(__fini)l.jal atexitl.ori r3,r3,lo(__fini) /* Delay slot *//* Check if UART is to be initialised */l.movhi r4,hi(_board_uart_base)l.ori r4,r4,lo(_board_uart_base)l.lwz r4,0(r4)l.sfne r4,r0 /* Is base set? If not, no UART */l.bnf .L2l.or r3,r0,r0l.jal __uart_initl.nop.L2:/* Jump to main program entry point (argc = argv = envp = 0) */l.or r3,r0,r0l.or r4,r0,r0l.jal mainl.or r5,r0,r0 /* Delay slot *//* If program exits, call exit routine */l.jal exitl.addi r3,r11,0 /* Delay slot *//* Loop forever */.L3: l.j .L3l.nop.size _start, .-_start
Go to most recent revision | Compare with Previous | Blame | View Log
