idt in progress

This commit is contained in:
Adrien Bourmault 2019-04-22 20:15:32 +02:00
parent ceb08e77dd
commit 79f7b736e6
9 changed files with 180 additions and 89 deletions

View File

@ -119,7 +119,7 @@ $(KOBJDIR)/libc/atoi.o: $(KALEIDDIR)/libc/atoi.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR
@$(KCC) -D_NEED_ATOL $< -o $@.2 @$(KCC) -D_NEED_ATOL $< -o $@.2
@$(KCC) -D_NEED_ATOU $< -o $@.3 @$(KCC) -D_NEED_ATOU $< -o $@.3
@$(KCC) -D_NEED_ATOUL $< -o $@.4 @$(KCC) -D_NEED_ATOUL $< -o $@.4
@$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@ @$(LD) $(LDFLAGS) -r $@.1 $@.2 $@.3 $@.4 -o $@
@rm -f $@.1 $@.2 $@.3 $@.4 @rm -f $@.1 $@.2 $@.3 $@.4
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -129,7 +129,7 @@ $(KOBJDIR)/libc/itoa.o: $(KALEIDDIR)/libc/itoa.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR
@$(KCC) -D_NEED_LTOA $< -o $@.2 @$(KCC) -D_NEED_LTOA $< -o $@.2
@$(KCC) -D_NEED_UTOA $< -o $@.3 @$(KCC) -D_NEED_UTOA $< -o $@.3
@$(KCC) -D_NEED_ULTOA $< -o $@.4 @$(KCC) -D_NEED_ULTOA $< -o $@.4
@$(LD) -r $@.1 $@.2 $@.3 $@.4 -o $@ @$(LD) $(LDFLAGS) -r $@.1 $@.2 $@.3 $@.4 -o $@
@rm -f $@.1 $@.2 $@.3 $@.4 @rm -f $@.1 $@.2 $@.3 $@.4
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
@ -138,6 +138,15 @@ $(KOBJDIR)/libc/mem.o: $(KALEIDDIR)/libc/mem.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
@$(KCC) -fno-strict-aliasing $< -o $@ @$(KCC) -fno-strict-aliasing $< -o $@
@echo ${CL2}[$@] ${CL}Compiled.${CL3} @echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/cpu/idt.o: $(KALEIDDIR)/kernel/cpu/idt.c \
$(KALEIDDIR)/kernel/cpu/isr.asm $(INCLUDEDIR)/*/*.h | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/cpu/isr.asm -o $@.1
@$(KCC) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
## MAIN MAKEFILE ------------------------------------------------------------- # ## MAIN MAKEFILE ------------------------------------------------------------- #
$(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR) $(KOBJDIR)/%.o: %.c $(INCLUDEDIR)/*/*.h | $(KOBJDIR)

View File

@ -132,8 +132,11 @@
│   │   └── prog.c │   │   └── prog.c
│   ├── kernel │   ├── kernel
│   │   ├── cpu │   │   ├── cpu
│   │   │   ├── cpu.asm
│   │   │   ├── cpuid.c │   │   │   ├── cpuid.c
│   │   │   └── idt.c │   │   │   ├── handlers.asm
│   │   │   ├── idt.c
│   │   │   └── isr.inc
│   │   ├── init │   │   ├── init
│   │   │   ├── info.c │   │   │   ├── info.c
│   │   │   ├── init.c │   │   │   ├── init.c
@ -174,4 +177,4 @@
├── ProjectTree ├── ProjectTree
└── README.md └── README.md
37 directories, 112 files 37 directories, 115 files

View File

@ -172,6 +172,7 @@ _loader64:
mov qword [newKernelEnd], KERNEL_STACK mov qword [newKernelEnd], KERNEL_STACK
mov rdi, [mbInfo] mov rdi, [mbInfo]
mov rsi, [mbMagic] mov rsi, [mbMagic]
mov rdx, GDT64.code
call BtStartKern call BtStartKern
;; We must never reach this point ------------------------------------------- ;; ;; We must never reach this point ------------------------------------------- ;;

