mirror of
https://github.com/tailix/kernel.git
synced 2025-02-17 15:45:37 -05:00
Join "arch/gdt.c" and "arch/idt.c" into "arch/protected.c"
This commit is contained in:
parent
00948f035c
commit
1dbef1b866
3 changed files with 56 additions and 62 deletions
|
@ -3,7 +3,7 @@ CCPREFIX = i686-elf-
|
|||
AS = $(CCPREFIX)as
|
||||
CC = $(CCPREFIX)gcc
|
||||
|
||||
OBJS = boot.s.o main.c.o logger.c.o console.c.o gdt.c.o idt.c.o isr.c.o isr.asm.o multiboot.c.o protected.asm.cpp.o
|
||||
OBJS = boot.s.o main.c.o logger.c.o console.c.o isr.c.o isr.asm.o multiboot.c.o protected.asm.cpp.o protected.c.o
|
||||
|
||||
all: kernel
|
||||
|
||||
|
|
60
arch/gdt.c
60
arch/gdt.c
|
@ -1,60 +0,0 @@
|
|||
#include "protected.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "logger.h"
|
||||
|
||||
struct GdtPointer {
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct GdtEntry {
|
||||
unsigned short limit_low;
|
||||
unsigned short base_low;
|
||||
unsigned char base_middle;
|
||||
unsigned char access;
|
||||
unsigned char granularity;
|
||||
unsigned char base_high;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
static struct GdtPointer gdt_pointer;
|
||||
|
||||
static struct GdtEntry gdt_entries[GDT_SIZE];
|
||||
|
||||
static void gdt_set_gate(int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran);
|
||||
|
||||
void gdt_flush(unsigned int pointer);
|
||||
|
||||
void gdt_initialize()
|
||||
{
|
||||
logger_info("Setup GDT.");
|
||||
|
||||
gdt_set_gate(GDT_NULL_INDEX, 0, 0x00000000, 0, 0);
|
||||
gdt_set_gate(GDT_KERNEL_CS_INDEX, 0, 0xFFFFFFFF, 0x9A, 0xCF);
|
||||
gdt_set_gate(GDT_KERNEL_DS_INDEX, 0, 0xFFFFFFFF, 0x92, 0xCF);
|
||||
gdt_set_gate(GDT_USER_CS_INDEX, 0, 0xFFFFFFFF, 0xFA, 0xCF);
|
||||
gdt_set_gate(GDT_USER_DS_INDEX, 0, 0xFFFFFFFF, 0xF2, 0xCF);
|
||||
|
||||
logger_info("Load GDT.");
|
||||
|
||||
gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1;
|
||||
gdt_pointer.base = (unsigned int)&gdt_entries;
|
||||
|
||||
gdt_flush((unsigned int)&gdt_pointer);
|
||||
}
|
||||
|
||||
void gdt_set_gate(int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran)
|
||||
{
|
||||
gdt_entries[num].base_low = (base & 0xFFFF);
|
||||
gdt_entries[num].base_middle = (base >> 16) & 0xFF;
|
||||
gdt_entries[num].base_high = (base >> 24) & 0xFF;
|
||||
|
||||
gdt_entries[num].limit_low = (limit & 0xFFFF);
|
||||
gdt_entries[num].granularity = (limit >> 16) & 0x0F;
|
||||
|
||||
gdt_entries[num].granularity |= gran & 0xF0;
|
||||
|
||||
gdt_entries[num].access = access;
|
||||
}
|
|
@ -1,13 +1,30 @@
|
|||
#include "protected.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "logger.h"
|
||||
|
||||
struct GdtPointer {
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct IdtPointer {
|
||||
unsigned short limit;
|
||||
unsigned int base;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct GdtEntry {
|
||||
unsigned short limit_low;
|
||||
unsigned short base_low;
|
||||
unsigned char base_middle;
|
||||
unsigned char access;
|
||||
unsigned char granularity;
|
||||
unsigned char base_high;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct IdtEntry {
|
||||
unsigned short base_lo;
|
||||
unsigned short sel;
|
||||
|
@ -17,12 +34,17 @@ struct IdtEntry {
|
|||
}
|
||||
__attribute__((packed));
|
||||
|
||||
static struct GdtPointer gdt_pointer;
|
||||
static struct IdtPointer idt_pointer;
|
||||
|
||||
static struct IdtEntry idt_entries[256];
|
||||
static struct GdtEntry gdt_entries[GDT_SIZE];
|
||||
static struct IdtEntry idt_entries[IDT_SIZE];
|
||||
|
||||
static void gdt_set_gate(int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran);
|
||||
|
||||
static void idt_set_gate(unsigned char num, unsigned int base, unsigned short sel, unsigned char flags);
|
||||
|
||||
void gdt_flush(unsigned int pointer);
|
||||
void idt_flush(unsigned int pointer);
|
||||
|
||||
void isr0();
|
||||
|
@ -58,6 +80,24 @@ void isr29();
|
|||
void isr30();
|
||||
void isr31();
|
||||
|
||||
void gdt_initialize()
|
||||
{
|
||||
logger_info("Setup GDT.");
|
||||
|
||||
gdt_set_gate(GDT_NULL_INDEX, 0, 0x00000000, 0, 0);
|
||||
gdt_set_gate(GDT_KERNEL_CS_INDEX, 0, 0xFFFFFFFF, 0x9A, 0xCF);
|
||||
gdt_set_gate(GDT_KERNEL_DS_INDEX, 0, 0xFFFFFFFF, 0x92, 0xCF);
|
||||
gdt_set_gate(GDT_USER_CS_INDEX, 0, 0xFFFFFFFF, 0xFA, 0xCF);
|
||||
gdt_set_gate(GDT_USER_DS_INDEX, 0, 0xFFFFFFFF, 0xF2, 0xCF);
|
||||
|
||||
logger_info("Load GDT.");
|
||||
|
||||
gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1;
|
||||
gdt_pointer.base = (unsigned int)&gdt_entries;
|
||||
|
||||
gdt_flush((unsigned int)&gdt_pointer);
|
||||
}
|
||||
|
||||
void idt_initialize()
|
||||
{
|
||||
logger_info("Setup IDT.");
|
||||
|
@ -107,6 +147,20 @@ void idt_initialize()
|
|||
idt_flush((unsigned int)&idt_pointer);
|
||||
}
|
||||
|
||||
void gdt_set_gate(int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran)
|
||||
{
|
||||
gdt_entries[num].base_low = (base & 0xFFFF);
|
||||
gdt_entries[num].base_middle = (base >> 16) & 0xFF;
|
||||
gdt_entries[num].base_high = (base >> 24) & 0xFF;
|
||||
|
||||
gdt_entries[num].limit_low = (limit & 0xFFFF);
|
||||
gdt_entries[num].granularity = (limit >> 16) & 0x0F;
|
||||
|
||||
gdt_entries[num].granularity |= gran & 0xF0;
|
||||
|
||||
gdt_entries[num].access = access;
|
||||
}
|
||||
|
||||
void idt_set_gate(unsigned char num, unsigned int base, unsigned short sel, unsigned char flags)
|
||||
{
|
||||
idt_entries[num].base_lo = base & 0xFFFF;
|
Loading…
Add table
Reference in a new issue