Redid timer architecture, only tick handling remaining.
[tart.git] / arch / arm / start.S
blob39a4e575c548c1ad7381a744aad00c8492f9fba2
1 #include <asm.h>
2 #include <arm.h>
4 #if ARMV < 6
5     #error ARM versions below ARMv6 not supported yet.
6 #endif
8 #define STACK_SIZE     0x1000
10 // Text section.
11 .section ".text.boot"
14  * Entry point for the kernel.
15  *     r15 -> entry point.
16  *     r0  -> 0x00000000.
17  *     r1  -> machine type number.
18  *     r2  -> start address of ATAGS.
19  */
20 GLOBAL(_start)
21 FUNCTION(_start)
23 # Since these can only branch to 32MiB from instruction, put the address
24 # of the handlers nearby, and copy them too.
25 .vectors:
26     # Execution starts here too, so we set this to "Start."
27     ldr pc, reset
28     ldr pc, ud
29     ldr pc, swi
30     ldr pc, prefetch_abort
31     ldr pc, data_abort
32     ldr pc, unused
33     ldr pc, irq
34     ldr pc, fiq
36 reset:              .word start
37 ud:                 .word exception_ud
38 swi:                .word exception_swi
39 prefetch_abort:     .word exception_prefetch_abort
40 data_abort:         .word exception_data_abort
41 unused:             .word exception_unused
42 irq:                .word exception_irq
43 fiq:                .word exception_fiq
45 start:
46     // Read control register 1 from CP15.
47     mrc p15, #0, r3, c1, c0, #0
49     // No MMU, no alignment fault checking, no data cache.
50     bic r3, #((1 << 0) | (1 << 1) | (1 << 2))
51     // No instruction cache, low vectors, loads to PC set the T bit.
52     bic r3, #((1 << 12) | (1 << 13) | (1 << 15))
53     // Fixed interrupt vector.
54     bic r3, #(1 << 24)
56     // Write it back.
57     mcr p15, #0, r3, c1, c0, #0
59     // Move vectors to 0x00000000.
60     mov r3, r0
61     ldr r4, =.vectors
62     
63     // 64 bytes.
64     ldmia r4!, {r5-r12}
65     stmia r3!, {r5-r12}
67     ldmia r4!, {r5-r12}
68     stmia r3!, {r5-r12}
70     .stack_init:
71 #if ARMV >= 6
72         // Switch to FIQ mode. 
73         cpsid if, #FIQ_MODE
74         ldr sp, =fiq_stack + (STACK_SIZE)
76         cpsid if, #IRQ_MODE
77         ldr sp, =abort_stack + (STACK_SIZE)
79         cpsid if, #ABT_MODE
80         ldr sp, =abort_stack + (STACK_SIZE)
82         cpsid if, #UND_MODE
83         ldr sp, =abort_stack + (STACK_SIZE)
85         cpsid if, #SYS_MODE
86         ldr sp, =abort_stack + (STACK_SIZE)
88         cpsid if, #SVC_MODE
89         ldr sp, =abort_stack + (STACK_SIZE)
90 #endif
92     // Clear out bss.
93     ldr r3, =bss_start
94     ldr r4, =bss_end
96     .bss_zero:
97         // If lower than end, continue.
98         cmp r3, r4
99         strlt r0, [r3], #4
100         blt .bss_zero
102     // Jump to init().
103     blx init
105     // DO NOT RETURN HERE.
106     b .
108 GLOBAL(delay)
109 FUNCTION(delay)
110     // Subtract 1 and keep looping till not 0.
111     subs r0, r0, #1
112     nop
113     bne delay
115     bx lr
117 // The stacks in the BSS section.
118 .bss
120 // Stack for abort.
121 DATA(abort_stack)
122     .skip STACK_SIZE
124 // Stack for FIQ.
125 DATA(fiq_stack)
126     .skip STACK_SIZE