Rev 1187 | Rev 1203 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1187 | Rev 1201 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 | #ifndef __amd64_PM_H__ |
29 | #ifndef __amd64_PM_H__ |
30 | #define __amd64_PM_H__ |
30 | #define __amd64_PM_H__ |
31 | 31 | ||
32 | #ifndef __ASM__ |
32 | #ifndef __ASM__ |
33 | # include <arch/types.h> |
33 | # include <arch/types.h> |
34 | # include <typedefs.h> |
34 | # include <typedefs.h> |
35 | # include <arch/context.h> |
35 | # include <arch/context.h> |
36 | #endif |
36 | #endif |
37 | 37 | ||
38 | #define IDT_ITEMS 64 |
38 | #define IDT_ITEMS 64 |
39 | #define GDT_ITEMS 8 |
39 | #define GDT_ITEMS 8 |
40 | 40 | ||
41 | #define NULL_DES 0 |
41 | #define NULL_DES 0 |
42 | /* Warning: Do not reorder next items, unless you look into syscall.c!!! */ |
42 | /* Warning: Do not reorder next items, unless you look into syscall.c!!! */ |
43 | #define KTEXT_DES 1 |
43 | #define KTEXT_DES 1 |
44 | #define KDATA_DES 2 |
44 | #define KDATA_DES 2 |
45 | #define UDATA_DES 3 |
45 | #define UDATA_DES 3 |
46 | #define UTEXT_DES 4 |
46 | #define UTEXT_DES 4 |
47 | #define KTEXT32_DES 5 |
47 | #define KTEXT32_DES 5 |
48 | /* EndOfWarning */ |
48 | /* EndOfWarning */ |
49 | #define TSS_DES 6 |
49 | #define TSS_DES 6 |
50 | 50 | ||
51 | #define gdtselector(des) ((des)<<3) |
51 | #define gdtselector(des) ((des)<<3) |
52 | #define idtselector(des) ((des)<<4) |
52 | #define idtselector(des) ((des)<<4) |
53 | 53 | ||
54 | #define PL_KERNEL 0 |
54 | #define PL_KERNEL 0 |
55 | #define PL_USER 3 |
55 | #define PL_USER 3 |
56 | 56 | ||
57 | #define AR_PRESENT (1<<7) |
57 | #define AR_PRESENT (1<<7) |
58 | #define AR_DATA (2<<3) |
58 | #define AR_DATA (2<<3) |
59 | #define AR_CODE (3<<3) |
59 | #define AR_CODE (3<<3) |
60 | #define AR_WRITABLE (1<<1) |
60 | #define AR_WRITABLE (1<<1) |
61 | #define AR_READABLE (1<<1) |
61 | #define AR_READABLE (1<<1) |
62 | #define AR_TSS (0x9) |
62 | #define AR_TSS (0x9) |
63 | #define AR_INTERRUPT (0xe) |
63 | #define AR_INTERRUPT (0xe) |
64 | #define AR_TRAP (0xf) |
64 | #define AR_TRAP (0xf) |
65 | 65 | ||
66 | #define DPL_KERNEL (PL_KERNEL<<5) |
66 | #define DPL_KERNEL (PL_KERNEL<<5) |
67 | #define DPL_USER (PL_USER<<5) |
67 | #define DPL_USER (PL_USER<<5) |
68 | 68 | ||
69 | #define TSS_BASIC_SIZE 104 |
69 | #define TSS_BASIC_SIZE 104 |
- | 70 | #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ |
|
70 | 71 | ||
71 | #ifndef __ASM__ |
72 | #ifndef __ASM__ |
72 | 73 | ||
73 | struct descriptor { |
74 | struct descriptor { |
74 | unsigned limit_0_15: 16; |
75 | unsigned limit_0_15: 16; |
75 | unsigned base_0_15: 16; |
76 | unsigned base_0_15: 16; |
76 | unsigned base_16_23: 8; |
77 | unsigned base_16_23: 8; |
77 | unsigned access: 8; |
78 | unsigned access: 8; |
78 | unsigned limit_16_19: 4; |
79 | unsigned limit_16_19: 4; |
79 | unsigned available: 1; |
80 | unsigned available: 1; |
80 | unsigned longmode: 1; |
81 | unsigned longmode: 1; |
81 | unsigned special: 1; |
82 | unsigned special: 1; |
82 | unsigned granularity : 1; |
83 | unsigned granularity : 1; |
83 | unsigned base_24_31: 8; |
84 | unsigned base_24_31: 8; |
84 | } __attribute__ ((packed)); |
85 | } __attribute__ ((packed)); |
85 | typedef struct descriptor descriptor_t; |
86 | typedef struct descriptor descriptor_t; |
86 | 87 | ||
87 | struct tss_descriptor { |
88 | struct tss_descriptor { |
88 | unsigned limit_0_15: 16; |
89 | unsigned limit_0_15: 16; |
89 | unsigned base_0_15: 16; |
90 | unsigned base_0_15: 16; |
90 | unsigned base_16_23: 8; |
91 | unsigned base_16_23: 8; |
91 | unsigned type: 4; |
92 | unsigned type: 4; |
92 | unsigned : 1; |
93 | unsigned : 1; |
93 | unsigned dpl : 2; |
94 | unsigned dpl : 2; |
94 | unsigned present : 1; |
95 | unsigned present : 1; |
95 | unsigned limit_16_19: 4; |
96 | unsigned limit_16_19: 4; |
96 | unsigned available: 1; |
97 | unsigned available: 1; |
97 | unsigned : 2; |
98 | unsigned : 2; |
98 | unsigned granularity : 1; |
99 | unsigned granularity : 1; |
99 | unsigned base_24_31: 8; |
100 | unsigned base_24_31: 8; |
100 | unsigned base_32_63 : 32; |
101 | unsigned base_32_63 : 32; |
101 | unsigned : 32; |
102 | unsigned : 32; |
102 | } __attribute__ ((packed)); |
103 | } __attribute__ ((packed)); |
103 | typedef struct tss_descriptor tss_descriptor_t; |
104 | typedef struct tss_descriptor tss_descriptor_t; |
104 | 105 | ||
105 | struct idescriptor { |
106 | struct idescriptor { |
106 | unsigned offset_0_15: 16; |
107 | unsigned offset_0_15: 16; |
107 | unsigned selector: 16; |
108 | unsigned selector: 16; |
108 | unsigned ist:3; |
109 | unsigned ist:3; |
109 | unsigned unused: 5; |
110 | unsigned unused: 5; |
110 | unsigned type: 5; |
111 | unsigned type: 5; |
111 | unsigned dpl: 2; |
112 | unsigned dpl: 2; |
112 | unsigned present : 1; |
113 | unsigned present : 1; |
113 | unsigned offset_16_31: 16; |
114 | unsigned offset_16_31: 16; |
114 | unsigned offset_32_63: 32; |
115 | unsigned offset_32_63: 32; |
115 | unsigned : 32; |
116 | unsigned : 32; |
116 | } __attribute__ ((packed)); |
117 | } __attribute__ ((packed)); |
117 | typedef struct idescriptor idescriptor_t; |
118 | typedef struct idescriptor idescriptor_t; |
118 | 119 | ||
119 | struct ptr_16_64 { |
120 | struct ptr_16_64 { |
120 | __u16 limit; |
121 | __u16 limit; |
121 | __u64 base; |
122 | __u64 base; |
122 | } __attribute__ ((packed)); |
123 | } __attribute__ ((packed)); |
123 | typedef struct ptr_16_64 ptr_16_64_t; |
124 | typedef struct ptr_16_64 ptr_16_64_t; |
124 | 125 | ||
125 | struct ptr_16_32 { |
126 | struct ptr_16_32 { |
126 | __u16 limit; |
127 | __u16 limit; |
127 | __u32 base; |
128 | __u32 base; |
128 | } __attribute__ ((packed)); |
129 | } __attribute__ ((packed)); |
129 | typedef struct ptr_16_32 ptr_16_32_t; |
130 | typedef struct ptr_16_32 ptr_16_32_t; |
130 | 131 | ||
131 | struct tss { |
132 | struct tss { |
132 | __u32 reserve1; |
133 | __u32 reserve1; |
133 | __u64 rsp0; |
134 | __u64 rsp0; |
134 | __u64 rsp1; |
135 | __u64 rsp1; |
135 | __u64 rsp2; |
136 | __u64 rsp2; |
136 | __u64 reserve2; |
137 | __u64 reserve2; |
137 | __u64 ist1; |
138 | __u64 ist1; |
138 | __u64 ist2; |
139 | __u64 ist2; |
139 | __u64 ist3; |
140 | __u64 ist3; |
140 | __u64 ist4; |
141 | __u64 ist4; |
141 | __u64 ist5; |
142 | __u64 ist5; |
142 | __u64 ist6; |
143 | __u64 ist6; |
143 | __u64 ist7; |
144 | __u64 ist7; |
144 | __u64 reserve3; |
145 | __u64 reserve3; |
145 | __u16 reserve4; |
146 | __u16 reserve4; |
146 | __u16 iomap_base; |
147 | __u16 iomap_base; |
147 | __u8 iomap[0x10000 + 1]; /* 64K + 1 terminating byte */ |
148 | __u8 iomap[TSS_IOMAP_SIZE]; |
148 | } __attribute__ ((packed)); |
149 | } __attribute__ ((packed)); |
149 | typedef struct tss tss_t; |
150 | typedef struct tss tss_t; |
150 | 151 | ||
151 | extern tss_t *tss_p; |
152 | extern tss_t *tss_p; |
152 | 153 | ||
153 | extern descriptor_t gdt[]; |
154 | extern descriptor_t gdt[]; |
154 | extern idescriptor_t idt[]; |
155 | extern idescriptor_t idt[]; |
155 | 156 | ||
156 | extern ptr_16_64_t gdtr; |
157 | extern ptr_16_64_t gdtr; |
157 | extern ptr_16_32_t bootstrap_gdtr; |
158 | extern ptr_16_32_t bootstrap_gdtr; |
158 | extern ptr_16_32_t protected_ap_gdtr; |
159 | extern ptr_16_32_t protected_ap_gdtr; |
159 | 160 | ||
160 | extern void pm_init(void); |
161 | extern void pm_init(void); |
161 | 162 | ||
162 | extern void gdt_tss_setbase(descriptor_t *d, __address base); |
163 | extern void gdt_tss_setbase(descriptor_t *d, __address base); |
163 | extern void gdt_tss_setlimit(descriptor_t *d, __u32 limit); |
164 | extern void gdt_tss_setlimit(descriptor_t *d, __u32 limit); |
164 | 165 | ||
165 | extern void idt_init(void); |
166 | extern void idt_init(void); |
166 | extern void idt_setoffset(idescriptor_t *d, __address offset); |
167 | extern void idt_setoffset(idescriptor_t *d, __address offset); |
167 | 168 | ||
168 | extern void tss_initialize(tss_t *t); |
169 | extern void tss_initialize(tss_t *t); |
169 | 170 | ||
170 | #endif /* __ASM__ */ |
171 | #endif /* __ASM__ */ |
171 | 172 | ||
172 | #endif |
173 | #endif |
173 | 174 |