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 qemu-system-x86_64 disk.img
debug: 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) 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 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 { namespace Global {
Allocator* allocator = 0; Allocator* allocator = 0;
Kernel* kernel = 0;
} }
void* operator new (uint32_t size) { void* operator new (uint32_t size) {

View File

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

View File

@ -1,9 +1,20 @@
#include "kernel.h" #include "kernel.h"
Kernel* Kernel::kernel;
Kernel::Kernel(PageDirectory* page_directory, PageMap* phys, PageMap* virt, uint32_t virt_alloc_base) Kernel::Kernel(PageDirectory* page_directory, PageMap* phys, PageMap* virt, uint32_t virt_alloc_base)
: Process(0, 0x8a000, page_directory, phys, virt, 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 #define KERNEL_H
#include "process.h" #include "process.h"
#include "datatypes/hashtable.h"
#include "global.h"
class Kernel : public Process { class Kernel : public Process {
private: private:
static Kernel* kernel; uint32_t currentPID;
public: 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); Kernel(PageDirectory* page_directory, PageMap* phys, PageMap* virt, uint32_t virt_alloc_base);
void init_kernel();
Process* createProcess();
}; };
#endif #endif

View File

@ -28,7 +28,7 @@ int main() {
PageMap virt_pm(0xc0620000); PageMap virt_pm(0xc0620000);
Kernel kernel = Kernel(&kernel_pd, &phys_pm, &virt_pm, 0xc0000000); Kernel kernel = Kernel(&kernel_pd, &phys_pm, &virt_pm, 0xc0000000);
Global::allocator = &kernel; kernel.init_kernel();
Terminal* current_term; Terminal* current_term;
@ -46,8 +46,8 @@ int main() {
term->printf("Hello, World!\n\nWe are running XnoeOS Code in C++ now, Protected Mode has been achieved (as well as Virtual Memory / Paging!!!) and everything is working super nicely!\n\nHow wonderful!\n\nNow I just need to hope my print function works properly too~~\n"); term->printf("Hello, World!\n\nWe are running XnoeOS Code in C++ now, Protected Mode has been achieved (as well as Virtual Memory / Paging!!!) and everything is working super nicely!\n\nHow wonderful!\n\nNow I just need to hope my print function works properly too~~\n");
term->printf("KERNEL OK!\n"); term->printf("KERNEL OK!\n");
Process* process = new Process(1); kernel.createProcess();
term->deactivate(); term->deactivate();
term2->activate(); term2->activate();