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