Line 1... |
Line 1... |
#include "spr_defs.h"
|
/* Makefile.in. Autoconf input makefile.
|
#include "board.h"
|
|
/* ======================================================= [ macros ] === */
|
|
|
|
|
|
#define CLEAR_GPR(gpr) \
|
|
l.or gpr, r0, r0
|
|
|
|
#define LOAD_SYMBOL_2_GPR(gpr,symbol) \
|
|
.global symbol ; \
|
|
l.movhi gpr, hi(symbol) ; \
|
|
l.ori gpr, gpr, lo(symbol)
|
|
|
|
#define UNHANDLED_EXCEPTION \
|
|
l.addi r1, r1, -128; \
|
|
l.sw 4(r1), r3; \
|
|
l.sw 8(r1), r4; \
|
|
l.mfspr r3,r0,SPR_PC; \
|
|
l.mfspr r4,r0,SPR_EPCR_BASE; \
|
|
l.j default_exception_handler; \
|
|
l.nop;
|
|
|
|
|
Copyright (C) 2004, Jacob Bower
|
|
Copyright (C) 2010, Embecosm Limited
|
|
|
/* =================================================== [ exceptions ] === */
|
Contributor Jeremy Bennett
|
.section .vectors,"ax"
|
|
|
This file is part of Newlib.
|
|
|
|
The original work by Jacob Bower is provided as-is without any kind of
|
|
warranty. 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 it
|
|
under the terms of the GNU General Public License as published by the Free
|
|
Software 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 WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program. If not, see . */
|
|
/* -------------------------------------------------------------------------- */
|
|
/* This program is commented throughout in a fashion suitable for processing
|
|
with Doxygen. */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
#include "spr-defs.h"
|
|
#include "or1ksim-board.h"
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/*!Macro for expressions which do not have their own handler.
|
|
|
|
Construct the arguments for a call to printf, then exit. Being varargs, the
|
|
arguments to printf must be on the stack, which we update using the
|
|
standard prologue.
|
|
|
|
@param[in] str Label for a string describing the macro, suitable for
|
|
printf. */
|
|
/* -------------------------------------------------------------------------- */
|
|
#define UNHANDLED_EXCEPTION(str) \
|
|
l.addi r1,r1,-20 /* Standard prologue */ ;\
|
|
l.sw 16(r1),r2 ;\
|
|
l.addi r2,r1,20 ;\
|
|
l.sw 12(r1),r9 ;\
|
|
;\
|
|
l.movhi r3,hi(.Lfmt) /* printf format string */ ;\
|
|
l.ori r3,r3,lo(.Lfmt) ;\
|
|
l.sw 0(r1),r3 ;\
|
|
l.movhi r4,hi(str) /* Name of exception */ ;\
|
|
l.ori r4,r4,lo(str) ;\
|
|
l.sw 4(r1),r4 ;\
|
|
l.mfspr r5,r0,SPR_EPCR_BASE /* Source of the interrupt */ ;\
|
|
l.jal _printf ;\
|
|
l.sw 8(r1),r5 ;\
|
|
;\
|
|
l.ori r3,r0,0xffff /* Failure RC */ ;\
|
|
l.jal _exit ;\
|
|
l.nop ;\
|
|
;\
|
|
l.rfe /* Never executed we hope */
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/*!Text strings for the different exceptions */
|
|
/* -------------------------------------------------------------------------- */
|
|
.section .rodata
|
|
.Lfmt: .string "Unhandled %s exception at address %08p\n"
|
|
.L200: .string "bus error"
|
|
.L300: .string "data page fault"
|
|
.L400: .string "instruction page fault"
|
|
.L500: .string "timer"
|
|
.L600: .string "alignment"
|
|
.L700: .string "illegal instruction"
|
|
.L800: .string "external interrupt"
|
|
.L900: .string "data TLB"
|
|
.La00: .string "instruction TLB"
|
|
.Lb00: .string "range"
|
|
.Lc00: .string "syscall"
|
|
.Ld00: .string "floating point"
|
|
.Le00: .string "trap"
|
|
.Lf00: .string "undefined 0xf00"
|
|
.L1000: .string "undefined 0x1000"
|
|
.L1100: .string "undefined 0x1100"
|
|
.L1200: .string "undefined 0x1200"
|
|
.L1300: .string "undefined 0x1300"
|
|
.L1400: .string "undefined 0x1400"
|
|
.L1500: .string "undefined 0x1500"
|
|
.L1600: .string "undefined 0x1600"
|
|
.L1700: .string "undefined 0x1700"
|
|
.L1800: .string "undefined 0x1800"
|
|
.L1900: .string "undefined 0x1900"
|
|
.L1a00: .string "undefined 0x1a00"
|
|
.L1b00: .string "undefined 0x1b00"
|
|
.L1c00: .string "undefined 0x1c00"
|
|
.L1d00: .string "undefined 0x1d00"
|
|
.L1e00: .string "undefined 0x1e00"
|
|
.L1f00: .string "undefined 0x1f00"
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/*!Exception vectors */
|
|
/* -------------------------------------------------------------------------- */
|
|
.section .vectors,"ax"
|
|
|
/* ---[ 0x100: RESET exception ]----------------------------------------- */
|
/* 0x100: RESET exception */
|
.org 0x100
|
.org 0x100
|
|
_reset:
|
l.nop
|
l.nop
|
|
|
/* Jump to program initialisation code */
|
/* Jump to program initialisation code */
|
l.movhi r2,hi(_start)
|
l.movhi r2,hi(_start)
|
l.ori r2,r2,lo(_start)
|
l.ori r2,r2,lo(_start)
|
l.jr r2
|
l.jr r2
|
l.nop
|
l.nop
|
|
|
/* ---[ 0x200: BUS exception ]------------------------------------------- */
|
/* 0x200: BUS exception is special, because during startup we use it
|
|
to detect where the stack should go. So we need some special code
|
|
before we return, which wel will later overwrite with l.nop.
|
|
|
|
We use registers we know will not interfere in this case. */
|
.org 0x200
|
.org 0x200
|
UNHANDLED_EXCEPTION
|
_buserr:
|
|
l.mfspr r24,r0,SPR_EPCR_BASE
|
|
l.addi r24,r24,4 /* Return one instruction on */
|
|
l.mtspr r0,r24,SPR_EPCR_BASE
|
|
l.rfe
|
|
|
|
_buserr_std:
|
|
UNHANDLED_EXCEPTION (.L200)
|
|
|
/* ---[ 0x300: Data Page Fault exception ]------------------------------- */
|
/* 0x300: Data Page Fault exception */
|
.org 0x300
|
.org 0x300
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L300)
|
|
|
/* ---[ 0x400: Insn Page Fault exception ]------------------------------- */
|
/* 0x400: Insn Page Fault exception */
|
.org 0x400
|
.org 0x400
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L400)
|
|
|
/* ---[ 0x500: Timer exception ]----------------------------------------- */
|
/* 0x500: Timer exception */
|
.org 0x500
|
.org 0x500
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L500)
|
|
|
/* ---[ 0x600: Aligment exception ]-------------------------------------- */
|
/* 0x600: Aligment exception */
|
.org 0x600
|
.org 0x600
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L600)
|
|
|
/* ---[ 0x700: Illegal insn exception ]---------------------------------- */
|
/* 0x700: Illegal insn exception */
|
.org 0x700
|
.org 0x700
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L700)
|
|
|
/* ---[ 0x800: External interrupt exception ]---------------------------- */
|
/* 0x800: External interrupt exception */
|
.org 0x800
|
.org 0x800
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L800)
|
|
|
/* ---[ 0x900: DTLB miss exception ]------------------------------------- */
|
/* 0x900: DTLB miss exception */
|
.org 0x900
|
.org 0x900
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L900)
|
|
|
/* ---[ 0xa00: ITLB miss exception ]------------------------------------- */
|
/* 0xa00: ITLB miss exception */
|
.org 0xa00
|
.org 0xa00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.La00)
|
|
|
|
/* 0xb00: Range exception */
|
/* ---[ 0xb00: Range exception ]----------------------------------------- */
|
|
.org 0xb00
|
.org 0xb00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.Lb00)
|
|
|
|
|
/* ---[ 0xc00: Syscall exception ]--------------------------------------- */
|
/* 0xc00: Syscall exception */
|
.org 0xc00
|
.org 0xc00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.Lc00)
|
|
|
|
/* 0xd00: floating point exception */
|
/* ---[ 0xd00: Trap exception ]------------------------------------------ */
|
|
.org 0xd00
|
.org 0xd00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.Ld00)
|
|
|
|
|
/* ---[ 0xe00: Trap exception ]------------------------------------------ */
|
/* 0xe00: Trap exception */
|
.org 0xe00
|
.org 0xe00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.Le00)
|
|
|
|
/* 0xf00: Reserved exceptions */
|
/* ---[ 0xf00: Reserved exceptions ]------------------------------------- */
|
|
.org 0xf00
|
.org 0xf00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.Lf00)
|
|
|
.org 0x1000
|
.org 0x1000
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1000)
|
|
|
.org 0x1100
|
.org 0x1100
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1100)
|
|
|
.org 0x1200
|
.org 0x1200
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1200)
|
|
|
.org 0x1300
|
.org 0x1300
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1300)
|
|
|
.org 0x1400
|
.org 0x1400
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1400)
|
|
|
.org 0x1500
|
.org 0x1500
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1500)
|
|
|
.org 0x1600
|
.org 0x1600
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1600)
|
|
|
.org 0x1700
|
.org 0x1700
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1700)
|
|
|
.org 0x1800
|
.org 0x1800
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1800)
|
|
|
.org 0x1900
|
.org 0x1900
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1900)
|
|
|
.org 0x1a00
|
.org 0x1a00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1a00)
|
|
|
.org 0x1b00
|
.org 0x1b00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1b00)
|
|
|
.org 0x1c00
|
.org 0x1c00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1c00)
|
|
|
.org 0x1d00
|
.org 0x1d00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1d00)
|
|
|
.org 0x1e00
|
.org 0x1e00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1e00)
|
|
|
.org 0x1f00
|
.org 0x1f00
|
UNHANDLED_EXCEPTION
|
UNHANDLED_EXCEPTION (.L1f00)
|
|
|
|
/* Pad to the end */
|
|
.org 0x1ffc
|
|
l.nop
|
|
|
/* -----------------------------------------------------------------------------
|
/* -------------------------------------------------------------------------- */
|
* Main entry point
|
/*!Main entry point
|
* ---------------------------------------------------------------------------*/
|
|
.text
|
We initialise the stack and frame pointer first, before we set up the
|
|
caches, since otherwise we'll need to disable the instruction cache when
|
|
patching 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
|
|
- initialize the UART (may be dummy, if no UART supported)
|
|
- 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 _stack
|
|
_stack: .space 4,0
|
|
|
|
.section .text
|
.global _start
|
.global _start
|
.type _start,@function
|
.type _start,@function
|
|
|
_start:
|
_start:
|
|
/* Determine where the stack should end. Must be somewhere above the
|
|
end of loaded memory. We look in blocks of 64KB. */
|
|
l.movhi r30,hi(end)
|
|
l.ori r30,r30,lo(end)
|
|
l.srli r30,r30,16 /* Round down to 64KB boundary */
|
|
l.slli r30,r30,16
|
|
|
|
l.addi r28,r0,1 /* Constant 64KB in register */
|
|
l.slli r28,r28,16
|
|
|
|
l.add r30,r30,r28
|
|
l.addi r30,r30,-4 /* SP one word inside next 64KB? */
|
|
|
|
l.movhi r26,0xaaaa /* Test pattern to store in memory */
|
|
l.ori r26,r26,0xaaaa
|
|
|
|
/* Is this a writeable location? */
|
|
.L3:
|
|
l.sw 0(r30),r26
|
|
l.lwz r24,0(r30)
|
|
l.sfeq r24,r26
|
|
l.bnf .L4
|
|
l.nop
|
|
|
|
l.j .L3
|
|
l.add r30,r30,r28 /* Try 64KB higher */
|
|
|
|
.L4:
|
|
l.sub r30,r30,r28 /* Previous value was wanted */
|
|
l.movhi r26,hi(_stack)
|
|
l.ori r26,r26,lo(_stack)
|
|
l.sw 0(r26),r30
|
|
|
|
/* Initialise stack and frame pointer (set to same value) */
|
|
l.add r1,r30,r0
|
|
l.add r2,r30,r0
|
|
|
|
/* Clear out the bus error vector special code. */
|
|
l.movhi r30,hi(_buserr)
|
|
l.ori r30,r30,lo(_buserr)
|
|
l.movhi r28,hi(_buserr_std)
|
|
l.ori r28,r28,lo(_buserr_std)
|
|
l.movhi r26,0x1500 /* l.nop 0 */
|
|
l.ori r26,r26,0x0000
|
|
|
|
.L5:
|
|
l.sfeq r28,r30
|
|
l.bf .L6
|
|
l.nop
|
|
|
|
l.sw 0(r30),r26 /* Patch the instruction */
|
|
l.j .L5
|
|
l.addi r30,r30,4 /* Next instruction */
|
|
|
|
.L6:
|
/* Cache initialisation */
|
/* Cache initialisation */
|
.if IC_ENABLE || DC_ENABLE
|
.if IC_ENABLE || DC_ENABLE
|
/* Flush IC and/or DC */
|
/* Flush IC and/or DC */
|
l.addi r10,r0,0
|
l.addi r10,r0,0
|
l.addi r11,r0,0
|
l.addi r11,r0,0
|
Line 194... |
Line 361... |
l.nop
|
l.nop
|
l.nop
|
l.nop
|
l.nop
|
l.nop
|
.endif
|
.endif
|
|
|
/* Initialise stack and frame pointer (set to samve value) */
|
|
l.and r1,r1,r2
|
|
l.movhi r1,hi(_stack)
|
|
l.ori r1,r1,lo(_stack)
|
|
l.add r2,r1,r0
|
|
|
|
|
|
/* Clear BSS */
|
/* Clear BSS */
|
l.movhi r28,hi(___bss_start)
|
l.movhi r28,hi(__bss_start)
|
l.ori r28,r28,lo(___bss_start)
|
l.ori r28,r28,lo(__bss_start)
|
l.movhi r30,hi(__end)
|
l.movhi r30,hi(end)
|
l.ori r30,r30,lo(__end)
|
l.ori r30,r30,lo(end)
|
|
|
.L1:
|
.L1:
|
l.sw (0)(r28),r0
|
l.sw (0)(r28),r0
|
l.sfltu r28,r30
|
l.sfltu r28,r30
|
l.bf .L1
|
l.bf .L1
|
l.addi r28,r28,4
|
l.addi r28,r28,4
|
|
|
/* Call global and static constructors */
|
/* Call global and static constructors */
|
/* l.jal init */
|
l.movhi r3,hi(init)
|
|
l.ori r3,r3,lo(init)
|
|
l.jalr r3
|
|
|
/* Setup destructors to be called from exit if main never returns */
|
/* Setup destructors to be called from exit if main never returns */
|
/* l.movhi r3,hi(fini) */
|
l.movhi r3,hi(fini)
|
/* l.ori r3,r3,lo(fini) */
|
l.ori r3,r3,lo(fini)
|
/* l.jal _atexit */
|
l.jal _atexit
|
|
|
/* Initialise UART in a C function */
|
/* Initialise UART in a C function. If the UART isn't present, we'll */
|
/* l.jal _uart_init */
|
/* link against a dummy function. */
|
/* l.nop */
|
l.jal _uart_init
|
|
l.nop
|
|
|
/* Jump to main program entry point (argc = argv = envp = 0) */
|
/* Jump to main program entry point (argc = argv = envp = 0) */
|
l.or r3,r0,r0
|
l.or r3,r0,r0
|
l.or r4,r0,r0
|
l.or r4,r0,r0
|
l.jal _main
|
l.jal _main
|
Line 235... |
Line 398... |
|
|
/* If program exits, call exit routine */
|
/* If program exits, call exit routine */
|
l.jal _exit
|
l.jal _exit
|
l.addi r3,r11,0
|
l.addi r3,r11,0
|
|
|
.size _start, .-_start
|
/* Loop forever */
|
|
.L2:
|
/* ====================================== [ default exception handler ] === */
|
l.j .L2
|
|
|
default_exception_handler:
|
|
l.sw 0x00(r1),r2
|
|
l.sw 0x0c(r1),r5
|
|
l.sw 0x10(r1),r6
|
|
l.sw 0x14(r1),r7
|
|
l.sw 0x18(r1),r8
|
|
l.sw 0x1c(r1),r9
|
|
l.sw 0x20(r1),r10
|
|
l.sw 0x24(r1),r11
|
|
l.sw 0x28(r1),r12
|
|
l.sw 0x2c(r1),r13
|
|
l.sw 0x30(r1),r14
|
|
l.sw 0x34(r1),r15
|
|
l.sw 0x38(r1),r16
|
|
l.sw 0x3c(r1),r17
|
|
l.sw 0x40(r1),r18
|
|
l.sw 0x44(r1),r19
|
|
l.sw 0x48(r1),r20
|
|
l.sw 0x4c(r1),r21
|
|
l.sw 0x50(r1),r22
|
|
l.sw 0x54(r1),r23
|
|
l.sw 0x58(r1),r24
|
|
l.sw 0x5c(r1),r25
|
|
l.sw 0x60(r1),r26
|
|
l.sw 0x64(r1),r27
|
|
l.sw 0x68(r1),r28
|
|
l.sw 0x6c(r1),r29
|
|
l.sw 0x70(r1),r30
|
|
l.sw 0x74(r1),r31
|
|
l.sw 0x78(r1),r32
|
|
|
|
l.jal _default_exception_handler_c
|
|
l.nop
|
|
|
|
l.lwz r2,0x00(r1)
|
|
l.lwz r3,0x04(r1)
|
|
l.lwz r4,0x08(r1)
|
|
l.lwz r5,0x0c(r1)
|
|
l.lwz r6,0x10(r1)
|
|
l.lwz r7,0x14(r1)
|
|
l.lwz r8,0x18(r1)
|
|
l.lwz r9,0x1c(r1)
|
|
l.lwz r10,0x20(r1)
|
|
l.lwz r11,0x24(r1)
|
|
l.lwz r12,0x28(r1)
|
|
l.lwz r13,0x2c(r1)
|
|
l.lwz r14,0x30(r1)
|
|
l.lwz r15,0x34(r1)
|
|
l.lwz r16,0x38(r1)
|
|
l.lwz r17,0x3c(r1)
|
|
l.lwz r18,0x40(r1)
|
|
l.lwz r19,0x44(r1)
|
|
l.lwz r20,0x48(r1)
|
|
l.lwz r21,0x4c(r1)
|
|
l.lwz r22,0x50(r1)
|
|
l.lwz r23,0x54(r1)
|
|
l.lwz r24,0x58(r1)
|
|
l.lwz r25,0x5c(r1)
|
|
l.lwz r26,0x60(r1)
|
|
l.lwz r27,0x64(r1)
|
|
l.lwz r28,0x68(r1)
|
|
l.lwz r29,0x6c(r1)
|
|
l.lwz r30,0x70(r1)
|
|
l.lwz r31,0x74(r1)
|
|
l.lwz r32,0x78(r1)
|
|
|
|
l.addi r1,r1,128
|
|
|
|
l.rfe
|
|
l.nop
|
l.nop
|
|
|
|
.size _start, .-_start
|