View File

@ -46,6 +46,7 @@ struct BootInfo_t
void *modulesAddr; //mods_addr void *modulesAddr; //mods_addr
char *grubName; //boot_loader_name char *grubName; //boot_loader_name
void *kernelAddr; void *kernelAddr;
void *codeSegment;
void *kernelEndAddr; void *kernelEndAddr;
} btldr; } btldr;

View File

@ -33,6 +33,8 @@
typedef struct IdtDescriptor_t IdtDescriptor_t; typedef struct IdtDescriptor_t IdtDescriptor_t;
typedef struct IdtEntry_t IdtEntry_t; typedef struct IdtEntry_t IdtEntry_t;
typedef struct IdtPtr_t IdtPtr_t;
typedef struct Registers_t Registers_t;
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// //
@ -97,30 +99,79 @@ enum {
FEAT_EDX_PBE = 1 << 31 FEAT_EDX_PBE = 1 << 31
}; };
typedef struct IdtDescriptor_t struct IdtDescriptor_t {
{
ushort limit; ushort limit;
ulong base; ulong base;
} __attribute__((packed)); } __attribute__((packed)) ;
typedef struct IdtEntry_t struct IdtEntry_t
{ {
ushort baseLow; ushort baseLow;
ushort selector; ushort selector;
uchar reservedIst; uchar reservedIst;
uchar flags; uchar flags;
ushort baseMiddle; ushort baseMid;
uint baseHigh; uint baseHigh;
uint reserved; uint reserved;
} __attribute__((packed)); } __attribute__((packed));
// -------------------------------------------------------------------------- // struct IdtPtr_t
{
typedef struct { ushort limit;
ushort length; void *base;
void* base; } __attribute__((packed));
} __attribute__((packed)) Idtr_t;
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
struct Registers_t
{
ulong ds;
ulong rdi, rsi, rbp, rsp, rbx, rdx, rcx, rax;
ulong intNo, errCode;
ulong rip, cs, eflags, useresp, ss;
} __attribute__((packed));
// -------------------------------------------------------------------------- //
void idtSetup(void);
void idtSet(uchar rank, ulong base, ushort selector, uchar flags);
void isrHandler(Registers_t reg);
// -------------------------------------------------------------------------- //
extern void idtInit();
extern void isr0();
extern void isr1();
extern void isr2();
extern void isr3();
extern void isr4();
extern void isr5();
extern void isr6();
extern void isr7();
extern void isr8();
extern void isr9();
extern void isr10();
extern void isr11();
extern void isr12();
extern void isr13();
extern void isr14();
extern void isr15();
extern void isr16();
extern void isr17();
extern void isr18();
extern void isr19();
extern void isr20();
extern void isr21();
extern void isr22();
extern void isr23();
extern void isr24();
extern void isr25();
extern void isr26();
extern void isr27();
extern void isr28();
extern void isr29();
extern void isr30();
extern void isr31();
#endif #endif

View File

@ -1,39 +0,0 @@
;=----------------------------------------------------------------------------=;
; GNU GPL OS/K ;
; ;
; Desc: ;
; ;
; ;
; Copyright © 2018-2019 The OS/K Team ;
; ;
; This file is part of OS/K. ;
; ;
; OS/K is free software: you can redistribute it and/or modify ;
; it under the terms of the GNU General Public License as published by ;
; the Free Software Foundation, either version 3 of the License, or ;
; (at your option) any later version. ;
; ;
; OS/K is distributed in the hope that it will be useful, ;
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
; GNU General Public License for more details. ;
; ;
; You should have received a copy of the GNU General Public License ;
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=;
;; Divide Error Fault
;; Debug Exception Fault/trap
;; NMI Interrupt
;; Breakpoint Trap
;; Overflow Trap
;; Bound Range Exceeded Fault
;;

View File

