Annotation of linux/kernel/traps.c, revision 1.1.1.5

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

unix.superglobalmegacorp.com