Add: IDT implementation without ISRs
This commit is contained in:
42
idt.c
Normal file
42
idt.c
Normal 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
8
idt.h
Normal 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.
BIN
kernel.elf
BIN
kernel.elf
Binary file not shown.
2
kmain.c
2
kmain.c
@@ -1,11 +1,13 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
|
#include "idt.h"
|
||||||
|
|
||||||
int kmain(int retvalue)
|
int kmain(int retvalue)
|
||||||
{
|
{
|
||||||
|
|
||||||
gdt_install();
|
gdt_install();
|
||||||
|
idt_install();
|
||||||
|
|
||||||
// serial testing
|
// serial testing
|
||||||
|
|
||||||
|
|||||||
7
loader.s
7
loader.s
@@ -38,6 +38,13 @@ gdt_flush:
|
|||||||
flush2:
|
flush2:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
global idt_load
|
||||||
|
extern idtp
|
||||||
|
|
||||||
|
idt_load:
|
||||||
|
lidt [idtp]
|
||||||
|
ret
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
align 4
|
align 4
|
||||||
kernel_stack:
|
kernel_stack:
|
||||||
|
|||||||
2
makefile
2
makefile
@@ -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
|
CC = gcc
|
||||||
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c
|
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c
|
||||||
LDFLAGS = -T link.ld -melf_i386
|
LDFLAGS = -T link.ld -melf_i386
|
||||||
|
|||||||
8
system.c
Normal file
8
system.c
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user