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

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:  */
                     13: #include <string.h>
                     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.1.4 ! root       63: int send_sig(long, struct task_struct *, int);
1.1       root       64: 
                     65: static void die(char * str,long esp_ptr,long nr)
                     66: {
                     67:        long * esp = (long *) esp_ptr;
                     68:        int i;
                     69: 
                     70:        printk("%s: %04x\n\r",str,nr&0xffff);
1.1.1.4 ! root       71:        printk("EIP:    %04x:%p\nEFLAGS: %p\n", 0xffff & esp[1],esp[0],esp[2]);
        !            72:        if ((0xffff & esp[1]) == 0xf)
        !            73:                printk("ESP:    %04x:%p\n",0xffff & esp[4],esp[3]);
1.1       root       74:        printk("fs: %04x\n",_fs());
                     75:        printk("base: %p, limit: %p\n",get_base(current->ldt[1]),get_limit(0x17));
1.1.1.4 ! root       76:        if ((0xffff & esp[1]) == 0xf) {
1.1       root       77:                printk("Stack: ");
                     78:                for (i=0;i<4;i++)
                     79:                        printk("%p ",get_seg_long(0x17,i+(long *)esp[3]));
                     80:                printk("\n");
                     81:        }
                     82:        str(i);
                     83:        printk("Pid: %d, process nr: %d\n\r",current->pid,0xffff & i);
                     84:        for(i=0;i<10;i++)
                     85:                printk("%02x ",0xff & get_seg_byte(esp[1],(i+(char *)esp[0])));
                     86:        printk("\n\r");
                     87:        do_exit(11);            /* play segment exception */
                     88: }
                     89: 
                     90: void do_double_fault(long esp, long error_code)
                     91: {
                     92:        die("double fault",esp,error_code);
                     93: }
                     94: 
                     95: void do_general_protection(long esp, long error_code)
                     96: {
                     97:        die("general protection",esp,error_code);
                     98: }
                     99: 
1.1.1.3   root      100: void do_alignment_check(long esp, long error_code)
                    101: {
                    102:     die("alignment check",esp,error_code);
                    103: }
                    104: 
1.1       root      105: void do_divide_error(long esp, long error_code)
                    106: {
                    107:        die("divide error",esp,error_code);
                    108: }
                    109: 
1.1.1.4 ! root      110: void do_int3(long esp, long error_code)
        !           111: {
        !           112:        send_sig(SIGTRAP, current, 0);
1.1       root      113: }
                    114: 
                    115: void do_nmi(long esp, long error_code)
                    116: {
                    117:        die("nmi",esp,error_code);
                    118: }
                    119: 
                    120: void do_debug(long esp, long error_code)
                    121: {
1.1.1.4 ! root      122:   send_sig(SIGTRAP, current, 0);
1.1       root      123: }
                    124: 
                    125: void do_overflow(long esp, long error_code)
                    126: {
                    127:        die("overflow",esp,error_code);
                    128: }
                    129: 
                    130: void do_bounds(long esp, long error_code)
                    131: {
                    132:        die("bounds",esp,error_code);
                    133: }
                    134: 
                    135: void do_invalid_op(long esp, long error_code)
                    136: {
                    137:        die("invalid operand",esp,error_code);
                    138: }
                    139: 
                    140: void do_device_not_available(long esp, long error_code)
                    141: {
                    142:        die("device not available",esp,error_code);
                    143: }
                    144: 
                    145: void do_coprocessor_segment_overrun(long esp, long error_code)
                    146: {
                    147:        die("coprocessor segment overrun",esp,error_code);
                    148: }
                    149: 
                    150: void do_invalid_TSS(long esp,long error_code)
                    151: {
                    152:        die("invalid TSS",esp,error_code);
                    153: }
                    154: 
                    155: void do_segment_not_present(long esp,long error_code)
                    156: {
                    157:        die("segment not present",esp,error_code);
                    158: }
                    159: 
                    160: void do_stack_segment(long esp,long error_code)
                    161: {
                    162:        die("stack segment",esp,error_code);
                    163: }
                    164: 
                    165: void do_coprocessor_error(long esp, long error_code)
                    166: {
1.1.1.2   root      167:        if (last_task_used_math != current)
                    168:                return;
1.1       root      169:        die("coprocessor error",esp,error_code);
                    170: }
                    171: 
                    172: void do_reserved(long esp, long error_code)
                    173: {
1.1.1.2   root      174:        die("reserved (15,17-47) error",esp,error_code);
1.1       root      175: }
                    176: 
                    177: void trap_init(void)
                    178: {
                    179:        int i;
                    180: 
                    181:        set_trap_gate(0,&divide_error);
                    182:        set_trap_gate(1,&debug);
                    183:        set_trap_gate(2,&nmi);
                    184:        set_system_gate(3,&int3);       /* int3-5 can be called from all */
                    185:        set_system_gate(4,&overflow);
                    186:        set_system_gate(5,&bounds);
                    187:        set_trap_gate(6,&invalid_op);
                    188:        set_trap_gate(7,&device_not_available);
                    189:        set_trap_gate(8,&double_fault);
                    190:        set_trap_gate(9,&coprocessor_segment_overrun);
                    191:        set_trap_gate(10,&invalid_TSS);
                    192:        set_trap_gate(11,&segment_not_present);
                    193:        set_trap_gate(12,&stack_segment);
                    194:        set_trap_gate(13,&general_protection);
                    195:        set_trap_gate(14,&page_fault);
                    196:        set_trap_gate(15,&reserved);
                    197:        set_trap_gate(16,&coprocessor_error);
1.1.1.3   root      198:        set_trap_gate(17,&alignment_check);
                    199:        for (i=18;i<48;i++)
1.1       root      200:                set_trap_gate(i,&reserved);
1.1.1.2   root      201:        set_trap_gate(45,&irq13);
                    202:        outb_p(inb_p(0x21)&0xfb,0x21);
                    203:        outb(inb_p(0xA1)&0xdf,0xA1);
                    204:        set_trap_gate(39,&parallel_interrupt);
1.1       root      205: }

unix.superglobalmegacorp.com