New TSS IST used by all ISRs

This commit is contained in:
Adrien Bourmault 2020-01-05 20:13:53 +01:00
parent ea95dce749
commit 5829d7a353
9 changed files with 108 additions and 88 deletions

View File

@ -22,7 +22,7 @@
# along with OS/K. If not, see <https://www.gnu.org/licenses/>. # # along with OS/K. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=# #=----------------------------------------------------------------------------=#
.PHONY: all test testnokvm testnosnd test32 debug gdb installonimage dust clean OS/K run .PHONY: all test testnokvm testnosnd test32 debug gdb ddd gdbnokvm dddnokvm installonimage dust clean OS/K run
.DELETE_ON_ERROR: $(BINDIR)/kaleid .DELETE_ON_ERROR: $(BINDIR)/kaleid
.DEFAULT_GOAL := all .DEFAULT_GOAL := all
@ -41,7 +41,7 @@ CCNAME=x86_64-elf-gcc
ASMFLAGS=-f elf64 ASMFLAGS=-f elf64
LDFLAGS=-melf_x86_64 LDFLAGS=-melf_x86_64
COPTIM=-O2 COPTIM=-O2
CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type CWARNS=-Wall -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough -Werror=implicit-function-declaration -Werror=return-type -Wpadded
CINCLUDES=-Iinclude CINCLUDES=-Iinclude
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 -fstack-protector-all -fdump-rtl-expand CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 -fstack-protector-all -fdump-rtl-expand
CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2 CFLAGS2= -c -mno-red-zone -mno-mmx -mno-sse -mno-sse2
@ -292,7 +292,7 @@ test32: all installonimage
cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log &
gdb: all installonimage gdb: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -soundhw pcspk -rtc base=localtime \ @setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \ -hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@gdb \ @gdb \
@ -302,9 +302,26 @@ gdb: all installonimage
-ex "break BtStartKern" \ -ex "break BtStartKern" \
ddd: all installonimage ddd: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -hda $(installdisk) -no-reboot -soundhw pcspk \ @setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \
-no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log & -hda $(installdisk) -no-reboot -no-shutdown -d \
@ddd cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@ddd -n
gdbnokvm: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@gdb \
-ex "set arch i386:x86-64:intel" \
-ex "target remote localhost:1234" \
-ex "symbol-file $(BINDIR)/kaleid" \
-ex "break BtStartKern" \
dddnokvm: all installonimage
@setsid qemu-system-x86_64 -m $(ram) -rtc base=localtime \
-hda $(installdisk) -no-reboot -no-shutdown -d \
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
@ddd -n
## HD IMAGE RELATED ---------------------------------------------------------- # ## HD IMAGE RELATED ---------------------------------------------------------- #

View File

