Improved SWI service routine to handle C functions
This commit is contained in:
parent
c4342f1b89
commit
52c288a056
8
src/isr.cpp
Normal file
8
src/isr.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <dbg.h>
|
||||||
|
|
||||||
|
extern "C" void c_swi_handler(uint32_t type) {
|
||||||
|
printk("Serving SWI # ");
|
||||||
|
printkl(itoa(type));
|
||||||
|
// TODO: to be done =)
|
||||||
|
}
|
@ -2,14 +2,21 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <interrupt.h>
|
#include <interrupt.h>
|
||||||
|
|
||||||
|
extern "C" void go_usr(void);
|
||||||
|
|
||||||
/* KERNEL MAIN */
|
/* KERNEL MAIN */
|
||||||
extern "C" int main(int argc, char** argv) {
|
extern "C" int main(int argc, char** argv) {
|
||||||
printkl("Welcome to STKARM -- Simple and Trivial Kernel for Advanced Reduced Instruction Set Computer Machines");
|
printkl("Welcome to STKARM -- Simple and Trivial Kernel for Advanced Reduced Instruction Set Computer Machines");
|
||||||
|
|
||||||
printkl("Now firing software interrupt...");
|
printkl("Installing kernel...");
|
||||||
|
|
||||||
|
printkl("Now firing test software interrupt...");
|
||||||
fireswi();
|
fireswi();
|
||||||
|
|
||||||
printkl("EOK -- End of Kernel -- Now returning to assembly");
|
printkl("Go user...");
|
||||||
|
go_usr();
|
||||||
|
|
||||||
|
printkl("EOK -- End of Kernel -- This point can not be reached");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,31 +1,29 @@
|
|||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
|
|
||||||
MEMORY {
|
MEMORY {
|
||||||
m_text (RX) : ORIGIN = 0x40000000, LENGTH = 16M
|
m_ram (RWX) : ORIGIN = 0x40000000, LENGTH = 2048M
|
||||||
m_data (RW) : ORIGIN = 0x41000000, LENGTH = 16M
|
|
||||||
m_stack (RW) : ORIGIN = 0x42000000, LENGTH = 16M
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x40000000;
|
.stack : ALIGN(0x100) {
|
||||||
.text : ALIGN(0x1000) {
|
. = . + 0x100; stack_svc = .;
|
||||||
*(.text)
|
. = . + 0x100; stack_und = .;
|
||||||
} > m_text
|
. = . + 0x100; stack_abt = .;
|
||||||
.data : ALIGN(0x1000) {
|
. = . + 0x100; stack_irq = .;
|
||||||
|
. = . + 0x100; stack_fiq = .;
|
||||||
|
. = . + 0x100; stack_sys = .; stack_usr = .;
|
||||||
|
} > m_ram
|
||||||
|
.data : ALIGN(0x4) {
|
||||||
*(.data)
|
*(.data)
|
||||||
} > m_data
|
} > m_ram
|
||||||
.bss : ALIGN(0x1000) {
|
.bss : ALIGN(0x4) {
|
||||||
*(.bss)
|
*(.bss)
|
||||||
} > m_data
|
} > m_ram
|
||||||
|
|
||||||
. = ALIGN(0x100); stack_svc = .;
|
.text : ALIGN(0x4) {
|
||||||
. = . + 0x100; stack_und = .;
|
*(.text)
|
||||||
. = . + 0x100; stack_abt = .;
|
} > m_ram
|
||||||
. = . + 0x100; stack_irq = .;
|
|
||||||
. = . + 0x100; stack_fiq = .;
|
|
||||||
. = . + 0x100; stack_sys = .;
|
|
||||||
. = . + 0x100; stack_usr = .;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,8 @@ _start:
|
|||||||
cps #0x1f
|
cps #0x1f
|
||||||
ldr sp, =stack_sys
|
ldr sp, =stack_sys
|
||||||
|
|
||||||
// Leave in usr mode
|
/* Enter SuperVisor Mode */
|
||||||
// cps #0x10
|
cps #0x13
|
||||||
// ldr sp, =stack_usr
|
|
||||||
|
|
||||||
/* Enable Vector Table BAR remapping (clears bit 13 of SCTLR) */
|
/* Enable Vector Table BAR remapping (clears bit 13 of SCTLR) */
|
||||||
mrc p15, 0, r0, c1, c0, 0
|
mrc p15, 0, r0, c1, c0, 0
|
||||||
|
20
src/user.s
Normal file
20
src/user.s
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
.global go_usr
|
||||||
|
go_usr:
|
||||||
|
mrs r0, cpsr
|
||||||
|
bl itoa
|
||||||
|
bl printkl
|
||||||
|
|
||||||
|
/* Actually go to user mode */
|
||||||
|
cps #0x10
|
||||||
|
ldr sp, =stack_usr
|
||||||
|
|
||||||
|
mrs r0, cpsr
|
||||||
|
bl itoa
|
||||||
|
bl printkl
|
||||||
|
|
||||||
|
swi #0xc
|
||||||
|
swi #0x1
|
||||||
|
swi #0xa
|
||||||
|
swi #0x0
|
||||||
|
|
||||||
|
b .
|
18
src/vectab.s
18
src/vectab.s
@ -37,12 +37,22 @@ und_handler:
|
|||||||
ldmfd sp!, {pc}^
|
ldmfd sp!, {pc}^
|
||||||
|
|
||||||
swi_handler:
|
swi_handler:
|
||||||
stmfd sp!, {lr}
|
stmfd sp!, {r0-r12, lr}
|
||||||
|
|
||||||
ldr r0, =swi_msg
|
/* Get SWI number to pass to c_swi_handler */
|
||||||
bl printkl
|
ldr r10, [lr, #-4]
|
||||||
|
and r10, #0x00ffffff
|
||||||
|
mov r0, r10
|
||||||
|
|
||||||
ldmfd sp!, {pc}^
|
mov r1, sp
|
||||||
|
mrs r2, spsr
|
||||||
|
stmfd sp!, {r2}
|
||||||
|
|
||||||
|
bl c_swi_handler
|
||||||
|
|
||||||
|
ldmfd sp!, {r2}
|
||||||
|
msr spsr_cxsf, r2
|
||||||
|
ldmfd sp!, {r0-r12, pc}^
|
||||||
|
|
||||||
// TODO: untested
|
// TODO: untested
|
||||||
prefetch_abt_handler:
|
prefetch_abt_handler:
|
||||||
|
Loading…
Reference in New Issue
Block a user