This source file includes following definitions.
- die_if_kernel
- do_double_fault
- do_general_protection
- do_alignment_check
- do_divide_error
- do_int3
- do_nmi
- do_debug
- do_overflow
- do_bounds
- do_invalid_op
- do_device_not_available
- do_coprocessor_segment_overrun
- do_invalid_TSS
- do_segment_not_present
- do_stack_segment
- math_error
- do_coprocessor_error
- do_reserved
- trap_init
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/head.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/segment.h>
19 #include <linux/ptrace.h>
20
21 #include <asm/system.h>
22 #include <asm/segment.h>
23 #include <asm/io.h>
24
25 #define get_seg_byte(seg,addr) ({ \
26 register char __res; \
27 __asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \
28 :"=a" (__res):"0" (seg),"m" (*(addr))); \
29 __res;})
30
31 #define get_seg_long(seg,addr) ({ \
32 register unsigned long __res; \
33 __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \
34 :"=a" (__res):"0" (seg),"m" (*(addr))); \
35 __res;})
36
37 #define _fs() ({ \
38 register unsigned short __res; \
39 __asm__("mov %%fs,%%ax":"=a" (__res):); \
40 __res;})
41
42 void page_exception(void);
43
44 asmlinkage void divide_error(void);
45 asmlinkage void debug(void);
46 asmlinkage void nmi(void);
47 asmlinkage void int3(void);
48 asmlinkage void overflow(void);
49 asmlinkage void bounds(void);
50 asmlinkage void invalid_op(void);
51 asmlinkage void device_not_available(void);
52 asmlinkage void double_fault(void);
53 asmlinkage void coprocessor_segment_overrun(void);
54 asmlinkage void invalid_TSS(void);
55 asmlinkage void segment_not_present(void);
56 asmlinkage void stack_segment(void);
57 asmlinkage void general_protection(void);
58 asmlinkage void page_fault(void);
59 asmlinkage void coprocessor_error(void);
60 asmlinkage void reserved(void);
61 asmlinkage void alignment_check(void);
62
63 void die_if_kernel(char * str, struct pt_regs * regs, long err)
64 {
65 int i;
66
67 if ((regs->eflags & VM_MASK) || (3 & regs->cs) == 3)
68 return;
69
70 printk("%s: %04lx\n", str, err & 0xffff);
71 printk("EIP: %04x:%08lx\nEFLAGS: %08lx\n", 0xffff & regs->cs,regs->eip,regs->eflags);
72 printk("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
73 regs->eax, regs->ebx, regs->ecx, regs->edx);
74 printk("esi: %08lx edi: %08lx ebp: %08lx\n",
75 regs->esi, regs->edi, regs->ebp);
76 printk("ds: %04x es: %04x fs: %04x gs: %04x\n",
77 regs->ds, regs->es, regs->fs, regs->gs);
78 store_TR(i);
79 printk("Pid: %d, process nr: %d\n", current->pid, 0xffff & i);
80 for(i=0;i<10;i++)
81 printk("%02x ",0xff & get_seg_byte(regs->cs,(i+(char *)regs->eip)));
82 printk("\n");
83 do_exit(SIGSEGV);
84 }
85
86 asmlinkage void do_double_fault(struct pt_regs * regs, long error_code)
87 {
88 send_sig(SIGSEGV, current, 1);
89 die_if_kernel("double fault",regs,error_code);
90 }
91
92 asmlinkage void do_general_protection(struct pt_regs * regs, long error_code)
93 {
94 send_sig(SIGSEGV, current, 1);
95 die_if_kernel("general protection",regs,error_code);
96 }
97
98 asmlinkage void do_alignment_check(struct pt_regs * regs, long error_code)
99 {
100 send_sig(SIGSEGV, current, 1);
101 die_if_kernel("alignment check",regs,error_code);
102 }
103
104 asmlinkage void do_divide_error(struct pt_regs * regs, long error_code)
105 {
106 send_sig(SIGFPE, current, 1);
107 die_if_kernel("divide error",regs,error_code);
108 }
109
110 asmlinkage void do_int3(struct pt_regs * regs, long error_code)
111 {
112 if (current->flags & PF_PTRACED)
113 current->blocked &= ~(1 << (SIGTRAP-1));
114 send_sig(SIGTRAP, current, 1);
115 die_if_kernel("int3",regs,error_code);
116 }
117
118 asmlinkage void do_nmi(struct pt_regs * regs, long error_code)
119 {
120 printk("Uhhuh. NMI received. Dazed and confused, but trying to continue\n");
121 printk("You probably have a hardware problem with your RAM chips\n");
122 }
123
124 asmlinkage void do_debug(struct pt_regs * regs, long error_code)
125 {
126 if (current->flags & PF_PTRACED)
127 current->blocked &= ~(1 << (SIGTRAP-1));
128 send_sig(SIGTRAP, current, 1);
129 if((regs->cs & 3) == 0) {
130
131 __asm__("movl $0,%%edx\n\t" \
132 "movl %%edx,%%db7\n\t" \
133 : \
134 : :"dx");
135
136 return;
137 };
138 die_if_kernel("debug",regs,error_code);
139 }
140
141 asmlinkage void do_overflow(struct pt_regs * regs, long error_code)
142 {
143 send_sig(SIGSEGV, current, 1);
144 die_if_kernel("overflow",regs,error_code);
145 }
146
147 asmlinkage void do_bounds(struct pt_regs * regs, long error_code)
148 {
149 send_sig(SIGSEGV, current, 1);
150 die_if_kernel("bounds",regs,error_code);
151 }
152
153 asmlinkage void do_invalid_op(struct pt_regs * regs, long error_code)
154 {
155 send_sig(SIGILL, current, 1);
156 die_if_kernel("invalid operand",regs,error_code);
157 }
158
159 asmlinkage void do_device_not_available(struct pt_regs * regs, long error_code)
160 {
161 send_sig(SIGSEGV, current, 1);
162 die_if_kernel("device not available",regs,error_code);
163 }
164
165 asmlinkage void do_coprocessor_segment_overrun(struct pt_regs * regs, long error_code)
166 {
167 send_sig(SIGFPE, last_task_used_math, 1);
168 die_if_kernel("coprocessor segment overrun",regs,error_code);
169 }
170
171 asmlinkage void do_invalid_TSS(struct pt_regs * regs,long error_code)
172 {
173 send_sig(SIGSEGV, current, 1);
174 die_if_kernel("invalid TSS",regs,error_code);
175 }
176
177 asmlinkage void do_segment_not_present(struct pt_regs * regs,long error_code)
178 {
179 send_sig(SIGSEGV, current, 1);
180 die_if_kernel("segment not present",regs,error_code);
181 }
182
183 asmlinkage void do_stack_segment(struct pt_regs * regs,long error_code)
184 {
185 send_sig(SIGSEGV, current, 1);
186 die_if_kernel("stack segment",regs,error_code);
187 }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 void math_error(void)
205 {
206 struct i387_hard_struct * env;
207
208 clts();
209 if (!last_task_used_math) {
210 __asm__("fnclex");
211 return;
212 }
213 env = &last_task_used_math->tss.i387.hard;
214 send_sig(SIGFPE, last_task_used_math, 1);
215 __asm__ __volatile__("fnsave %0":"=m" (*env));
216 last_task_used_math = NULL;
217 stts();
218 env->fcs = (env->swd & 0x0000ffff) | (env->fcs & 0xffff0000);
219 env->fos = env->twd;
220 env->swd &= 0xffff0000;
221 env->twd = 0xffffffff;
222 }
223
224 asmlinkage void do_coprocessor_error(struct pt_regs * regs, long error_code)
225 {
226 ignore_irq13 = 1;
227 math_error();
228 }
229
230 asmlinkage void do_reserved(struct pt_regs * regs, long error_code)
231 {
232 send_sig(SIGSEGV, current, 1);
233 die_if_kernel("reserved (15,17-47) error",regs,error_code);
234 }
235
236 void trap_init(void)
237 {
238 int i;
239
240 set_trap_gate(0,÷_error);
241 set_trap_gate(1,&debug);
242 set_trap_gate(2,&nmi);
243 set_system_gate(3,&int3);
244 set_system_gate(4,&overflow);
245 set_system_gate(5,&bounds);
246 set_trap_gate(6,&invalid_op);
247 set_trap_gate(7,&device_not_available);
248 set_trap_gate(8,&double_fault);
249 set_trap_gate(9,&coprocessor_segment_overrun);
250 set_trap_gate(10,&invalid_TSS);
251 set_trap_gate(11,&segment_not_present);
252 set_trap_gate(12,&stack_segment);
253 set_trap_gate(13,&general_protection);
254 set_trap_gate(14,&page_fault);
255 set_trap_gate(15,&reserved);
256 set_trap_gate(16,&coprocessor_error);
257 set_trap_gate(17,&alignment_check);
258 for (i=18;i<48;i++)
259 set_trap_gate(i,&reserved);
260 }