x86: add GDT and IDT
Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
f10e3f31d7
commit
e5b55a6ba5
25 changed files with 1211 additions and 13 deletions
91
amd64/init/descriptor.h
Normal file
91
amd64/init/descriptor.h
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _DESCRIPTOR_H_
|
||||
#define _DESCRIPTOR_H_
|
||||
|
||||
#define GDT_ACCESS_DATA_RING0 0b10010010
|
||||
#define GDT_ACCESS_CODE_RING0 0b10011010
|
||||
|
||||
#define GDT_ACCESS_DATA_RING3 0b11110010
|
||||
#define GDT_ACCESS_CODE_RING3 0b11111010
|
||||
|
||||
#define GDT_SEGMENT_CODE_RING0 0x28
|
||||
#define GDT_SEGMENT_DATA_RING0 0x30
|
||||
#define GDT_SEGMENT_CODE_RING3 0x38
|
||||
#define GDT_SEGMENT_DATA_RING3 0x40
|
||||
|
||||
#define GATE_INTR 0x8E
|
||||
#define GATE_TRAP 0x8F
|
||||
|
||||
#define GATE_INTR_DPL3 0xEE
|
||||
|
||||
|
||||
#include <kernel/common.h>
|
||||
|
||||
struct gdt_desc {
|
||||
uint16_t limit;
|
||||
uint16_t base;
|
||||
uint8_t base_2;
|
||||
uint8_t access;
|
||||
uint8_t flags;
|
||||
uint8_t base_3;
|
||||
} PACKED;
|
||||
|
||||
struct gdt_desc_sys {
|
||||
uint16_t limit;
|
||||
uint16_t base;
|
||||
uint8_t base_2;
|
||||
uint8_t access;
|
||||
uint8_t flags;
|
||||
uint8_t base_3;
|
||||
uint32_t base_4;
|
||||
uint32_t reserved;
|
||||
} PACKED;
|
||||
|
||||
struct tss {
|
||||
uint32_t reserved;
|
||||
uint64_t rsp0;
|
||||
uint64_t rsp1;
|
||||
uint64_t rsp2;
|
||||
uint64_t reserved2;
|
||||
uint64_t ist1;
|
||||
uint64_t ist2;
|
||||
uint64_t ist3;
|
||||
uint64_t ist4;
|
||||
uint64_t ist5;
|
||||
uint64_t ist6;
|
||||
uint64_t ist7;
|
||||
uint64_t reserved3;
|
||||
uint16_t reserved4;
|
||||
uint16_t iomap_base;
|
||||
} PACKED;
|
||||
|
||||
struct gdtr {
|
||||
uint16_t size;
|
||||
uint64_t offset;
|
||||
} PACKED;
|
||||
|
||||
struct irq_desc {
|
||||
uint16_t offset_low;
|
||||
uint16_t segment;
|
||||
uint8_t ist;
|
||||
uint8_t attrs;
|
||||
uint16_t offset_mid;
|
||||
uint32_t offset_high;
|
||||
uint32_t reserved;
|
||||
} PACKED;
|
||||
|
||||
struct idtr {
|
||||
uint16_t size;
|
||||
uint64_t offset;
|
||||
} PACKED;
|
||||
|
||||
extern struct gdtr __gdtr;
|
||||
extern struct gdt_desc __gdt[64];
|
||||
|
||||
extern struct idtr __idtr;
|
||||
extern struct irq_desc __idt[64];
|
||||
|
||||
void gdt_init();
|
||||
void idt_init();
|
||||
|
||||
#endif /* _DESCRIPTOR_H_ */
|
||||
Loading…
Reference in a new issue