Move user exception support into userprog.
[pintos-anon] / src / userprog / tss.c
1 #include "tss.h"
2 #include <stddef.h>
3 #include "debug.h"
4 #include "gdt.h"
5 #include "mmu.h"
6 #include "palloc.h"
7
8 struct tss
9   {
10     uint16_t back_link, :16;
11     void *esp0;
12     uint16_t ss0, :16;
13     void *esp1;
14     uint16_t ss1, :16;
15     void *esp2;
16     uint16_t ss2, :16;
17     uint32_t cr3;
18     void (*eip) (void);
19     uint32_t eflags;
20     uint32_t eax, ecx, edx, ebx;
21     uint32_t esp, ebp, esi, edi;
22     uint16_t es, :16;
23     uint16_t cs, :16;
24     uint16_t ss, :16;
25     uint16_t ds, :16;
26     uint16_t fs, :16;
27     uint16_t gs, :16;
28     uint16_t ldt, :16;
29     uint16_t trace, bitmap;
30   };
31
32 static struct tss *tss;
33
34 void
35 tss_init (void) 
36 {
37   /* Our TSS is never used in a call gate or task gate, so only a
38      few fields of it are ever referenced, and those are the only
39      ones we initialize. */
40   tss = palloc_get (PAL_ASSERT | PAL_ZERO);
41   tss->esp0 = ptov(0x20000);
42   tss->ss0 = SEL_KDSEG;
43   tss->bitmap = 0xdfff;
44 }
45
46 struct tss *
47 tss_get (void) 
48 {
49   ASSERT (tss != NULL);
50   return tss;
51 }
52
53 void
54 tss_set_esp0 (uint8_t *esp0) 
55 {
56   ASSERT (tss != NULL);
57   tss->esp0 = esp0;
58 }