2 Copyright � 2013-2015, The AROS Development Team. All rights reserved.
7 #include <aros/kernel.h>
8 #include <aros/libcall.h>
9 #include <hardware/intbits.h>
13 #include <proto/exec.h>
14 #include <proto/kernel.h>
16 #include "kernel_cpu.h"
17 #include "kernel_intern.h"
18 #include "kernel_debug.h"
19 #include "kernel_interrupts.h"
20 #include "kernel_intr.h"
22 #define BOOT_STACK_SIZE (256 << 2)
23 #define BOOT_TAGS_SIZE (128 << 3)
30 extern void *__intvecs_start
, *__intvecs_end
;
31 extern void __arm_halt(void);
33 void ictl_enable_irq(uint8_t irq
, struct KernelBase
*KernelBase
)
35 if (__arm_arosintern
.ARMI_IRQEnable
)
36 __arm_arosintern
.ARMI_IRQEnable(irq
);
39 void ictl_disable_irq(uint8_t irq
, struct KernelBase
*KernelBase
)
41 if (__arm_arosintern
.ARMI_IRQDisable
)
42 __arm_arosintern
.ARMI_IRQDisable(irq
);
46 ".globl __arm_halt \n"
47 ".type __arm_halt,%function \n"
53 ** UNDEF INSTRUCTION EXCEPTION
59 ".set MODE_SYSTEM, 0x1f \n"
61 ".globl __vectorhand_undef \n"
62 ".type __vectorhand_undef,%function \n"
63 "__vectorhand_undef: \n"
65 " cpsid i, #" STR(MODE_SYSTEM
)"\n" // switch to system mode, with interrupts disabled..
66 " str sp, [r0, #13*4] \n"
67 " str lr, [r0, #14*4] \n" // store lr in ctx_lr
68 " mov fp, #0 \n" // clear fp
75 void handle_undef(regs_t
*regs
)
77 bug("[Kernel] Trap ARM Undef Exception\n");
78 bug("[Kernel] exception #4 (Illegal instruction)\n");
79 bug("[Kernel] at 0x%p\n", regs
[14]);
81 if (krnRunExceptionHandlers(KernelBase
, 4, regs
))
84 D(bug("[Kernel] exception handler(s) returned\n"));
86 if (core_Trap(4, regs
))
88 D(bug("[Kernel] trap handler(s) returned\n"));
92 bug("[Kernel] UNHANDLED EXCEPTION #4\n");
106 ".globl __vectorhand_reset \n"
107 ".type __vectorhand_reset,%function \n"
108 "__vectorhand_reset: \n"
109 " mov sp, #0x1000 - 16 \n" // re-use bootstrap tmp stack
111 " sub r0, r0, #" STR(BOOT_STACK_SIZE
)"\n" // get the boottag's
112 " sub r0, r0, #" STR(BOOT_TAGS_SIZE
) "\n"
113 " mov fp, #0 \n" // clear fp
115 " ldr pc, 2f \n" // jump into kernel resource
117 "2: .word kernel_cstart \n"
121 /* ** SWI HANDLER ** */
123 /** SWI handled in syscall.c */
127 return address = lr - 4
132 ".set MODE_IRQ, 0x12 \n"
133 ".set MODE_SUPERVISOR, 0x13 \n"
134 ".set MODE_SYSTEM, 0x1f \n"
136 ".globl __vectorhand_irq \n"
137 ".type __vectorhand_irq,%function \n"
138 "__vectorhand_irq: \n"
139 " sub lr, lr, #4 \n" // adjust lr_irq
141 " cpsid i, #MODE_SYSTEM \n" // switch to system mode, with interrupts disabled..
142 " str sp, [r0, #13*4] \n"
143 " str lr, [r0, #14*4] \n" // store lr in ctx_lr
144 " mov fp, #0 \n" // clear fp
148 " cpsid i, #MODE_IRQ \n" // switch to IRQ mode, with interrupts disabled..
150 " ldr r1, [r0, #16*4] \n" // load the spr register
151 " and r1, r1, #31 \n" // mask processor mode
152 " cmp r1, #16 \n" // will we go back to user mode?
153 " cmpne r1, #31 \n" // or maybe system mode which is basically privileged user mode?
154 " bne 1f \n" // no? don't call core_ExitInterrupt!
155 " mov fp, #0 \n" // clear fp
156 " bl core_ExitInterrupt \n"
161 void handle_irq(regs_t
*regs
)
163 DIRQ(bug("[KRN] ## IRQ ##\n"));
165 DREGS(cpu_DumpRegs(regs
));
167 if (__arm_arosintern
.ARMI_IRQProcess
)
168 __arm_arosintern
.ARMI_IRQProcess();
170 DIRQ(bug("[KRN] IRQ processing finished\n"));
177 return address = lr -4
181 __attribute__ ((interrupt ("FIQ"))) void __vectorhand_fiq(void)
183 DIRQ(bug("[KRN] ## FIQ ##\n"));
185 DIRQ(bug("[KRN] FIQ processing finished\n"));
191 ** DATA ABORT EXCEPTION
192 return address = lr - 8
197 ".set MODE_SYSTEM, 0x1f \n"
199 ".globl __vectorhand_dataabort \n"
200 ".type __vectorhand_dataabort,%function \n"
201 "__vectorhand_dataabort: \n"
202 " sub lr, lr, #8 \n" // adjust lr_irq
204 " cpsid i, #MODE_SYSTEM \n" // switch to system mode, with interrupts disabled..
205 " str sp, [r0, #13*4] \n"
206 " str lr, [r0, #14*4] \n" // store lr in ctx_lr
207 " mov fp, #0 \n" // clear fp
209 " bl handle_dataabort \n"
214 void handle_dataabort(regs_t
*regs
)
216 register unsigned int far
;
218 // Read fault address register
219 asm volatile("mrc p15, 0, %[far], c6, c0, 0": [far
] "=r" (far
) );
221 bug("[Kernel] Trap ARM Data Abort Exception\n");
222 bug("[Kernel] exception #2 (Bus Error)\n");
223 bug("[Kernel] attempt to access 0x%p from 0x%p\n", far
, regs
[14]);
225 if (krnRunExceptionHandlers(KernelBase
, 2, regs
))
228 D(bug("[Kernel] exception handler(s) returned\n"));
230 if (core_Trap(2, regs
))
232 D(bug("[Kernel] trap handler(s) returned\n"));
236 bug("[Kernel] UNHANDLED EXCEPTION #2\n");
244 ** PREFETCH ABORT EXCEPTION
245 return address = lr - 4
250 ".set MODE_SYSTEM, 0x1f \n"
252 ".globl __vectorhand_prefetchabort \n"
253 ".type __vectorhand_prefetchabort,%function \n"
254 "__vectorhand_prefetchabort: \n"
255 " sub lr, lr, #4 \n" // adjust lr_irq
257 " cpsid i, #MODE_SYSTEM \n" // switch to system mode, with interrupts disabled..
258 " str sp, [r0, #13*4] \n"
259 " str lr, [r0, #14*4] \n" // store lr in ctx_lr
260 " mov fp, #0 \n" // clear fp
262 " bl handle_prefetchabort \n"
267 void handle_prefetchabort(regs_t
*regs
)
269 bug("[Kernel] Trap ARM Prefetch Abort Exception\n");
270 bug("[Kernel] exception #3 (Address Error)\n");
271 bug("[Kernel] at 0x%p\n", regs
[14]);
273 if (krnRunExceptionHandlers(KernelBase
, 3, regs
))
276 D(bug("[Kernel] exception handler(s) returned\n"));
278 if (core_Trap(3, regs
))
280 D(bug("[Kernel] trap handler(s) returned\n"));
284 bug("[Kernel] UNHANDLED EXCEPTION #3\n");
294 void arm_flush_cache(uint32_t addr
, uint32_t length
)
298 __asm__
__volatile__("mcr p15, 0, %0, c7, c14, 1"::"r"(addr
));
302 __asm__
__volatile__("mcr p15, 0, %0, c7, c10, 4"::"r"(addr
));
305 void arm_icache_invalidate(uint32_t addr
, uint32_t length
)
309 __asm__
__volatile__("mcr p15, 0, %0, c7, c5, 1"::"r"(addr
));
313 __asm__
__volatile__("mcr p15, 0, %0, c7, c10, 4"::"r"(addr
));
316 void core_SetupIntr(void)
319 bug("[KRN] Initializing cpu vectors\n");
321 /* Copy vectors into place */
322 memcpy(0, &__intvecs_start
,
323 (unsigned int)&__intvecs_end
-
324 (unsigned int)&__intvecs_start
);
326 arm_flush_cache(0, 1024);
327 arm_icache_invalidate(0, 1024);
329 D(bug("[KRN] Copied %d bytes from 0x%p to 0x00000000\n", (unsigned int)&__intvecs_end
- (unsigned int)&__intvecs_start
, &__intvecs_start
));
333 bug("[KRN]: Vector dump-:");
334 for (x
=0; x
< (unsigned int)&__intvecs_end
- (unsigned int)&__intvecs_start
; x
++) {
337 bug("\n[KRN]: %08x:", x
);
339 bug(" %02x", *((volatile UBYTE
*)x
));
344 if (__arm_arosintern
.ARMI_IRQInit
)
345 __arm_arosintern
.ARMI_IRQInit();