From 2d7c0a36fee022e35fd32c042922516fd858510d Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 29 Jul 2017 12:06:30 +0100 Subject: [PATCH] added more files --- .gitignore | 4 -- kernel/arch/arm/include/regs.h | 21 ++++++++ kernel/arch/arm/int.s | 89 +++++++++++++++++++++++++++++++++ kernel/mmaps/3ds9.mh | 5 ++ kernel/mmaps/3ds9.mmap | Bin 0 -> 129 bytes 5 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 kernel/arch/arm/include/regs.h create mode 100644 kernel/arch/arm/int.s create mode 100644 kernel/mmaps/3ds9.mh create mode 100644 kernel/mmaps/3ds9.mmap diff --git a/.gitignore b/.gitignore index 8798039..df226d7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,4 @@ iso/kernel *.firm html/ latex/ -int.s -regs.h out/ -*.mmap -*.mh diff --git a/kernel/arch/arm/include/regs.h b/kernel/arch/arm/include/regs.h new file mode 100644 index 0000000..08a6e90 --- /dev/null +++ b/kernel/arch/arm/include/regs.h @@ -0,0 +1,21 @@ +#include +struct cpu_state { + uint32_t cpsr; + uint32_t sp; + uint32_t lr; + uint32_t returnAddr; + uint32_t r0; + uint32_t r1; + uint32_t r2; + uint32_t r3; + uint32_t r4; + uint32_t r5; + uint32_t r6; + uint32_t r7; + uint32_t r8; + uint32_t r9; + uint32_t r10; + uint32_t r11; + uint32_t r12; + uint32_t pc; +}; \ No newline at end of file diff --git a/kernel/arch/arm/int.s b/kernel/arch/arm/int.s new file mode 100644 index 0000000..0f17f0b --- /dev/null +++ b/kernel/arch/arm/int.s @@ -0,0 +1,89 @@ +.arm +.fpu vfpv2 +.section .bss +.space 4096 +exception_stack: +.section .data +.space 4 +oldsp: +.section .text +.global branch_macro +branch_macro: + ldr pc, [pc, #-4] //Load the next word into PC +.macro interrupt_handler intid + push {r0-r12,lr} //Push registers + + //Get previous sp and lr + mrs r1, cpsr //Current mode + mrs r0, spsr //Previous mode + orr r0, #0xC0 //Disable interrupts in the previous mode + bic r0, #0x20 //enable ARM mode in there + + //If the mode is user, switch to system mode + and r2, r0, #0x1F + cmp r2, #0x10 + bne 1f + orr r0, #0x1F +1: + //Change mode + msr cpsr, r0 + mov r2, sp + mov r3, lr + //Switch back + msr cpsr, r1 + mrs r0, spsr + + //Push those registers + push {r0, r2, r3, lr} + + //Set argument 1 + ldr r0, =\intid + + //Jump to generic handler + + bl intr_common_handler + + //pop the special registers + pop {r0, r3, r4, lr} + msr spsr, r0 + tst r0, #0x20 //Is code ARM or thumb? + beq 2f + orr lr, lr, #1 //Enable thumb mode on return# +2: + str lr, [sp, #0x34] //Set correct lr + + ldmfd sp!, {r0-r12, pc}^ //Return back to original mode +.endm +.global data_abort +data_abort: + interrupt_handler 0 +.global fast_irq +fast_irq: + interrupt_handler 1 +.global normal_irq +normal_irq: + interrupt_handler 2 +.global prefetch_abort +prefetch_abort: + interrupt_handler 3 +.global svc_call +svc_call: + interrupt_handler 4 +.global undefined_op +undefined_op: + interrupt_handler 5 + +.extern handleINT +intr_common_handler: + mov r1, sp + push {lr} + blx handleINT + pop {lr} + mov sp, r0 + bx lr +.global panic +.extern panic2 +panic: + push {r0-r12,lr} + mov r1, sp + b panic diff --git a/kernel/mmaps/3ds9.mh b/kernel/mmaps/3ds9.mh new file mode 100644 index 0000000..2b0660e --- /dev/null +++ b/kernel/mmaps/3ds9.mh @@ -0,0 +1,5 @@ +#pragma once +#include +uint8_t mmap[] = { +0x4d, 0x4d, 0x41, 0x50, 0x0, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x4, 0x33, 0x44, 0x53, 0x39, 0x2, 0x1, 0x2, 0x3, 0x1, 0x1, 0x4, 0x1, 0x20, 0x5, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x6, 0x5, 0x9, 0x0, 0x0, 0x0, 0x8, 0x0, 0x0, 0x10, 0x8, 0x7, 0x5, 0x9, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0, 0x18, 0x6, 0x5, 0x9, 0x0, 0x0, 0x0, 0x18, 0x0, 0x0, 0x60, 0x18, 0x6, 0x5, 0x9, 0x0, 0x0, 0xf0, 0x1f, 0x0, 0x0, 0xf8, 0x1f, 0x6, 0x5, 0x9, 0x0, 0x0, 0xf8, 0x1f, 0x0, 0x0, 0x0, 0x20, 0x6, 0x5, 0x9, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x28, 0x6, 0x5, 0x9, 0x0, 0x0, 0xf0, 0xff, 0x0, 0x40, 0xf0, 0xff, 0x6, 0x5, 0x9, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x5, +}; diff --git a/kernel/mmaps/3ds9.mmap b/kernel/mmaps/3ds9.mmap new file mode 100644 index 0000000000000000000000000000000000000000..26d6045c3c684839c9c346d2da544225d1519099 GIT binary patch literal 129 zcmebEbqrtt0zMGI$jHcI>=JCr#K^=9WHKtSa)N{z8WjqFh9sMF#M1Qi~ayI85AH26o5<(F!RHI28R#-!OZ{vfuano0G5#sKmY&$ literal 0 HcmV?d00001