1 | /* |
---|
2 | * cpu-internal.h - cpu internal data structures |
---|
3 | * |
---|
4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
---|
5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
---|
6 | * |
---|
7 | * This file is part of ALMOS-kernel. |
---|
8 | * |
---|
9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
---|
10 | * under the terms of the GNU General Public License as published by |
---|
11 | * the Free Software Foundation; version 2.0 of the License. |
---|
12 | * |
---|
13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
---|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | * General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef _CPU_INTERNAL_H_ |
---|
24 | #define _CPU_INTERNAL_H_ |
---|
25 | |
---|
26 | #include <types.h> |
---|
27 | |
---|
28 | enum |
---|
29 | { |
---|
30 | GDT_NULL_ENTRY = 0, /* 0x00 */ |
---|
31 | |
---|
32 | GDT_KTEXT_ENTRY, /* 0x08 */ |
---|
33 | GDT_KDATA_ENTRY, /* 0x10 */ |
---|
34 | |
---|
35 | GDT_UTEXT_ENTRY, /* 0x18 used in cpu_context.c::__cpu_context_init */ |
---|
36 | GDT_UDATA_ENTRY, /* 0x20 used in cpu_context.c::__cpu_context_init */ |
---|
37 | GDT_UTLS_ENTRY, /* 0x28 used in cpu_context.c::__cpu_context_init */ |
---|
38 | GDT_FIXED_NR |
---|
39 | }; |
---|
40 | |
---|
41 | /* GDT table entry type */ |
---|
42 | struct cpu_gdt_entry_s |
---|
43 | { |
---|
44 | uint16_t limit_low; |
---|
45 | uint16_t base_low; |
---|
46 | uint8_t base_middle; |
---|
47 | uint8_t access; |
---|
48 | uint8_t granularity; |
---|
49 | uint8_t base_high; |
---|
50 | } __attribute__((packed)); |
---|
51 | |
---|
52 | /* GDT pointer type */ |
---|
53 | struct cpu_gdt_ptr_s |
---|
54 | { |
---|
55 | uint16_t limit; |
---|
56 | uint32_t base; |
---|
57 | } __attribute__((packed)); |
---|
58 | |
---|
59 | void cpu_gdt_init(); |
---|
60 | void cpu_idt_init(); |
---|
61 | |
---|
62 | struct cpu_gdt_entry_s* cpu_get_gdt_entry(int entry); |
---|
63 | struct cpu_gdt_ptr_s* cpu_get_gdt_ptr(void); |
---|
64 | |
---|
65 | /* IDT table entry type */ |
---|
66 | struct cpu_idt_entry_s |
---|
67 | { |
---|
68 | uint16_t offset_low; |
---|
69 | uint16_t selector; |
---|
70 | uint8_t reserved; |
---|
71 | uint8_t flags; |
---|
72 | uint16_t offset_high; |
---|
73 | } __attribute__((packed)); |
---|
74 | |
---|
75 | /* IDT pointer type */ |
---|
76 | struct cpu_idt_ptr_s |
---|
77 | { |
---|
78 | uint16_t limit; |
---|
79 | uint32_t base; |
---|
80 | } __attribute__((packed)); |
---|
81 | |
---|
82 | /* Task State Segment type */ |
---|
83 | struct cpu_tss_s |
---|
84 | { |
---|
85 | uint16_t pred_link; /* 0 */ |
---|
86 | uint16_t reserved_0; |
---|
87 | |
---|
88 | uint32_t esp_r0; /* 1 */ |
---|
89 | uint16_t ss_r0; /* 2 */ |
---|
90 | uint16_t reserved_1; |
---|
91 | |
---|
92 | uint32_t esp_r1; /* 3 */ |
---|
93 | uint16_t ss_r1; /* 4 */ |
---|
94 | uint16_t reserved_2; |
---|
95 | |
---|
96 | uint32_t esp_r2; /* 5 */ |
---|
97 | uint16_t ss_r2; /* 6 */ |
---|
98 | uint16_t reserved_3; |
---|
99 | |
---|
100 | uint32_t cr3_pdbr; /* 7 */ |
---|
101 | uint32_t eip; |
---|
102 | uint32_t eflags; |
---|
103 | |
---|
104 | uint32_t eax,ecx,edx,ebx; /* 10 */ |
---|
105 | uint32_t esp,ebp,esi,edi; /* 14 */ |
---|
106 | |
---|
107 | uint16_t es, reserved_4; /* 18 */ |
---|
108 | uint16_t cs, reserved_5; /* 19 */ |
---|
109 | uint16_t ss, reserved_6; /* 20 */ |
---|
110 | uint16_t ds, reserved_7; /* 21 */ |
---|
111 | uint16_t fs, reserved_8; /* 22 */ |
---|
112 | uint16_t gs, reserved_9; /* 23 */ |
---|
113 | uint16_t ldt,reserved_10; /* 24 */ |
---|
114 | |
---|
115 | uint16_t T:1; /* 25 */ |
---|
116 | uint16_t reserved_11:15; |
---|
117 | uint16_t io_map; |
---|
118 | } __attribute__ ((packed)); |
---|
119 | |
---|
120 | |
---|
121 | struct cpu_tss_s* cpu_get_tss(int cpu_id); |
---|
122 | void cpu_set_utls(uint_t addr); |
---|
123 | |
---|
124 | /* CPU Registers */ |
---|
125 | struct cpu_regs_s |
---|
126 | { |
---|
127 | uint_t gs; |
---|
128 | uint_t fs; |
---|
129 | uint_t es; |
---|
130 | uint_t ds; |
---|
131 | uint_t edi; |
---|
132 | uint_t esi; |
---|
133 | uint_t ebp; |
---|
134 | uint_t esp; |
---|
135 | uint_t ebx; |
---|
136 | uint_t edx; |
---|
137 | uint_t ecx; |
---|
138 | uint_t eax; |
---|
139 | uint_t int_nr; |
---|
140 | uint_t err_code; |
---|
141 | uint_t ret_eip; |
---|
142 | uint_t ret_cs; |
---|
143 | uint_t eflags; |
---|
144 | uint_t old_esp; |
---|
145 | uint_t old_ss; |
---|
146 | } __attribute__ ((packed)); |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | #endif /* _CPU_INTERNAL_H_ */ |
---|