1 #include <asm/system.h>
5 unsigned long long *idt
= (unsigned long long *)0x80000;
7 #define get_seg_byte(seg,addr) ({ \
9 __asm__("push %%fs;mov %%ax,%%fs;movb %%fs:%2,%%al;pop %%fs" \
10 :"=a" (__res):"0" (seg),"m" (*(addr))); \
13 #define get_seg_long(seg,addr) ({ \
14 register unsigned long __res; \
15 __asm__("push %%fs;mov %%ax,%%fs;movl %%fs:%2,%%eax;pop %%fs" \
16 :"=a" (__res):"0" (seg),"m" (*(addr))); \
20 register unsigned short __res; \
21 __asm__("mov %%fs,%%ax":"=a" (__res):); \
25 register unsigned short __res; \
26 __asm__("mov %%ds,%%ax":"=a" (__res):); \
30 register unsigned short __res; \
31 __asm__("mov %%es,%%ax":"=a" (__res):); \
35 /*int do_exit(long code); *** Not finished *** */
37 void ipc_install(void);
39 void page_exception(void);
40 void divide_error(void);
46 void invalid_op(void);
47 void device_not_available(void);
48 void double_fault(void);
49 void coprocessor_segment_overrun(void);
50 void invalid_TSS(void);
51 void segment_not_present(void);
52 void stack_segment(void);
53 void general_protection(void);
54 void page_fault(void);
55 void coprocessor_error(void);
58 static void die(char * str
,long esp_ptr
,long nr
)
60 long * esp
= (long *) esp_ptr
;
62 //unsigned long eip = esp[0];
66 printk("%s: %04x\n\r",str
,nr
&0xffff);
67 printk("EIP:\t%04x:%p\nEFLAGS:\t%p\nESP:\t%04x:%p\n",
68 esp
[1],esp
[0],esp
[2],esp
[4],esp
[3]);
69 printk("fs: %04x\n",_fs());
70 printk("ds: %04x\n",_ds());
71 printk("es: %04x\n",_es());
76 printk("%p ",get_seg_long(0x17,i
+(long *)esp
[3]));
81 if (strcmp(str, "divide error" == 0)) {
90 void do_double_fault(long esp
, long error_code
)
92 die("double fault",esp
,error_code
);
95 void do_general_protection(long esp
, long error_code
)
97 die("general protection",esp
,error_code
);
100 void do_divide_error(long esp
, long error_code
)
102 die("divide error",esp
,error_code
);
105 void do_int3(long * esp
, long error_code
,
106 long fs
,long es
,long ds
,
107 long ebp
,long esi
,long edi
,
108 long edx
,long ecx
,long ebx
,long eax
)
111 /* __asm__("str %%ax":"=a" (tr):"0" (0));*/
112 printk("eax\t\tebx\t\tecx\t\tedx\n\r%8x\t%8x\t%8x\t%8x\n\r",
114 printk("esi\t\tedi\t\tebp\t\tesp\n\r%8x\t%8x\t%8x\t%8x\n\r",
115 esi
,edi
,ebp
,(long) esp
);
116 printk("\n\rds\tes\tfs\ttr\n\r%4x\t%4x\t%4x\t\n\r",
118 printk("EIP: %8x CS: %4x EFLAGS: %8x\n\r",esp
[0],esp
[1],esp
[2]);
124 void do_nmi(long esp
, long error_code
)
126 die("nmi",esp
,error_code
);
129 void do_debug(long esp
, long error_code
)
131 die("debug",esp
,error_code
);
134 void do_overflow(long esp
, long error_code
)
136 die("overflow",esp
,error_code
);
139 void do_bounds(long esp
, long error_code
)
141 die("bounds",esp
,error_code
);
144 void do_invalid_op(long esp
, long error_code
)
146 die("invalid operand",esp
,error_code
);
149 void do_device_not_available(long esp
, long error_code
)
151 die("device not available",esp
,error_code
);
154 void do_coprocessor_segment_overrun(long esp
, long error_code
)
156 die("coprocessor segment overrun",esp
,error_code
);
159 void do_invalid_TSS(long esp
,long error_code
)
161 die("invalid TSS",esp
,error_code
);
164 void do_segment_not_present(long esp
,long error_code
)
166 die("segment not present",esp
,error_code
);
169 void do_stack_segment(long esp
,long error_code
)
171 die("stack segment",esp
,error_code
);
174 void do_coprocessor_error(long esp
, long error_code
)
176 die("coprocessor error",esp
,error_code
);
179 void do_reserved(long esp
, long error_code
)
181 die("reserved (15,17-31) error",esp
,error_code
);
186 void ipc_install(void)
207 extern void keyboard_interrupt();
210 unsigned short length
;
211 unsigned long long *address
;
212 } __attribute__((packed
)) idt_descr
= {256*8-1, idt
};
216 set_trap_gate(0,÷_error
);
217 set_trap_gate(1,&debug
);
218 set_trap_gate(2,&nmi
);
219 set_system_gate(3,&int3
); /*int3*/
220 set_system_gate(4,&overflow
);
221 set_system_gate(5,&bounds
);
222 set_trap_gate(6,&invalid_op
);
223 set_trap_gate(7,&reserved
);/*device_not_available*/
224 set_trap_gate(8,&double_fault
);
225 set_trap_gate(9,&coprocessor_segment_overrun
);
226 set_trap_gate(10,&invalid_TSS
);
227 set_trap_gate(11,&segment_not_present
);
228 set_trap_gate(12,&stack_segment
);
229 set_trap_gate(13,&general_protection
);
230 set_trap_gate(14,&reserved
);/*page_fault*/
231 set_trap_gate(15,&reserved
);
232 set_trap_gate(16,&reserved
); /*coprocessor_error*/
234 for (i
=17;i
< 48;i
++)
235 set_trap_gate(i
,&reserved
);
239 __asm__ ("lidt %0\n\t"::"m"(idt_descr
));
243 /*set_trap_gate(45,&irq13);*/
245 outb_p(inb_p(0x21)&0xfb, 0x21);
246 outb_p(inb_p(0xa1)&0xdf, 0xa1);
248 /* set_trap_gate(39,¶llel_interrupt);*/