This commit is contained in:
2025-12-15 13:20:58 +01:00
parent 7e02e20878
commit b064038c2d
9 changed files with 27 additions and 10 deletions

View File

@@ -10,6 +10,7 @@
#include "../debug/output.h" #include "../debug/output.h"
#include "../object/bbuffer.h" #include "../object/bbuffer.h"
#include "epilogues.h" #include "epilogues.h"
#include "../debug/copystream.h"
//! \brief The protected data for the epilogue level //! \brief The protected data for the epilogue level
static Vault global_vault; static Vault global_vault;

View File

@@ -12,17 +12,21 @@
#include "../thread/scheduler.h" #include "../thread/scheduler.h"
#include "../types.h" #include "../types.h"
#include "./epilogues.h" #include "./epilogues.h"
#include "../device/serialstream.h"
//! \brief The epilogue vault contains the protected data for the epilogue level //! \brief The epilogue vault contains the protected data for the epilogue level
struct Vault { struct Vault {
TextStream kout = TextStream(0, 80, 0, 17, true); TextStream kout = TextStream(0, 80, 0, 17, true);
//TextStream dout = TextStream(0, 80, 17, 25);
//SerialStream sout;
Scheduler scheduler; Scheduler scheduler;
Bellringer bellringer; Bellringer bellringer;
BBuffer<Key, 16> keys; BBuffer<Key, 16> keys;
Semaphore keys_sem; Semaphore keys_sem;
static constexpr int MAX_SEMS =32;
static constexpr int MAX_SEMS =32;
Semaphore sems[MAX_SEMS]; Semaphore sems[MAX_SEMS];
// Ignore this for now, this is for a bonus task // Ignore this for now, this is for a bonus task
Graphics graphics; Graphics graphics;

View File

@@ -1,18 +1,19 @@
#include "./arch/lapic.h" #include "./arch/lapic.h"
#include "./debug/copystream.h"
#include "./debug/output.h" #include "./debug/output.h"
#include "./device/serialstream.h"
#include "./types.h" // This is actually used #include "./types.h" // This is actually used
#include "arch/core_interrupt.h" #include "arch/core_interrupt.h"
#include "syscall/handler.h" #include "syscall/handler.h"
SerialStream sout;
#include "./device/textstream.h" #include "./device/textstream.h"
#include "./debug/copystream.h"
#include "./device/serialstream.h"
// Separate title window on first line (for simplicity at scrolling) // Separate title window on first line (for simplicity at scrolling)
static TextStream tout(0, CGA::COLUMNS, 0, 1); static TextStream tout(0, CGA::COLUMNS, 0, 1);
SerialStream sout;
TextStream dout(0, 80, 17, 25); TextStream dout(0, 80, 17, 25);
CopyStream copystream(&dout, &sout); CopyStream copystream(&dout, &sout);
OutputStream* copyout = &copystream; OutputStream* copyout = &copystream;
@@ -23,8 +24,8 @@ OutputStream* copyout = &copystream;
#include "./interrupt/guard.h" #include "./interrupt/guard.h"
#include "./sync/semaphore.h" #include "./sync/semaphore.h"
#include "./thread/thread.h" #include "./thread/thread.h"
Semaphore koutsem(1); //Semaphore koutsem(1);
TextStream kout(0, 80, 1, 17, true); //TextStream kout(0, 80, 1, 17, true);
// Applications // Applications
#include "./user/app1/appl.h" #include "./user/app1/appl.h"

View File

@@ -20,7 +20,9 @@ syscall_entry:
cld cld
; Call the high-level (C++) system call handler ; Call the high-level (C++) system call handler
sti
call syscall_handler call syscall_handler
cli
; Optional: Prevent kernel information leakage ; Optional: Prevent kernel information leakage
; by zeroing scratch registers ; by zeroing scratch registers

View File

@@ -36,6 +36,8 @@ namespace Syscall {
* instruction pointer) * instruction pointer)
* \return system call return value * \return system call return value
*/ */
extern "C" size_t syscall_handler(size_t sysnum, size_t p1, size_t p2, extern "C" size_t syscall_handler(size_t sysnum, size_t p1, size_t p2,
size_t p3, size_t p4, size_t p5, size_t p3, size_t p4, size_t p5,
InterruptContext *user) { InterruptContext *user) {

View File

@@ -68,6 +68,7 @@ size_t read(Vault &vault, uint32_t id, void *buf, size_t len) {
size_t read_cnt = 0; size_t read_cnt = 0;
while(read_cnt <= len){ while(read_cnt <= len){
Key key; Key key;
vault.keys_sem.p(vault);
vault.keys.consume(key); vault.keys.consume(key);
if(key.valid()) if(key.valid())
((char*)buf)[read_cnt++] = key.ascii(); ((char*)buf)[read_cnt++] = key.ascii();

View File

@@ -21,6 +21,8 @@ void IdleThread::action() {
} }
Core::idle(); Core::idle();
// We woke up. Start ticking again // We woke up. Start ticking again
dout << "idle ";
LAPIC::Timer::setMasked(false); LAPIC::Timer::setMasked(false);
} else { } else {
Core::Interrupt::enable(); Core::Interrupt::enable();

View File

@@ -19,7 +19,7 @@
*/ */
class IdleThread : public Thread { class IdleThread : public Thread {
public: public:
explicit IdleThread() : Thread() {} explicit IdleThread() : Thread(true) {}
/*! \brief Wait for a thread to become ready and sleep in the meantime. /*! \brief Wait for a thread to become ready and sleep in the meantime.
* *

View File

@@ -12,9 +12,13 @@ void Application::action() { // NOLINT
text[4] = 0x30+id; text[4] = 0x30+id;
for (unsigned i = 1;; ++i) { for (unsigned i = 1;; ++i) {
write(0, text, sizeof(text)); write(1, text, sizeof(text));
if(i==id) if(i==id){
write(2, "kill", 4);
write(2, &text[4], 1);
write(2, " ", 1);
sys_exit(); sys_exit();
}
sleep(1000); sleep(1000);
} }
} }