From fa921fe626ee0388376700f785579c9e0b0ba946 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 18 Nov 2022 06:46:43 +0200 Subject: [PATCH] Update files --- .../amd64/cpu/InterruptDescriptorTable.cpp | 40 ++++++++++++++++++- Makefile | 10 ++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Architecture/amd64/cpu/InterruptDescriptorTable.cpp b/Architecture/amd64/cpu/InterruptDescriptorTable.cpp index c9b2de3..a562f32 100644 --- a/Architecture/amd64/cpu/InterruptDescriptorTable.cpp +++ b/Architecture/amd64/cpu/InterruptDescriptorTable.cpp @@ -37,7 +37,15 @@ namespace InterruptDescriptorTable extern "C" __attribute__((naked, used, no_stack_protector)) void ExceptionHandlerStub() { - asm("cld\n" // clear direction flag + asm( + // "cmp $0x1000, %rsp\n" // Just in case the stack is corrupted + // "jng .skip_swap_check_1\n" /* if is not greater than */ + // "cmpw $0x8, 0x8(%rsp)\n" + // "je .skip_swap_check_1\n" + // "swapgs\n" + // ".skip_swap_check_1:\n" + + "cld\n" // clear direction flag // push all registers "pushq %rax\n" @@ -77,12 +85,31 @@ namespace InterruptDescriptorTable "popq %rax\n" "addq $16, %rsp\n" + + // "cmp $0x1000, %rsp\n" + // "jng .skip_swap_check_2\n" + // "cmpw $0x8, 0x8(%rsp)\n" + // "je .skip_swap_check_2\n" + // "swapgs\n" + // ".skip_swap_check_2:\n" + "iretq"); // pop CS RIP RFLAGS SS ESP } + extern "C" void WarnSwapgs() { warn("swapgs"); } + extern "C" __attribute__((naked, used, no_stack_protector)) void InterruptHandlerStub() { - asm("cld\n" + asm( + // "cmp $0x1000, %rsp\n" + // "jng .skip_swap_check__1\n" + // "cmpw $0x8, 0x8(%rsp)\n" + // "je .skip_swap_check__1\n" + // "swapgs\n" + // "call WarnSwapgs\n" + // ".skip_swap_check__1:\n" + + "cld\n" "pushq %rax\n" "pushq %rbx\n" "pushq %rcx\n" @@ -119,6 +146,15 @@ namespace InterruptDescriptorTable "popq %rax\n" "addq $16, %rsp\n" + + // "cmp $0x1000, %rsp\n" + // "jng .skip_swap_check__2\n" + // "cmpw $0x8, 0x8(%rsp)\n" + // "je .skip_swap_check__2\n" + // "call WarnSwapgs\n" + // "swapgs\n" + // ".skip_swap_check__2:\n" + "iretq"); } diff --git a/Makefile b/Makefile index 2edd824..7232406 100644 --- a/Makefile +++ b/Makefile @@ -111,7 +111,15 @@ prepare: gzip -d Files/ter-powerline-v12n.psf.gz build: $(KERNEL_FILENAME) + +dump: +ifeq (,$(wildcard $(KERNEL_FILENAME))) + $(error $(KERNEL_FILENAME) does not exist) +endif + $(info Dumping $(KERNEL_FILENAME) in AT T syntax...) $(OBJDUMP) -D -d $(KERNEL_FILENAME) > kernel_dump.map + $(info Dumping $(KERNEL_FILENAME) in Intel syntax...) + $(OBJDUMP) -M intel -D -d $(KERNEL_FILENAME) > kernel_dump_intel.map $(KERNEL_FILENAME): $(OBJ) $(CC) $(LDFLAGS) $(OBJ) -o $@ @@ -160,4 +168,4 @@ endif $(NM) $@ clean: - rm -f *.bin *.o *.elf *.sym kernel.map kernel_dump.map initrd.tar.gz $(OBJ) $(KERNEL_FILENAME) + rm -f *.bin *.o *.elf *.sym kernel.map kernel_dump.map kernel_dump_intel.map initrd.tar.gz $(OBJ) $(KERNEL_FILENAME)