Rev 2787 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 4377 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup amd64 |
29 | /** @addtogroup amd64 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #ifndef KERN_amd64_PM_H_ |
35 | #ifndef KERN_amd64_PM_H_ |
36 | #define KERN_amd64_PM_H_ |
36 | #define KERN_amd64_PM_H_ |
37 | 37 | ||
38 | #ifndef __ASM__ |
38 | #ifndef __ASM__ |
39 | # include <arch/types.h> |
39 | #include <arch/types.h> |
40 | # include <arch/context.h> |
40 | #include <arch/context.h> |
41 | #endif |
41 | #endif |
42 | 42 | ||
43 | #define IDT_ITEMS 64 |
43 | #define IDT_ITEMS 64 |
44 | #define GDT_ITEMS 8 |
44 | #define GDT_ITEMS 8 |
45 | - | ||
46 | - | ||
47 | #define NULL_DES 0 |
- | |
48 | /* Warning: Do not reorder next items, unless you look into syscall.c!!! */ |
- | |
49 | #define KTEXT_DES 1 |
- | |
50 | #define KDATA_DES 2 |
- | |
51 | #define UDATA_DES 3 |
- | |
52 | #define UTEXT_DES 4 |
- | |
53 | #define KTEXT32_DES 5 |
- | |
54 | /* EndOfWarning */ |
- | |
55 | #define TSS_DES 6 |
- | |
56 | 45 | ||
57 | 46 | ||
- | 47 | #define NULL_DES 0 |
|
- | 48 | /* Warning: Do not reorder the following items, unless you look into syscall.c! */ |
|
- | 49 | #define KTEXT_DES 1 |
|
- | 50 | #define KDATA_DES 2 |
|
- | 51 | #define UDATA_DES 3 |
|
- | 52 | #define UTEXT_DES 4 |
|
- | 53 | #define KTEXT32_DES 5 |
|
- | 54 | /* End of warning */ |
|
- | 55 | #define TSS_DES 6 |
|
58 | 56 | ||
59 | #ifdef CONFIG_FB |
57 | #ifdef CONFIG_FB |
60 | 58 | ||
61 | #define VESA_INIT_DES 8 |
59 | #define VESA_INIT_DES 8 |
62 | #define VESA_INIT_SEGMENT 0x8000 |
60 | #define VESA_INIT_SEGMENT 0x8000 |
63 | #undef GDT_ITEMS |
- | |
64 | #define GDT_ITEMS 9 |
- | |
65 | - | ||
66 | #endif /*CONFIG_FB*/ |
- | |
67 | 61 | ||
- | 62 | #undef GDT_ITEMS |
|
- | 63 | #define GDT_ITEMS 9 |
|
68 | 64 | ||
- | 65 | #endif /* CONFIG_FB */ |
|
69 | 66 | ||
70 | #define gdtselector(des) ((des) << 3) |
67 | #define gdtselector(des) ((des) << 3) |
71 | #define idtselector(des) ((des) << 4) |
68 | #define idtselector(des) ((des) << 4) |
72 | 69 | ||
73 | #define PL_KERNEL 0 |
70 | #define PL_KERNEL 0 |
74 | #define PL_USER 3 |
71 | #define PL_USER 3 |
75 | 72 | ||
76 | #define AR_PRESENT (1<<7) |
73 | #define AR_PRESENT ( 1 << 7) |
77 | #define AR_DATA (2<<3) |
74 | #define AR_DATA (2 << 3) |
78 | #define AR_CODE (3<<3) |
75 | #define AR_CODE (3 << 3) |
79 | #define AR_WRITABLE (1<<1) |
76 | #define AR_WRITABLE (1 << 1) |
80 | #define AR_READABLE (1<<1) |
77 | #define AR_READABLE (1 << 1) |
81 | #define AR_TSS (0x9) |
78 | #define AR_TSS (0x09) |
82 | #define AR_INTERRUPT (0xe) |
79 | #define AR_INTERRUPT (0x0e) |
83 | #define AR_TRAP (0xf) |
80 | #define AR_TRAP (0x0f) |
84 | 81 | ||
85 | #define DPL_KERNEL (PL_KERNEL<<5) |
82 | #define DPL_KERNEL (PL_KERNEL << 5) |
86 | #define DPL_USER (PL_USER<<5) |
83 | #define DPL_USER (PL_USER << 5) |
87 | 84 | ||
88 | #define TSS_BASIC_SIZE 104 |
85 | #define TSS_BASIC_SIZE 104 |
89 | #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ |
86 | #define TSS_IOMAP_SIZE (16 * 1024 + 1) /* 16K for bitmap + 1 terminating byte for convenience */ |
90 | 87 | ||
91 | #define IO_PORTS (64*1024) |
88 | #define IO_PORTS (64 * 1024) |
92 | 89 | ||
93 | #ifndef __ASM__ |
90 | #ifndef __ASM__ |
94 | 91 | ||
95 | struct descriptor { |
92 | typedef struct { |
96 | unsigned limit_0_15: 16; |
93 | unsigned limit_0_15: 16; |
97 | unsigned base_0_15: 16; |
94 | unsigned base_0_15: 16; |
98 | unsigned base_16_23: 8; |
95 | unsigned base_16_23: 8; |
99 | unsigned access: 8; |
96 | unsigned access: 8; |
100 | unsigned limit_16_19: 4; |
97 | unsigned limit_16_19: 4; |
101 | unsigned available: 1; |
98 | unsigned available: 1; |
102 | unsigned longmode: 1; |
99 | unsigned longmode: 1; |
103 | unsigned special: 1; |
100 | unsigned special: 1; |
104 | unsigned granularity : 1; |
101 | unsigned granularity : 1; |
105 | unsigned base_24_31: 8; |
102 | unsigned base_24_31: 8; |
106 | } __attribute__ ((packed)); |
103 | } __attribute__ ((packed)) descriptor_t; |
107 | typedef struct descriptor descriptor_t; |
- | |
108 | 104 | ||
109 | struct tss_descriptor { |
105 | typedef struct { |
110 | unsigned limit_0_15: 16; |
106 | unsigned limit_0_15: 16; |
111 | unsigned base_0_15: 16; |
107 | unsigned base_0_15: 16; |
112 | unsigned base_16_23: 8; |
108 | unsigned base_16_23: 8; |
113 | unsigned type: 4; |
109 | unsigned type: 4; |
114 | unsigned : 1; |
110 | unsigned : 1; |
Line 119... | Line 115... | ||
119 | unsigned : 2; |
115 | unsigned : 2; |
120 | unsigned granularity : 1; |
116 | unsigned granularity : 1; |
121 | unsigned base_24_31: 8; |
117 | unsigned base_24_31: 8; |
122 | unsigned base_32_63 : 32; |
118 | unsigned base_32_63 : 32; |
123 | unsigned : 32; |
119 | unsigned : 32; |
124 | } __attribute__ ((packed)); |
120 | } __attribute__ ((packed)) tss_descriptor_t; |
125 | typedef struct tss_descriptor tss_descriptor_t; |
- | |
126 | 121 | ||
127 | struct idescriptor { |
122 | typedef struct { |
128 | unsigned offset_0_15: 16; |
123 | unsigned offset_0_15: 16; |
129 | unsigned selector: 16; |
124 | unsigned selector: 16; |
130 | unsigned ist:3; |
125 | unsigned ist:3; |
131 | unsigned unused: 5; |
126 | unsigned unused: 5; |
132 | unsigned type: 5; |
127 | unsigned type: 5; |
133 | unsigned dpl: 2; |
128 | unsigned dpl: 2; |
134 | unsigned present : 1; |
129 | unsigned present : 1; |
135 | unsigned offset_16_31: 16; |
130 | unsigned offset_16_31: 16; |
136 | unsigned offset_32_63: 32; |
131 | unsigned offset_32_63: 32; |
137 | unsigned : 32; |
132 | unsigned : 32; |
138 | } __attribute__ ((packed)); |
133 | } __attribute__ ((packed)) idescriptor_t; |
139 | typedef struct idescriptor idescriptor_t; |
- | |
140 | 134 | ||
141 | struct ptr_16_64 { |
135 | typedef struct { |
142 | uint16_t limit; |
136 | uint16_t limit; |
143 | uint64_t base; |
137 | uint64_t base; |
144 | } __attribute__ ((packed)); |
138 | } __attribute__ ((packed)) ptr_16_64_t; |
145 | typedef struct ptr_16_64 ptr_16_64_t; |
- | |
146 | 139 | ||
147 | struct ptr_16_32 { |
140 | typedef struct { |
148 | uint16_t limit; |
141 | uint16_t limit; |
149 | uint32_t base; |
142 | uint32_t base; |
150 | } __attribute__ ((packed)); |
143 | } __attribute__ ((packed)) ptr_16_32_t; |
151 | typedef struct ptr_16_32 ptr_16_32_t; |
- | |
152 | 144 | ||
153 | struct tss { |
145 | typedef struct { |
154 | uint32_t reserve1; |
146 | uint32_t reserve1; |
155 | uint64_t rsp0; |
147 | uint64_t rsp0; |
156 | uint64_t rsp1; |
148 | uint64_t rsp1; |
157 | uint64_t rsp2; |
149 | uint64_t rsp2; |
158 | uint64_t reserve2; |
150 | uint64_t reserve2; |
Line 165... | Line 157... | ||
165 | uint64_t ist7; |
157 | uint64_t ist7; |
166 | uint64_t reserve3; |
158 | uint64_t reserve3; |
167 | uint16_t reserve4; |
159 | uint16_t reserve4; |
168 | uint16_t iomap_base; |
160 | uint16_t iomap_base; |
169 | uint8_t iomap[TSS_IOMAP_SIZE]; |
161 | uint8_t iomap[TSS_IOMAP_SIZE]; |
170 | } __attribute__ ((packed)); |
162 | } __attribute__ ((packed)) tss_t; |
171 | typedef struct tss tss_t; |
- | |
172 | 163 | ||
173 | extern tss_t *tss_p; |
164 | extern tss_t *tss_p; |
174 | 165 | ||
175 | extern descriptor_t gdt[]; |
166 | extern descriptor_t gdt[]; |
176 | extern idescriptor_t idt[]; |
167 | extern idescriptor_t idt[]; |