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 . @ 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
54 @ Enable access faults on domains 0 & 1
55 mov r0, #0x55 @ 01010101b
56 mcr p15, 0, r0, c3, c0, 0
62 @ Check for security extensions
64 mrc p15, 0, r0, c0, c1, 1
68 mcrne p15, 0, r0, c12, c0, 0 @ Set the VBAR (brings exceptions into high memory)
70 mrceq p15, 0, r0, c1, c0, 0 @ Set SCTLR.V
72 mcreq p15, 0, r0, c1, c0, 0
77 @ Prepare for interrupts
79 ldr sp, =irqstack+0x1000 @ Set up stack
81 ldr sp, =abortstack+0x1000
91 ldr sp, =0x80000000-4 @ Set up stack (top of user range)
94 1: b 1b @ Infinite loop
98 .comm irqstack, 0x1000 @ ; 4KiB Stack
99 .comm abortstack, 0x1000 @ ; 4KiB Stack
101 .extern SyscallHandler
104 srsdb sp!, #19 @ Save state to stack
105 cpsie ifa, #19 @ Ensure we're in supervisor with interrupts enabled (should already be there)
118 ldr r4, =SyscallHandler
121 @ ldr r0, =csSyscallPrintRetAddr
122 @ ldr r1, [sp,#9*4+5*4]
127 pop {r0,r1} @ Ret/RetHi
128 add sp, #2*4 @ Saved r2/r3
131 rfeia sp! @ Pop state (actually RFEFD)
135 mov r1, sp @ Arguments
137 ldr r4, =ARMv7_int_HandleSyscalls
146 gpIRQHandler: .long 0
147 IRQ_saved_sp: .long 0
148 IRQ_saved_lr: .long 0
151 sub lr, #4 @ Adjust LR to the correct value
152 srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
162 @ Call the registered handler
169 rfeia sp! @ Pop state (actually RFEFD)
174 sub lr, #8 @ Adjust LR to the correct value
175 srsdb sp!, #23 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
179 mov r3, #0 @ not a prefetch abort
180 mrc p15, 0, r2, c5, c0, 0 @ Read DFSR (Data Fault Status Register) to R2
181 mrc p15, 0, r1, c6, c0, 0 @ Read DFAR (Data Fault Address Register) into R1
183 ldr r4, =MM_PageFault
187 rfeia sp! @ Pop state (actually RFEFD)
191 sub lr, #4 @ Adjust LR to the correct value
192 @ srsdb sp!, #19 @ Switch to supervisor mode (DDI0406B D1.6.5) (actually SRSFD)
197 ldr r1, =csPrefetchAbort_Fmt
199 mrc p15, 0, r3, c5, c0, 0 @ Read IFSR (Instruction Fault Address Register) into R3
211 .asciz "Data Abort - %p accessed %p, DFSR=%x Unk:%x Unk:%x"
213 .asciz "Prefetch Abort at %p, IFSR=%x"
214 csSyscallPrintRetAddr:
215 .asciz "Syscall ret to %p"
221 .long 0x00000402 @ Identity map the first 1 MiB
225 .long user_table1_map + 0x000 - KERNEL_BASE + 1 @ 0x7FC00000
226 .long user_table1_map + 0x400 - KERNEL_BASE + 1 @ 0x7FD00000
227 .long user_table1_map + 0x800 - KERNEL_BASE + 1 @ KStacks
228 .long user_table1_map + 0xC00 - KERNEL_BASE + 1
229 @ 0x80000000 - User/Kernel split
230 .long 0x00000402 @ Map first 4 MiB to 2GiB (KRW only)
234 .rept 0xF00 - 0x800 - 4
238 .long PCI_PADDR + 0*(1 << 20) + 0x402 @ Map PCI config space
239 .long PCI_PADDR + 1*(1 << 20) + 0x402
240 .long PCI_PADDR + 2*(1 << 20) + 0x402
241 .long PCI_PADDR + 3*(1 << 20) + 0x402
242 .long PCI_PADDR + 4*(1 << 20) + 0x402
243 .long PCI_PADDR + 5*(1 << 20) + 0x402
244 .long PCI_PADDR + 6*(1 << 20) + 0x402
245 .long PCI_PADDR + 7*(1 << 20) + 0x402
246 .long PCI_PADDR + 8*(1 << 20) + 0x402
247 .long PCI_PADDR + 9*(1 << 20) + 0x402
248 .long PCI_PADDR + 10*(1 << 20) + 0x402
249 .long PCI_PADDR + 11*(1 << 20) + 0x402
250 .long PCI_PADDR + 12*(1 << 20) + 0x402
251 .long PCI_PADDR + 13*(1 << 20) + 0x402
252 .long PCI_PADDR + 14*(1 << 20) + 0x402
253 .long PCI_PADDR + 15*(1 << 20) + 0x402
259 .long hwmap_table_0 + 0x000 - KERNEL_BASE + 1
260 .long hwmap_table_0 + 0x400 - KERNEL_BASE + 1
261 .long hwmap_table_0 + 0x800 - KERNEL_BASE + 1
262 .long hwmap_table_0 + 0xC00 - KERNEL_BASE + 1
263 .rept 0xFF8 - 0xF00 - 16 - 4
267 .long kernel_table1_map + 0x000 - KERNEL_BASE + 1
268 .long kernel_table1_map + 0x400 - KERNEL_BASE + 1
269 .long kernel_table1_map + 0x800 - KERNEL_BASE + 1
270 .long kernel_table1_map + 0xC00 - KERNEL_BASE + 1
271 .long kernel_exception_map + 0x000 - KERNEL_BASE + 1
272 .long kernel_exception_map + 0x400 - KERNEL_BASE + 1
273 .long kernel_exception_map + 0x800 - KERNEL_BASE + 1
274 .long kernel_exception_map + 0xC00 - KERNEL_BASE + 1
277 .globl user_table1_map
278 @ User table1 data table (only the first half is needed)
279 @ - Abused to provide kernel stacks in the unused half of the table
280 user_table1_map: @ Size = 4KiB (only 2KiB used)
284 .long user_table1_map - KERNEL_BASE + 0x13 @ ...1FF000 = 0x7FDFF000
286 .long kernel_table0 + 0x0000 - KERNEL_BASE + 0x13 @ ...200000 = 0x7FE00000
287 .long kernel_table0 + 0x1000 - KERNEL_BASE + 0x13 @ ...201000 = 0x7FE01000
288 .rept (0x800/4)-(MM_KSTACK_SIZE/0x1000)-2
291 #if MM_KSTACK_SIZE != 0x2000
292 #error Kernel stack size not changed in start.S
294 .long stack + 0x0000 - KERNEL_BASE + 0x13 @ Kernel Stack
295 .long stack + 0x1000 - KERNEL_BASE + 0x13 @
297 .globl kernel_table1_map
298 kernel_table1_map: @ Size = 4KiB
302 .long hwmap_table_0 - KERNEL_BASE + 0x13
303 .rept 0xFF8/4 - (0xF00+16)/4 - 1
306 .long kernel_table1_map - KERNEL_BASE + 0x13
307 .long kernel_exception_map - KERNEL_BASE + 0x13
312 .long UART0_PADDR + 0x13 @ UART0
316 .globl kernel_exception_map
317 kernel_exception_map:
322 @ Align to nearly the end
326 .long 0x212 @ Map first page for exceptions (Kernel RO, Execute)
330 .long gUsertextPhysStart + 0x22 @ User .text (User RO, Kernel RW, because both is COW)
335 .space MM_KSTACK_SIZE, 0 @ Original kernel stack
337 // vim: ts=8, ft=armv7