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 @ 0x00 Reset
11 ivt_undef: b Undef_Handler @ 0x04 #UD
12 ivt_svc: b SVC_Handler @ 0x08 SVC (used to be called SWI)
13 ivt_prefetch: b PrefetchAbort @ 0x0C Prefetch abort
14 ivt_data: b DataAbort @ 0x10 Data abort
15 ivt_unused: b . @ 0x14 Not Used
16 ivt_irq: b IRQHandler @ 0x18 IRQ
17 ivt_fiq: b . @ 0x1C FIQ (Fast interrupt)
25 ldr r0, =kernel_table0-KERNEL_BASE
26 mcr p15, 0, r0, c2, c0, 1 @ Set TTBR1 to r0
27 mcr p15, 0, r0, c2, c0, 0 @ Set TTBR0 to r0 too (for identity)
33 mcr p15, 0, r0, c2, c0, 2 @ Set TTCR to 1 (50/50 split)
39 mcr p15, 0, r0, c3, c0, 0 @ Set Domain 0 to Manager
45 mrc p15, 0, r0, c1, c0, 0
48 mcr p15, 0, r0, c1, c0, 0
50 @ HACK: Set ASID to non zero
58 @ Enable access faults on domains 0 & 1
59 mov r0, #0x55 @ 01010101b
60 mcr p15, 0, r0, c3, c0, 0
66 @ Check for security extensions
68 mrc p15, 0, r0, c0, c1, 1
72 mcrne p15, 0, r0, c12, c0, 0 @ Set the VBAR (brings exceptions into high memory)
74 mrceq p15, 0, r0, c1, c0, 0 @ Set SCTLR.V
76 mcreq p15, 0, r0, c1, c0, 0
81 @ Prepare for interrupts
83 ldr sp, =irqstack+0x1000 @ Set up stack
85 ldr sp, =abortstack+0x1000
100 .extern bss_size_div_4
111 ldr sp, =0x80000000-8 @ Set up stack (top of user range)
114 1: b 1b @ Infinite loop
116 .comm irqstack, 0x1000 @ ; 4KiB Stack
117 .comm abortstack, 0x1000 @ ; 4KiB Stack
119 .extern SyscallHandler
122 srsdb sp!, #19 @ Save state to stack
123 cpsie ifa, #19 @ Ensure we're in supervisor with interrupts enabled (should already be there)
136 ldr r4, =SyscallHandler
139 @ ldr r0, =csSyscallPrintRetAddr
140 @ ldr r1, [sp,#9*4+5*4]
145 pop {r0,r1} @ Ret/RetHi
146 add sp, #2*4 @ Saved r2/r3
149 rfeia sp! @ Pop state (actually RFEFD)
153 mov r1, sp @ Arguments
155 ldr r4, =ARMv7_int_HandleSyscalls
164 gpIRQHandler: .long 0
165 IRQ_saved_sp: .long 0
166 IRQ_saved_lr: .long 0
169 sub lr, #4 @ Adjust LR to the correct value
170 srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
180 @ Call the registered handler
187 rfeia sp! @ Pop state (actually RFEFD)
192 sub lr, #8 @ Adjust LR to the correct value
193 srsdb sp!, #23 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
197 mov r3, #0 @ not a prefetch abort
198 mrc p15, 0, r2, c5, c0, 0 @ Read DFSR (Data Fault Status Register) to R2
199 mrc p15, 0, r1, c6, c0, 0 @ Read DFAR (Data Fault Address Register) into R1
201 ldr r4, =MM_PageFault
205 rfeia sp! @ Pop state (actually RFEFD)
209 sub lr, #4 @ Adjust LR to the correct value
210 srsdb sp!, #23 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
215 ldr r1, =csPrefetchAbort_Fmt
217 mrc p15, 0, r2, c6, c0, 2 @ Read IFAR (Instruction Fault Address Register) into R3
218 mrc p15, 0, r3, c5, c0, 1 @ Read IFSR (Instruction Fault Status Register) into R3
239 .asciz "Data Abort - %p accessed %p, DFSR=%x Unk:%x Unk:%x"
241 .asciz "Prefetch Abort at %p, IFSR=%x"
242 csSyscallPrintRetAddr:
243 .asciz "Syscall ret to %p"
249 .long 0x00000402 @ Identity map the first 1 MiB
253 .long user_table1_map + 0x000 - KERNEL_BASE + 1 @ 0x7FC00000
254 .long user_table1_map + 0x400 - KERNEL_BASE + 1 @ 0x7FD00000
255 .long user_table1_map + 0x800 - KERNEL_BASE + 1 @ KStacks
256 .long user_table1_map + 0xC00 - KERNEL_BASE + 1
257 @ 0x80000000 - User/Kernel split
258 .long 0x00000402 @ Map first 4 MiB to 2GiB (KRW only)
262 .rept 0xF00 - 0x800 - 4
266 .long PCI_PADDR + 0*(1 << 20) + 0x402 @ Map PCI config space
267 .long PCI_PADDR + 1*(1 << 20) + 0x402
268 .long PCI_PADDR + 2*(1 << 20) + 0x402
269 .long PCI_PADDR + 3*(1 << 20) + 0x402
270 .long PCI_PADDR + 4*(1 << 20) + 0x402
271 .long PCI_PADDR + 5*(1 << 20) + 0x402
272 .long PCI_PADDR + 6*(1 << 20) + 0x402
273 .long PCI_PADDR + 7*(1 << 20) + 0x402
274 .long PCI_PADDR + 8*(1 << 20) + 0x402
275 .long PCI_PADDR + 9*(1 << 20) + 0x402
276 .long PCI_PADDR + 10*(1 << 20) + 0x402
277 .long PCI_PADDR + 11*(1 << 20) + 0x402
278 .long PCI_PADDR + 12*(1 << 20) + 0x402
279 .long PCI_PADDR + 13*(1 << 20) + 0x402
280 .long PCI_PADDR + 14*(1 << 20) + 0x402
281 .long PCI_PADDR + 15*(1 << 20) + 0x402
287 .long hwmap_table_0 + 0x000 - KERNEL_BASE + 1
288 .long hwmap_table_0 + 0x400 - KERNEL_BASE + 1
289 .long hwmap_table_0 + 0x800 - KERNEL_BASE + 1
290 .long hwmap_table_0 + 0xC00 - KERNEL_BASE + 1
291 .rept 0xFF8 - 0xF00 - 16 - 4
295 .long kernel_table1_map + 0x000 - KERNEL_BASE + 1
296 .long kernel_table1_map + 0x400 - KERNEL_BASE + 1
297 .long kernel_table1_map + 0x800 - KERNEL_BASE + 1
298 .long kernel_table1_map + 0xC00 - KERNEL_BASE + 1
299 .long kernel_exception_map + 0x000 - KERNEL_BASE + 1
300 .long kernel_exception_map + 0x400 - KERNEL_BASE + 1
301 .long kernel_exception_map + 0x800 - KERNEL_BASE + 1
302 .long kernel_exception_map + 0xC00 - KERNEL_BASE + 1
305 .globl user_table1_map
306 @ User table1 data table (only the first half is needed)
307 @ - Abused to provide kernel stacks in the unused half of the table
308 user_table1_map: @ Size = 4KiB (only 2KiB used)
312 .long user_table1_map - KERNEL_BASE + 0x13 @ ...1FF000 = 0x7FDFF000
314 .long kernel_table0 + 0x0000 - KERNEL_BASE + 0x13 @ ...200000 = 0x7FE00000
315 .long kernel_table0 + 0x1000 - KERNEL_BASE + 0x13 @ ...201000 = 0x7FE01000
316 .rept (0x800/4)-(MM_KSTACK_SIZE/0x1000)-2
319 #if MM_KSTACK_SIZE != 0x2000
320 #error Kernel stack size not changed in start.S
322 .long stack + 0x0000 - KERNEL_BASE + 0x13 @ Kernel Stack
323 .long stack + 0x1000 - KERNEL_BASE + 0x13 @
325 .globl kernel_table1_map
326 kernel_table1_map: @ Size = 4KiB
330 .long hwmap_table_0 - KERNEL_BASE + 0x13
331 .rept 0xFF8/4 - (0xF00+16)/4 - 1
334 .long kernel_table1_map - KERNEL_BASE + 0x13
335 .long kernel_exception_map - KERNEL_BASE + 0x13
340 .long UART0_PADDR + 0x13 @ UART0
344 .globl kernel_exception_map
345 kernel_exception_map:
350 @ Align to nearly the end
354 .long 0x212 @ Map first page for exceptions (Kernel RO, Execute)
358 .long gUsertextPhysStart + 0x22 @ User .text (User RO, Kernel RW, because both is COW)
363 .space MM_KSTACK_SIZE, 0 @ Original kernel stack
365 // vim: ts=8 ft=armv7