Fix IO memory access .. SB128 driver makes noises in VMWare - CMI is untested (Curren...
[AROS.git] / arch / i386-pc / exec / traps.c
blob721d375084ada19acae8d847d99c75f520461131
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <asm/segments.h>
7 #include <asm/linkage.h>
8 #include <asm/ptrace.h>
9 #include <exec/alerts.h>
10 #include <proto/exec.h>
11 #include <aros/debug.h>
13 #include "traps.h"
15 #define __text __attribute__((section(".text")))
17 BUILD_COMMON_TRAP()
19 /* 0,1,5-7,9-17,19:
20 return address of these exceptions is the address of faulting instr
21 1,3,4:
22 return address is address of instruction followed by trapping instr
23 (1 can be FAULT and TRAP)
24 others:
25 ABORT = ??? (no information = no return address)
28 BUILD_TRAP(0x00)
29 BUILD_TRAP(0x01)
30 BUILD_TRAP(0x02)
31 BUILD_TRAP(0x03)
32 BUILD_TRAP(0x04)
33 BUILD_TRAP(0x05)
34 BUILD_TRAP(0x06)
35 BUILD_TRAP(0x07)
36 BUILD_TRAP(0x08)
37 BUILD_TRAP(0x09)
38 BUILD_TRAP(0x0a)
39 BUILD_TRAP(0x0b)
40 BUILD_TRAP(0x0c)
41 BUILD_TRAP(0x0d)
42 BUILD_TRAP(0x0e)
43 BUILD_TRAP(0x0f)
44 BUILD_TRAP(0x10)
45 BUILD_TRAP(0x11)
46 BUILD_TRAP(0x12)
47 BUILD_TRAP(0x13)
49 typedef asmlinkage void (*trap_type)(void);
51 const trap_type traps[0x14] __text =
53 TRAP0x00_trap,
54 TRAP0x01_trap,
55 TRAP0x02_trap,
56 TRAP0x03_trap,
57 TRAP0x04_trap,
58 TRAP0x05_trap,
59 TRAP0x06_trap,
60 TRAP0x07_trap,
61 TRAP0x08_trap,
62 TRAP0x09_trap,
63 TRAP0x0a_trap,
64 TRAP0x0b_trap,
65 TRAP0x0c_trap,
66 TRAP0x0d_trap,
67 TRAP0x0e_trap,
68 TRAP0x0f_trap,
69 TRAP0x10_trap,
70 TRAP0x11_trap,
71 TRAP0x12_trap,
72 TRAP0x13_trap
75 typedef struct { long long a; } dummy_double;
76 static const dummy_double *idt_base = (const dummy_double *)0x100;
78 #define _set_gate(gate_addr,type,dpl,addr) \
79 do { \
80 int __d0, __d1; \
81 __asm__ __volatile__ ("movw %%dx,%%ax\n\t" \
82 "movw %4,%%dx\n\t" \
83 "movl %%eax,%0\n\t" \
84 "movl %%edx,%1" \
85 :"=m" (*((long *) (gate_addr))), \
86 "=m" (*(1+(long *) (gate_addr))), "=&a" (__d0), "=&d" (__d1) \
87 :"i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
88 "3" ((char *) (addr)),"2" (KERNEL_CS << 16)); \
89 } while (0)
92 void set_intr_gate(unsigned int n, void *addr)
94 _set_gate(idt_base+n,14,0,addr);
97 void set_system_gate(unsigned int n, void *addr)
99 _set_gate(idt_base+n,14,3,addr);
102 void printException(struct pt_regs regs)
104 kprintf("*** trap: eip = %x eflags = %x ds = %x sp ~= %x\n",
105 regs.eip, regs.eflags, regs.xds, &regs.esp);
108 void handleException(ULONG exceptionNo)
110 ULONG alert;
111 struct Task *task;
112 VOID (*trapHandler)(ULONG, void *);
114 // Determine alert number
115 switch (exceptionNo)
117 case 0:
118 alert = ACPU_DivZero;
119 break;
120 case 6:
121 alert = ACPU_InstErr;
122 break;
123 default:
124 alert = AT_DeadEnd | 0x100 | exceptionNo;
127 // Call task's trap handler
128 task = FindTask(NULL);
129 trapHandler = task->tc_TrapCode;
130 trapHandler(alert, NULL);
133 void Init_Traps(void) {
134 int i;
136 for (i=0;i<20;i++)
138 _set_gate(idt_base+i,14,0,traps[i]);