1
This commit is contained in:
2022-07-04 22:05:07 +02:00
parent 19ab6fef06
commit 51390ef277
10 changed files with 52 additions and 47 deletions

View File

@ -72,7 +72,7 @@ CC ?= gcc
CXX ?= g++
# I added O0 to allow paging/bluescreen to work (We need the ebp on the stack)
CFLAGS := $(CFLAGS) -O0 -m32 -march=i486 -Wall -fno-stack-protector -nostdlib -I. -g -ffreestanding -fno-pie -fno-pic -mpreferred-stack-boundary=2 -Wno-write-strings -mno-sse -mno-sse2 -mmanual-endbr
CFLAGS := $(CFLAGS) -O0 -m32 -march=i486 -Wall -fno-stack-protector -nostdlib -I. -g -ffreestanding -fno-pie -fno-pic -Wno-write-strings -mno-sse -mno-sse2 -mmanual-endbr -mpreferred-stack-boundary=2
# I added -std=c++17 for if constexpr, but it isn't necessary for anything critical
# Needed for template concepts, but we don't have it available: -std=c++20

View File

@ -10,18 +10,21 @@
#include "kernel/Globals.h"
CPU cpu; // CPU-spezifische Funktionen
PCSPK pcspk; // PC-Lautsprecher
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
Keyboard kb; // Tastatur
IntDispatcher intdis; // Unterbrechungsverteilung
PIC pic; // Interrupt-Controller
unsigned int total_mem; // RAM total
unsigned long systime = 0;
CPU cpu; // CPU-spezifische Funktionen
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
BIOS bios; // Schnittstelle zum 16-Bit BIOS
VESA vesa; // VESA-Treiber
PIC pic; // Interrupt-Controller
IntDispatcher intdis; // Unterbrechungsverteilung
PIT pit(10000);
Keyboard kb; // Tastatur
PCSPK pcspk; // PC-Lautsprecher
// BumpAllocator allocator;
// LinkedListAllocator allocator;
TreeAllocator allocator;
Scheduler scheduler;
BIOS bios; // Schnittstelle zum 16-Bit BIOS
VESA vesa; // VESA-Treiber
PIT pit(10000);
unsigned int total_mem; // RAM total
unsigned long systime = 0;

View File

@ -13,6 +13,7 @@
#include "devices/CGA_Stream.h"
#include "devices/Keyboard.h"
#include "devices/PCSPK.h"
#include "devices/PIT.h"
#include "devices/VESA.h"
#include "kernel/allocator/BumpAllocator.h"
#include "kernel/allocator/LinkedListAllocator.h"
@ -22,24 +23,26 @@
#include "kernel/interrupts/IntDispatcher.h"
#include "kernel/interrupts/PIC.h"
#include "kernel/threads/Scheduler.h"
#include "devices/PIT.h"
extern CPU cpu; // CPU-spezifische Funktionen
extern PCSPK pcspk; // PC-Lautsprecher
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
extern Keyboard kb; // Tastatur
extern IntDispatcher intdis; // Unterbrechungsverteilung
extern PIC pic; // Interrupt-Controller
extern PIT pit; // Zeitgeber
extern unsigned int total_mem; // RAM total
extern unsigned long systime; // wird all 10ms hochgezaehlt
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
extern PIC pic; // Interrupt-Controller
extern IntDispatcher intdis; // Unterbrechungsverteilung
extern PIT pit; // Zeitgeber
extern Keyboard kb; // Tastatur
extern PCSPK pcspk; // PC-Lautsprecher
// extern BumpAllocator allocator;
// extern LinkedListAllocator allocator;
extern TreeAllocator allocator;
extern Scheduler scheduler;
extern BIOS bios; // Schnittstelle zum 16-Bit BIOS
extern VESA vesa; // VESA-Treiber
constexpr bool DEBUG = true;
extern unsigned int total_mem; // RAM total
extern unsigned long systime; // wird all 10ms hochgezaehlt
#endif

View File

@ -92,7 +92,7 @@ unsigned int* pg_alloc_page() {
// pruefe ob Page frei
if (((*p_page) & PAGE_RESERVED) == 0) {
*p_page = (*p_page | PAGE_RESERVED);
return (unsigned int*)(i << 12); // Address without flags (Offset 0)
return (unsigned int*)(i << 12); // Address without flags (Offset 0)
}
}
return 0;
@ -108,10 +108,10 @@ void pg_write_protect_page(unsigned int* p_page) {
/* hier muss Code eingefügt werden */
unsigned int* page = (unsigned int*)PAGE_TABLE + ((unsigned int)p_page >> 12); // Pagetable entry
unsigned int* page = (unsigned int*)PAGE_TABLE + ((unsigned int)p_page >> 12); // Pagetable entry
unsigned int mask = PAGE_WRITEABLE; // fill to 32bit
*page = *page & ~mask; // set writable to 0
*page = *page & ~mask; // set writable to 0
}
/*****************************************************************************
@ -123,7 +123,7 @@ void pg_notpresent_page(unsigned int* p_page) {
/* hier muss Code eingefügt werden */
unsigned int* page = (unsigned int*)PAGE_TABLE + ((unsigned int)p_page >> 12); // Pagetable entry
unsigned int* page = (unsigned int*)PAGE_TABLE + ((unsigned int)p_page >> 12); // Pagetable entry
unsigned int mask = PAGE_PRESENT;
*page = *page & ~mask; // set present to 0

