.text
.globl _start
_start:
	b	reset
	b	arm_undefined
	b	arm_syscall
	b	arm_prefetch_abort
	b	arm_data_abort
	b	arm_reserved
	b	arm_irq
	b	arm_fiq

reset:
	/* set up the stack for irq, fiq, abort, undefined, system/user, and lastly supervisor mode */
	mrs     r0, cpsr
	bic     r0, r0, #0x1f
	    
	orr     r1, r0, #0x12 // irq
	msr     cpsr_c, r1
	ldr     sp, =irq_stack_top
	    
	orr     r1, r0, #0x11 // fiq
	msr     cpsr_c, r1
	ldr     sp, =fiq_stack_top
	            
	orr     r1, r0, #0x17 // abort
	msr     cpsr_c, r1
	ldr     sp, =abt_stack_top
	    
	orr     r1, r0, #0x1b // undefined
	msr     cpsr_c, r1
	ldr     sp, =und_stack_top
	    
	orr     r1, r0, #0x1f // system
	msr     cpsr_c, r1
	ldr     sp, =sys_stack_top /* also sets user stack */

	orr	r1, r0, #0x13 // supervisor
	msr	cpsr_c, r1
	ldr     sp, =svc_stack_top
	
	bl		kmain
	b		.

.data
.align 4
sys_stack:
	.skip 4096
sys_stack_top:

irq_stack:
	.skip 4096
irq_stack_top:

fiq_stack:
	.skip 4096
fiq_stack_top:

abt_stack:
	.skip 4096
abt_stack_top:

und_stack:
	.skip 4096
und_stack_top:

svc_stack:
	.skip 4096
svc_stack_top:

