Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
52ccbd0
template for task 2
l3nkz Apr 27, 2026
aeef969
template for task 3
l3nkz May 11, 2026
74428f9
Merge tag 'task2' into task2-work
Lioncat2002 May 11, 2026
f829b3e
refactor: remove swap file
Lioncat2002 May 12, 2026
ea2c468
feat: added plugbox and panic impl
Lioncat2002 May 12, 2026
317d0b5
feat: pic implementation and keyboard interrupts
Tweedle2Dum May 13, 2026
b4940b9
template for task 4
l3nkz Jun 1, 2026
8424141
Merge tag 'task3' of https://os.inf.tu-dresden.de/Studium/OSC/SS2026/…
Lioncat2002 Jun 1, 2026
99f4eac
feat: started working on task 3
Lioncat2002 Jun 1, 2026
4c10838
feat: working on sync
Lioncat2002 Jun 1, 2026
fabd431
chore: bug fix
Lioncat2002 Jun 1, 2026
1dc2b04
feat: sync working
Lioncat2002 Jun 1, 2026
02f373a
feat: everything now works with prelogue epilogue model
Lioncat2002 Jun 1, 2026
c28b565
more or less working
Lioncat2002 Jun 1, 2026
7a18c20
refactor: added missing locks
Lioncat2002 Jun 2, 2026
f968c4b
refactor: added missing locks
Lioncat2002 Jun 2, 2026
6211dd4
refactor: change to leave
Lioncat2002 Jun 2, 2026
3572c5d
refactor: lock issues
Lioncat2002 Jun 2, 2026
b928d4e
refactor: lock issues
Lioncat2002 Jun 2, 2026
6c5c6b8
race condition fixes
Tweedle2Dum Jun 3, 2026
1e12d2f
Merge tag 'task4' of https://os.inf.tu-dresden.de/Studium/OSC/SS2026/…
Jun 14, 2026
b083f10
template for task 5
l3nkz Jun 14, 2026
5760f69
Merge branch 'task4-work' of github.com:LogBunny/PurrOS into task4-work
Tweedle2Dum Jun 16, 2026
f890598
feat: context switching implementation
Tweedle2Dum Jun 16, 2026
212b41d
fix: protect critical section in loop applicaiton
Tweedle2Dum Jun 16, 2026
1d3af2a
Merge tag 'task5' of https://os.inf.tu-dresden.de/Studium/OSC/SS2026/…
Jun 29, 2026
878841b
feat: task 5 should be done
Jun 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ clean:
bootdisk: $(OBJDIR)/bootdisk.iso
@echo "CP $<"
$(VERBOSE) cp $< $(DRIVE_HD)

#bootdisk: $(OBJDIR)/bootdisk.iso
# sudo dd if=$(OBJDIR)/bootdisk.iso of=$(DRIVE_HD) bs=4M conv=fsync status=progress
# sync
# --------------------------------------------------------------------------
# 'qemu' runs the QEMU emulator with the system

Expand Down
4 changes: 3 additions & 1 deletion device/cgastr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* C G A _ S T R E A M */
/* */
/*---------------------------------------------------------------------------*/
/* The CGA_Stream class allows to print different data types as text strings */
/* The CGA_Stream class allows to print different data types as text strings /
/* to a PC's CGA screen. */
/* For attributes/colors and cursor positioning use the methods of class */
/* CGA_Screen. */
Expand All @@ -14,6 +14,8 @@

#include "device/cgastr.h"

CGA_Stream kout;

void CGA_Stream::flush()
{
screen.print(buffer, pos, 0x07);
Expand Down
4 changes: 4 additions & 0 deletions device/cgastr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class CGA_Stream : public O_Stream
CGA_Stream& operator=(const CGA_Stream&) = delete;

void flush() override;
void setpos(int x, int y) { screen.setpos(x, y); }
void getpos(int &x, int &y) { screen.getpos(x, y); }
};

extern CGA_Stream kout;

#endif
45 changes: 45 additions & 0 deletions device/keyboard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* K E Y B O A R D */
/* */
/*---------------------------------------------------------------------------*/
/* Keyboard driver. */
/*****************************************************************************/

#include "device/keyboard.h"
#include "machine/plugbox.h"
#include "machine/pic.h"
#include "device/cgastr.h"

Keyboard keyboard;

void Keyboard::plugin() {
plugbox.assign(Plugbox::keyboard, *this);
pic.allow(PIC::keyboard);
}

bool Keyboard::prologue() {
//kout<< "IRQ"<<endl;
//kout.flush();
k = key_hit();
if (k.valid()) {
if (k.ctrl() && k.alt() && k.scancode() == Key::scan::del) {
reboot();
} //else if (k.ascii() != 0) {
// kout << k.ascii();
// kout.flush();
//}
}
return k.valid() && k.ascii() != 0;
}

void Keyboard::epilogue(){
//kout<<"EPI"<<endl;
//kout.flush();
if(k.ascii()){
kout << k.ascii();
kout.flush();
}
}
38 changes: 38 additions & 0 deletions device/keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* K E Y B O A R D */
/* */
/*---------------------------------------------------------------------------*/
/* Keyboard driver. */
/*****************************************************************************/

#ifndef __Keyboard_include__
#define __Keyboard_include__

#include "machine/keyctrl.h"
#include "guard/gate.h"
#include "machine/key.h"

class Keyboard : public Gate, public Keyboard_Controller
{
private:
Key k;
public:
Keyboard(const Keyboard &copy) = delete; // prevent copying
Keyboard& operator=(const Keyboard&) = delete; // prevent assignment
Keyboard() {}

// PLUGIN: "Plugs in" the keyboard (driver). From now on, keypresses are handled.
void plugin();

// PROLOGUE: To start the interrupt handling routine.
bool prologue() override;

void epilogue() override;
};

