reformat
This commit is contained in:
@ -72,7 +72,7 @@ CC ?= gcc
|
|||||||
CXX ?= g++
|
CXX ?= g++
|
||||||
|
|
||||||
# I added O0 to allow paging/bluescreen to work (We need the ebp on the stack)
|
# 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
|
# 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
|
# Needed for template concepts, but we don't have it available: -std=c++20
|
||||||
|
|||||||
@ -10,18 +10,21 @@
|
|||||||
|
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
CPU cpu; // CPU-spezifische Funktionen
|
CPU cpu; // CPU-spezifische Funktionen
|
||||||
PCSPK pcspk; // PC-Lautsprecher
|
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||||
CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
BIOS bios; // Schnittstelle zum 16-Bit BIOS
|
||||||
Keyboard kb; // Tastatur
|
VESA vesa; // VESA-Treiber
|
||||||
IntDispatcher intdis; // Unterbrechungsverteilung
|
|
||||||
PIC pic; // Interrupt-Controller
|
PIC pic; // Interrupt-Controller
|
||||||
unsigned int total_mem; // RAM total
|
IntDispatcher intdis; // Unterbrechungsverteilung
|
||||||
unsigned long systime = 0;
|
PIT pit(10000);
|
||||||
|
Keyboard kb; // Tastatur
|
||||||
|
PCSPK pcspk; // PC-Lautsprecher
|
||||||
|
|
||||||
// BumpAllocator allocator;
|
// BumpAllocator allocator;
|
||||||
// LinkedListAllocator allocator;
|
// LinkedListAllocator allocator;
|
||||||
TreeAllocator allocator;
|
TreeAllocator allocator;
|
||||||
Scheduler scheduler;
|
Scheduler scheduler;
|
||||||
BIOS bios; // Schnittstelle zum 16-Bit BIOS
|
|
||||||
VESA vesa; // VESA-Treiber
|
unsigned int total_mem; // RAM total
|
||||||
PIT pit(10000);
|
unsigned long systime = 0;
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include "devices/CGA_Stream.h"
|
#include "devices/CGA_Stream.h"
|
||||||
#include "devices/Keyboard.h"
|
#include "devices/Keyboard.h"
|
||||||
#include "devices/PCSPK.h"
|
#include "devices/PCSPK.h"
|
||||||
|
#include "devices/PIT.h"
|
||||||
#include "devices/VESA.h"
|
#include "devices/VESA.h"
|
||||||
#include "kernel/allocator/BumpAllocator.h"
|
#include "kernel/allocator/BumpAllocator.h"
|
||||||
#include "kernel/allocator/LinkedListAllocator.h"
|
#include "kernel/allocator/LinkedListAllocator.h"
|
||||||
@ -22,24 +23,26 @@
|
|||||||
#include "kernel/interrupts/IntDispatcher.h"
|
#include "kernel/interrupts/IntDispatcher.h"
|
||||||
#include "kernel/interrupts/PIC.h"
|
#include "kernel/interrupts/PIC.h"
|
||||||
#include "kernel/threads/Scheduler.h"
|
#include "kernel/threads/Scheduler.h"
|
||||||
#include "devices/PIT.h"
|
|
||||||
|
|
||||||
extern CPU cpu; // CPU-spezifische Funktionen
|
extern CPU cpu; // CPU-spezifische Funktionen
|
||||||
extern PCSPK pcspk; // PC-Lautsprecher
|
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
||||||
extern CGA_Stream kout; // Ausgabe-Strom fuer Kernel
|
extern BIOS bios; // Schnittstelle zum 16-Bit BIOS
|
||||||
extern Keyboard kb; // Tastatur
|
extern VESA vesa; // VESA-Treiber
|
||||||
extern IntDispatcher intdis; // Unterbrechungsverteilung
|
|
||||||
extern PIC pic; // Interrupt-Controller
|
extern PIC pic; // Interrupt-Controller
|
||||||
extern PIT pit; // Zeitgeber
|
extern IntDispatcher intdis; // Unterbrechungsverteilung
|
||||||
extern unsigned int total_mem; // RAM total
|
extern PIT pit; // Zeitgeber
|
||||||
extern unsigned long systime; // wird all 10ms hochgezaehlt
|
extern Keyboard kb; // Tastatur
|
||||||
|
extern PCSPK pcspk; // PC-Lautsprecher
|
||||||
|
|
||||||
// extern BumpAllocator allocator;
|
// extern BumpAllocator allocator;
|
||||||
// extern LinkedListAllocator allocator;
|
// extern LinkedListAllocator allocator;
|
||||||
extern TreeAllocator allocator;
|
extern TreeAllocator allocator;
|
||||||
extern Scheduler scheduler;
|
extern Scheduler scheduler;
|
||||||
extern BIOS bios; // Schnittstelle zum 16-Bit BIOS
|
|
||||||
extern VESA vesa; // VESA-Treiber
|
|
||||||
|
|
||||||
constexpr bool DEBUG = true;
|
constexpr bool DEBUG = true;
|
||||||
|
|
||||||
|
extern unsigned int total_mem; // RAM total
|
||||||
|
extern unsigned long systime; // wird all 10ms hochgezaehlt
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -92,7 +92,7 @@ unsigned int* pg_alloc_page() {
|
|||||||
// pruefe ob Page frei
|
// pruefe ob Page frei
|
||||||
if (((*p_page) & PAGE_RESERVED) == 0) {
|
if (((*p_page) & PAGE_RESERVED) == 0) {
|
||||||
*p_page = (*p_page | PAGE_RESERVED);
|
*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;
|
return 0;
|
||||||
@ -108,10 +108,10 @@ void pg_write_protect_page(unsigned int* p_page) {
|
|||||||
|
|
||||||
/* hier muss Code eingefügt werden */
|
/* 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
|
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 */
|
/* 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;
|
unsigned int mask = PAGE_PRESENT;
|
||||||
*page = *page & ~mask; // set present to 0
|
*page = *page & ~mask; // set present to 0
|
||||||
|
|||||||
@ -24,8 +24,8 @@ void Scheduler::schedule() {
|
|||||||
// We need to start the idle thread first as this one sets the scheduler to initialized
|
// 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
|
// Other wise preemption will be blocked and nothing will happen if the first threads
|
||||||
// ready() function is blocking
|
// ready() function is blocking
|
||||||
this->start(*(Thread*)new IdleThread()); // The idle thread set initialized to true, so preemption
|
this->start(*(Thread*)new IdleThread()); // The idle thread set initialized to true, so preemption
|
||||||
// only starts after this
|
// only starts after this
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -41,12 +41,12 @@ void Scheduler::ready(Thread* that) {
|
|||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT verhindern
|
// Thread-Wechsel durch PIT verhindern
|
||||||
cpu.disable_int ();
|
cpu.disable_int();
|
||||||
|
|
||||||
this->readyQueue.enqueue(that);
|
this->readyQueue.enqueue(that);
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT jetzt wieder erlauben
|
// 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 */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT verhindern
|
// Thread-Wechsel durch PIT verhindern
|
||||||
cpu.disable_int ();
|
cpu.disable_int();
|
||||||
|
|
||||||
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
||||||
this->dispatch(next);
|
this->dispatch(next);
|
||||||
@ -87,12 +87,12 @@ void Scheduler::kill(Thread* that) {
|
|||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT verhindern
|
// Thread-Wechsel durch PIT verhindern
|
||||||
cpu.disable_int ();
|
cpu.disable_int();
|
||||||
|
|
||||||
this->readyQueue.remove(that);
|
this->readyQueue.remove(that);
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT jetzt wieder erlauben
|
// 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
|
// Thread-Wechsel durch PIT verhindern
|
||||||
cpu.disable_int ();
|
cpu.disable_int();
|
||||||
|
|
||||||
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
||||||
this->readyQueue.enqueue(this->get_active());
|
this->readyQueue.enqueue(this->get_active());
|
||||||
@ -132,7 +132,7 @@ void Scheduler::yield() {
|
|||||||
* schaltet auf den naechsten Thread um, sofern einer vor- *
|
* schaltet auf den naechsten Thread um, sofern einer vor- *
|
||||||
* handen ist. *
|
* handen ist. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void Scheduler::preempt () {
|
void Scheduler::preempt() {
|
||||||
|
|
||||||
/* Hier muss Code eingefuegt werden */
|
/* Hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ void Scheduler::preempt () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Thread-Wechsel durch PIT verhindern
|
// Thread-Wechsel durch PIT verhindern
|
||||||
cpu.disable_int ();
|
cpu.disable_int();
|
||||||
|
|
||||||
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
Thread& next = *(Thread*)this->readyQueue.dequeue();
|
||||||
this->readyQueue.enqueue(this->get_active());
|
this->readyQueue.enqueue(this->get_active());
|
||||||
|
|||||||
@ -52,9 +52,8 @@ public:
|
|||||||
// CPU freiwillig abgeben und Auswahl des naechsten Threads
|
// CPU freiwillig abgeben und Auswahl des naechsten Threads
|
||||||
void yield();
|
void yield();
|
||||||
|
|
||||||
|
|
||||||
// Thread umschalten; wird aus der ISR des PITs gerufen
|
// Thread umschalten; wird aus der ISR des PITs gerufen
|
||||||
void preempt ();
|
void preempt();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -78,7 +78,7 @@ void Thread_init(struct ThreadState* regs, unsigned int* stack, void (*kickoff)(
|
|||||||
regs->edx = 0;
|
regs->edx = 0;
|
||||||
|
|
||||||
// flags initialisieren
|
// flags initialisieren
|
||||||
regs->efl = (void*)0x200; // Interrupt-Enable
|
regs->efl = (void*)0x200; // Interrupt-Enable
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
|||||||
@ -36,10 +36,10 @@ struct ThreadState {
|
|||||||
void* esp;
|
void* esp;
|
||||||
// nachfolgend die fluechtige Register
|
// nachfolgend die fluechtige Register
|
||||||
// wichtig fuer preemptives Multitasking
|
// wichtig fuer preemptives Multitasking
|
||||||
void *eax;
|
void* eax;
|
||||||
void *ecx;
|
void* ecx;
|
||||||
void *edx;
|
void* edx;
|
||||||
void *efl;
|
void* efl;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -15,9 +15,9 @@
|
|||||||
#include "kernel/threads/IdleThread.h"
|
#include "kernel/threads/IdleThread.h"
|
||||||
#include "user/CoopThreadDemo.h"
|
#include "user/CoopThreadDemo.h"
|
||||||
#include "user/HelloWorldThread.h"
|
#include "user/HelloWorldThread.h"
|
||||||
#include "user/VBEdemo.h"
|
|
||||||
#include "user/PCSPKdemo.h"
|
#include "user/PCSPKdemo.h"
|
||||||
#include "user/PreemptiveThreadDemo.h"
|
#include "user/PreemptiveThreadDemo.h"
|
||||||
|
#include "user/VBEdemo.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
kout.clear();
|
kout.clear();
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#ifndef __pre_loopthread_include__
|
#ifndef __pre_loopthread_include__
|
||||||
#define __pre_loopthread_include__
|
#define __pre_loopthread_include__
|
||||||
|
|
||||||
#include "kernel/threads/Thread.h"
|
|
||||||
#include "kernel/Globals.h"
|
#include "kernel/Globals.h"
|
||||||
|
#include "kernel/threads/Thread.h"
|
||||||
|
|
||||||
class PreemptiveLoopThread : public Thread {
|
class PreemptiveLoopThread : public Thread {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user