Created
April 20, 2016 01:43
-
-
Save TuxSH/2ea1940125e831be227e44d4a6215929 to your computer and use it in GitHub Desktop.
ARM9 exception vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ Copyright (C) 2015 The PASTA Team | |
@ | |
@ This program is free software; you can redistribute it and/or | |
@ modify it under the terms of the GNU General Public License | |
@ version 2 as published by the Free Software Foundation | |
@ | |
@ 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, write to the Free Software | |
@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
@ Slightly modified by TuxSH | |
.macro GEN_HANDLER name, type | |
.global \name | |
.type \name, %function | |
\name: | |
@ subs pc, lr, #4 <= this works as intended | |
str lr, [sp, #-8] | |
bl storeRegs | |
ldr r1, =\type | |
b mainHandler | |
.size \name, . - \name | |
.endm | |
.text | |
.align 2 | |
GEN_HANDLER handleFiq, 7 | |
GEN_HANDLER handleUndefinedInstr, 1 | |
GEN_HANDLER handleDataAbort, 4 | |
GEN_HANDLER handlePrefetchAbort, 3 | |
storeRegs: @ Except PC | |
sub sp, sp, #16 | |
push { r0-r12 } | |
mrs r0, cpsr | |
mov r1, sp | |
mrs r2, spsr | |
str r2, [sp, #64] | |
tst r2, #0xF | |
orreq r2, r2, #0xF | |
bic r2, r2, #0x10 | |
msr cpsr_c, r2 | |
str lr, [r1, #52] | |
str sp, [r1, #56] | |
msr cpsr_c, r0 | |
mov r0, sp | |
movs pc, r3 | |
bx lr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "types.h" | |
#include "i2c.h" | |
#define REG_NUM 17 | |
#define STACK_DUMP_SIZE 0x10000 | |
void __attribute__((noreturn)) mainHandler(u32 regs[REG_NUM], int type) | |
{ | |
/* | |
static const char regNames[REG_NUM][4] = { | |
"R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", | |
"R8", "R9", "R10", "R11", "R12", "SP", "LR", "PC", "CPSR" | |
};*/ | |
//Testing: | |
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0); // Shutdown | |
for(;;); | |
vu32* dump = (vu32 *)0x1FF80000; // AXIWRAM | |
//bool thumb = | |
dump[0] = 0xDEADC0DE; | |
dump[1] = 0xDEADCAFE; | |
dump[2] = (1 << 16) | 0; // dump format version number | |
dump[3] = 9; // processor | |
dump[4] = 4*REG_NUM; | |
dump[5] = STACK_DUMP_SIZE; | |
dump[6] = 0; | |
dump[7] = (u32)type; | |
// Dump registers | |
vu32* regdump = dump + 8; | |
for(int i = 0; i < REG_NUM; ++i) | |
regdump[i] = regs[i]; | |
// Dump stack | |
vu32* sp = (vu32*) regs[13]; | |
vu32* stackdump = regdump + REG_NUM; | |
for(int i = 0; i < STACK_DUMP_SIZE/4; ++i) | |
stackdump[i] = sp[i]; | |
//vu32* codedump = stackdump + STACK_DUMP_SIZE/4; | |
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0); // Shutdown | |
//i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2); // Reboot | |
for(;;); | |
} | |
// Implemented in handlers.s: | |
void handleFiq(void); | |
void handleUndefinedInstr(void); | |
void handleDataAbort(void); | |
void handlePrefetchAbort(void); | |
void main(void) | |
{ | |
for(vu32* vecs = (vu32 *)0x08000008; vecs < (vu32 *)0x08000030; vecs += 2) | |
{ | |
vecs[0] = 0xE51FF004; // ldr pc, [pc, -4] | |
vecs[1] = (u32)&handleDataAbort; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment