MentOS  0.8.0
The Mentoring Operating System
gdt.h
Go to the documentation of this file.
1 
22 #pragma once
23 
24 #include "stdint.h"
25 
77 enum gdt_bits_t {
79  GDT_PRESENT = 128U,
81  GDT_KERNEL = 0U,
83  GDT_USER = 96U,
85  GDT_S = 16U,
87  GDT_EX = 8U,
89  GDT_DC = 4U,
91  GDT_RW = 2U,
93  GDT_AC = 1U,
102 };
103 
105 #define IDT_PADDING 14U // `0b00001110U
106 
108 typedef struct gdt_descriptor_t {
121 } __attribute__((packed)) gdt_descriptor_t;
122 
124 typedef struct gdt_pointer_t {
129 } __attribute__((packed)) gdt_pointer_t;
130 
137 void init_gdt(void);
138 
145 void gdt_set_gate(uint8_t index, uint32_t base, uint32_t limit, uint8_t access, uint8_t granul);
146 
gdt_bits_t
Bitmasks used to access to specific bits of the GDT.
Definition: gdt.h:77
void gdt_set_gate(uint8_t index, uint32_t base, uint32_t limit, uint8_t access, uint8_t granul)
Sets the value of one GDT entry.
Definition: gdt.c:113
void init_gdt(void)
Initialise the GDT.
Definition: gdt.c:29
@ GDT_DATA
0b00001001U (Writable Data): Identifies a writable data segment.
Definition: gdt.h:97
@ GDT_USER
0b01100000U (Privilege): Sets the 2 privilege bits (ring level) to 3 = lowest (user applications).
Definition: gdt.h:83
@ GDT_DC
0b00000100U (Direction/Conforming)
Definition: gdt.h:89
@ GDT_GRANULARITY
0b10000000U (Granularity): If 0 the limit is in 1 B blocks (byte granularity), if 1 the limit is in 4...
Definition: gdt.h:99
@ GDT_CODE
0b00001100U (Executable Code): Identifies an executable code segment.
Definition: gdt.h:95
@ GDT_OPERAND_SIZE
0b01000000U (Size): If 0 the selector defines 16 bit protected mode. If 1 it defines 32 bit protected...
Definition: gdt.h:101
@ GDT_RW
0b00000010U (Readable/Writable)
Definition: gdt.h:91
@ GDT_PRESENT
0b10000000U (Present): This must be 1 for all valid selectors.
Definition: gdt.h:79
@ GDT_KERNEL
0b00000000U (Privilege): Sets the 2 privilege bits (ring level) to 0 = highest (kernel).
Definition: gdt.h:81
@ GDT_S
0b00010000U (Descriptor): This bit should be set for code or data segments and should be cleared for ...
Definition: gdt.h:85
@ GDT_AC
0b00000001U (Accessed): Just set to 0. The CPU sets this to 1 when the segment is accessed.
Definition: gdt.h:93
@ GDT_EX
0b00001000U (Executable): If 1 code in this segment can be executed, ie. a code selector....
Definition: gdt.h:87
Standard integer data-types.
unsigned short uint16_t
Define the unsigned 16-bit integer.
Definition: stdint.h:24
unsigned int uint32_t
Define the unsigned 32-bit integer.
Definition: stdint.h:18
unsigned char uint8_t
Define the unsigned 8-bit integer.
Definition: stdint.h:30
Data structure representing a GDT descriptor.
Definition: gdt.h:108
uint16_t limit_low
The lower 16 bits of the limit.
Definition: gdt.h:110
uint16_t base_low
The lower 16 bits of the base.
Definition: gdt.h:112
uint8_t base_middle
The next 8 bits of the base.
Definition: gdt.h:114
uint8_t base_high
The last 8 bits of the base.
Definition: gdt.h:120
uint8_t granularity
SegLimit_hi(4 bit) AVL(1 bit) L(1 bit) D/B(1 bit) G(1bit).
Definition: gdt.h:118
uint8_t access
Access flags, determine what ring this segment can be used in.
Definition: gdt.h:116
Data structure used to load the GDT into the GDTR.
Definition: gdt.h:124
uint32_t base
The starting address of the GDT.
Definition: gdt.h:128
uint16_t limit
The size of the GDT (entry number).
Definition: gdt.h:126