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

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

unix.superglobalmegacorp.com