Implemented IDT, modified Makefile and boot.S
This commit is contained in:
parent
b5640dfb24
commit
83ae049f71
|
@ -25,7 +25,7 @@ CFLAGS:=$(CFLAGS) -ffreestanding -D__is_kernel -Iinclude -Wall -Wextra -Werror
|
|||
CPPFLAGS:=$(CPPFLAGS)
|
||||
LDFLAGS:=$(LDFLAGS)
|
||||
LIB_INCLUDE_FLAGS=-L./lib/so
|
||||
LIBS:=$(LIBS) -nostdlib -lgcc -lklib #-lk -lgcc
|
||||
LIBS:=$(LIBS) -nostdlib -lgcc -lklib -lk
|
||||
|
||||
# Current architecture directory
|
||||
|
||||
|
@ -37,6 +37,7 @@ include $(ARCHDIR)/make.config
|
|||
|
||||
# Updated compiler flags with architecture settings added
|
||||
|
||||
CFLAGS+=-I$(KERNEL_ARCH_INCLUDE)
|
||||
CFLAGS:=$(CFLAGS) $(KERNEL_ARCH_CFLAGS)
|
||||
CPPFLAGS:=$(CPPFLAGS) $(KERNEL_ARCH_CPPFLAGS)
|
||||
LDFLAGS:=$(LDFLAGS) $(KERNEL_ARCH_LDFLAGS)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "gdt.h"
|
||||
#include "a20.h"
|
||||
#include "tables/gdt.h"
|
||||
#include "tables/a20.h"
|
||||
|
||||
.global _start
|
||||
|
||||
|
|
|
@ -5,3 +5,10 @@ KERNEL_ARCH_LIBS=
|
|||
|
||||
KERNEL_ARCH_OBJS=\
|
||||
$(ARCHDIR)/boot.o \
|
||||
$(ARCHDIR)/tables/idt.o \
|
||||
$(ARCHDIR)/tables/idt_flush.o \
|
||||
$(ARCHDIR)/tables/isr.o \
|
||||
$(ARCHDIR)/tables/isr_gate.o \
|
||||
|
||||
KERNEL_ARCH_INCLUDE=\
|
||||
$(ARCHDIR)/ \
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#define GDT_ENTRY(base, limit, options) \
|
||||
(limit & 0x0000FFFF) | (base << 16) | \
|
||||
((((base >> 16) & 0x000000FF) | ((options << 8) & 0x00F0FF00) | \
|
|
@ -0,0 +1,34 @@
|
|||
#include "idt.h"
|
||||
|
||||
#include "types/idt_types.h"
|
||||
|
||||
/* Data structures used to fill the IDT. */
|
||||
|
||||
idt_entry_t idt_entries[256];
|
||||
idt_ptr_t idt_ptr;
|
||||
|
||||
/* Routine that installs the IDT. */
|
||||
|
||||
extern void idt_flush(uint32_t idt_ptr);
|
||||
|
||||
/*
|
||||
* idt_init:
|
||||
* ---------
|
||||
*
|
||||
* After the table and the table pointer are filled, flush the table pointer
|
||||
* using gdt_flush.
|
||||
*
|
||||
*/
|
||||
|
||||
void idt_init(void) {
|
||||
|
||||
idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1;
|
||||
idt_ptr.base = (uint32_t) &idt_entries;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
idt_entries[i] = (idt_entry_t) {};
|
||||
|
||||
idt_flush((uint32_t) &idt_ptr);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef INTRPT_H_
|
||||
#define INTRPT_H_
|
||||
|
||||
/*
|
||||
* idt_init:
|
||||
* Creates an array of 256 empty entries that will be loaded in the CPU as
|
||||
* an IDT.
|
||||
*
|
||||
*/
|
||||
|
||||
void idt_init(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,15 @@
|
|||
.global idt_flush
|
||||
|
||||
/*
|
||||
* idt_flush - load the 48bit memory that contains the information about
|
||||
* the IDT in its corresponding register using the LIDT instruction.
|
||||
*
|
||||
* @param [esp + 4] - pointer to a 48bit memory location
|
||||
*
|
||||
*/
|
||||
|
||||
idt_flush:
|
||||
|
||||
mov 0x04(%esp), %eax
|
||||
lidt (%eax)
|
||||
ret
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef INTRPT_IDT_H_
|
||||
#define INTRPT_IDT_H_
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
/*
|
||||
* idt_entry_t - entry in Interrupt Descriptor Table
|
||||
* idt_set_gate - creates an IDT entry
|
||||
*
|
||||
*/
|
||||
|
||||
struct idt_entry_struct {
|
||||
|
||||
uint16_t base_low;
|
||||
uint16_t selector;
|
||||
uint8_t zero;
|
||||
uint8_t flags;
|
||||
uint16_t base_high;
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct idt_entry_struct idt_entry_t;
|
||||
|
||||
|
||||
static inline idt_entry_t idt_set_gate(uint32_t base, uint16_t sel, uint8_t flags) {
|
||||
|
||||
idt_entry_t entry;
|
||||
|
||||
entry.base_low = base & 0xFFFF;
|
||||
entry.selector = sel;
|
||||
entry.zero = 0x00;
|
||||
entry.flags = flags;
|
||||
entry.base_high = (base >> 16) & 0xFFFF;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* idt_ptr_t - IDT pointer that will be loaded in CPU */
|
||||
|
||||
struct idt_ptr_struct {
|
||||
|
||||
uint16_t limit;
|
||||
uint32_t base;
|
||||
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct idt_ptr_struct idt_ptr_t;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue