2021-07-13 03:05:58 +00:00
|
|
|
#ifndef GDT_H
|
|
|
|
#define GDT_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2021-07-13 19:38:19 +00:00
|
|
|
#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
|
|
|
|
|
2021-07-13 03:05:58 +00:00
|
|
|
struct gdt_entry
|
|
|
|
{
|
|
|
|
uint16_t limit_1 : 16;
|
2021-07-13 18:10:35 +00:00
|
|
|
uint16_t base_1 : 16;
|
|
|
|
uint8_t base_2 : 8;
|
2021-07-13 20:31:01 +00:00
|
|
|
uint8_t accessed : 1;
|
|
|
|
uint8_t rw : 1;
|
|
|
|
uint8_t dc : 1;
|
|
|
|
uint8_t ex : 1;
|
2021-07-13 18:10:35 +00:00
|
|
|
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;
|
2021-07-13 16:19:12 +00:00
|
|
|
} __attribute__ ((packed));
|
2021-07-13 03:05:58 +00:00
|
|
|
|
2021-07-13 19:38:19 +00:00
|
|
|
struct gdt
|
|
|
|
{
|
|
|
|
struct gdt_entry entries[GDT_NB_ENTRIES];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gdt_r
|
|
|
|
{
|
|
|
|
uint32_t addr;
|
|
|
|
uint16_t limit;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct segment_selector
|
|
|
|
{
|
|
|
|
uint8_t rpl : 2;
|
|
|
|
uint8_t table_indicator : 1;
|
|
|
|
uint16_t index : 13;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
void init_gdt();
|
|
|
|
|
2021-07-13 03:05:58 +00:00
|
|
|
#endif /* !GDT_H */
|