From 0cd522f39687d1fed9e204e5504d19baa8d85e04 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Duje=20Mihanovi=C4=87?= <duje.mihanovic@skole.hr>
Date: Sun, 8 May 2022 14:47:14 +0200
Subject: [PATCH] Fix interrupt trap gates

Until now the code would set the most significant bit in the type part
of the IDT descriptor for trap gates as a result of my error, causing a
triple fault when trying to handle a double fault. A less significant, but still
noteworthy change is that the double fault handler has been slightly revamped to
print out :( on a red background and no longer spits out a warning because I
accidentally wrote a string there, not a char.
---
 include/arch/x86/irq/idt.h           | 4 ++--
 kernel/arch/x86/irq/sample_handler.c | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/arch/x86/irq/idt.h b/include/arch/x86/irq/idt.h
index 8b2efa1..daf586f 100644
--- a/include/arch/x86/irq/idt.h
+++ b/include/arch/x86/irq/idt.h
@@ -6,8 +6,8 @@
 #define IDT_VECTOR_COUNT 256 /* our IDT will have 256 vectors */
 #define IDT_DESCRIPTOR_SIZE 8 /* each IDT descriptor is 8 bytes long */
 
-#define IDT_TRAP_GATE 		0x1F
-#define IDT_INTERRUPT_GATE 	0x0E
+#define IDT_TRAP_GATE 		0xF
+#define IDT_INTERRUPT_GATE 	0xE
 
 struct idt_descriptor {
 	uint16_t offset_1; /* bits 0-15 of offset */
diff --git a/kernel/arch/x86/irq/sample_handler.c b/kernel/arch/x86/irq/sample_handler.c
index d9bd8f9..f4f4a4b 100644
--- a/kernel/arch/x86/irq/sample_handler.c
+++ b/kernel/arch/x86/irq/sample_handler.c
@@ -25,9 +25,9 @@ void keyb_handler(struct interrupt_frame *frame)
 __attribute__((interrupt))
 void double_fault(struct abort_frame *frame)
 {
-	*(volatile char *) (0xb8000) = ":";
-	*(volatile char *) (0xb8002) = "(";
+	*(volatile uint32_t *) (0xb8000) = 0xcf28cf3a;
+halt:
 	asm volatile ("cli; hlt");
-	while(1);
+	goto halt;
 }
 
-- 
2.39.5