@ -44,24 +44,24 @@ struct BootInfo_t
{ {
// The Bootloader infos // The Bootloader infos
struct { struct {
ushort valid;
uint grubFlags; //flags
uint modulesCount; //mods_count
void *modulesAddr; //mods_addr void *modulesAddr; //mods_addr
char *grubName; //boot_loader_name
void *kernelAddr; void *kernelAddr;
void *codeSegment; void *codeSegment;
void *kernelEndAddr; void *kernelEndAddr;
void *stackEndAddr; // stack begins 16B after kernelEndAddr void *stackEndAddr; // stack begins 16B after kernelEndAddr
uint grubFlags; //flags
uint modulesCount; //mods_count
ushort valid;
char *grubName; //boot_loader_name
} btldr; } btldr;
// Informations about drives // Informations about drives
struct { struct {
ushort drvValid; void *bufferAddr; //drives_addr
ushort bufferValid;
uint bootDrv; //boot_device uint bootDrv; //boot_device
uint bufferLength; //drives_length uint bufferLength; //drives_length
void *bufferAddr; //drives_addr ushort drvValid;
ushort bufferValid;
} drives; } drives;
// Informations about memory // Informations about memory
@ -74,36 +74,36 @@ struct BootInfo_t
uint upMemory; //mem_upper uint upMemory; //mem_upper
//GRUB provided memory map //GRUB provided memory map
uint mapLength; //mmap_length
void *mapAddr; //mmap_addr void *mapAddr; //mmap_addr
uint mapLength; //mmap_length
uint ramSize; //The ram (init by map.c) uint ramSize; //The ram (init by map.c)
} memory; } memory;
// Informations about the video drive // Informations about the video drive
struct { struct {
ushort vbeValid;
ushort fbuValid;
void *vbeControl; //vbe_control_info void *vbeControl; //vbe_control_info
void *vbeModeInfo; //vbe_mode_info void *vbeModeInfo; //vbe_mode_info
ushort vbeMode; //vbe_mode
ushort vbeInterfaceSeg; //vbe_interface_seg
ushort vbeInterfaceOff; //vbe_interface_off
ushort vbeInterfaceLen; //vbe_interface_len
void *framebufferAddr; //framebuffer_addr void *framebufferAddr; //framebuffer_addr
uint framebufferPitch; //framebuffer_pitch uint framebufferPitch; //framebuffer_pitch
uint framebufferWidth; //framebuffer_width uint framebufferWidth; //framebuffer_width
uint framebufferHeight; //framebuffer_height uint framebufferHeight; //framebuffer_height
ushort vbeValid;
ushort fbuValid;
ushort vbeMode; //vbe_mode
ushort vbeInterfaceSeg; //vbe_interface_seg
ushort vbeInterfaceOff; //vbe_interface_off
ushort vbeInterfaceLen; //vbe_interface_len
uchar framebufferBpp; //framebuffer_bpp uchar framebufferBpp; //framebuffer_bpp
uchar framebufferType; //framebuffer_type uchar framebufferType; //framebuffer_type
} video; } video;
// Informations about the microcode firmware (BIOS/EFI) // Informations about the microcode firmware (BIOS/EFI)
struct { struct {
ushort apmValid;
ushort romValid;
uint apmTable; //apm_table uint apmTable; //apm_table
uint romTable; //config_table uint romTable; //config_table
ushort apmValid;
ushort romValid;
} firmware; } firmware;
}; };

View File

@ -108,7 +108,7 @@ struct Tss_t
ushort iomap_base; ushort iomap_base;
uchar iomap[IOMAP_SIZE]; uchar iomap[IOMAP_SIZE];
} __attribute__ ((packed)); } __attribute__ ((packed)) __attribute__((aligned(8)));

View File

@ -64,6 +64,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
MmInitMemoryMap(); MmInitMemoryMap();
MmInitPaging(); MmInitPaging();
MmInitHeap(); MmInitHeap();
MmInitGdt();
// Basics for interrupts // Basics for interrupts
KeSetupIDT(); KeSetupIDT();
@ -73,7 +74,6 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
KeGetCpuInfos(); KeGetCpuInfos();
// Memory (2) // Memory (2)
MmInitGdt();
MmActivatePageHandler(); MmActivatePageHandler();
// Drivers // Drivers

View File

