voron

experimental ARM OS
git clone git@git.2f30.org/voron.git
Log | Files | Refs | README | LICENSE

start.S (2101B)


      1 #include <p_modes.h>
      2 
      3 .section .text
      4 .globl _start
      5 _start:
      6 	cpsid if		@ disable interrupts
      7 	ldr sp, =_svc_stack_top	@ set SVC stack
      8 
      9 	@@ set leds off
     10 	mov r0, #0
     11 	bl set_leds
     12 
     13 	@@ print booting message
     14 	ldr r0, =boot_msg
     15 	bl kputs
     16 
     17 	@@ init .bss section
     18 	ldr r0, =_kernel_bss_start
     19 	ldr r1, =_kernel_bss_end
     20 	mov r2, #0
     21 	mov r3, #0
     22 1:
     23 	stmia r0!, { r2, r3 }
     24 	cmp r0, r1
     25 	blo 1b
     26 
     27 	@@ initialize vector table
     28 	bl vector_table_init
     29 
     30 	@@ disable caches for now
     31 	mrc p15, 0, r0, c1, c0, 0
     32 	bic r0, r0, #(1 << 12)          @ set I flag to 0 (disable instruction cache)
     33 	bic r0, r0, #(1 << 2)		@ set C flag to 0 (disable data cache)
     34 	mcr p15, 0, r0, c1, c0, 0
     35 
     36 	@@ initialize memory management
     37 	bl mm_init
     38 
     39 	@@ initialize interrupts
     40 	cps #CPS_FIQ		@ change to FIQ mode
     41 	ldr sp, =_fiq_stack_top @ set FIQ stack
     42 
     43 	cps #CPS_IRQ		@ change to IRQ mode
     44 	ldr sp, =_irq_stack_top @ set IRQ stack
     45 
     46 	cps #CPS_ABT	      @ change to Abort mode
     47 	ldr sp, =_abort_stack_top @ set stack
     48 
     49 	cps #CPS_SVC		@ change back to SVC mode
     50 	bl irq_init		@ initialize controler
     51 	cpsie if		@ enable interrupts
     52 
     53 	bl dmtimer_init
     54 
     55 	@@ run constructors
     56 	ldr r0, =_kernel_ctors_start
     57 	ldr r1, =_kernel_ctors_end
     58 1:
     59 	teq r0, r1
     60 	beq 3f
     61 	ldr r2, [r0], #4
     62 	stmfd sp!, { r0, r1 }
     63 	ldr lr, =2f
     64 	mov pc, r2
     65 2:
     66 	ldmfd sp!, { r0, r1 }
     67 	b 1b
     68 3:
     69 
     70 	@@ example of calling a system call with 1 argument
     71 	mov r0, #1
     72 	@@ the syscall number is 0
     73 	mov r7, #0
     74 	swi #0
     75 
     76 	@@ example of calling a system call with 4 arguments
     77 	mov r0, #1
     78 	mov r1, #2
     79 	mov r2, #3
     80 	mov r3, #4
     81 	@@ the syscall number is 0
     82 	mov r7, #1
     83 	swi #0
     84 
     85 	@@ example of calling a system call with 5 arguments
     86 	mov r0, #1
     87 	mov r1, #2
     88 	mov r2, #3
     89 	mov r3, #4
     90 	mov r4, #5
     91 	@@ the syscall number is 0
     92 	mov r7, #2
     93 	swi #0
     94 
     95 	@@ example of calling a system call with 7 arguments
     96 	mov r0, #1
     97 	mov r1, #2
     98 	mov r2, #3
     99 	mov r3, #4
    100 	mov r4, #5
    101 	mov r5, #6
    102 	mov r6, #7
    103 	@@ the syscall number is 0
    104 	mov r7, #3
    105 	swi #0
    106 
    107 	@@ out of boundary syscall number example
    108 	mov r7, #1000
    109 	swi #0
    110 
    111 	ldr r0, =kmain
    112 	mov r1, #0
    113 	bl kthread_create
    114 	b schedule
    115 
    116 .section .rodata
    117 boot_msg:
    118 	.asciz "\n\nVoron booting...\n\n"