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