@ -120,56 +120,56 @@ void KeSetupIDT(void)
_KeIdtPtr.base = &idt; _KeIdtPtr.base = &idt;
// Set IDT Exception Gates // Set IDT Exception Gates
KeSetIDTGate(0x00, (ulong)isr0, codeSeg, 0x8E, 0); KeSetIDTGate(0x00, (ulong)isr0, codeSeg, 0x8E, 2);
KeSetIDTGate(0x01, (ulong)isr1, codeSeg, 0x8E, 0); KeSetIDTGate(0x01, (ulong)isr1, codeSeg, 0x8E, 2);
KeSetIDTGate(0x02, (ulong)isr2, codeSeg, 0x8E, 0); KeSetIDTGate(0x02, (ulong)isr2, codeSeg, 0x8E, 2);
KeSetIDTGate(0x03, (ulong)isr3, codeSeg, 0x8E, 0); KeSetIDTGate(0x03, (ulong)isr3, codeSeg, 0x8E, 2);
KeSetIDTGate(0x04, (ulong)isr4, codeSeg, 0x8E, 0); KeSetIDTGate(0x04, (ulong)isr4, codeSeg, 0x8E, 2);
KeSetIDTGate(0x05, (ulong)isr5, codeSeg, 0x8E, 0); KeSetIDTGate(0x05, (ulong)isr5, codeSeg, 0x8E, 2);
KeSetIDTGate(0x06, (ulong)isr6, codeSeg, 0x8E, 0); KeSetIDTGate(0x06, (ulong)isr6, codeSeg, 0x8E, 2);
KeSetIDTGate(0x07, (ulong)isr7, codeSeg, 0x8E, 0); KeSetIDTGate(0x07, (ulong)isr7, codeSeg, 0x8E, 2);
KeSetIDTGate(0x08, (ulong)isr8, codeSeg, 0x8E, 1); KeSetIDTGate(0x08, (ulong)isr8, codeSeg, 0x8E, 1);
KeSetIDTGate(0x09, (ulong)isr9, codeSeg, 0x8E, 0); KeSetIDTGate(0x09, (ulong)isr9, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0A, (ulong)isr10, codeSeg, 0x8E, 0); KeSetIDTGate(0x0A, (ulong)isr10, codeSeg, 0x8E, 0); // INVALID TSS
KeSetIDTGate(0x0B, (ulong)isr11, codeSeg, 0x8E, 0); KeSetIDTGate(0x0B, (ulong)isr11, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0C, (ulong)isr12, codeSeg, 0x8E, 0); KeSetIDTGate(0x0C, (ulong)isr12, codeSeg, 0x8E, 1);
KeSetIDTGate(0x0D, (ulong)isr13, codeSeg, 0x8E, 0); KeSetIDTGate(0x0D, (ulong)isr13, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0E, (ulong)isr14, codeSeg, 0x8E, 0); KeSetIDTGate(0x0E, (ulong)isr14, codeSeg, 0x8E, 2);
KeSetIDTGate(0x0F, (ulong)isr15, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x0F, (ulong)isr15, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x10, (ulong)isr16, codeSeg, 0x8E, 0); KeSetIDTGate(0x10, (ulong)isr16, codeSeg, 0x8E, 2);
KeSetIDTGate(0x11, (ulong)isr17, codeSeg, 0x8E, 0); KeSetIDTGate(0x11, (ulong)isr17, codeSeg, 0x8E, 2);
KeSetIDTGate(0x12, (ulong)isr18, codeSeg, 0x8E, 0); KeSetIDTGate(0x12, (ulong)isr18, codeSeg, 0x8E, 2);
KeSetIDTGate(0x13, (ulong)isr19, codeSeg, 0x8E, 0); KeSetIDTGate(0x13, (ulong)isr19, codeSeg, 0x8E, 2);
KeSetIDTGate(0x14, (ulong)isr20, codeSeg, 0x8E, 0); KeSetIDTGate(0x14, (ulong)isr20, codeSeg, 0x8E, 2);
KeSetIDTGate(0x15, (ulong)isr21, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x15, (ulong)isr21, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x16, (ulong)isr22, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x16, (ulong)isr22, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x17, (ulong)isr23, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x17, (ulong)isr23, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x18, (ulong)isr24, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x18, (ulong)isr24, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x19, (ulong)isr25, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x19, (ulong)isr25, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x1A, (ulong)isr26, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x1A, (ulong)isr26, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x1B, (ulong)isr27, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x1B, (ulong)isr27, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x1C, (ulong)isr28, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x1C, (ulong)isr28, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x1D, (ulong)isr29, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x1D, (ulong)isr29, codeSeg, 0x8E, 2); // INTEL RESERVED
KeSetIDTGate(0x1E, (ulong)isr30, codeSeg, 0x8E, 0); KeSetIDTGate(0x1E, (ulong)isr30, codeSeg, 0x8E, 2);
KeSetIDTGate(0x1F, (ulong)isr31, codeSeg, 0x8E, 0); // INTEL RESERVED KeSetIDTGate(0x1F, (ulong)isr31, codeSeg, 0x8E, 2); // INTEL RESERVED
// Set IDT IRQs Gates // Set IDT IRQs Gates
KeSetIDTGate(0x20, (ulong)isr32, codeSeg, 0x8E, 2); KeSetIDTGate(0x20, (ulong)isr32, codeSeg, 0x8E, 2);
KeSetIDTGate(0x21, (ulong)isr33, codeSeg, 0x8E, 0); KeSetIDTGate(0x21, (ulong)isr33, codeSeg, 0x8E, 2);
KeSetIDTGate(0x22, (ulong)isr34, codeSeg, 0x8E, 0); KeSetIDTGate(0x22, (ulong)isr34, codeSeg, 0x8E, 2);
KeSetIDTGate(0x23, (ulong)isr35, codeSeg, 0x8E, 0); KeSetIDTGate(0x23, (ulong)isr35, codeSeg, 0x8E, 2);
KeSetIDTGate(0x24, (ulong)isr36, codeSeg, 0x8E, 0); KeSetIDTGate(0x24, (ulong)isr36, codeSeg, 0x8E, 2);
KeSetIDTGate(0x25, (ulong)isr37, codeSeg, 0x8E, 0); KeSetIDTGate(0x25, (ulong)isr37, codeSeg, 0x8E, 2);
KeSetIDTGate(0x26, (ulong)isr38, codeSeg, 0x8E, 0); KeSetIDTGate(0x26, (ulong)isr38, codeSeg, 0x8E, 2);
KeSetIDTGate(0x27, (ulong)isr39, codeSeg, 0x8E, 0); KeSetIDTGate(0x27, (ulong)isr39, codeSeg, 0x8E, 2);
KeSetIDTGate(0x28, (ulong)isr40, codeSeg, 0x8E, 0); KeSetIDTGate(0x28, (ulong)isr40, codeSeg, 0x8E, 2);
KeSetIDTGate(0x29, (ulong)isr41, codeSeg, 0x8E, 0); KeSetIDTGate(0x29, (ulong)isr41, codeSeg, 0x8E, 2);
KeSetIDTGate(0x2A, (ulong)isr42, codeSeg, 0x8E, 0); KeSetIDTGate(0x2A, (ulong)isr42, codeSeg, 0x8E, 2);
KeSetIDTGate(0x2B, (ulong)isr43, codeSeg, 0x8E, 0); KeSetIDTGate(0x2B, (ulong)isr43, codeSeg, 0x8E, 2);
KeSetIDTGate(0x2C, (ulong)isr44, codeSeg, 0x8E, 0); KeSetIDTGate(0x2C, (ulong)isr44, codeSeg, 0x8E, 2);
KeSetIDTGate(0x2D, (ulong)isr45, codeSeg, 0x8E, 0); KeSetIDTGate(0x2D, (ulong)isr45, codeSeg, 0x8E, 2);
KeSetIDTGate(0x2E, (ulong)isr46, codeSeg, 0x8E, 0); KeSetIDTGate(0x2E, (ulong)isr46, codeSeg, 0x8E, 2);
KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 0); KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 2);
KeIdtIsInitialized++; KeIdtIsInitialized++;
@ -293,8 +293,8 @@ void KeDisableNMI(void)
// //
void _KeHandleISR(ISRFrame_t *regs) void _KeHandleISR(ISRFrame_t *regs)
{ {
if ((!regs) || (!regs->rip)) /* if ((!regs) || (!regs->rip)) */
KeStartPanic("[ISR ?] Unknown ISR Exception Abort\n"); /* KeStartPanic("[ISR ?] Unknown ISR Exception Abort\n"); */
if ((regs->intNo >= 0x15) && (regs->intNo <= 0x1D)) if ((regs->intNo >= 0x15) && (regs->intNo <= 0x1D))
return; // INTEL RESERVED return; // INTEL RESERVED

View File

@ -58,11 +58,10 @@ isrPreHandler:
push rax push rax
; Check if we are switching from user mode to supervisor mode ; Check if we are switching from user mode to supervisor mode
mov rax, [rsp + 152] ;mov rax, [rsp + 152]
and rax, 0x3000 ;and rax, 0x3000
jz .SEnter ;jz .SEnter
;swapgs ; XXX need TSS
swapgs ; XXX need TSS
.SEnter: .SEnter:
; Increment mask count as we configure all interrupts to mask IF ; Increment mask count as we configure all interrupts to mask IF
@ -95,6 +94,10 @@ isrPreHandler:
iretq iretq
Die:
hlt
jmp Die
;; Divide Error Fault ;; Divide Error Fault
IsrWithoutErrCode 0 IsrWithoutErrCode 0

View File

@ -128,7 +128,7 @@ void KeEnablePIT(void)
DebugLog("\tPIT activated with period %d ms\n", 1000/PIT_FREQUENCY); DebugLog("\tPIT activated with period %d ms\n", 1000/PIT_FREQUENCY);
KeRestoreIRQs(flags); KeRestoreIRQs(flags);
KeEnableNMI(); //XXX KeEnableNMI();
} }
char *KeFormatCurTime(void) char *KeFormatCurTime(void)

