From 5d4454e57ab22ff1c4010748ac02e5f1ee1284b5 Mon Sep 17 00:00:00 2001 From: Xnoe Date: Sat, 27 Nov 2021 15:56:35 +0000 Subject: [PATCH] Remove debug code from terminal.cpp. Update kmain, update world.c, update process.cpp to construct the initial value of EBP correctly. --- src/kernel/idt.cpp | 8 ++++---- src/kernel/kmain.cpp | 2 +- src/kernel/process.cpp | 4 +++- src/kernel/process.h | 3 +-- src/kernel/terminal.cpp | 4 +--- src/program/world.c | 7 ++++++- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/kernel/idt.cpp b/src/kernel/idt.cpp index 78789a8..62b4208 100644 --- a/src/kernel/idt.cpp +++ b/src/kernel/idt.cpp @@ -73,11 +73,11 @@ __attribute__((interrupt)) void context_switch(interrupt_frame* frame) { processes->start->next->prev = processes->start; processes->end->prev->next = processes->end; } - - // Get the next process. - nextProc = processes->start->elem; } + // Get the next process. + nextProc = processes->start->elem; + Global::currentProc = nextProc; uint32_t cESP; @@ -94,7 +94,7 @@ __attribute__((interrupt)) void context_switch(interrupt_frame* frame) { asm ("popa"); // Clear the garbage that was on the stack from previous switch_context call. - asm ("add $84, %esp"); + asm ("mov %ebp, %esp"); // Pop EBP asm ("pop %ebp"); diff --git a/src/kernel/kmain.cpp b/src/kernel/kmain.cpp index 1e8be37..569169e 100644 --- a/src/kernel/kmain.cpp +++ b/src/kernel/kmain.cpp @@ -47,7 +47,7 @@ int main() { Global::currentProc = &kernel; Process* p1 = kernel.createProcess("WORLD BIN"); - Process* p2 = kernel.createProcess("HELLO BIN"); + //Process* p2 = kernel.createProcess("HELLO BIN"); init_keyboard(); diff --git a/src/kernel/process.cpp b/src/kernel/process.cpp index e1c7ea9..d428013 100644 --- a/src/kernel/process.cpp +++ b/src/kernel/process.cpp @@ -59,6 +59,8 @@ Process::Process(uint32_t PID, PageDirectory* inherit, uint32_t inheritBase, cha stack32--; *stack32 = ((uint32_t)this->stack + 0x8000); // EBP + uint32_t rEBP = stack32; + stack32 -= 21; stack32--; @@ -72,7 +74,7 @@ Process::Process(uint32_t PID, PageDirectory* inherit, uint32_t inheritBase, cha stack32--; *stack32 = 0; // ESP stack32--; - *stack32 = (uint32_t)this->stack + 0x7ffc; // EBP + *stack32 = rEBP; // EBP stack32--; *stack32 = 0; // ESI stack32--; diff --git a/src/kernel/process.h b/src/kernel/process.h index af969e1..c2fd0ee 100644 --- a/src/kernel/process.h +++ b/src/kernel/process.h @@ -20,8 +20,6 @@ struct AllocTracker { class Process : public Allocator { private: - uint32_t PID; - uint32_t last_page_pointer; uint32_t page_remaining; @@ -33,6 +31,7 @@ private: xnoe::Maybe*> get_alloc_tracker(uint32_t address); public: + uint32_t PID; uint32_t esp; Process(uint32_t PID, void* stack, PageDirectory* page_directory, PageMap* phys, PageMap* virt, uint32_t virt_alloc_base); diff --git a/src/kernel/terminal.cpp b/src/kernel/terminal.cpp index d329d56..52bfe59 100644 --- a/src/kernel/terminal.cpp +++ b/src/kernel/terminal.cpp @@ -63,10 +63,8 @@ void Terminal::printf(const char* string, ...) { this->cur_y++; } - if (this->cur_y == this->height) { + if (this->cur_y == this->height) this->scroll_up(); - printf("This gets called..."); - } if (current == '%') { int type = string[index++]; diff --git a/src/program/world.c b/src/program/world.c index 8603aae..df5d5b4 100644 --- a/src/program/world.c +++ b/src/program/world.c @@ -1,7 +1,12 @@ #include "../common/common.h" int main() { + char buffer[2]; + buffer[0] = 0; + buffer[1] = 0; + while (1) { - print("World"); + buffer[0] = getch(); + print(buffer); } } \ No newline at end of file