This source file includes following definitions.
- console_verbose
- die_if_kernel
- DO_ERROR
- do_nmi
- do_debug
- math_error
- do_coprocessor_error
- math_state_restore
- math_emulate
- 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/ptrace.h>
19 #include <linux/config.h>
20 #include <linux/timer.h>
21 #include <linux/mm.h>
22
23 #include <asm/system.h>
24 #include <asm/segment.h>
25 #include <asm/io.h>
26
27 asmlinkage int system_call(void);
28 asmlinkage void lcall7(void);
29 struct desc_struct default_ldt;
30
31 static inline void console_verbose(void)
32 {
33 extern int console_loglevel;
34 console_loglevel = 15;
35 }
36
37 #define DO_ERROR(trapnr, signr, str, name, tsk) \
38 asmlinkage void do_##name(struct pt_regs * regs, long error_code) \
39 { \
40 tsk->tss.error_code = error_code; \
41 tsk->tss.trap_no = trapnr; \
42 if (signr == SIGTRAP && current->flags & PF_PTRACED) \
43 current->blocked &= ~(1 << (SIGTRAP-1)); \
44 send_sig(signr, tsk, 1); \
45 die_if_kernel(str,regs,error_code); \
46 }
47
48 #define get_seg_byte(seg,addr) ({ \
49 register unsigned char __res; \
50 __asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \
51 :"=a" (__res):"0" (seg),"m" (*(addr))); \
52 __res;})
53
54 #define get_seg_long(seg,addr) ({ \
55 register unsigned long __res; \
56 __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \
57 :"=a" (__res):"0" (seg),"m" (*(addr))); \
58 __res;})
59
60 #define _fs() ({ \
61 register unsigned short __res; \
62 __asm__("mov %%fs,%%ax":"=a" (__res):); \
63 __res;})
64
65 void page_exception(void);
66
67 asmlinkage void divide_error(void);
68 asmlinkage void debug(void);
69 asmlinkage void nmi(void);
70 asmlinkage void int3(void);
71 asmlinkage void overflow(void);
72 asmlinkage void bounds(void);
73 asmlinkage void invalid_op(void);
74 asmlinkage void device_not_available(void);
75 asmlinkage void double_fault(void);
76 asmlinkage void coprocessor_segment_overrun(void);
77 asmlinkage void invalid_TSS(void);
78 asmlinkage void segment_not_present(void);
79 asmlinkage void stack_segment(void);
80 asmlinkage void general_protection(void);
81 asmlinkage void page_fault(void);
82 asmlinkage void coprocessor_error(void);
83 asmlinkage void reserved(void);
84 asmlinkage void alignment_check(void);
85
86 int kstack_depth_to_print = 24;
87
88
89
90
91
92
93 #define VMALLOC_OFFSET (8*1024*1024)
94 #define MODULE_RANGE (8*1024*1024)
95
96 void die_if_kernel(char * str, struct pt_regs * regs, long err)
97 {
98 int i;
99 unsigned long esp;
100 unsigned short ss;
101 unsigned long *stack, addr, module_start, module_end;
102 extern char start_kernel, etext;
103
104 esp = (unsigned long) ®s->esp;
105 ss = KERNEL_DS;
106 if ((regs->eflags & VM_MASK) || (3 & regs->cs) == 3)
107 return;
108 if (regs->cs & 3) {
109 esp = regs->esp;
110 ss = regs->ss;
111 }
112 console_verbose();
113 printk("%s: %04lx\n", str, err & 0xffff);
114 printk("EIP: %04x:%08lx\nEFLAGS: %08lx\n", 0xffff & regs->cs,regs->eip,regs->eflags);
115 printk("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
116 regs->eax, regs->ebx, regs->ecx, regs->edx);
117 printk("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
118 regs->esi, regs->edi, regs->ebp, esp);
119 printk("ds: %04x es: %04x fs: %04x gs: %04x ss: %04x\n",
120 regs->ds, regs->es, regs->fs, regs->gs, ss);
121 store_TR(i);
122 if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
123 printk("Corrupted stack page\n");
124 printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)\nStack: ",
125 current->comm, current->pid, 0xffff & i, current->kernel_stack_page);
126 stack = (unsigned long *) esp;
127 for(i=0; i < kstack_depth_to_print; i++) {
128 if (((long) stack & 4095) == 0)
129 break;
130 if (i && ((i % 8) == 0))
131 printk("\n ");
132 printk("%08lx ", get_seg_long(ss,stack++));
133 }
134 printk("\nCall Trace: ");
135 stack = (unsigned long *) esp;
136 i = 1;
137 module_start = ((high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1));
138 module_end = module_start + MODULE_RANGE;
139 while (((long) stack & 4095) != 0) {
140 addr = get_seg_long(ss, stack++);
141
142
143
144
145
146
147
148
149 if (((addr >= (unsigned long) &start_kernel) &&
150 (addr <= (unsigned long) &etext)) ||
151 ((addr >= module_start) && (addr <= module_end))) {
152 if (i && ((i % 8) == 0))
153 printk("\n ");
154 printk("%08lx ", addr);
155 i++;
156 }
157 }
158 printk("\nCode: ");
159 for(i=0;i<20;i++)
160 printk("%02x ",0xff & get_seg_byte(regs->cs,(i+(char *)regs->eip)));
161 printk("\n");
162 do_exit(SIGSEGV);
163 }
164
165 DO_ERROR( 0, SIGFPE, "divide error", divide_error, current)
166 DO_ERROR( 3, SIGTRAP, "int3", int3, current)
167 DO_ERROR( 4, SIGSEGV, "overflow", overflow, current)
168 DO_ERROR( 5, SIGSEGV, "bounds", bounds, current)
169 DO_ERROR( 6, SIGILL, "invalid operand", invalid_op, current)
170 DO_ERROR( 7, SIGSEGV, "device not available", device_not_available, current)
171 DO_ERROR( 8, SIGSEGV, "double fault", double_fault, current)
172 DO_ERROR( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun, last_task_used_math)
173 DO_ERROR(10, SIGSEGV, "invalid TSS", invalid_TSS, current)
174 DO_ERROR(11, SIGBUS, "segment not present", segment_not_present, current)
175 DO_ERROR(12, SIGBUS, "stack segment", stack_segment, current)
176 DO_ERROR(15, SIGSEGV, "reserved", reserved, current)
177 DO_ERROR(17, SIGSEGV, "alignment check", alignment_check, current)
178
179 asmlinkage void do_general_protection(struct pt_regs * regs, long error_code)
180 {
181 int signr = SIGSEGV;
182
183 if (regs->eflags & VM_MASK) {
184 handle_vm86_fault((struct vm86_regs *) regs, error_code);
185 return;
186 }
187 die_if_kernel("general protection",regs,error_code);
188 switch (get_seg_byte(regs->cs, (char *)regs->eip)) {
189 case 0xCD:
190 case 0xF4:
191 case 0xFA:
192 case 0xFB:
193 signr = SIGILL;
194 }
195 current->tss.error_code = error_code;
196 current->tss.trap_no = 13;
197 send_sig(signr, current, 1);
198 }
199
200 asmlinkage void do_nmi(struct pt_regs * regs, long error_code)
201 {
202 printk("Uhhuh. NMI received. Dazed and confused, but trying to continue\n");
203 printk("You probably have a hardware problem with your RAM chips\n");
204 }
205
206 asmlinkage void do_debug(struct pt_regs * regs, long error_code)
207 {
208 if (regs->eflags & VM_MASK) {
209 handle_vm86_debug((struct vm86_regs *) regs, error_code);
210 return;
211 }
212 if (current->flags & PF_PTRACED)
213 current->blocked &= ~(1 << (SIGTRAP-1));
214 send_sig(SIGTRAP, current, 1);
215 current->tss.trap_no = 1;
216 current->tss.error_code = error_code;
217 if ((regs->cs & 3) == 0) {
218
219 __asm__("movl %0,%%db7"
220 :
221 : "r" (0));
222 return;
223 }
224 die_if_kernel("debug",regs,error_code);
225 }
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242 void math_error(void)
243 {
244 struct i387_hard_struct * env;
245
246 clts();
247 if (!last_task_used_math) {
248 __asm__("fnclex");
249 return;
250 }
251 env = &last_task_used_math->tss.i387.hard;
252 send_sig(SIGFPE, last_task_used_math, 1);
253 last_task_used_math->tss.trap_no = 16;
254 last_task_used_math->tss.error_code = 0;
255 __asm__ __volatile__("fnsave %0":"=m" (*env));
256 last_task_used_math = NULL;
257 stts();
258 env->fcs = (env->swd & 0x0000ffff) | (env->fcs & 0xffff0000);
259 env->fos = env->twd;
260 env->swd &= 0xffff3800;
261 env->twd = 0xffffffff;
262 }
263
264 asmlinkage void do_coprocessor_error(struct pt_regs * regs, long error_code)
265 {
266 ignore_irq13 = 1;
267 math_error();
268 }
269
270
271
272
273
274
275
276
277 asmlinkage void math_state_restore(void)
278 {
279 __asm__ __volatile__("clts");
280 if (last_task_used_math == current)
281 return;
282 timer_table[COPRO_TIMER].expires = jiffies+50;
283 timer_active |= 1<<COPRO_TIMER;
284 if (last_task_used_math)
285 __asm__("fnsave %0":"=m" (last_task_used_math->tss.i387));
286 else
287 __asm__("fnclex");
288 last_task_used_math = current;
289 if (current->used_math) {
290 __asm__("frstor %0": :"m" (current->tss.i387));
291 } else {
292 __asm__("fninit");
293 current->used_math=1;
294 }
295 timer_active &= ~(1<<COPRO_TIMER);
296 }
297
298 #ifndef CONFIG_MATH_EMULATION
299
300 asmlinkage void math_emulate(long arg)
301 {
302 printk("math-emulation not enabled and no coprocessor found.\n");
303 printk("killing %s.\n",current->comm);
304 send_sig(SIGFPE,current,1);
305 schedule();
306 }
307
308 #endif
309
310 void trap_init(void)
311 {
312 int i;
313 struct desc_struct * p;
314
315 if (strncmp((char*)0x0FFFD9, "EISA", 4) == 0)
316 EISA_bus = 1;
317 set_call_gate(&default_ldt,lcall7);
318 set_trap_gate(0,÷_error);
319 set_trap_gate(1,&debug);
320 set_trap_gate(2,&nmi);
321 set_system_gate(3,&int3);
322 set_system_gate(4,&overflow);
323 set_system_gate(5,&bounds);
324 set_trap_gate(6,&invalid_op);
325 set_trap_gate(7,&device_not_available);
326 set_trap_gate(8,&double_fault);
327 set_trap_gate(9,&coprocessor_segment_overrun);
328 set_trap_gate(10,&invalid_TSS);
329 set_trap_gate(11,&segment_not_present);
330 set_trap_gate(12,&stack_segment);
331 set_trap_gate(13,&general_protection);
332 set_trap_gate(14,&page_fault);
333 set_trap_gate(15,&reserved);
334 set_trap_gate(16,&coprocessor_error);
335 set_trap_gate(17,&alignment_check);
336 for (i=18;i<48;i++)
337 set_trap_gate(i,&reserved);
338 set_system_gate(0x80,&system_call);
339
340 p = gdt+FIRST_TSS_ENTRY;
341 set_tss_desc(p, &init_task.tss);
342 p++;
343 set_ldt_desc(p, &default_ldt, 1);
344 p++;
345 for(i=1 ; i<NR_TASKS ; i++) {
346 p->a=p->b=0;
347 p++;
348 p->a=p->b=0;
349 p++;
350 }
351
352 __asm__("pushfl ; andl $0xffffbfff,(%esp) ; popfl");
353 load_TR(0);
354 load_ldt(0);
355 }