revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-pc / kernel / cpu_traps.c
bloba4b3c24afc1566092eb47951665ddce253f25b27
1 /*
2 Copyright © 2011-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Common trap handling routines for x86 CPU
6 Lang: English
7 */
9 #include <exec/execbase.h>
10 #include <exec/tasks.h>
11 #include <proto/exec.h>
13 #include "kernel_base.h"
14 #include "kernel_debug.h"
15 #include "kernel_interrupts.h"
16 #include "kernel_intr.h"
17 #include "cpu_traps.h"
19 #define D(x)
20 #define DUMP_CONTEXT
22 #ifdef DUMP_CONTEXT
24 static void PrintContext(struct ExceptionContext *regs, unsigned long error_code)
26 int i;
27 unsigned long *ptr;
28 struct Task *t = GET_THIS_TASK;
30 if (t)
32 bug("[Kernel] %s %p '%s'\n", t->tc_Node.ln_Type == NT_TASK?"task":"process", t, t->tc_Node.ln_Name);
33 bug("[Kernel] SPLower=%p SPUpper=%p\n", t->tc_SPLower, t->tc_SPUpper);
35 if (((void *)SP(regs) < t->tc_SPLower) || ((void *)SP(regs) > t->tc_SPUpper))
36 bug("[Kernel] Stack out of Bounds!\n");
39 bug("[Kernel] Error 0x%p\n", error_code);
40 PRINT_CPUCONTEXT(regs);
42 bug("[Kernel] Stack:\n");
43 ptr = (unsigned long *)SP(regs);
44 for (i=0; i < 10; i++)
45 bug("[Kernel] %02x: %p\n", i * sizeof(unsigned long), ptr[i]);
48 #else
50 #define PrintContext(regs, err)
52 #endif
55 * This table is used to translate x86 trap number
56 * to AmigaOS trap number to be passed to exec exception handler.
58 #define AMIGATRAP_COUNT 19
59 static const char AmigaTraps[AMIGATRAP_COUNT] =
61 5, 9, -1, 4, 11, 2,
62 4, 0, 8, 11, 3, 3,
63 2, 8, 3, -1, 11, 3,
67 void cpu_Trap(struct ExceptionContext *regs, unsigned long error_code, unsigned long irq_number)
69 D(bug("[Kernel] Trap exception %u\n", irq_number));
71 if (krnRunExceptionHandlers(KernelBase, irq_number, regs))
72 return;
74 if ((irq_number < AMIGATRAP_COUNT) && (AmigaTraps[irq_number] != -1))
76 D(bug("[Kernel] Passing on to exec, Amiga trap %d\n", AmigaTraps[irq_number]));
78 if (core_Trap(AmigaTraps[irq_number], regs))
80 /* If the trap handler returned, we can continue */
81 D(bug("[Kernel] Trap handler returned\n"));
82 return;
86 bug("[Kernel] UNHANDLED EXCEPTION %lu\n", irq_number);
87 PrintContext(regs, error_code);
89 while (1) asm volatile ("hlt");