FENIX_kernel/arch/i386/init.c

51 lines
1 KiB
C
Raw Normal View History

2020-12-02 02:59:33 +00:00
#include <kernel/init.h>
#include <kernel/interrupt.h>
2020-12-02 02:59:33 +00:00
#include <string.h>
2020-12-18 18:38:32 +00:00
#include <sys/io.h>
#include "gdt.h"
int tss[16][2];
2020-12-02 02:59:33 +00:00
2020-12-18 18:38:32 +00:00
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 = 0; gdt[1].limit = 0xFFFFFFFF; gdt[1].type = 0x9A;
gdt[2].base = 0; gdt[2].limit = 0xFFFFFFFF; 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));
}
2020-12-02 02:59:33 +00:00
int init(void) {
2020-12-18 18:38:32 +00:00
NMI_disable();
A20_enable();
setup_gdt();
idt_init();
2020-12-02 02:59:33 +00:00
printf("Fenix Dev Pre-release v0.0.3\n");
2020-12-22 23:26:30 +00:00
return 0;
2020-12-02 02:59:33 +00:00
}