From 0aac6c888d23d70fb4792ce42c90b150cc464f85 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 5 Jan 2023 21:53:48 +0100 Subject: [PATCH] x86_64: Basic exit() syscall! User processes need to do something, amirite? --- kernel/src/arch/x86_64/CPU.asm | 3 ++- kernel/src/arch/x86_64/CPU.cpp | 6 ++++++ kernel/src/arch/x86_64/init/IDT.cpp | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/src/arch/x86_64/CPU.asm b/kernel/src/arch/x86_64/CPU.asm index f5a2c98a..00b58b7e 100644 --- a/kernel/src/arch/x86_64/CPU.asm +++ b/kernel/src/arch/x86_64/CPU.asm @@ -187,4 +187,5 @@ ISR 20 ; virtualization exception (#VE) ISR_ERROR 21 ; control-protection exception (#CP) ; ISR 22-31 reserved IRQ 32, 0 ; timer interrupt -IRQ 33, 0 ; keyboard interrupt \ No newline at end of file +IRQ 33, 0 ; keyboard interrupt +ISR 66 ; user exit diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index bb0455d8..8dca8b89 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -107,6 +107,12 @@ extern "C" void arch_interrupt_entry(Registers* regs) scancode_queue.try_push(scancode); pic_eoi(regs); } + else if (regs->isr == 66) // Exit!! + { + kdbgln("exiting from user task!!"); + Scheduler::current()->state = ThreadState::Dying; + kernel_yield(); + } else { kwarnln("IRQ catched! Halting."); diff --git a/kernel/src/arch/x86_64/init/IDT.cpp b/kernel/src/arch/x86_64/init/IDT.cpp index e507613e..22ea980a 100644 --- a/kernel/src/arch/x86_64/init/IDT.cpp +++ b/kernel/src/arch/x86_64/init/IDT.cpp @@ -36,7 +36,7 @@ u64 IDTEntry::get_offset() const static IDTEntry idt[256]; #define IDT_TA_InterruptGate 0b10001110 -#define IDT_TA_UserInterruptGate 0b11101110 +#define IDT_TA_UserCallableInterruptGate 0b11101110 #define IDT_TA_TrapGate 0b10001111 struct [[gnu::packed]] IDTR @@ -60,6 +60,7 @@ static void idt_add_handler(short num, void* handler, u8 type_attr) #define INT(x) extern "C" void _isr##x() #define TRAP(x) idt_add_handler(x, (void*)_isr##x, IDT_TA_TrapGate) #define IRQ(x) idt_add_handler(x, (void*)_isr##x, IDT_TA_InterruptGate) +#define SYS(x) idt_add_handler(x, (void*)_isr##x, IDT_TA_UserCallableInterruptGate) INT(0); INT(1); @@ -83,6 +84,7 @@ INT(20); INT(21); INT(32); INT(33); +INT(66); void setup_idt() { @@ -110,6 +112,7 @@ void setup_idt() TRAP(21); IRQ(32); IRQ(33); + SYS(66); static IDTR idtr; idtr.limit = 0x0FFF;