FENIX_kernel/arch/i386/init.c
2021-01-10 14:42:49 -06:00

52 lines
1.1 KiB
C
Executable file

#include <kernel/init.h>
#include <kernel/interrupt.h>
#include <string.h>
#include <sys/io.h>
#include "gdt.h"
int tss[16][2];
void NMI_disable(void) {
outb(0x70, inb(0x70) | 0x80);
}
void NMI_enable(void) {
outb(0x70, inb(0x70) & 0x7F);
}
void A20_enable(void) {
unsigned short int a = inb(0x92);
if((a & 2) != 0) {
return;
}
a |= 2;
outb(a, 0x92);
}
void setup_gdt(void) {
struct GDT gdt[4];
gdt[0].base = 0; gdt[0].limit = 0; gdt[0].type = 0;
gdt[1].base = 0x4000000; gdt[1].limit = 0x3FFFFFF; gdt[1].type = 0x9A;
gdt[2].base = 0x8000000; gdt[2].limit = 0x3FFFFFF; gdt[2].type = 0x92;
gdt[3].base = (unsigned int) tss; gdt[3].limit=sizeof(tss); gdt[3].type = 0x89;
unsigned short int GDT[4];
encode_gdt_entry(&GDT[0], gdt[0]);
encode_gdt_entry(&GDT[1], gdt[1]);
encode_gdt_entry(&GDT[2], gdt[2]);
encode_gdt_entry(&GDT[3], gdt[3]);
set_gdt(GDT, sizeof(GDT));
}
extern void enter_pmode(void);
int init(void) {
printf("Setting up GDT...\n");
setup_gdt();
printf("Enabling interrupts...\n");
idt_init();
printf("Fenix Dev Pre-release v0.0.3\n");
return 0;
}