POK(kernelpart)
gdt.h
Go to the documentation of this file.
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Thu Jan 15 23:34:13 2009
15  */
16 
17 
18 #ifndef __POK_X86_GDT_H__
19 #define __POK_X86_GDT_H__
20 
21 #include <types.h>
22 
23 typedef enum e_gdte_type
24 {
25  GDTE_CODE = 0xB,
26  GDTE_DATA = 0x3,
27  GDTE_TSS = 0x9
28 } e_gdte_type;
29 
30 typedef struct
31 {
32  uint32_t limit_low:16;
33  uint32_t base_low:24 __attribute__ ((packed));
34  uint32_t type:4;
35  uint32_t s:1;
36  uint32_t dpl:2;
37  uint32_t present:1;
38  uint32_t limit_high:4;
39  uint32_t available:2;
40  uint32_t op_size:1;
41  uint32_t granularity:1;
42  uint32_t base_high:8;
43 } __attribute__((packed)) gdt_entry_t;
44 
45 #define GDT_CORE_CODE_SEGMENT 1
46 #define GDT_CORE_DATA_SEGMENT 2
47 #define GDT_TSS_SEGMENT 3
48 
49 #define GDT_PARTITION_CODE_SEGMENT(partition_id) (4 + 2 * partition_id)
50 #define GDT_PARTITION_DATA_SEGMENT(partition_id) (4 + 2 * partition_id + 1)
51 
52 #define GDT_BUILD_SELECTOR(seg, local, rpl) \
53  ((seg << 3) | ((local & 0x1) << 2) | (rpl & 0x3))
54 
56 int pok_tss_init();
57 
58 void tss_set_esp0(uint32_t esp0);
59 
60 void gdt_set_segment (uint16_t index,
61  uint32_t base_address,
62  uint32_t limit,
63  e_gdte_type t,
64  int dpl);
65 
66 void gdt_set_system (uint16_t index,
67  uint32_t base_address,
68  uint32_t limit,
69  e_gdte_type t,
70  int dpl);
71 
72 void gdt_enable (uint16_t index);
73 void gdt_disable (uint16_t index);
74 
75 /*
76  * DEPRECATED
77 uint32_t gdt_segment_base(uint16_t idx);
78 */
79 
80 #endif /* !__POK_X86_GDT_H__ */
81