View File

@ -25,10 +25,10 @@
#include <mm/mm.h> #include <mm/mm.h>
#include <init/boot.h> #include <init/boot.h>
GdtPtr_t gdtPtr; volatile GdtPtr_t gdtPtr;
GdtEntry_t gdt[4] __attribute__((__aligned__(KPAGESIZE))); volatile GdtEntry_t gdt[4] __attribute__((__aligned__(KPAGESIZE)));
TssDescriptor_t tssDesc __attribute__((__aligned__(KPAGESIZE))); volatile TssDescriptor_t tssDesc __attribute__((__aligned__(KPAGESIZE)));
Tss_t tss __attribute__((__aligned__(KPAGESIZE))); volatile Tss_t tss __attribute__((__aligned__(KPAGESIZE)));
void MmInitGdt(void) void MmInitGdt(void)
{ {
@ -53,8 +53,8 @@ void MmInitGdt(void)
tssDesc.veryHighBase = ((ulong)&tss >> 32) & 0xFFFFFFFF; tssDesc.veryHighBase = ((ulong)&tss >> 32) & 0xFFFFFFFF;
tssDesc.lowLimit = sizeof(tss); tssDesc.lowLimit = sizeof(tss);
tss.ist1 = 0x0007FFFF; // ISR RESCUE STACK, GARANTIED FREE FOR USE BY OSDEV.ORG tss.ist1 = (ulong)0x0007FFFF; // ISR RESCUE STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
tss.ist2 = 0x00EFFFFF; // ISR STACK, GARANTIED FREE FOR USE BY OSDEV.ORG tss.ist2 = (ulong)0x00EFFFFF; // ISR STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
tss.iomap_base = sizeof(tss); tss.iomap_base = sizeof(tss);
memmove(&gdt[2], &tssDesc, sizeof(TssDescriptor_t)); memmove(&gdt[2], &tssDesc, sizeof(TssDescriptor_t));

View File

@ -117,10 +117,10 @@ void MmInitPaging(void)
MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE; MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE;
MmLoadPML4((void *)MmPML4); MmLoadPML4((void *)MmPML4);
DebugLog("Read only : %p\n", (ulong)&_text); /* DebugLog("Read only : %p\n", (ulong)&_text); */
DebugLog("Read only : %p\n", (ulong)&_text_end); /* DebugLog("Read only : %p\n", (ulong)&_text_end); */
DebugLog("Read only : %p\n", (ulong)&_rodata); /* DebugLog("Read only : %p\n", (ulong)&_rodata); */
DebugLog("Read only : %p\n", (ulong)&_rodata_end); /* DebugLog("Read only : %p\n", (ulong)&_rodata_end); */
//DebugLog("\tPaging tables initialized at %p, %p\n", &MmPD, &MmPT); //DebugLog("\tPaging tables initialized at %p, %p\n", &MmPD, &MmPT);
//DebugLog("\tStack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]); //DebugLog("\tStack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]);
} }