xref: /xv6-public/trap.c (revision a4c03dea)
1 #include "types.h"
2 #include "param.h"
3 #include "mmu.h"
4 #include "proc.h"
5 #include "defs.h"
6 #include "x86.h"
7 #include "traps.h"
8 
9 struct Gatedesc idt[256];
10 struct Pseudodesc idt_pd = { 0, sizeof(idt) - 1, (unsigned) &idt };
11 extern unsigned vectors[]; /* vectors.S, array of 256 entry point addresses */
12 
13 extern void trapenter();
14 extern void trapenter1();
15 
16 void
17 tinit()
18 {
19   int i;
20 
21   for(i = 0; i < 256; i++){
22     SETGATE(idt[i], 1, SEG_KCODE << 3, vectors[i], 0);
23   }
24   SETGATE(idt[T_SYSCALL], T_SYSCALL, SEG_KCODE << 3, vectors[48], 3);
25   asm volatile("lidt %0" : : "g" (idt_pd.pd_lim));
26 }
27 
28 void
29 trap(struct Trapframe *tf)
30 {
31   int v = tf->tf_trapno;
32   cprintf("trap %d eip %x:%x\n", tf->tf_trapno, tf->tf_cs, tf->tf_eip);
33 
34   if(v == T_SYSCALL){
35     curproc->tf = tf;
36     syscall();
37     return;
38   }
39 
40   if(v == 32){
41     // probably clock
42     return;
43   }
44 
45   while(1)
46     ;
47   // XXX probably ought to lgdt on trap return
48 }
49