This commit is contained in:
Niklas Gollenstede
2025-10-31 22:37:36 +01:00
commit 174fe17e89
197 changed files with 79558 additions and 0 deletions

42
kernel/user/app1/appl.cc Normal file
View File

@@ -0,0 +1,42 @@
// vim: set noet ts=4 sw=4:
#include "appl.h"
#include "../../arch/core.h"
#include "../../arch/system.h"
#include "../../debug/output.h"
#include "../../device/textstream.h"
#include "../../interrupt/guard.h"
#include "../../sync/semaphore.h"
#include "../../thread/scheduler.h"
extern Semaphore koutsem;
extern TextStream kout;
extern Application apps[];
void Application::action() { // NOLINT
// Thread 1 may be an auxiliary thread
unsigned id = 0;
while (&apps[id++] != this);
for (unsigned i = 0;; ++i) {
// Make sure that we can use kout exclusively due to the hardware cursor
// otherwise we'd get a word jumble
koutsem.p(Guard::enter().vault());
kout.setPos(0U, id);
kout << i;
kout.flush();
koutsem.v(Guard::enter().vault());
// XXX: Doing this (the first time) in TASK 16 breaks all scheduling
if (i == 10000) {
if (id % 2 == 1) {
Guard::enter().vault().scheduler.kill(&apps[id - 1]);
}
}
Guard::enter().vault().scheduler.resume();
if (id > 1) {
Guarded g = Guard::enter();
g.vault().bellringer.sleep(g.vault(), id * id * 10);
}
}
}

32
kernel/user/app1/appl.h Normal file
View File

@@ -0,0 +1,32 @@
// vim: set noet ts=4 sw=4:
/*! \file
* \brief Enthält die Klasse Application
*/
#pragma once
#include "../../thread/thread.h"
#include "../../types.h"
//! \brief Test application
//!
//! \note Any class derived from Thread defines an application for StuBS.
//!
class Application : public Thread {
// Prevent copies and assignments
Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
public:
Application(Application&&) = delete;
/*! \brief Constructor
*
*/
Application() {}
/*! \brief Contains the application code.
*
*/
void action() override;
};

48
kernel/user/app2/kappl.cc Normal file
View File

@@ -0,0 +1,48 @@
// vim: set noet ts=4 sw=4:
#include "./kappl.h"
#include "../../device/textstream.h"
extern TextStream kout;
#include "../../interrupt/guard.h"
extern Semaphore koutsem;
void KeyboardApplication::action() { // NOLINT
const unsigned line = 10 + 2;
for (unsigned column = 0;; ++column) {
Key key;
{
Guarded g = Guard::enter();
g.vault().keys_sem.p(g.vault());
assert(g.vault().keys.consume(key) && "No key but sem returned!");
}
if (key.valid()) {
if (column >= CGA::COLUMNS - 1) {
column = 0;
koutsem.p(Guard::enter().vault());
for (unsigned offset = 0; offset < 3; offset++) {
for (unsigned column = 0; column < CGA::COLUMNS; ++column) {
CGA::show(column, line + offset, ' ');
}
}
koutsem.v(Guard::enter().vault());
}
koutsem.p(Guard::enter().vault());
kout.setPos(column, line);
kout << static_cast<char>(key.ascii());
kout.flush();
koutsem.v(Guard::enter().vault());
}
for (unsigned offset = 0; offset < 3; offset++) {
{
Guarded g = Guard::enter();
g.vault().bellringer.sleep(g.vault(), 10);
koutsem.p(g.vault());
}
kout.setPos(column, line + offset);
kout << static_cast<char>(key.ascii());
kout.flush();
koutsem.v(Guard::enter().vault());
}
}
}

26
kernel/user/app2/kappl.h Normal file
View File

@@ -0,0 +1,26 @@
// vim: set noet ts=4 sw=4:
/*! \file
* \brief Enthält die Klasse KeyboardApplication
*/
#pragma once
#include "../../thread/thread.h"
#include "../../types.h"
/*! \brief Keyboard Application
*
*/
class KeyboardApplication : public Thread {
// Prevent copies and assignments
KeyboardApplication(const KeyboardApplication&) = delete;
KeyboardApplication& operator=(const KeyboardApplication&) = delete;
public:
KeyboardApplication() {}
/*! \brief Contains the application code.
*
*/
void action() override;
};

1
kernel/user/loader.cc Normal file
View File

@@ -0,0 +1 @@
#include "device/textstream.h"