mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
fixed overlooked ARM9 exception handler issue where code would be dumped incorrectly, modified ARM11 exception vectors to not take an entire page of compiled code
This commit is contained in:
parent
07c009de72
commit
8a7448995f
@ -10,15 +10,6 @@ MEMORY
|
|||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
.vector : ALIGN(4K)
|
|
||||||
{
|
|
||||||
__vector_pa = LOADADDR(.vector);
|
|
||||||
__vector_va = ABSOLUTE(.);
|
|
||||||
KEEP(*(.vector))
|
|
||||||
. = ALIGN(4K);
|
|
||||||
__vector_len = . - __vector_va;
|
|
||||||
} >HIGHRAM AT>AXIWRAM
|
|
||||||
|
|
||||||
.text : ALIGN(4K)
|
.text : ALIGN(4K)
|
||||||
{
|
{
|
||||||
__text_pa = LOADADDR(.text);
|
__text_pa = LOADADDR(.text);
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// kinda hardcoded and all over the place, but it needs to stay simple
|
||||||
|
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
#include <arm.h>
|
#include <arm.h>
|
||||||
|
|
21
arm11/source/arm/xrq.h
Normal file
21
arm11/source/arm/xrq.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of GodMode9
|
||||||
|
* Copyright (C) 2020 Wolfvak
|
||||||
|
*
|
||||||
|
* 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 2 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
u32 xrqInstallVectorTable(void);
|
@ -28,47 +28,46 @@
|
|||||||
|
|
||||||
.macro TRAP_ENTRY xrq
|
.macro TRAP_ENTRY xrq
|
||||||
msr cpsr_f, #(\xrq << 29)
|
msr cpsr_f, #(\xrq << 29)
|
||||||
b XRQ_Main
|
b xrqMain
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.section .vector, "ax"
|
xrqVectorTable:
|
||||||
vectors:
|
ldr pc, =xrqReset
|
||||||
b XRQ_Reset
|
ldr pc, =xrqUndefined
|
||||||
b XRQ_Undefined
|
ldr pc, =xrqSVC
|
||||||
b XRQ_SVC
|
ldr pc, =xrqPrefetchAbort
|
||||||
b XRQ_PrefetchAbt
|
ldr pc, =xrqDataAbort
|
||||||
b XRQ_DataAbt
|
b . @ ignore the reserved exception
|
||||||
b XRQ_Reserved
|
ldr pc, =xrqIRQ
|
||||||
b XRQ_IRQ
|
ldr pc, =xrqFIQ
|
||||||
b XRQ_FIQ
|
.pool
|
||||||
|
xrqVectorTableEnd:
|
||||||
|
|
||||||
XRQ_Reset:
|
xrqReset:
|
||||||
TRAP_ENTRY 0
|
TRAP_ENTRY 0
|
||||||
|
|
||||||
XRQ_Undefined:
|
xrqUndefined:
|
||||||
TRAP_ENTRY 1
|
TRAP_ENTRY 1
|
||||||
|
|
||||||
XRQ_SVC:
|
xrqSVC:
|
||||||
TRAP_ENTRY 2
|
TRAP_ENTRY 2
|
||||||
|
|
||||||
XRQ_PrefetchAbt:
|
xrqPrefetchAbort:
|
||||||
TRAP_ENTRY 3
|
TRAP_ENTRY 3
|
||||||
|
|
||||||
XRQ_DataAbt:
|
xrqDataAbort:
|
||||||
TRAP_ENTRY 4
|
TRAP_ENTRY 4
|
||||||
|
|
||||||
XRQ_Reserved:
|
xrqFIQ:
|
||||||
TRAP_ENTRY 5
|
|
||||||
|
|
||||||
XRQ_FIQ:
|
|
||||||
TRAP_ENTRY 7
|
TRAP_ENTRY 7
|
||||||
|
|
||||||
XRQ_Main:
|
xrqMain:
|
||||||
ldr sp, =(exception_stack_top - 32*4)
|
clrex
|
||||||
stmia sp, {r0-r7}
|
|
||||||
|
|
||||||
cpsid aif
|
cpsid aif
|
||||||
|
|
||||||
|
ldr sp, =(xrqStackTop - 32*4)
|
||||||
|
stmia sp, {r0-r7}
|
||||||
|
|
||||||
mrs r1, cpsr
|
mrs r1, cpsr
|
||||||
lsr r0, r1, #29
|
lsr r0, r1, #29
|
||||||
|
|
||||||
@ -82,11 +81,7 @@ XRQ_Main:
|
|||||||
|
|
||||||
add r3, sp, #8*4
|
add r3, sp, #8*4
|
||||||
msr cpsr_c, r2
|
msr cpsr_c, r2
|
||||||
nop
|
|
||||||
nop
|
|
||||||
stmia r3!, {r8-r14}
|
stmia r3!, {r8-r14}
|
||||||
nop
|
|
||||||
nop
|
|
||||||
msr cpsr_c, r1
|
msr cpsr_c, r1
|
||||||
|
|
||||||
mrc p15, 0, r4, c5, c0, 0 @ data fault status register
|
mrc p15, 0, r4, c5, c0, 0 @ data fault status register
|
||||||
@ -99,7 +94,8 @@ XRQ_Main:
|
|||||||
bl do_exception
|
bl do_exception
|
||||||
|
|
||||||
|
|
||||||
XRQ_IRQ:
|
xrqIRQ:
|
||||||
|
clrex
|
||||||
sub lr, lr, #4 @ Fix return address
|
sub lr, lr, #4 @ Fix return address
|
||||||
srsfd sp!, #SR_SVC_MODE @ Store IRQ mode LR and SPSR on the SVC stack
|
srsfd sp!, #SR_SVC_MODE @ Store IRQ mode LR and SPSR on the SVC stack
|
||||||
cps #SR_SVC_MODE @ Switch to SVC mode
|
cps #SR_SVC_MODE @ Switch to SVC mode
|
||||||
@ -108,17 +104,26 @@ XRQ_IRQ:
|
|||||||
and r4, sp, #7 @ Fix SP to be 8byte aligned
|
and r4, sp, #7 @ Fix SP to be 8byte aligned
|
||||||
sub sp, sp, r4
|
sub sp, sp, r4
|
||||||
|
|
||||||
mov lr, pc
|
bl gicTopHandler
|
||||||
ldr pc, =gicTopHandler
|
|
||||||
|
|
||||||
add sp, sp, r4
|
add sp, sp, r4
|
||||||
|
|
||||||
pop {r0-r4, r12, lr}
|
pop {r0-r4, r12, lr}
|
||||||
rfeia sp! @ Return from exception
|
rfeia sp! @ Return from exception
|
||||||
|
|
||||||
.section .bss.xrq_stk
|
@ u32 xrqInstallVectorTable(void)
|
||||||
|
.global xrqInstallVectorTable
|
||||||
|
.type xrqInstallVectorTable, %function
|
||||||
|
xrqInstallVectorTable:
|
||||||
|
ldr r0, =xrqPage
|
||||||
|
ldr r1, =xrqVectorTable
|
||||||
|
mov r2, #(xrqVectorTableEnd - xrqVectorTable)
|
||||||
|
b memcpy
|
||||||
|
|
||||||
|
.section .bss.xrqPage
|
||||||
.align 12
|
.align 12
|
||||||
exception_stack: @ reserve a single aligned page for the exception stack
|
.global xrqPage
|
||||||
.space 4096
|
xrqPage:
|
||||||
exception_stack_top:
|
.space 8192 @ reserve two 4K aligned pages for vectors and abort stack
|
||||||
.global exception_stack_top
|
.global xrqStackTop
|
||||||
|
xrqStackTop:
|
@ -21,7 +21,6 @@
|
|||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
#define DEF_SECT_(n) extern u32 __##n##_pa, __##n##_va, __##n##_len;
|
#define DEF_SECT_(n) extern u32 __##n##_pa, __##n##_va, __##n##_len;
|
||||||
DEF_SECT_(vector)
|
|
||||||
DEF_SECT_(text)
|
DEF_SECT_(text)
|
||||||
DEF_SECT_(data)
|
DEF_SECT_(data)
|
||||||
DEF_SECT_(rodata)
|
DEF_SECT_(rodata)
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "arm/gic.h"
|
#include "arm/gic.h"
|
||||||
#include "arm/mmu.h"
|
#include "arm/mmu.h"
|
||||||
#include "arm/scu.h"
|
#include "arm/scu.h"
|
||||||
#include "arm/timer.h"
|
#include "arm/xrq.h"
|
||||||
|
|
||||||
#include "hw/codec.h"
|
#include "hw/codec.h"
|
||||||
#include "hw/gpulcd.h"
|
#include "hw/gpulcd.h"
|
||||||
@ -79,13 +79,15 @@ void SYS_CoreZeroInit(void)
|
|||||||
SCU_Init();
|
SCU_Init();
|
||||||
|
|
||||||
// Map all sections here
|
// Map all sections here
|
||||||
mmuMapArea(SECTION_TRI(vector), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 0));
|
|
||||||
mmuMapArea(SECTION_TRI(text), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
|
mmuMapArea(SECTION_TRI(text), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
|
||||||
mmuMapArea(SECTION_TRI(data), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
|
mmuMapArea(SECTION_TRI(data), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
|
||||||
mmuMapArea(SECTION_TRI(rodata), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 1, 1));
|
mmuMapArea(SECTION_TRI(rodata), MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 1, 1));
|
||||||
mmuMapArea(SECTION_TRI(bss), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
|
mmuMapArea(SECTION_TRI(bss), MMU_FLAGS(MMU_CACHE_WBA, MMU_READ_WRITE, 1, 1));
|
||||||
mmuMapArea(SECTION_TRI(shared), MMU_FLAGS(MMU_STRONG_ORDER, MMU_READ_WRITE, 1, 1));
|
mmuMapArea(SECTION_TRI(shared), MMU_FLAGS(MMU_STRONG_ORDER, MMU_READ_WRITE, 1, 1));
|
||||||
|
|
||||||
|
// High exception vectors
|
||||||
|
mmuMapArea(0xFFFF0000, xrqInstallVectorTable(), 4UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 0));
|
||||||
|
|
||||||
// BootROM
|
// BootROM
|
||||||
mmuMapArea(0x00010000, 0x00010000, 32UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
|
mmuMapArea(0x00010000, 0x00010000, 32UL << 10, MMU_FLAGS(MMU_CACHE_WT, MMU_READ_ONLY, 0, 1));
|
||||||
|
|
||||||
|
@ -108,11 +108,10 @@ void XRQ_DumpRegisters(u32 xrq, u32 *regs)
|
|||||||
pc = regs[15] & ~0xF;
|
pc = regs[15] & ~0xF;
|
||||||
if (pc_dumpable(pc, &pc_lower, &pc_upper)) {
|
if (pc_dumpable(pc, &pc_lower, &pc_upper)) {
|
||||||
wstr += sprintf(wstr, "Code:\n");
|
wstr += sprintf(wstr, "Code:\n");
|
||||||
wstr += XRQ_DumpData_u32(wstr, pc_lower, pc_upper);
|
|
||||||
if (regs[16] & SR_THUMB) { // need to take Thumb code into account
|
if (regs[16] & SR_THUMB) { // need to take Thumb code into account
|
||||||
wstr += XRQ_DumpData_u16(wstr, pc-PC_DUMPRAD, pc+PC_DUMPRAD);
|
wstr += XRQ_DumpData_u16(wstr, pc_lower, pc_upper);
|
||||||
} else {
|
} else {
|
||||||
wstr += XRQ_DumpData_u32(wstr, pc-PC_DUMPRAD, pc+PC_DUMPRAD);
|
wstr += XRQ_DumpData_u32(wstr, pc_lower, pc_upper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user