Rev 2089 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
178 | palkovsky | 1 | /* |
2071 | jermar | 2 | * Copyright (c) 2001-2004 Jakub Jermar |
178 | palkovsky | 3 | * All rights reserved. |
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
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 |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
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 |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
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 |
||
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 |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1888 | jermar | 29 | /** @addtogroup amd64 |
1702 | cejka | 30 | * @{ |
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
1888 | jermar | 35 | #ifndef KERN_amd64_PM_H_ |
36 | #define KERN_amd64_PM_H_ |
||
178 | palkovsky | 37 | |
194 | palkovsky | 38 | #ifndef __ASM__ |
2089 | decky | 39 | # include <arch/types.h> |
40 | # include <arch/context.h> |
||
194 | palkovsky | 41 | #endif |
178 | palkovsky | 42 | |
43 | #define IDT_ITEMS 64 |
||
1292 | vana | 44 | #define GDT_ITEMS 8 |
178 | palkovsky | 45 | |
1289 | vana | 46 | |
178 | palkovsky | 47 | #define NULL_DES 0 |
803 | palkovsky | 48 | /* Warning: Do not reorder next items, unless you look into syscall.c!!! */ |
178 | palkovsky | 49 | #define KTEXT_DES 1 |
50 | #define KDATA_DES 2 |
||
803 | palkovsky | 51 | #define UDATA_DES 3 |
52 | #define UTEXT_DES 4 |
||
194 | palkovsky | 53 | #define KTEXT32_DES 5 |
803 | palkovsky | 54 | /* EndOfWarning */ |
194 | palkovsky | 55 | #define TSS_DES 6 |
1292 | vana | 56 | |
57 | |||
58 | |||
59 | #ifdef CONFIG_FB |
||
60 | |||
1289 | vana | 61 | #define VESA_INIT_DES 8 |
1292 | vana | 62 | #define VESA_INIT_SEGMENT 0x8000 |
63 | #undef GDT_ITEMS |
||
64 | #define GDT_ITEMS 9 |
||
178 | palkovsky | 65 | |
1292 | vana | 66 | #endif /*CONFIG_FB*/ |
67 | |||
68 | |||
69 | |||
1811 | decky | 70 | #define gdtselector(des) ((des) << 3) |
71 | #define idtselector(des) ((des) << 4) |
||
178 | palkovsky | 72 | |
73 | #define PL_KERNEL 0 |
||
74 | #define PL_USER 3 |
||
75 | |||
76 | #define AR_PRESENT (1<<7) |
||
77 | #define AR_DATA (2<<3) |
||
78 | #define AR_CODE (3<<3) |
||
79 | #define AR_WRITABLE (1<<1) |
||
188 | palkovsky | 80 | #define AR_READABLE (1<<1) |
178 | palkovsky | 81 | #define AR_TSS (0x9) |
206 | palkovsky | 82 | #define AR_INTERRUPT (0xe) |
83 | #define AR_TRAP (0xf) |
||
178 | palkovsky | 84 | |
85 | #define DPL_KERNEL (PL_KERNEL<<5) |
||
86 | #define DPL_USER (PL_USER<<5) |
||
87 | |||
1187 | jermar | 88 | #define TSS_BASIC_SIZE 104 |
1201 | jermar | 89 | #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ |
178 | palkovsky | 90 | |
1203 | jermar | 91 | #define IO_PORTS (64*1024) |
92 | |||
194 | palkovsky | 93 | #ifndef __ASM__ |
94 | |||
178 | palkovsky | 95 | struct descriptor { |
96 | unsigned limit_0_15: 16; |
||
97 | unsigned base_0_15: 16; |
||
98 | unsigned base_16_23: 8; |
||
99 | unsigned access: 8; |
||
100 | unsigned limit_16_19: 4; |
||
101 | unsigned available: 1; |
||
102 | unsigned longmode: 1; |
||
103 | unsigned special: 1; |
||
104 | unsigned granularity : 1; |
||
105 | unsigned base_24_31: 8; |
||
106 | } __attribute__ ((packed)); |
||
1187 | jermar | 107 | typedef struct descriptor descriptor_t; |
178 | palkovsky | 108 | |
206 | palkovsky | 109 | struct tss_descriptor { |
110 | unsigned limit_0_15: 16; |
||
111 | unsigned base_0_15: 16; |
||
112 | unsigned base_16_23: 8; |
||
113 | unsigned type: 4; |
||
1187 | jermar | 114 | unsigned : 1; |
206 | palkovsky | 115 | unsigned dpl : 2; |
116 | unsigned present : 1; |
||
117 | unsigned limit_16_19: 4; |
||
118 | unsigned available: 1; |
||
224 | palkovsky | 119 | unsigned : 2; |
206 | palkovsky | 120 | unsigned granularity : 1; |
121 | unsigned base_24_31: 8; |
||
122 | unsigned base_32_63 : 32; |
||
224 | palkovsky | 123 | unsigned : 32; |
206 | palkovsky | 124 | } __attribute__ ((packed)); |
1187 | jermar | 125 | typedef struct tss_descriptor tss_descriptor_t; |
206 | palkovsky | 126 | |
178 | palkovsky | 127 | struct idescriptor { |
128 | unsigned offset_0_15: 16; |
||
129 | unsigned selector: 16; |
||
206 | palkovsky | 130 | unsigned ist:3; |
131 | unsigned unused: 5; |
||
132 | unsigned type: 5; |
||
133 | unsigned dpl: 2; |
||
134 | unsigned present : 1; |
||
178 | palkovsky | 135 | unsigned offset_16_31: 16; |
224 | palkovsky | 136 | unsigned offset_32_63: 32; |
137 | unsigned : 32; |
||
178 | palkovsky | 138 | } __attribute__ ((packed)); |
1187 | jermar | 139 | typedef struct idescriptor idescriptor_t; |
178 | palkovsky | 140 | |
206 | palkovsky | 141 | struct ptr_16_64 { |
1780 | jermar | 142 | uint16_t limit; |
143 | uint64_t base; |
||
206 | palkovsky | 144 | } __attribute__ ((packed)); |
1187 | jermar | 145 | typedef struct ptr_16_64 ptr_16_64_t; |
178 | palkovsky | 146 | |
273 | palkovsky | 147 | struct ptr_16_32 { |
1780 | jermar | 148 | uint16_t limit; |
149 | uint32_t base; |
||
273 | palkovsky | 150 | } __attribute__ ((packed)); |
1187 | jermar | 151 | typedef struct ptr_16_32 ptr_16_32_t; |
273 | palkovsky | 152 | |
178 | palkovsky | 153 | struct tss { |
1780 | jermar | 154 | uint32_t reserve1; |
155 | uint64_t rsp0; |
||
156 | uint64_t rsp1; |
||
157 | uint64_t rsp2; |
||
158 | uint64_t reserve2; |
||
159 | uint64_t ist1; |
||
160 | uint64_t ist2; |
||
161 | uint64_t ist3; |
||
162 | uint64_t ist4; |
||
163 | uint64_t ist5; |
||
164 | uint64_t ist6; |
||
165 | uint64_t ist7; |
||
166 | uint64_t reserve3; |
||
167 | uint16_t reserve4; |
||
168 | uint16_t iomap_base; |
||
169 | uint8_t iomap[TSS_IOMAP_SIZE]; |
||
178 | palkovsky | 170 | } __attribute__ ((packed)); |
1187 | jermar | 171 | typedef struct tss tss_t; |
178 | palkovsky | 172 | |
1187 | jermar | 173 | extern tss_t *tss_p; |
178 | palkovsky | 174 | |
1187 | jermar | 175 | extern descriptor_t gdt[]; |
176 | extern idescriptor_t idt[]; |
||
178 | palkovsky | 177 | |
1187 | jermar | 178 | extern ptr_16_64_t gdtr; |
179 | extern ptr_16_32_t bootstrap_gdtr; |
||
180 | extern ptr_16_32_t protected_ap_gdtr; |
||
206 | palkovsky | 181 | |
178 | palkovsky | 182 | extern void pm_init(void); |
183 | |||
1780 | jermar | 184 | extern void gdt_tss_setbase(descriptor_t *d, uintptr_t base); |
185 | extern void gdt_tss_setlimit(descriptor_t *d, uint32_t limit); |
||
178 | palkovsky | 186 | |
187 | extern void idt_init(void); |
||
1780 | jermar | 188 | extern void idt_setoffset(idescriptor_t *d, uintptr_t offset); |
178 | palkovsky | 189 | |
1187 | jermar | 190 | extern void tss_initialize(tss_t *t); |
178 | palkovsky | 191 | |
194 | palkovsky | 192 | #endif /* __ASM__ */ |
193 | |||
178 | palkovsky | 194 | #endif |
1702 | cejka | 195 | |
1888 | jermar | 196 | /** @} |
1702 | cejka | 197 | */ |