From 4ee45e27c2930fa70865b67b04e22e9bd870c058 Mon Sep 17 00:00:00 2001 From: Eggert Jung Date: Tue, 20 May 2025 23:21:25 +0200 Subject: [PATCH] wip aufg 3 --- interrupt/epilogues.cc | 4 +++- interrupt/guard.cc | 42 +++++++++++++++++++++++++++++++++++++++--- interrupt/handlers.cc | 10 +++++++--- main.cc | 1 + 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/interrupt/epilogues.cc b/interrupt/epilogues.cc index 18bbd91..f0f9c9b 100644 --- a/interrupt/epilogues.cc +++ b/interrupt/epilogues.cc @@ -4,7 +4,9 @@ namespace Epilogues { -void keyboard(Vault& g) { (void)g; } +void keyboard(Vault& g) { + +} void timer(Vault& g) { (void)g; } diff --git a/interrupt/guard.cc b/interrupt/guard.cc index 957975e..63631a7 100644 --- a/interrupt/guard.cc +++ b/interrupt/guard.cc @@ -4,6 +4,7 @@ #include "../debug/output.h" #include "../object/bbuffer.h" #include "../sync/ticketlock.h" +#include "../arch/core_interrupt.h" #include "epilogues.h" #define FOR_CURRENT_CORE [Core::getID()] @@ -21,10 +22,45 @@ Vault::Vault() {} Guarded::~Guarded() { Guard::leave(); } -Guarded Guard::enter() { while (true); } +Guarded Guard::enter() { + epi_flag FOR_CURRENT_CORE = true; + Core::Interrupt::enable(); + global_lock.lock(); +} -void Guard::leave() {} +void Guard::leave() { + bool istate = Core::Interrupt::disable(); -void Guard::relay(Epilogue handler) { (void)handler; } + Epilogue next; + while(epilogue_queue FOR_CURRENT_CORE.consume(next)){ + Core::Interrupt::enable(); + next(global_vault); + Core::Interrupt::disable(); + } + epi_flag FOR_CURRENT_CORE = false; + global_lock.unlock(); + Core::Interrupt::restore(istate); +} + +void Guard::relay(Epilogue handler) { + if(!epilogue_queue FOR_CURRENT_CORE.consume(handler)) + return; // enqueue, but dont execute + if(epi_flag FOR_CURRENT_CORE){ + enter(); + Core::Interrupt::disable(); + leave(); + } + //Core::Interrupt::enable(); // goto level 0.5 + //if(epi_flag FOR_CURRENT_CORE){ + // epilogue_queue->produce(handler); + //} + //else{ + // epi_flag FOR_CURRENT_CORE = true; + // handler(global_vault); + // leave(); // maybe not needed since destructor also calls leave + //} +} const Vault &Guard::unsafeConstAccess() { return global_vault; } + + diff --git a/interrupt/handlers.cc b/interrupt/handlers.cc index 7b120b8..d2bd0f2 100644 --- a/interrupt/handlers.cc +++ b/interrupt/handlers.cc @@ -10,6 +10,8 @@ #include "../device/ps2controller.h" #include "../sync/ticketlock.h" +#include "epilogues.h" +#include "guard.h" void printContext(const InterruptContext *context) { DBG << "ip: " << hex << context->cs << ':' << context->ip @@ -71,12 +73,14 @@ enum PAGE_FAULT_ERROR { extern TextStream kout; extern Ticketlock koutlock; +extern Vault keyboard_vault; void handle_keyboard() { Key key = Key(); if (PS2Controller::fetch(key)) { - koutlock.lock(); - kout << key.ascii() << endl << flush ; - koutlock.unlock(); + Guard::relay(Epilogues::keyboard); + //koutlock.lock(); + //kout << key.ascii() << endl << flush ; + //koutlock.unlock(); } else if (key.ctrl() && key.alt() && key.scancode == Key::KEY_DEL) System::reboot(); diff --git a/main.cc b/main.cc index 0213dad..cf48433 100644 --- a/main.cc +++ b/main.cc @@ -14,6 +14,7 @@ #include "arch/ioapic.h" #include "user/app1/appl.h" #include "sync/ticketlock.h" +#include "interrupt/guard.h" TextStream kout = TextStream(0, 80, 0, 10, true); Ticketlock koutlock;