@ -1,41 +1,102 @@
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
// GNU GPL OS/K // // GNU GPL OS/K //
// // // //
// Desc: Interrupt related functions // // Desc: Interrupt related functions //
// // // //
// // // //
// Copyright © 2018-2019 The OS/K Team // // Copyright © 2018-2019 The OS/K Team //
// // // //
// This file is part of OS/K. // // This file is part of OS/K. //
// // // //
// OS/K is free software: you can redistribute it and/or modify // // OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by // // it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or // // the Free Software Foundation, either version 3 of the License, or //
// any later version. // // any later version. //
// // // //
// OS/K is distributed in the hope that it will be useful, // // OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of // // but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. // // GNU General Public License for more details. //
// // // //
// You should have received a copy of the GNU General Public License // // You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. // // along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
#include <kernel/base.h> #include <kernel/base.h>
#include <kernel/cpu.h> #include <kernel/cpu.h>
#include <kernel/boot.h>
extern void lidt(Idtr_t reg); IdtEntry_t idt[256] = { 0 };
IdtPtr_t idtPtr;
// void isrHandlerPrint(Registers_t regs)
// Registers the new idt in the idtr register.
//
static inline void loadIdt(void* idtAddr, ushort size)
{ {
// The IDTR register structure that will be sent DebugLog("Interrupt %d !!! \n", regs.intNo);
Idtr_t IDTR = { size, idtAddr };
lidt(IDTR);
} }
void idtSetup(void)
{
ushort codeSeg = (ushort)(ulong)BtLoaderInfo.codeSegment;
// Set IDT ptr
idtPtr.limit = (sizeof(IdtEntry_t) * 256) - 1;
idtPtr.base = &idt;
// Set IDT gates
idtSet(0, (ulong)isr0, codeSeg, 0x8E);
idtSet(1, (ulong)isr1, codeSeg, 0x8E);
idtSet(2, (ulong)isr2, codeSeg, 0x8E);
idtSet(3, (ulong)isr3, codeSeg, 0x8E);
idtSet(4, (ulong)isr4, codeSeg, 0x8E);
idtSet(5, (ulong)isr5, codeSeg, 0x8E);
idtSet(6, (ulong)isr6, codeSeg, 0x8E);
idtSet(7, (ulong)isr7, codeSeg, 0x8E);
idtSet(8, (ulong)isr8, codeSeg, 0x8E);
idtSet(9, (ulong)isr9, codeSeg, 0x8E);
idtSet(10, (ulong)isr10, codeSeg, 0x8E);
idtSet(11, (ulong)isr11, codeSeg, 0x8E);
idtSet(12, (ulong)isr12, codeSeg, 0x8E);
idtSet(13, (ulong)isr13, codeSeg, 0x8E);
idtSet(14, (ulong)isr14, codeSeg, 0x8E);
//idtSet(15, (ulong)isr15, codeSeg, 0x8E); INTEL RESERVED
idtSet(16, (ulong)isr16, codeSeg, 0x8E);
idtSet(17, (ulong)isr17, codeSeg, 0x8E);
idtSet(18, (ulong)isr18, codeSeg, 0x8E);
idtSet(19, (ulong)isr19, codeSeg, 0x8E);
idtSet(20, (ulong)isr20, codeSeg, 0x8E);
//idtSet(21, (ulong)isr21, codeSeg, 0x8E); INTEL RESERVED
//idtSet(22, (ulong)isr22, codeSeg, 0x8E); INTEL RESERVED
//idtSet(23, (ulong)isr23, codeSeg, 0x8E); INTEL RESERVED
//idtSet(24, (ulong)isr24, codeSeg, 0x8E); INTEL RESERVED
//idtSet(25, (ulong)isr25, codeSeg, 0x8E); INTEL RESERVED
//idtSet(26, (ulong)isr26, codeSeg, 0x8E); INTEL RESERVED
//idtSet(27, (ulong)isr27, codeSeg, 0x8E); INTEL RESERVED
//idtSet(28, (ulong)isr28, codeSeg, 0x8E); INTEL RESERVED
//idtSet(29, (ulong)isr29, codeSeg, 0x8E); INTEL RESERVED
//idtSet(30, (ulong)isr30, codeSeg, 0x8E); INTEL RESERVED
// Load IDT
idtInit();
DebugLog("[IdtSetup] Filled at %d with %d bytes\n", sizeof(idtPtr), sizeof(IdtEntry_t));
DebugLog("[IdtSetup] offset %p with %p bytes\n", (ulong)(&idtPtr), (ulong)(idt));
//asm volatile ("sti":::"memory");
DebugLog(" And initialized !\n");
asm volatile ("int %0" : : "N" (0) : "cc", "memory");
}
void idtSet(uchar rank, ulong base, ushort selector, uchar flags)
{
// Set Base Address
idt[rank].baseLow = base & 0xFFFF;
idt[rank].baseMid = (base >> 16) & 0xFFFF;
idt[rank].baseHigh = (base >> 32) & 0xFFFFFFFF;
// Set Selector
idt[rank].selector = selector;
idt[rank].flags = flags;
// Set Reserved Areas to Zero
idt[rank].reservedIst = 0;
idt[rank].reserved = 0;
}

