2 #include "include/assembly.h"
3 #include "include/options.h"
6 @ Exception defs taken from ARM DDI 0406B
9 interrupt_vector_table:
10 ivt_reset: b _start @ Reset
12 ivt_svc: b SVC_Handler @ SVC (used to be called SWI)
13 ivt_prefetch: b PrefetchAbort @ Prefetch abort
14 ivt_data: b DataAbort @ Data abort
15 ivt_unused: b . @ Not Used
16 ivt_irq: b IRQHandler @ IRQ
17 ivt_fiq: b . @ FIQ (Fast interrupt)
21 ldr r0, =kernel_table0-KERNEL_BASE
22 mcr p15, 0, r0, c2, c0, 1 @ Set TTBR1 to r0
23 mcr p15, 0, r0, c2, c0, 0 @ Set TTBR0 to r0 too (for identity)
26 mcr p15, 0, r0, c2, c0, 2 @ Set TTCR to 1 (50/50 split)
29 mcr p15, 0, r0, c3, c0, 0 @ Set Domain 0 to Manager
32 mrc p15, 0, r0, c1, c0, 0
35 mcr p15, 0, r0, c1, c0, 0
38 @ Check for security extensions
40 mrc p15, 0, r0, c0, c1, 1
44 mcrne p15, 0, r0, c12, c0, 0 @ Set the VBAR (brings exceptions into high memory)
46 mrceq p15, 0, r0, c1, c0, 0 @ Set SCTLR.V
48 mcreq p15, 0, r0, c1, c0, 0
51 @ Prepare for interrupts
53 ldr sp, =irqstack+0x1000 @ Set up stack
55 ldr sp, =abortstack+0x1000
58 ldr sp, =0x80000000-4 @ Set up stack (top of user range)
61 1: b 1b @ Infinite loop
65 .comm irqstack, 0x1000 @ ; 4KiB Stack
66 .comm abortstack, 0x1000 @ ; 4KiB Stack
68 .extern SyscallHandler
71 srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
82 ldr r4, =SyscallHandler
86 pop {r0,r1} @ Ret/RetHi
87 add sp, #2*4 @ Saved r2/r3
90 rfeia sp! @ Pop state (actually RFEFD)
98 sub lr, #4 @ Adjust LR to the correct value
99 srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
109 @ Call the registered handler
116 rfeia sp! @ Pop state (actually RFEFD)
121 sub lr, #8 @ Adjust LR to the correct value
122 @ srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
126 mrc p15, 0, r4, c5, c0, 0 @ Read DFSR (Data Fault Address Register) to stack
128 mrc p15, 0, r3, c6, c0, 0 @ Read DFAR (Data Fault Address Register) into R3
130 ldr r1, =csDataAbort_Fmt
137 @ rfeia sp! @ Pop state (actually RFEFD)
142 sub lr, #4 @ Adjust LR to the correct value
143 @ srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
148 ldr r1, =csPrefetchAbort_Fmt
150 mrc p15, 0, r3, c5, c0, 0 @ Read IFSR (Instruction Fault Address Register) into R3
161 .asciz "Data Abort - %p accessed %p, DFSR=%x Unk:%x Unk:%x"
163 .asciz "Prefetch Abort at %p, IFSR=%x"
169 .long 0x00000002 @ Identity map the first 1 MiB
173 .long user_table1_map + 0x000 - KERNEL_BASE + 1 @ 0x7FC00000
174 .long user_table1_map + 0x400 - KERNEL_BASE + 1 @ 0x7FD00000
175 .long user_table1_map + 0x800 - KERNEL_BASE + 1 @ KStacks
176 .long user_table1_map + 0xC00 - KERNEL_BASE + 1
177 @ 0x80000000 - User/Kernel split
178 .long 0x00000002 @ Map first 4 MiB to 2GiB
182 .rept 0xF00 - 0x800 - 4
186 .long PCI_PADDR + 0*(1 << 20) + 2 @ Map PCI config space
187 .long PCI_PADDR + 1*(1 << 20) + 2
188 .long PCI_PADDR + 2*(1 << 20) + 2
189 .long PCI_PADDR + 3*(1 << 20) + 2
190 .long PCI_PADDR + 4*(1 << 20) + 2
191 .long PCI_PADDR + 5*(1 << 20) + 2
192 .long PCI_PADDR + 6*(1 << 20) + 2
193 .long PCI_PADDR + 7*(1 << 20) + 2
194 .long PCI_PADDR + 8*(1 << 20) + 2
195 .long PCI_PADDR + 9*(1 << 20) + 2
196 .long PCI_PADDR + 10*(1 << 20) + 2
197 .long PCI_PADDR + 11*(1 << 20) + 2
198 .long PCI_PADDR + 12*(1 << 20) + 2
199 .long PCI_PADDR + 13*(1 << 20) + 2
200 .long PCI_PADDR + 14*(1 << 20) + 2
201 .long PCI_PADDR + 15*(1 << 20) + 2
207 .long hwmap_table_0 + 0x000 - KERNEL_BASE + 1
208 .long hwmap_table_0 + 0x400 - KERNEL_BASE + 1
209 .long hwmap_table_0 + 0x800 - KERNEL_BASE + 1
210 .long hwmap_table_0 + 0xC00 - KERNEL_BASE + 1
211 .rept 0xFF8 - 0xF00 - 16 - 4
215 .long kernel_table1_map + 0x000 - KERNEL_BASE + 1
216 .long kernel_table1_map + 0x400 - KERNEL_BASE + 1
217 .long kernel_table1_map + 0x800 - KERNEL_BASE + 1
218 .long kernel_table1_map + 0xC00 - KERNEL_BASE + 1
219 .long kernel_exception_map + 0x000 - KERNEL_BASE + 1
220 .long kernel_exception_map + 0x400 - KERNEL_BASE + 1
221 .long kernel_exception_map + 0x800 - KERNEL_BASE + 1
222 .long kernel_exception_map + 0xC00 - KERNEL_BASE + 1
225 .globl user_table1_map
226 @ User table1 data table (only the first half is needed)
227 @ - Abused to provide kernel stacks in upper half
228 user_table1_map: @ Size = 4KiB (only 2KiB used)
232 .long user_table1_map - KERNEL_BASE + 0x10 + 3 @ ...1FF000 = 0x7FDFF000
234 .long kernel_table0 + 0x0000 - KERNEL_BASE + 0x10 + 3 @ ...200000 = 0x7FE00000
235 .long kernel_table0 + 0x1000 - KERNEL_BASE + 0x10 + 3 @ ...201000 = 0x7FE01000
236 .rept (0x800/4)-(MM_KSTACK_SIZE/0x1000)-2
239 #if MM_KSTACK_SIZE != 0x2000
240 #error Kernel stack size not changed in start.S
242 .long stack + 0x0000 - KERNEL_BASE + 0x10 + 3 @ Kernel Stack
243 .long stack + 0x1000 - KERNEL_BASE + 0x10 + 3 @
245 .globl kernel_table1_map
246 kernel_table1_map: @ Size = 4KiB
250 .long hwmap_table_0 - KERNEL_BASE + (1 << 4) + 3
251 .rept 0xFF8/4 - (0xF00+16)/4 - 1
254 .long kernel_table1_map - KERNEL_BASE + (1 << 4) + 3
255 .long kernel_exception_map - KERNEL_BASE + 0x13
260 .long UART0_PADDR + (1 << 4) + 3 @ UART0
264 .globl kernel_exception_map
265 kernel_exception_map:
270 @ Align to nearly the end
274 .long 0x213 @ Map first page for exceptions (Kernel RO)
281 .space MM_KSTACK_SIZE, 0 @ Original kernel stack