Preparations towards context switching

This commit is contained in:
Xnoe 2021-11-21 16:56:50 +00:00
parent b79ae4ec95
commit 2dd799b406
Signed by: xnoe
GPG Key ID: 45AC398F44F0DAFE
6 changed files with 33 additions and 9 deletions

View File

@ -13,7 +13,7 @@ run: disk.img
qemu-system-x86_64 disk.img
debug: disk.img
qemu-system-x86_64 -s -S disk.img & gdb --command=gdbscript
qemu-system-x86_64 -s -S -no-reboot -no-shutdown disk.img & gdb --command=gdbscript
disk.img: clean prepare build/boot/boot.bin build/boot_stage2/boot.bin $(DISK_IMG_FILES)
dd if=/dev/zero of=disk.img count=43 bs=100k

View File

@ -1,7 +1,8 @@
#include "memory.h"
#include "global.h"
namespace Global {
Allocator* allocator = 0;
Kernel* kernel = 0;
}
void* operator new (uint32_t size) {

View File

@ -1,10 +1,14 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#include "memory.h"
class Kernel;
class Allocator;
namespace Global {
extern Allocator* allocator;
extern Kernel* kernel;
}
void* operator new (uint32_t size);

View File

@ -1,9 +1,20 @@
#include "kernel.h"
Kernel* Kernel::kernel;
Kernel::Kernel(PageDirectory* page_directory, PageMap* phys, PageMap* virt, uint32_t virt_alloc_base)
: Process(0, 0x8a000, page_directory, phys, virt, virt_alloc_base)
{
this->kernel = this;
this->currentPID = 1;
Global::allocator = this;
Global::kernel = this;
}
void Kernel::init_kernel() {
this->pid_map = new xnoe::hashtable<uint32_t, Process*>();
}
Process* Kernel::createProcess() {
Process* p = new Process(currentPID);
this->pid_map->set(currentPID, p);
currentPID++;
return p;
}

View File

@ -2,14 +2,22 @@
#define KERNEL_H
#include "process.h"
#include "datatypes/hashtable.h"
#include "global.h"
class Kernel : public Process {
private:
static Kernel* kernel;
uint32_t currentPID;
public:
xnoe::hashtable<uint32_t, Process*>* pid_map; // Map of PIDs -> Process*s
uint32_t current_PID;
Kernel(PageDirectory* page_directory, PageMap* phys, PageMap* virt, uint32_t virt_alloc_base);
void init_kernel();
Process* createProcess();
};
#endif

View File

@ -28,7 +28,7 @@ int main() {
PageMap virt_pm(0xc0620000);
Kernel kernel = Kernel(&kernel_pd, &phys_pm, &virt_pm, 0xc0000000);
Global::allocator = &kernel;
kernel.init_kernel();
Terminal* current_term;
@ -47,7 +47,7 @@ int main() {
term->printf("KERNEL OK!\n");
Process* process = new Process(1);
kernel.createProcess();
term->deactivate();
term2->activate();