New TSS IST used by all ISRs
This commit is contained in:
parent
ea95dce749
commit
5829d7a353
29
Makefile
29
Makefile
|
@ -22,7 +22,7 @@
|
|||
# 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
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
|
@ -41,7 +41,7 @@ CCNAME=x86_64-elf-gcc
|
|||
ASMFLAGS=-f elf64
|
||||
LDFLAGS=-melf_x86_64
|
||||
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
|
||||
CFLAGS1=-nostdlib -ffreestanding -mcmodel=large -std=gnu11 -fstack-protector-all -fdump-rtl-expand
|
||||
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 &
|
||||
|
||||
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 \
|
||||
cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log &
|
||||
@gdb \
|
||||
|
@ -302,9 +302,26 @@ gdb: all installonimage
|
|||
-ex "break BtStartKern" \
|
||||
|
||||
ddd: all installonimage
|
||||
@setsid qemu-system-x86_64 -m $(ram) -hda $(installdisk) -no-reboot -soundhw pcspk \
|
||||
-no-shutdown -d cpu_reset,guest_errors,pcall,int -s 2> $(BUILDDIR)/qemu.log &
|
||||
@ddd
|
||||
@setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \
|
||||
-hda $(installdisk) -no-reboot -no-shutdown -d \
|
||||
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 ---------------------------------------------------------- #
|
||||
|
|
|
@ -44,24 +44,24 @@ struct BootInfo_t
|
|||
{
|
||||
// The Bootloader infos
|
||||
struct {
|
||||
ushort valid;
|
||||
uint grubFlags; //flags
|
||||
uint modulesCount; //mods_count
|
||||
void *modulesAddr; //mods_addr
|
||||
char *grubName; //boot_loader_name
|
||||
void *kernelAddr;
|
||||
void *codeSegment;
|
||||
void *kernelEndAddr;
|
||||
void *stackEndAddr; // stack begins 16B after kernelEndAddr
|
||||
uint grubFlags; //flags
|
||||
uint modulesCount; //mods_count
|
||||
ushort valid;
|
||||
char *grubName; //boot_loader_name
|
||||
} btldr;
|
||||
|
||||
// Informations about drives
|
||||
struct {
|
||||
ushort drvValid;
|
||||
ushort bufferValid;
|
||||
void *bufferAddr; //drives_addr
|
||||
uint bootDrv; //boot_device
|
||||
uint bufferLength; //drives_length
|
||||
void *bufferAddr; //drives_addr
|
||||
ushort drvValid;
|
||||
ushort bufferValid;
|
||||
} drives;
|
||||
|
||||
// Informations about memory
|
||||
|
@ -74,36 +74,36 @@ struct BootInfo_t
|
|||
uint upMemory; //mem_upper
|
||||
|
||||
//GRUB provided memory map
|
||||
uint mapLength; //mmap_length
|
||||
void *mapAddr; //mmap_addr
|
||||
uint mapLength; //mmap_length
|
||||
|
||||
uint ramSize; //The ram (init by map.c)
|
||||
} memory;
|
||||
|
||||
// Informations about the video drive
|
||||
struct {
|
||||
ushort vbeValid;
|
||||
ushort fbuValid;
|
||||
void *vbeControl; //vbe_control_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
|
||||
uint framebufferPitch; //framebuffer_pitch
|
||||
uint framebufferWidth; //framebuffer_width
|
||||
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 framebufferType; //framebuffer_type
|
||||
} video;
|
||||
|
||||
// Informations about the microcode firmware (BIOS/EFI)
|
||||
struct {
|
||||
ushort apmValid;
|
||||
ushort romValid;
|
||||
uint apmTable; //apm_table
|
||||
uint romTable; //config_table
|
||||
ushort apmValid;
|
||||
ushort romValid;
|
||||
} firmware;
|
||||
};
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ struct Tss_t
|
|||
ushort iomap_base;
|
||||
uchar iomap[IOMAP_SIZE];
|
||||
|
||||
} __attribute__ ((packed));
|
||||
} __attribute__ ((packed)) __attribute__((aligned(8)));
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
|
|||
MmInitMemoryMap();
|
||||
MmInitPaging();
|
||||
MmInitHeap();
|
||||
MmInitGdt();
|
||||
|
||||
// Basics for interrupts
|
||||
KeSetupIDT();
|
||||
|
@ -73,7 +74,6 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
|
|||
KeGetCpuInfos();
|
||||
|
||||
// Memory (2)
|
||||
MmInitGdt();
|
||||
MmActivatePageHandler();
|
||||
|
||||
// Drivers
|
||||
|
|
|
@ -120,56 +120,56 @@ void KeSetupIDT(void)
|
|||
_KeIdtPtr.base = &idt;
|
||||
|
||||
// Set IDT Exception Gates
|
||||
KeSetIDTGate(0x00, (ulong)isr0, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x01, (ulong)isr1, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x02, (ulong)isr2, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x03, (ulong)isr3, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x04, (ulong)isr4, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x05, (ulong)isr5, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x06, (ulong)isr6, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x07, (ulong)isr7, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x00, (ulong)isr0, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x01, (ulong)isr1, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x02, (ulong)isr2, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x03, (ulong)isr3, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x04, (ulong)isr4, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x05, (ulong)isr5, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x06, (ulong)isr6, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x07, (ulong)isr7, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x08, (ulong)isr8, codeSeg, 0x8E, 1);
|
||||
KeSetIDTGate(0x09, (ulong)isr9, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x0A, (ulong)isr10, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x0B, (ulong)isr11, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x0C, (ulong)isr12, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x0D, (ulong)isr13, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x0E, (ulong)isr14, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x0F, (ulong)isr15, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x10, (ulong)isr16, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x11, (ulong)isr17, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x12, (ulong)isr18, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x13, (ulong)isr19, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x14, (ulong)isr20, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x15, (ulong)isr21, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x16, (ulong)isr22, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x17, (ulong)isr23, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x18, (ulong)isr24, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x19, (ulong)isr25, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1A, (ulong)isr26, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1B, (ulong)isr27, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1C, (ulong)isr28, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1D, (ulong)isr29, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1E, (ulong)isr30, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x1F, (ulong)isr31, codeSeg, 0x8E, 0); // INTEL RESERVED
|
||||
KeSetIDTGate(0x09, (ulong)isr9, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x0A, (ulong)isr10, codeSeg, 0x8E, 0); // INVALID TSS
|
||||
KeSetIDTGate(0x0B, (ulong)isr11, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x0C, (ulong)isr12, codeSeg, 0x8E, 1);
|
||||
KeSetIDTGate(0x0D, (ulong)isr13, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x0E, (ulong)isr14, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x0F, (ulong)isr15, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x10, (ulong)isr16, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x11, (ulong)isr17, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x12, (ulong)isr18, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x13, (ulong)isr19, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x14, (ulong)isr20, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x15, (ulong)isr21, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x16, (ulong)isr22, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x17, (ulong)isr23, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x18, (ulong)isr24, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x19, (ulong)isr25, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1A, (ulong)isr26, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1B, (ulong)isr27, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1C, (ulong)isr28, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1D, (ulong)isr29, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
KeSetIDTGate(0x1E, (ulong)isr30, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x1F, (ulong)isr31, codeSeg, 0x8E, 2); // INTEL RESERVED
|
||||
|
||||
// Set IDT IRQs Gates
|
||||
KeSetIDTGate(0x20, (ulong)isr32, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x21, (ulong)isr33, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x22, (ulong)isr34, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x23, (ulong)isr35, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x24, (ulong)isr36, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x25, (ulong)isr37, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x26, (ulong)isr38, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x27, (ulong)isr39, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x28, (ulong)isr40, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x29, (ulong)isr41, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x2A, (ulong)isr42, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x2B, (ulong)isr43, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x2C, (ulong)isr44, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x2D, (ulong)isr45, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x2E, (ulong)isr46, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 0);
|
||||
KeSetIDTGate(0x21, (ulong)isr33, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x22, (ulong)isr34, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x23, (ulong)isr35, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x24, (ulong)isr36, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x25, (ulong)isr37, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x26, (ulong)isr38, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x27, (ulong)isr39, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x28, (ulong)isr40, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x29, (ulong)isr41, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x2A, (ulong)isr42, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x2B, (ulong)isr43, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x2C, (ulong)isr44, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x2D, (ulong)isr45, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x2E, (ulong)isr46, codeSeg, 0x8E, 2);
|
||||
KeSetIDTGate(0x2F, (ulong)isr47, codeSeg, 0x8E, 2);
|
||||
|
||||
KeIdtIsInitialized++;
|
||||
|
||||
|
@ -293,8 +293,8 @@ void KeDisableNMI(void)
|
|||
//
|
||||
void _KeHandleISR(ISRFrame_t *regs)
|
||||
{
|
||||
if ((!regs) || (!regs->rip))
|
||||
KeStartPanic("[ISR ?] Unknown ISR Exception Abort\n");
|
||||
/* if ((!regs) || (!regs->rip)) */
|
||||
/* KeStartPanic("[ISR ?] Unknown ISR Exception Abort\n"); */
|
||||
|
||||
if ((regs->intNo >= 0x15) && (regs->intNo <= 0x1D))
|
||||
return; // INTEL RESERVED
|
||||
|
|
|
@ -58,11 +58,10 @@ isrPreHandler:
|
|||
push rax
|
||||
|
||||
; Check if we are switching from user mode to supervisor mode
|
||||
mov rax, [rsp + 152]
|
||||
and rax, 0x3000
|
||||
jz .SEnter
|
||||
|
||||
swapgs ; XXX need TSS
|
||||
;mov rax, [rsp + 152]
|
||||
;and rax, 0x3000
|
||||
;jz .SEnter
|
||||
;swapgs ; XXX need TSS
|
||||
|
||||
.SEnter:
|
||||
; Increment mask count as we configure all interrupts to mask IF
|
||||
|
@ -95,6 +94,10 @@ isrPreHandler:
|
|||
|
||||
iretq
|
||||
|
||||
Die:
|
||||
hlt
|
||||
jmp Die
|
||||
|
||||
;; Divide Error Fault
|
||||
IsrWithoutErrCode 0
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ void KeEnablePIT(void)
|
|||
DebugLog("\tPIT activated with period %d ms\n", 1000/PIT_FREQUENCY);
|
||||
|
||||
KeRestoreIRQs(flags);
|
||||
KeEnableNMI();
|
||||
//XXX KeEnableNMI();
|
||||
}
|
||||
|
||||
char *KeFormatCurTime(void)
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
#include <mm/mm.h>
|
||||
#include <init/boot.h>
|
||||
|
||||
GdtPtr_t gdtPtr;
|
||||
GdtEntry_t gdt[4] __attribute__((__aligned__(KPAGESIZE)));
|
||||
TssDescriptor_t tssDesc __attribute__((__aligned__(KPAGESIZE)));
|
||||
Tss_t tss __attribute__((__aligned__(KPAGESIZE)));
|
||||
volatile GdtPtr_t gdtPtr;
|
||||
volatile GdtEntry_t gdt[4] __attribute__((__aligned__(KPAGESIZE)));
|
||||
volatile TssDescriptor_t tssDesc __attribute__((__aligned__(KPAGESIZE)));
|
||||
volatile Tss_t tss __attribute__((__aligned__(KPAGESIZE)));
|
||||
|
||||
void MmInitGdt(void)
|
||||
{
|
||||
|
@ -53,8 +53,8 @@ void MmInitGdt(void)
|
|||
tssDesc.veryHighBase = ((ulong)&tss >> 32) & 0xFFFFFFFF;
|
||||
tssDesc.lowLimit = sizeof(tss);
|
||||
|
||||
tss.ist1 = 0x0007FFFF; // ISR RESCUE STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
|
||||
tss.ist2 = 0x00EFFFFF; // ISR STACK, GARANTIED FREE FOR USE BY OSDEV.ORG
|
||||
tss.ist1 = (ulong)0x0007FFFF; // ISR RESCUE 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);
|
||||
|
||||
memmove(&gdt[2], &tssDesc, sizeof(TssDescriptor_t));
|
||||
|
|
|
@ -117,10 +117,10 @@ void MmInitPaging(void)
|
|||
MmPML4[0] = (ulong)(&MmPDP[0])| MF_PRESENT | MF_READWRITE;
|
||||
|
||||
MmLoadPML4((void *)MmPML4);
|
||||
DebugLog("Read only : %p\n", (ulong)&_text);
|
||||
DebugLog("Read only : %p\n", (ulong)&_text_end);
|
||||
DebugLog("Read only : %p\n", (ulong)&_rodata);
|
||||
DebugLog("Read only : %p\n", (ulong)&_rodata_end);
|
||||
/* DebugLog("Read only : %p\n", (ulong)&_text); */
|
||||
/* DebugLog("Read only : %p\n", (ulong)&_text_end); */
|
||||
/* DebugLog("Read only : %p\n", (ulong)&_rodata); */
|
||||
/* DebugLog("Read only : %p\n", (ulong)&_rodata_end); */
|
||||
//DebugLog("\tPaging tables initialized at %p, %p\n", &MmPD, &MmPT);
|
||||
//DebugLog("\tStack Guards at %p, %p\n", MmStackGuards[0], MmStackGuards[1]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue