Add: IDT implementation without ISRs

This commit is contained in:
xamidev
2024-07-14 16:58:35 +02:00
parent 007018790a
commit da6cb6c86d
10 changed files with 76 additions and 1 deletions

42
idt.c Normal file
View File

@@ -0,0 +1,42 @@
#include "idt.h"
#include "system.h"
struct idt_entry
{
unsigned short base_lo;
unsigned short sel;
unsigned char always0;
unsigned char flags;
unsigned short base_hi;
} __attribute__((packed));
struct idt_ptr
{
unsigned short limit;
unsigned int base;
} __attribute__((packed));
struct idt_entry idt[256];
struct idt_ptr idtp;
extern void idt_load();
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags)
{
idt[num].base_lo = (base & 0xFFFF);
idt[num].base_hi = (base >> 16) & 0xFFFF;
idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags;
}
void idt_install()
{
idtp.limit = (sizeof (struct idt_entry)*256) - 1;
idtp.base = (unsigned int)&idt;
memset(&idt, 0, sizeof(struct idt_entry)*256);
idt_load();
}

8
idt.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef IDT_H
#define IDT_H
void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags);
void idt_install();
#endif

Binary file not shown.

Binary file not shown.

View File

@@ -1,11 +1,13 @@
#include "stdio.h"
#include "serial.h"
#include "gdt.h"
#include "idt.h"
int kmain(int retvalue)
{
gdt_install();
idt_install();
// serial testing

View File

@@ -38,6 +38,13 @@ gdt_flush:
flush2:
ret
global idt_load
extern idtp
idt_load:
lidt [idtp]
ret
section .bss
align 4
kernel_stack:

View File

@@ -1,4 +1,4 @@
OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o
OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o idt.o system.o
CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c
LDFLAGS = -T link.ld -melf_i386

BIN
os.iso

Binary file not shown.

8
system.c Normal file
View File

@@ -0,0 +1,8 @@
#include "system.h"
void *memset(void *dest, char val, size_t count)
{
char *temp = (char *)dest;
for(; count != 0; count--) *temp++ = val;
return dest;
}

8
system.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef SYSTEM_H
#define SYSTEM_H
typedef int size_t;
void *memset(void *dest, char val, size_t count);
#endif