View File

@ -24,8 +24,8 @@ void Scheduler::schedule() {
// We need to start the idle thread first as this one sets the scheduler to initialized
// Other wise preemption will be blocked and nothing will happen if the first threads
// ready() function is blocking
this->start(*(Thread*)new IdleThread()); // The idle thread set initialized to true, so preemption
// only starts after this
this->start(*(Thread*)new IdleThread()); // The idle thread set initialized to true, so preemption
// only starts after this
}
/*****************************************************************************
@ -41,12 +41,12 @@ void Scheduler::ready(Thread* that) {
/* hier muss Code eingefuegt werden */
// Thread-Wechsel durch PIT verhindern
cpu.disable_int ();
cpu.disable_int();
this->readyQueue.enqueue(that);
// Thread-Wechsel durch PIT jetzt wieder erlauben
cpu.enable_int ();
cpu.enable_int();
}
/*****************************************************************************
@ -62,7 +62,7 @@ void Scheduler::exit() {
/* hier muss Code eingefuegt werden */
// Thread-Wechsel durch PIT verhindern
cpu.disable_int ();
cpu.disable_int();
Thread& next = *(Thread*)this->readyQueue.dequeue();
this->dispatch(next);
@ -87,12 +87,12 @@ void Scheduler::kill(Thread* that) {
/* hier muss Code eingefuegt werden */
// Thread-Wechsel durch PIT verhindern
cpu.disable_int ();
cpu.disable_int();
this->readyQueue.remove(that);
// Thread-Wechsel durch PIT jetzt wieder erlauben
cpu.enable_int ();
cpu.enable_int();
}
/*****************************************************************************
@ -118,7 +118,7 @@ void Scheduler::yield() {
}
// Thread-Wechsel durch PIT verhindern
cpu.disable_int ();
cpu.disable_int();
Thread& next = *(Thread*)this->readyQueue.dequeue();
this->readyQueue.enqueue(this->get_active());
@ -132,7 +132,7 @@ void Scheduler::yield() {
* schaltet auf den naechsten Thread um, sofern einer vor- *
* handen ist. *
*****************************************************************************/
void Scheduler::preempt () {
void Scheduler::preempt() {
/* Hier muss Code eingefuegt werden */
@ -142,7 +142,7 @@ void Scheduler::preempt () {
}
// Thread-Wechsel durch PIT verhindern
cpu.disable_int ();
cpu.disable_int();
Thread& next = *(Thread*)this->readyQueue.dequeue();
this->readyQueue.enqueue(this->get_active());

View File

@ -52,9 +52,8 @@ public:
// CPU freiwillig abgeben und Auswahl des naechsten Threads
void yield();
// Thread umschalten; wird aus der ISR des PITs gerufen
void preempt ();
void preempt();
};
#endif

View File

@ -78,7 +78,7 @@ void Thread_init(struct ThreadState* regs, unsigned int* stack, void (*kickoff)(
regs->edx = 0;
// flags initialisieren
regs->efl = (void*)0x200; // Interrupt-Enable
regs->efl = (void*)0x200; // Interrupt-Enable
}
/*****************************************************************************

View File

@ -36,10 +36,10 @@ struct ThreadState {
void* esp;
// nachfolgend die fluechtige Register
// wichtig fuer preemptives Multitasking
void *eax;
void *ecx;
void *edx;
void *efl;
void* eax;
void* ecx;
void* edx;
void* efl;
};
#endif

View File

@ -15,9 +15,9 @@
#include "kernel/threads/IdleThread.h"
#include "user/CoopThreadDemo.h"
#include "user/HelloWorldThread.h"
#include "user/VBEdemo.h"
#include "user/PCSPKdemo.h"
#include "user/PreemptiveThreadDemo.h"
#include "user/VBEdemo.h"
int main() {
kout.clear();

View File

@ -1,8 +1,8 @@
#ifndef __pre_loopthread_include__
#define __pre_loopthread_include__
#include "kernel/threads/Thread.h"
#include "kernel/Globals.h"
#include "kernel/threads/Thread.h"
class PreemptiveLoopThread : public Thread {