Rev 1203 | Rev 1292 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1203 | Rev 1287 | ||
---|---|---|---|
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 __PM_H__ |
29 | #ifndef __PM_H__ |
30 | #define __PM_H__ |
30 | #define __PM_H__ |
31 | 31 | ||
32 | #define IDT_ITEMS 64 |
32 | #define IDT_ITEMS 64 |
33 | #define GDT_ITEMS 7 |
33 | #define GDT_ITEMS 8 |
- | 34 | ||
- | 35 | #define VESA_INIT_SEGMENT 0x8000 |
|
34 | 36 | ||
35 | #define NULL_DES 0 |
37 | #define NULL_DES 0 |
36 | #define KTEXT_DES 1 |
38 | #define KTEXT_DES 1 |
37 | #define KDATA_DES 2 |
39 | #define KDATA_DES 2 |
38 | #define UTEXT_DES 3 |
40 | #define UTEXT_DES 3 |
39 | #define UDATA_DES 4 |
41 | #define UDATA_DES 4 |
40 | #define TSS_DES 5 |
42 | #define TSS_DES 5 |
41 | #define TLS_DES 6 /* Pointer to Thread-Local-Storage data */ |
43 | #define TLS_DES 6 /* Pointer to Thread-Local-Storage data */ |
- | 44 | #define VESA_INIT_DES 7 |
|
42 | 45 | ||
43 | #define selector(des) ((des)<<3) |
46 | #define selector(des) ((des)<<3) |
44 | 47 | ||
45 | #define PL_KERNEL 0 |
48 | #define PL_KERNEL 0 |
46 | #define PL_USER 3 |
49 | #define PL_USER 3 |
47 | 50 | ||
48 | #define AR_PRESENT (1<<7) |
51 | #define AR_PRESENT (1<<7) |
49 | #define AR_DATA (2<<3) |
52 | #define AR_DATA (2<<3) |
50 | #define AR_CODE (3<<3) |
53 | #define AR_CODE (3<<3) |
51 | #define AR_WRITABLE (1<<1) |
54 | #define AR_WRITABLE (1<<1) |
52 | #define AR_INTERRUPT (0xe) |
55 | #define AR_INTERRUPT (0xe) |
53 | #define AR_TSS (0x9) |
56 | #define AR_TSS (0x9) |
54 | 57 | ||
55 | #define DPL_KERNEL (PL_KERNEL<<5) |
58 | #define DPL_KERNEL (PL_KERNEL<<5) |
56 | #define DPL_USER (PL_USER<<5) |
59 | #define DPL_USER (PL_USER<<5) |
57 | 60 | ||
58 | #define TSS_BASIC_SIZE 104 |
61 | #define TSS_BASIC_SIZE 104 |
59 | #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ |
62 | #define TSS_IOMAP_SIZE (16*1024+1) /* 16K for bitmap + 1 terminating byte for convenience */ |
60 | 63 | ||
61 | #define IO_PORTS (64*1024) |
64 | #define IO_PORTS (64*1024) |
62 | 65 | ||
63 | #ifndef __ASM__ |
66 | #ifndef __ASM__ |
64 | 67 | ||
65 | #include <arch/types.h> |
68 | #include <arch/types.h> |
66 | #include <typedefs.h> |
69 | #include <typedefs.h> |
67 | #include <arch/context.h> |
70 | #include <arch/context.h> |
68 | 71 | ||
69 | struct ptr_16_32 { |
72 | struct ptr_16_32 { |
70 | __u16 limit; |
73 | __u16 limit; |
71 | __u32 base; |
74 | __u32 base; |
72 | } __attribute__ ((packed)); |
75 | } __attribute__ ((packed)); |
73 | typedef struct ptr_16_32 ptr_16_32_t; |
76 | typedef struct ptr_16_32 ptr_16_32_t; |
74 | 77 | ||
75 | struct descriptor { |
78 | struct descriptor { |
76 | unsigned limit_0_15: 16; |
79 | unsigned limit_0_15: 16; |
77 | unsigned base_0_15: 16; |
80 | unsigned base_0_15: 16; |
78 | unsigned base_16_23: 8; |
81 | unsigned base_16_23: 8; |
79 | unsigned access: 8; |
82 | unsigned access: 8; |
80 | unsigned limit_16_19: 4; |
83 | unsigned limit_16_19: 4; |
81 | unsigned available: 1; |
84 | unsigned available: 1; |
82 | unsigned unused: 1; |
85 | unsigned unused: 1; |
83 | unsigned special: 1; |
86 | unsigned special: 1; |
84 | unsigned granularity : 1; |
87 | unsigned granularity : 1; |
85 | unsigned base_24_31: 8; |
88 | unsigned base_24_31: 8; |
86 | } __attribute__ ((packed)); |
89 | } __attribute__ ((packed)); |
87 | typedef struct descriptor descriptor_t; |
90 | typedef struct descriptor descriptor_t; |
88 | 91 | ||
89 | struct idescriptor { |
92 | struct idescriptor { |
90 | unsigned offset_0_15: 16; |
93 | unsigned offset_0_15: 16; |
91 | unsigned selector: 16; |
94 | unsigned selector: 16; |
92 | unsigned unused: 8; |
95 | unsigned unused: 8; |
93 | unsigned access: 8; |
96 | unsigned access: 8; |
94 | unsigned offset_16_31: 16; |
97 | unsigned offset_16_31: 16; |
95 | } __attribute__ ((packed)); |
98 | } __attribute__ ((packed)); |
96 | typedef struct idescriptor idescriptor_t; |
99 | typedef struct idescriptor idescriptor_t; |
97 | 100 | ||
98 | struct tss { |
101 | struct tss { |
99 | __u16 link; |
102 | __u16 link; |
100 | unsigned : 16; |
103 | unsigned : 16; |
101 | __u32 esp0; |
104 | __u32 esp0; |
102 | __u16 ss0; |
105 | __u16 ss0; |
103 | unsigned : 16; |
106 | unsigned : 16; |
104 | __u32 esp1; |
107 | __u32 esp1; |
105 | __u16 ss1; |
108 | __u16 ss1; |
106 | unsigned : 16; |
109 | unsigned : 16; |
107 | __u32 esp2; |
110 | __u32 esp2; |
108 | __u16 ss2; |
111 | __u16 ss2; |
109 | unsigned : 16; |
112 | unsigned : 16; |
110 | __u32 cr3; |
113 | __u32 cr3; |
111 | __u32 eip; |
114 | __u32 eip; |
112 | __u32 eflags; |
115 | __u32 eflags; |
113 | __u32 eax; |
116 | __u32 eax; |
114 | __u32 ecx; |
117 | __u32 ecx; |
115 | __u32 edx; |
118 | __u32 edx; |
116 | __u32 ebx; |
119 | __u32 ebx; |
117 | __u32 esp; |
120 | __u32 esp; |
118 | __u32 ebp; |
121 | __u32 ebp; |
119 | __u32 esi; |
122 | __u32 esi; |
120 | __u32 edi; |
123 | __u32 edi; |
121 | __u16 es; |
124 | __u16 es; |
122 | unsigned : 16; |
125 | unsigned : 16; |
123 | __u16 cs; |
126 | __u16 cs; |
124 | unsigned : 16; |
127 | unsigned : 16; |
125 | __u16 ss; |
128 | __u16 ss; |
126 | unsigned : 16; |
129 | unsigned : 16; |
127 | __u16 ds; |
130 | __u16 ds; |
128 | unsigned : 16; |
131 | unsigned : 16; |
129 | __u16 fs; |
132 | __u16 fs; |
130 | unsigned : 16; |
133 | unsigned : 16; |
131 | __u16 gs; |
134 | __u16 gs; |
132 | unsigned : 16; |
135 | unsigned : 16; |
133 | __u16 ldtr; |
136 | __u16 ldtr; |
134 | unsigned : 16; |
137 | unsigned : 16; |
135 | unsigned : 16; |
138 | unsigned : 16; |
136 | __u16 iomap_base; |
139 | __u16 iomap_base; |
137 | __u8 iomap[TSS_IOMAP_SIZE]; |
140 | __u8 iomap[TSS_IOMAP_SIZE]; |
138 | } __attribute__ ((packed)); |
141 | } __attribute__ ((packed)); |
139 | typedef struct tss tss_t; |
142 | typedef struct tss tss_t; |
140 | 143 | ||
141 | extern ptr_16_32_t gdtr; |
144 | extern ptr_16_32_t gdtr; |
142 | extern ptr_16_32_t bootstrap_gdtr; |
145 | extern ptr_16_32_t bootstrap_gdtr; |
143 | extern ptr_16_32_t protected_ap_gdtr; |
146 | extern ptr_16_32_t protected_ap_gdtr; |
144 | extern struct tss *tss_p; |
147 | extern struct tss *tss_p; |
145 | 148 | ||
146 | extern descriptor_t gdt[]; |
149 | extern descriptor_t gdt[]; |
147 | 150 | ||
148 | extern void pm_init(void); |
151 | extern void pm_init(void); |
149 | 152 | ||
150 | extern void gdt_setbase(descriptor_t *d, __address base); |
153 | extern void gdt_setbase(descriptor_t *d, __address base); |
151 | extern void gdt_setlimit(descriptor_t *d, __u32 limit); |
154 | extern void gdt_setlimit(descriptor_t *d, __u32 limit); |
152 | 155 | ||
153 | extern void idt_init(void); |
156 | extern void idt_init(void); |
154 | extern void idt_setoffset(idescriptor_t *d, __address offset); |
157 | extern void idt_setoffset(idescriptor_t *d, __address offset); |
155 | 158 | ||
156 | extern void tss_initialize(tss_t *t); |
159 | extern void tss_initialize(tss_t *t); |
157 | extern void set_tls_desc(__address tls); |
160 | extern void set_tls_desc(__address tls); |
158 | 161 | ||
159 | #endif /* __ASM__ */ |
162 | #endif /* __ASM__ */ |
160 | 163 | ||
161 | #endif |
164 | #endif |
162 | 165 |