1

switch cpu methods to static

This commit is contained in:
2022-07-24 00:29:21 +02:00
parent a5c14da0de
commit 605d4e8c8d
11 changed files with 52 additions and 62 deletions

View File

@ -33,7 +33,6 @@
#include "kernel/Allocator.h"
#include "kernel/Globals.h"
#include <stddef.h>
#define MEM_SIZE_DEF 8 * 1024 * 1024 // Groesse des Speichers = 8 MB

View File

@ -319,7 +319,7 @@ void BIOS::Int(int inter) {
// Interrupt-Nummer in 16-Bit Code-Segment schreiben (unschoen, aber ...)
*(ptr + 48) = (unsigned char)inter;
cpu.disable_int(); // Interrupts abschalten
CPU::disable_int(); // Interrupts abschalten
bios_call();
cpu.enable_int();
CPU::enable_int();
}

View File

@ -10,43 +10,37 @@
#ifndef __BIOS_include__
#define __BIOS_include__
// Speicherseite fuer Rueckgabewerte von BIOS-Aufrufen
#define RETURN_MEM 0x9F000
#define RETURN_MEM 0x9F000
// Struktur fuer Parameteruebergabe fuer einen BIOS-Aufruf
struct BIOScall_params {
unsigned short DS;
unsigned short ES;
unsigned short FS;
unsigned short Flags;
unsigned int DI;
unsigned int SI;
unsigned int BP;
unsigned int SP;
unsigned int BX;
unsigned int DX;
unsigned int CX;
unsigned int AX;
unsigned short DS;
unsigned short ES;
unsigned short FS;
unsigned short Flags;
unsigned int DI;
unsigned int SI;
unsigned int BP;
unsigned int SP;
unsigned int BX;
unsigned int DX;
unsigned int CX;
unsigned int AX;
} __attribute__((packed));
// kein Auffuellen von bytes auf Wortgrenzen
// Zeiger auf Speichbereich fuer Parameter fuer BIOS-Aufruf
extern struct BIOScall_params* BC_params;
class BIOS {
private:
BIOS(const BIOS &copy); // Verhindere Kopieren
BIOS(const BIOS& copy); // Verhindere Kopieren
public:
// Initialisierung: manuelles Anlegen einer Funktion
BIOS();
// BIOS-Aufruf, per Software-Interrupt
void Int(int inter);
};

View File

