Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | /* * linux/kernel/traps.c * * (C) 1991 Linus Torvalds */ /* * 'Traps.c' handles hardware traps and faults after we have saved some * state in 'asm.s'. Currently mostly a debugging-aid, will be extended * to mainly kill the offending process (probably by giving it a signal, * but possibly by killing it outright if necessary). */ #include <linux/string.h> #include <linux/head.h> #include <linux/sched.h> #include <linux/kernel.h> #include <asm/system.h> #include <asm/segment.h> #include <asm/io.h> #include <errno.h> #define get_seg_byte(seg,addr) ({ \ register char __res; \ __asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \ :"=a" (__res):"0" (seg),"m" (*(addr))); \ __res;}) #define get_seg_long(seg,addr) ({ \ register unsigned long __res; \ __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \ :"=a" (__res):"0" (seg),"m" (*(addr))); \ __res;}) #define _fs() ({ \ register unsigned short __res; \ __asm__("mov %%fs,%%ax":"=a" (__res):); \ __res;}) void page_exception(void); void divide_error(void); void debug(void); void nmi(void); void int3(void); void overflow(void); void bounds(void); void invalid_op(void); void device_not_available(void); void double_fault(void); void coprocessor_segment_overrun(void); void invalid_TSS(void); void segment_not_present(void); void stack_segment(void); void general_protection(void); void page_fault(void); void coprocessor_error(void); void reserved(void); void parallel_interrupt(void); void irq13(void); void alignment_check(void); static void die(char * str,long esp_ptr,long nr) { long * esp = (long *) esp_ptr; int i; printk("%s: %04x\n\r",str,nr&0xffff); printk("EIP: %04x:%p\nEFLAGS: %p\n", 0xffff & esp[1],esp[0],esp[2]); if ((0xffff & esp[1]) == 0xf) printk("ESP: %04x:%p\n",0xffff & esp[4],esp[3]); printk("fs: %04x\n",_fs()); printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17)); if ((0xffff & esp[1]) == 0xf) { printk("Stack: "); for (i=0;i<4;i++) printk("%p ",get_seg_long(0x17,i+(long *)esp[3])); printk("\n"); } str(i); printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i); for(i=0;i<10;i++) printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0]))); printk("\n\r"); if ((0xffff & esp[1]) == 0xf) send_sig(SIGSEGV, current, 0); else do_exit(SIGSEGV); } void do_double_fault(long esp, long error_code) { die("double fault",esp,error_code); } void do_general_protection(long esp, long error_code) { die("general protection",esp,error_code); } void do_alignment_check(long esp, long error_code) { die("alignment check",esp,error_code); } void do_divide_error(long esp, long error_code) { die("divide error",esp,error_code); } void do_int3(long esp, long error_code) { send_sig(SIGTRAP, current, 0); } void do_nmi(long esp, long error_code) { die("nmi",esp,error_code); } void do_debug(long esp, long error_code) { send_sig(SIGTRAP, current, 0); } void do_overflow(long esp, long error_code) { die("overflow",esp,error_code); } void do_bounds(long esp, long error_code) { die("bounds",esp,error_code); } void do_invalid_op(long esp, long error_code) { die("invalid operand",esp,error_code); } void do_device_not_available(long esp, long error_code) { die("device not available",esp,error_code); } void do_coprocessor_segment_overrun(long esp, long error_code) { die("coprocessor segment overrun",esp,error_code); } void do_invalid_TSS(long esp,long error_code) { die("invalid TSS",esp,error_code); } void do_segment_not_present(long esp,long error_code) { die("segment not present",esp,error_code); } void do_stack_segment(long esp,long error_code) { die("stack segment",esp,error_code); } void do_coprocessor_error(long esp, long error_code) { if (last_task_used_math != current) return; die("coprocessor error",esp,error_code); } void do_reserved(long esp, long error_code) { die("reserved (15,17-47) error",esp,error_code); } void trap_init(void) { int i; set_trap_gate(0,÷_error); set_trap_gate(1,&debug); set_trap_gate(2,&nmi); set_system_gate(3,&int3); /* int3-5 can be called from all */ set_system_gate(4,&overflow); set_system_gate(5,&bounds); set_trap_gate(6,&invalid_op); set_trap_gate(7,&device_not_available); set_trap_gate(8,&double_fault); set_trap_gate(9,&coprocessor_segment_overrun); set_trap_gate(10,&invalid_TSS); set_trap_gate(11,&segment_not_present); set_trap_gate(12,&stack_segment); set_trap_gate(13,&general_protection); set_trap_gate(14,&page_fault); set_trap_gate(15,&reserved); set_trap_gate(16,&coprocessor_error); set_trap_gate(17,&alignment_check); for (i=18;i<48;i++) set_trap_gate(i,&reserved); set_trap_gate(45,&irq13); outb_p(inb_p(0x21)&0xfb,0x21); outb(inb_p(0xA1)&0xdf,0xA1); set_trap_gate(39,¶llel_interrupt); } |