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