extern Keyboard keyboard;

#endif
26 changes: 26 additions & 0 deletions device/panic.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* P A N I C */
/* */
/*---------------------------------------------------------------------------*/
/* Default interrupt handler. */
/*****************************************************************************/
/* Add your code here */
/* Add your code here */
#include "device/panic.h"
#include "machine/cpu.h"
#include "device/cgastr.h"

extern CPU cpu;

Panic panic;

bool Panic::prologue(){
kout.setpos(0, 0);
kout << "PANIC: Unexpected interrupt! System halted." << endl;
kout.flush();
cpu.halt();
return true;
}
31 changes: 31 additions & 0 deletions device/panic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* P A N I C */
/* */
/*---------------------------------------------------------------------------*/
/* Default interrupt handler. */
/*****************************************************************************/

#ifndef __panic_include__
#define __panic_include__

/* INCLUDES */

#include "guard/gate.h"

class Panic: public Gate
/* Add your code here */
{
public:
Panic (const Panic &copy) = delete; // prevent copying
Panic& operator=(const Panic&) = delete; // prevent assignment
Panic () {}
bool prologue() override;
/* Add your code here */
};

extern Panic panic;

#endif
40 changes: 40 additions & 0 deletions device/watch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* W A T C H */
/* */
/*---------------------------------------------------------------------------*/
/* Handles timer interrupts by managing a time slice and triggering a */
/* process switch if necessary. */
/*****************************************************************************/

/* Add your code here */
/* Add your code here */

/* Add your code here */
/* Add your code here */
#include "watch.h"
#include "machine/plugbox.h"
#include "machine/pic.h"
#include "syscall/guarded_scheduler.h"

extern Plugbox plugbox;
extern PIC pic;
extern Guarded_Scheduler scheduler;

void Watch::windup()
{
plugbox.assign(Plugbox::timer, *this);
pic.allow(PIC::timer);
}

bool Watch::prologue()
{
return true;
}

void Watch::epilogue()
{
scheduler.resume();
}
39 changes: 39 additions & 0 deletions device/watch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* W A T C H */
/* */
/*---------------------------------------------------------------------------*/
/* Handles timer interrupts by managing a time slice and triggering a */
/* process switch if necessary. */
/*****************************************************************************/

#ifndef __watch_include__
#define __watch_include__

/* INCLUDES */

#include "guard/gate.h"
#include "machine/pit.h"

class Watch : public Gate, public PIT {
public:
// WATCH: Timer initialization, see PIT.
Watch(const Watch &copy) = delete; // prevent copying
Watch& operator=(const Watch&) = delete; // prevent assignment
Watch(int us) : PIT(us) {}

// WINDUP: "Winds up" the clock. To do this, the watch object must register
// with the Plugbox plugbox and allow the interrupts of the timer
// module with the help of the global pic object.
void windup();

// PROLOGUE: Contains the prologue of the interrupt handler.
bool prologue();

// EPILOGUE: This method triggers the process switch.
void epilogue();
};

#endif
Binary file added guard/.guard.cc.swo
Binary file not shown.
Binary file added guard/.guardian.cc.swo
Binary file not shown.
30 changes: 30 additions & 0 deletions guard/gate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* G A T E */
/* */
/*---------------------------------------------------------------------------*/
/* Class of objects that handle interrupts. */
/*****************************************************************************/

#ifndef __Gate_include__
#define __Gate_include__
#include "object/chain.h"

/* Add your code here */
class Gate: public Chain{
private:
volatile bool in_queue;
public:
Gate() : in_queue(false) {}
virtual bool prologue()=0;
virtual void epilogue() {}
void queued(bool q){
in_queue = q;
}
bool queued(){
return in_queue;
}
};
#endif
51 changes: 51 additions & 0 deletions guard/guard.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* G U A R D */
/* */
/*---------------------------------------------------------------------------*/
/* Using this class, we can synchronize activities with a critical section */
/* with interrupt handlers that also access this critical section. This */
/* synchronization takes place along the prologue/epilogue model. */
/*****************************************************************************/

/* Add your code here */

#include "guard.h"
#include "machine/cpu.h"
#include "gate.h"
extern CPU cpu;
void Guard::relay(Gate *item){
cpu.disable_int();
if(avail()){
enter();
item->queued(false);
cpu.enable_int();
item->epilogue();
cpu.disable_int();
leave();
cpu.enable_int();
}else{
if(!item->queued()){
item->queued(true);
queue.enqueue(item);
}
cpu.enable_int();
}
}

void Guard::leave(){
cpu.disable_int();
Gate *gate;
while((gate = (Gate*)queue.dequeue())){
gate->queued(false);
cpu.enable_int();
gate->epilogue();
cpu.disable_int();
}
retne();
cpu.enable_int();
}

Guard guard;
34 changes: 34 additions & 0 deletions guard/guard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*****************************************************************************/
/* Operating-System Construction */
/*---------------------------------------------------------------------------*/
/* */
/* G U A R D */
/* */
/*---------------------------------------------------------------------------*/
/* Using this class, we can synchronize activities with a critical section */
/* with interrupt handlers that also access this critical section. This */
/* synchronization takes place along the prologue/epilogue model. */
/*****************************************************************************/

#ifndef __Guard_include__
#define __Guard_include__

/* Add your code here */
#include "object/queue.h"
#include "locker.h"
#include "gate.h"
class Guard : public Locker {
private:
Queue queue;
public:
Guard (const Guard &copy) = delete; // prevent copying
Guard& operator=(const Guard&) = delete; // prevent assignment
Guard () {}

void leave();
void relay(Gate *item);
};

extern Guard guard;

#endif
Loading