more or less works (with kill)

test2
Eggert Jung 4 months ago
parent cc412f4902
commit fd021c98a7

@ -69,7 +69,8 @@ enum Vector {
// Interrupts // Interrupts
KEYBOARD=32, KEYBOARD=32,
PANIC=33, PANIC=33,
TIMER=34 TIMER=34,
ASSASSIN=35
}; };
constexpr size_t VECTORS = 256; constexpr size_t VECTORS = 256;

@ -1,17 +1,23 @@
#include "epilogues.h" #include "epilogues.h"
#include "../debug/output.h" #include "../debug/output.h"
#include "../arch/core.h"
#include "../arch/lapic.h"
#include "guard.h" #include "guard.h"
#include "../thread/scheduler.h" #include "../thread/scheduler.h"
extern Key kout_key; extern Key kout_key;
#include "../user/app1/appl.h"
extern Application application1;
namespace Epilogues { namespace Epilogues {
void keyboard(Vault& v) { void keyboard(Vault& v) {
v.kout.setPos(0,0); v.kout.setPos(0,0);
v.kout << kout_key.ascii() << flush ; v.kout << kout_key.ascii() << flush ;
if(kout_key.scancode == Key::KEY_K)
v.sch.kill(v.sch.dispatcher.lifePointer[3]);
} }
void timer(Vault& v) { void timer(Vault& v) {
@ -23,11 +29,13 @@ void timer(Vault& v) {
v.kout << counter++ << flush; v.kout << counter++ << flush;
v.kout.setPos(x, y); v.kout.setPos(x, y);
} }
DBG << "timer C:" << dec << Core::getID() << " L:" << LAPIC::getID() << "\n" << flush;
v.sch.resume(true); v.sch.resume(true);
} }
void assassin(Vault& v) { void assassin(Vault& v) {
DBG << "assassin epilog\n"<< endl;
if (v.sch.active()->kill_flag) { if (v.sch.active()->kill_flag) {
v.sch.exit(); v.sch.exit();
} }

@ -57,7 +57,7 @@ void Guard::relay(Epilogue handler) {
Core::Interrupt::enable(); // goto level 0.5 Core::Interrupt::enable(); // goto level 0.5
if(epi_flag FOR_CURRENT_CORE){ if(epi_flag FOR_CURRENT_CORE){
epilogue_queue->produce(handler); epilogue_queue FOR_CURRENT_CORE.produce(handler);
} }
else{ else{
epi_flag FOR_CURRENT_CORE = true; epi_flag FOR_CURRENT_CORE = true;

@ -10,9 +10,11 @@
#include "../device/ps2controller.h" #include "../device/ps2controller.h"
#include "../sync/ticketlock.h" #include "../sync/ticketlock.h"
#include "../arch/core_interrupt.h"
#include "epilogues.h" #include "epilogues.h"
#include "guard.h" #include "guard.h"
Key kout_key = Key(); Key kout_key = Key();
void printContext(const InterruptContext *context) { void printContext(const InterruptContext *context) {
@ -77,6 +79,7 @@ void handle_keyboard() {
LAPIC::endOfInterrupt(); LAPIC::endOfInterrupt();
if (kout_key.ctrl() && kout_key.alt() && kout_key.scancode == Key::KEY_DEL) if (kout_key.ctrl() && kout_key.alt() && kout_key.scancode == Key::KEY_DEL)
System::reboot(); System::reboot();
Guard::relay(Epilogues::keyboard); Guard::relay(Epilogues::keyboard);
} }
else else
@ -98,6 +101,7 @@ void handle_keyboard() {
[[gnu::interrupt]] void handle_assassin(InterruptContext *context) { [[gnu::interrupt]] void handle_assassin(InterruptContext *context) {
(void)context; (void)context;
LAPIC::endOfInterrupt(); LAPIC::endOfInterrupt();
DBG << "assassin handler\n"<< endl;
Guard::relay(Epilogues::assassin); Guard::relay(Epilogues::assassin);
} }
[[gnu::interrupt]] void handle_wakeup(InterruptContext *context) { [[gnu::interrupt]] void handle_wakeup(InterruptContext *context) {
@ -126,6 +130,8 @@ void initInterruptHandlers() {
IDT::InterruptDescriptor::Returning(handle_keyboard_asm)); IDT::InterruptDescriptor::Returning(handle_keyboard_asm));
IDT::set(Core::Interrupt::Vector::TIMER, IDT::set(Core::Interrupt::Vector::TIMER,
IDT::InterruptDescriptor::Returning(handle_timer)); IDT::InterruptDescriptor::Returning(handle_timer));
IDT::set(Core::Interrupt::Vector::ASSASSIN,
IDT::InterruptDescriptor::Returning(handle_assassin));
// Load the idt pointer // Load the idt pointer
IDT::load(); IDT::load();
} }

@ -146,10 +146,9 @@ extern "C" int main() {
// Main function for application processors // Main function for application processors
extern "C" int main_ap() { extern "C" int main_ap() {
DBG_VERBOSE << "CPU core " << static_cast<int>(Core::getID()) << " / LAPIC " DBG << "CPU core " << static_cast<int>(Core::getID()) << " / LAPIC "
<< static_cast<int>(LAPIC::getID()) << " in main_ap()" << endl; << static_cast<int>(LAPIC::getID()) << " in main_ap()" << endl;
DBG << "App CPU " << static_cast<int>(Core::getID()) << endl << flush;
LAPIC::Timer::setup(1000000); LAPIC::Timer::setup(1000000);
Core::Interrupt::enable(); Core::Interrupt::enable();

@ -1,6 +1,10 @@
// vim: set noet ts=4 sw=4: // vim: set noet ts=4 sw=4:
#include "scheduler.h" #include "scheduler.h"
#include "../arch/lapic.h"
#include "dispatcher.h"
#include "../interrupt/guard.h"
#include "../debug/output.h"
Queue<Thread> readyList = Queue<Thread>(); Queue<Thread> readyList = Queue<Thread>();
@ -39,6 +43,17 @@ void Scheduler::exit() {
void Scheduler::kill(Thread* that) { void Scheduler::kill(Thread* that) {
readyList.remove(that); readyList.remove(that);
that->kill_flag = true; that->kill_flag = true;
DBG << "kill..." << flush;
for(uint8_t i=0;i<Core::MAX; i++)
if(dispatcher.lifePointer[i] == that){
LAPIC::IPI::send(i, Core::Interrupt::Vector::ASSASSIN);
DBG << "found thread on Core << dec << static_cast<int>(i) << "! killing...\n" << flush;
return;
}
DBG << "not found\n" << flush;
} }
bool Scheduler::isActive(const Thread* thread, unsigned int* cpu) { bool Scheduler::isActive(const Thread* thread, unsigned int* cpu) {

@ -25,9 +25,6 @@ Ich bin Großmuttersniffer\n\
Und wacht sie aus'm Koma auf, kriegt sie von mir 'n Sticker\n\ Und wacht sie aus'm Koma auf, kriegt sie von mir 'n Sticker\n\
\n"; \n";
extern Ticketlock koutlock;
extern Context* test2; extern Context* test1;
extern uint8_t test1_stack[], test2_stack[];
void activeWaitDelay(uint64_t cycles) { void activeWaitDelay(uint64_t cycles) {
uint64_t counter = 0; // Use volatile to prevent optimization uint64_t counter = 0; // Use volatile to prevent optimization
for (uint64_t i = 0; i < cycles; ++i) { for (uint64_t i = 0; i < cycles; ++i) {

Loading…
Cancel
Save