]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/gdt.cpp
Some minor fixes.
[l4.git] / kernel / fiasco / src / kern / ia32 / gdt.cpp
1
2 INTERFACE:
3
4 #include "config_gdt.h"
5 #include "l4_types.h"
6 #include "x86desc.h"
7
8 class Gdt
9 {
10 public:
11    /** Segment numbers. */
12   enum 
13   {
14     gdt_tss             = GDT_TSS,
15     gdt_code_kernel     = GDT_CODE_KERNEL,
16     gdt_data_kernel     = GDT_DATA_KERNEL,
17     gdt_code_user       = GDT_CODE_USER,
18     gdt_data_user       = GDT_DATA_USER,
19     gdt_tss_dbf         = GDT_TSS_DBF,
20     gdt_utcb            = GDT_UTCB,
21     gdt_ldt             = GDT_LDT,
22     gdt_user_entry1     = GDT_USER_ENTRY1,
23     gdt_user_entry2     = GDT_USER_ENTRY2,
24     gdt_user_entry3     = GDT_USER_ENTRY3,
25     gdt_user_entry4     = GDT_USER_ENTRY4,
26     gdt_code_user32     = GDT_CODE_USER32,
27     gdt_max             = GDT_MAX,
28   };
29
30   enum
31   {
32     Selector_user       = 0x03,
33     Selector_kernel     = 0x00,
34   };
35
36 private:
37   Gdt_entry _entries[0];
38 };
39
40 //------------------------------------------------------------------
41 IMPLEMENTATION [amd64]:
42
43 PUBLIC inline
44 void
45 Gdt::set_entry_tss(int nr, Address base, Unsigned32 limit,
46                    Unsigned8 access, Unsigned8 szbits)
47 {
48   // system-segment descriptor is 16byte
49   _entries[nr] = Gdt_entry(base, limit >> 12, access, szbits | 0x08);
50   _entries[nr + 1].raw = base >> 32;
51 }
52
53 //------------------------------------------------------------------
54 IMPLEMENTATION:
55
56
57 PUBLIC inline
58 void
59 Gdt::set_entry_byte(int nr, Address base, Unsigned32 limit,
60                     Unsigned8 access, Unsigned8 szbits)
61 {
62   _entries[nr] = Gdt_entry(base, limit, access, szbits);
63 }
64
65 PUBLIC inline
66 void
67 Gdt::set_entry_4k(int nr, Address base, Unsigned32 limit,
68                   Unsigned8 access, Unsigned8 szbits)
69 {
70   _entries[nr] = Gdt_entry(base, limit >> 12, access, szbits | 0x08);
71 }
72
73 PUBLIC inline
74 void
75 Gdt::clear_entry(int nr)
76 {
77   _entries[nr].clear();
78 }
79
80 PUBLIC inline
81 Gdt_entry*
82 Gdt::entries()
83 {
84   return _entries;
85 }
86
87 PUBLIC inline
88 Gdt_entry &
89 Gdt::operator [] (unsigned idx)
90 { return _entries[idx]; }
91
92 PUBLIC inline
93 Gdt_entry const &
94 Gdt::operator [] (unsigned idx) const
95 { return _entries[idx]; }
96
97
98 IMPLEMENTATION[ia32 | amd64]:
99
100 PUBLIC static inline
101 void
102 Gdt::set (Pseudo_descriptor *desc)
103 {
104   asm volatile ("lgdt %0" : : "m" (*desc));
105 }
106
107 PUBLIC static inline
108 void
109 Gdt::get (Pseudo_descriptor *desc)
110 {
111   asm volatile ("sgdt %0" : "=m" (*desc) : : "memory");
112 }
113
114 PUBLIC static inline
115 int
116 Gdt::data_segment ()
117 { return gdt_data_user | Selector_user; }