53 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #ifndef GDT_H
 | |
| #define GDT_H
 | |
| 
 | |
| #include <stdint.h>
 | |
| 
 | |
| #define GDT_NB_ENTRIES 3
 | |
| #define GDT_SIZE (GDT_NB_ENTRIES * sizeof(struct gdt_entry))
 | |
| 
 | |
| #define KERNEL_CS_INDEX 1
 | |
| #define KERNEL_DS_INDEX 2
 | |
| 
 | |
| struct gdt_entry
 | |
| {
 | |
|     uint16_t limit_1    : 16;
 | |
|     uint16_t base_1     : 16;
 | |
|     uint8_t base_2      : 8;
 | |
|     uint8_t accessed    : 1;
 | |
|     uint8_t rw          : 1;
 | |
|     uint8_t dc          : 1;
 | |
|     uint8_t ex          : 1;
 | |
|     uint8_t desc_type   : 1;
 | |
|     uint8_t desc_priv   : 2;
 | |
|     uint8_t present     : 1;
 | |
|     uint8_t limit_2     : 4;
 | |
|     uint8_t available   : 1;
 | |
|     uint8_t l           : 1;
 | |
|     uint8_t db          : 1;
 | |
|     uint8_t granularity : 1;
 | |
|     uint8_t base_3      : 8;
 | |
| } __attribute__ ((packed));
 | |
| 
 | |
| struct gdt
 | |
| {
 | |
|     struct gdt_entry entries[GDT_NB_ENTRIES];
 | |
| };
 | |
| 
 | |
| struct gdt_r
 | |
| {
 | |
|     uint16_t limit;
 | |
|     uint32_t addr;
 | |
| } __attribute__ ((packed));
 | |
| 
 | |
| struct segment_selector
 | |
| {
 | |
|     uint8_t rpl             : 2;
 | |
|     uint8_t table_indicator : 1;
 | |
|     uint16_t index          : 13;
 | |
| } __attribute__ ((packed));
 | |
| 
 | |
| void init_gdt();
 | |
| 
 | |
| #endif  /* !GDT_H */
 |