Added support for basic x86 features

Includes 'gdt', 'idt' and a serial driver
This commit is contained in:
Michael Shaw 2023-02-27 18:36:15 -05:00
commit ca5351b847
11 changed files with 231 additions and 67 deletions

10
include/kernel/common.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef _COMMON_H_
#define _COMMON_H_
#include <limine/limine.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#endif /* _COMMON_H_ */

37
include/kernel/gdt.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef _GDT_H_
#define _GDT_H_
#define GDT_NUMDESC 64
#define GDT_SIZE (64 * GDT_NUMDESC)
#define GDT_ACCESS_DATA_RING0 0b10010010
#define GDT_ACCESS_CODE_RING0 0b10011010
#define GDT_ACCESS_DATA_RING3 0b11110010
#define GDT_ACCESS_CODE_RING3 0b11111010
#ifndef __ASM__
#include <stdint.h>
struct gdt_desc {
uint16_t limit;
uint16_t base;
uint8_t base_2;
uint8_t access;
uint8_t flags;
uint8_t base_3;
};
struct gdtr {
uint16_t size;
uint64_t offset;
};
extern struct gdtr __gdtr;
extern struct gdt_desc __gdt[GDT_NUMDESC];
void gdt_init();
#endif /* __ASM__ */
#endif /* _GDT_H_ */

34
include/kernel/idt.h Normal file
View file

@ -0,0 +1,34 @@
#ifndef _IDT_H_
#define _IDT_H_
#define GATE_INTR 0x8E
#define GATE_TRAP 0x8F
#define IDT_GATE_SIZE 16
#define IDT_NUM_VECTORS 256
#define IDT_SIZE 32768
#ifndef __ASM__
#include <stdint.h>
struct irqdesc {
uint16_t offset_low;
uint16_t segment;
uint8_t ist;
uint8_t attrs;
uint16_t offset_mid;
uint32_t offset_high;
uint32_t reserved;
};
struct idtr {
uint16_t size;
uint64_t offset;
};
extern struct idtr __idtr;
extern struct irqdesc __idt[IDT_NUM_VECTORS];
#endif /* __ASM__ */
#endif /* _IDT_H_ */