View File

@ -29,7 +29,7 @@
// BootInfo_t initialization. It is necessary because grub will potentially be // BootInfo_t initialization. It is necessary because grub will potentially be
// wiped since it is below 1MB.... And we must reorganize all that stuff. // wiped since it is below 1MB.... And we must reorganize all that stuff.
// //
void BtInitBootInfo(multiboot_info_t *mbi) void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg)
{ {
extern ulong MB_header; extern ulong MB_header;
extern ulong newKernelEnd; extern ulong newKernelEnd;
@ -44,6 +44,7 @@ void BtInitBootInfo(multiboot_info_t *mbi)
BtLoaderInfo.grubName = (char*)(ulong)(mbi->boot_loader_name); BtLoaderInfo.grubName = (char*)(ulong)(mbi->boot_loader_name);
BtLoaderInfo.kernelAddr = (void*)&MB_header; BtLoaderInfo.kernelAddr = (void*)&MB_header;
BtLoaderInfo.kernelEndAddr = (void*)newKernelEnd; BtLoaderInfo.kernelEndAddr = (void*)newKernelEnd;
BtLoaderInfo.codeSegment = codeSeg;
BtLoaderInfo.valid = 1; BtLoaderInfo.valid = 1;
} }
if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MODS) { if (BtLoaderInfo.grubFlags & MULTIBOOT_INFO_MODS) {

View File

@ -28,10 +28,11 @@
#include <kernel/mboot.h> #include <kernel/mboot.h>
#include <kernel/heap.h> #include <kernel/heap.h>
#include <kernel/mm.h> #include <kernel/mm.h>
#include <kernel/cpu.h>
// info.c // info.c
extern void BtDoSanityChecks(uint mbMagic); extern void BtDoSanityChecks(uint mbMagic);
extern void BtInitBootInfo(multiboot_info_t *mbi); extern void BtInitBootInfo(multiboot_info_t *mbi, void *codeSeg);
// io/vga.c // io/vga.c
extern error_t IoInitVGABuffer(void); extern error_t IoInitVGABuffer(void);
@ -42,12 +43,12 @@ extern void pstest(void);
// //
// Entry point of the Kaleid kernel // Entry point of the Kaleid kernel
// //
noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic) noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
{ {
KeDisableIRQs(); KeDisableIRQs();
// Initialize the BootInfo_t structure // Initialize the BootInfo_t structure
BtInitBootInfo(mbInfo); BtInitBootInfo(mbInfo, codeSeg);
// Screen I/O available from this point on // Screen I/O available from this point on
IoInitVGABuffer(); IoInitVGABuffer();
@ -68,6 +69,8 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
MmPrintMemoryMap(); MmPrintMemoryMap();
idtSetup();
// End this machine's suffering // End this machine's suffering
BFlushBuf(BStdOut); BFlushBuf(BStdOut);
KeCrashSystem(); KeCrashSystem();