@ -13,7 +13,6 @@
#define __CPU_include__
class CPU {
private:
CPU(const CPU& copy); // Verhindere Kopieren
@ -21,29 +20,29 @@ public:
CPU() {}
// Erlauben von (Hardware-)Interrupts
inline void enable_int() {
static inline void enable_int() {
asm volatile("sti");
}
// Interrupts werden ignoriert/verboten
inline void disable_int() {
static inline void disable_int() {
asm volatile("cli");
}
// Prozessor bis zum naechsten Interrupt anhalten
inline void idle() {
static inline void idle() {
asm volatile("sti;"
"hlt");
}
// Prozessor anhalten
inline void halt() {
static inline void halt() {
asm volatile("cli;"
"hlt");
}
// Time-Stamp-Counter auslesen
inline unsigned long long int rdtsc() {
static inline unsigned long long int rdtsc() {
unsigned long long int ret;
asm volatile("rdtsc"
: "=A"(ret));

View File

@ -10,7 +10,6 @@
#include "kernel/Globals.h"
CPU cpu; // CPU-spezifische Funktionen
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
BIOS bios; // Schnittstelle zum 16-Bit BIOS
VESA vesa; // VESA-Treiber

View File

@ -22,13 +22,13 @@
#include "kernel/CPU.h"
#include "kernel/interrupts/IntDispatcher.h"
#include "kernel/interrupts/PIC.h"
#include "kernel/Paging.h"
#include "kernel/threads/Scheduler.h"
#include "user/devices/SerialOut.h"
#include "user/event/KeyEventManager.h"
// I wanted to make more of these singletons but there were problems with atexit missing because of nostdlib I guess
extern CPU cpu; // CPU-spezifische Funktionen
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
extern BIOS bios; // Schnittstelle zum 16-Bit BIOS
extern VESA vesa; // VESA-Treiber

View File

@ -35,13 +35,13 @@ void int_disp(unsigned int vector) {
if (vector < 32) {
bs_dump(vector);
cpu.halt();
CPU::halt();
}
if (intdis.report(vector) < 0) {
kout << "Panic: unexpected interrupt " << vector;
kout << " - processor halted." << endl;
cpu.halt();
CPU::halt();
}
}

View File

@ -8,7 +8,7 @@
* *
* Der Scheduler wird mit 'schedule' gestartet. Neue Threads*
* können mit 'ready' hinzugefügt werden. Ein Thread muss *
* die CPU freiwillig mit 'yield' abgeben, damit andere auch*
* die CPU::freiwillig mit 'yield' abgeben, damit andere auch*
* rechnen koennen. Ein Thread kann sich selbst mit 'exit' *
* terminieren. Ein Thread kann einen anderen Thread mit *
* 'kill' beenden. Ein erzwungener Threadwechsel erfolgt *
@ -33,7 +33,7 @@ constexpr const bool INSANE_TRACE = false;
* Beschreibung: Auf den active thread wechseln. *
* *
* Parameter: *
* next Thread der die CPU erhalten soll. *
* next Thread der die CPU::erhalten soll. *
*****************************************************************************/
void Scheduler::start(bse::vector<bse::unique_ptr<Thread>>::iterator next) {
active = next;
@ -84,10 +84,10 @@ void Scheduler::schedule() {
* Beschreibung: Thread in readyQueue eintragen. *
*****************************************************************************/
void Scheduler::ready(bse::unique_ptr<Thread>&& thread) {
cpu.disable_int();
CPU::disable_int();
log.debug() << "Adding to ready_queue, ID: " << dec << thread->tid << endl;
ready_queue.push_back(std::move(thread));
cpu.enable_int();
CPU::enable_int();
}
/*****************************************************************************
@ -103,11 +103,11 @@ void Scheduler::exit() {
/* hier muss Code eingefuegt werden */
// Thread-Wechsel durch PIT verhindern
cpu.disable_int();
CPU::disable_int();
if (ready_queue.size() == 1) {
log.error() << "Can't exit last thread, active ID: " << dec << (*active)->tid << endl;
cpu.enable_int();
CPU::enable_int();
return;
}
@ -132,7 +132,7 @@ void Scheduler::exit() {
* that Zu terminierender Thread *
*****************************************************************************/
void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
cpu.disable_int();
CPU::disable_int();
unsigned int prev_tid = (*active)->tid;
@ -151,7 +151,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
block_queue.erase(it);
log.info() << "Killed thread from block_queue with id: " << tid << endl;
cpu.enable_int();
CPU::enable_int();
return;
}
}
@ -159,7 +159,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
// Ready queue, can't kill last one
if (ready_queue.size() == 1) {
log.error() << "Kill: Can't kill last thread in ready_queue with id: " << tid << endl;
cpu.enable_int();
CPU::enable_int();
return;
}
@ -185,26 +185,26 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
ready_queue.erase(it);
log.info() << "Killed thread from ready_queue with id: " << tid << endl;
cpu.enable_int();
CPU::enable_int();
return;
}
}
log.error() << "Kill: Couldn't find thread with id: " << tid << " in ready- or block-queue" << endl;
cpu.enable_int();
CPU::enable_int();
}
// TODO: Can't retrive the thread right now because it's not clear when it's finished,
// maybe introduce a exited_queue and get it from there
void Scheduler::nice_kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
cpu.disable_int();
CPU::disable_int();
for (bse::unique_ptr<Thread>& thread : block_queue) {
if (thread->tid == tid) {
thread->suicide();
log.info() << "Nice killed thread in block_queue with id: " << tid << endl;
deblock(tid);
cpu.enable_int();
CPU::enable_int();
return;
}
}
@ -213,19 +213,19 @@ void Scheduler::nice_kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
if (thread->tid == tid) {
thread->suicide();
log.info() << "Nice killed thread in ready_queue with id: " << tid << endl;
cpu.enable_int();
CPU::enable_int();
return;
}
}
log.error() << "Can't nice kill thread (not found) with id: " << tid << endl;
cpu.enable_int();
CPU::enable_int();
}
/*****************************************************************************
* Methode: Scheduler::yield *
*---------------------------------------------------------------------------*
* Beschreibung: CPU freiwillig abgeben und Auswahl des naechsten Threads.*
* Beschreibung: CPU::freiwillig abgeben und Auswahl des naechsten Threads.*
* Naechsten Thread aus der readyQueue holen, den aktuellen *
* in die readyQueue wieder eintragen. Das Umschalten soll *
* mithilfe des Dispatchers erfolgen. *
@ -238,13 +238,13 @@ void Scheduler::yield() {
/* hier muss Code eingefuegt werden */
// Thread-Wechsel durch PIT verhindern
cpu.disable_int();
CPU::disable_int();
if (ready_queue.size() == 1) {
if constexpr (INSANE_TRACE) {
log.trace() << "Skipping yield as no thread is waiting, active ID: " << dec << (*active)->tid << endl;
}
cpu.enable_int();
CPU::enable_int();
return;
}
if constexpr (INSANE_TRACE) {
@ -264,7 +264,7 @@ void Scheduler::preempt() {
/* Hier muss Code eingefuegt werden */
cpu.disable_int();
CPU::disable_int();
yield();
}
@ -282,11 +282,11 @@ void Scheduler::block() {
/* hier muss Code eingefuegt werden */
cpu.disable_int();
CPU::disable_int();
if (ready_queue.size() == 1) {
log.error() << "Can't block last thread, active ID: " << dec << (*active)->tid << endl;
cpu.enable_int();
CPU::enable_int();
return;
}
@ -316,7 +316,7 @@ void Scheduler::deblock(unsigned int tid) {
/* hier muss Code eingefuegt werden */
cpu.disable_int();
CPU::disable_int();
for (bse::vector<bse::unique_ptr<Thread>>::iterator it = block_queue.begin(); it != block_queue.end(); ++it) {
if ((*it)->tid == tid) {
@ -329,11 +329,11 @@ void Scheduler::deblock(unsigned int tid) {
if constexpr (INSANE_TRACE) {
log.trace() << "Deblocked thread with id: " << tid << endl;
}
cpu.enable_int();
CPU::enable_int();
return;
}
}
log.error() << "Couldn't deblock thread with id: " << tid << endl;
cpu.enable_int();
CPU::enable_int();
}

View File

@ -13,7 +13,7 @@ void Semaphore::p() {
// Block and manage thread in semaphore queue until it's woken up by v() again
this->wait_queue.push_back(scheduler.get_active());
cpu.disable_int(); // Make sure the block() comes through after releasing the lock
CPU::disable_int(); // Make sure the block() comes through after releasing the lock
this->lock.release();
scheduler.block(); // Moves to next thread, enables int
}
@ -27,7 +27,7 @@ void Semaphore::v() {
unsigned int tid = this->wait_queue.front();
this->wait_queue.erase(wait_queue.begin());
cpu.disable_int(); // Make sure the deblock() comes through after releasing the lock
CPU::disable_int(); // Make sure the deblock() comes through after releasing the lock
this->lock.release();
scheduler.deblock(tid); // Enables int
} else {

View File

@ -13,7 +13,6 @@
#define __SpinLock_include__
class SpinLock {
private:
SpinLock(const SpinLock& copy) = delete; // Verhindere Kopieren

View File

@ -53,7 +53,7 @@ int main() {
pit.plugin();
// Interrupts erlauben (Tastatur, PIT)
cpu.enable_int();
CPU::enable_int();
// Activate paging
// This has to happen after the allocator is initialized but before the scheduler is started