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