From db8cdc7119f9f23e27e124c10843e6f218cc2e74 Mon Sep 17 00:00:00 2001 From: Max Tyson <98maxt98@gmail.com> Date: Sat, 21 Oct 2023 15:31:57 +1300 Subject: [PATCH] Rewrite Handlers --- README.md | 35 ++++----- docs/commit.md | 5 +- kernel/include/common/vector.h | 65 +++++++++++------ kernel/include/drivers/clock/clock.h | 2 +- .../include/drivers/ethernet/amd_am79c973.h | 2 +- kernel/include/drivers/ethernet/intel_i217.h | 2 +- kernel/include/drivers/peripherals/keyboard.h | 2 +- kernel/include/drivers/peripherals/mouse.h | 2 +- .../hardwarecommunication/interrupts.h | 21 +++--- kernel/include/hardwarecommunication/serial.h | 2 +- kernel/include/system/syscalls.h | 2 +- kernel/src/drivers/clock/clock.cpp | 6 +- kernel/src/drivers/console/console.cpp | 2 +- kernel/src/drivers/ethernet/amd_am79c973.cpp | 9 +-- kernel/src/drivers/ethernet/intel_i217.cpp | 6 +- kernel/src/drivers/peripherals/keyboard.cpp | 5 +- kernel/src/drivers/peripherals/mouse.cpp | 8 +-- kernel/src/gui/desktop.cpp | 10 ++- kernel/src/gui/widgets/inputbox.cpp | 2 + kernel/src/gui/window.cpp | 3 - .../src/hardwarecommunication/interrupts.cpp | 71 +++++++++++-------- kernel/src/hardwarecommunication/serial.cpp | 5 +- kernel/src/kernel.cpp | 2 +- kernel/src/system/syscalls.cpp | 19 +---- 24 files changed, 147 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index f0b80a2a..3fdc1f88 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ MaxOS now has support for hardrives (Fat32 filesytem) and can be booted from an ## Screenshots Booting -![Screenshot](docs/Screenshots/Boot/Console%20v2.png) +![Screenshot](docs/Screenshots/Boot/Console%20v2.png) cd GUI Window System ![Screenshot](docs/Screenshots/GUI/Windows%20(VESA).png) @@ -50,37 +50,38 @@ Kernel Cleanup - [x] VESA Video Mode - [x] Kernel Boot Rewrite - [x] Rewrite Event Handlers -- [ ] Usable Desktop -- [ ] Better Doxygen Documentation +- [ ] Network Touch Up +- [ ] HTTP Protocol, DCHP protocol +- [ ] GUI Bug Fixes +- [ ] Better Commenting and Doxygen Documentation - [ ] Use better c++ coding conventions -- [ ] Fix Filesystem +- [ ] Fix filesystem (move to linux one?) - [ ] USB -- [ ] HTTP Protocol, DCHP protocol -- [ ] Codebase cleanup / rewrite -- [ ] CMAKE +- [ ] Custom Toolchain +- [ ] CMAKE Build System (and maybe get it building and debugging in CLion) -Road to Userspace +Road to Userspace pt 1 - kernel core features - [ ] New Process Manager / Scheduler +- [ ] Interprocess Communication +- [ ] Might need an I/O Rewrite (more to come) +- [ ] Better Memory Management +- [ ] Paging - ? +- [ ] Filesystem Fixes +- [ ] System Calls + +Road to Userspace pt 2 - kernel supporting features + - [ ] Elf Loader - [ ] Shell -- [ ] More System Calls - [ ] OS Specific Toolchain - [ ] LibC - [ ] LibM -- [ ] Interprocess Communication - [ ] Services, (GUI Server, Network Server, etc) - [ ] LibNet - SMB Needed -- [ ] Example Telnet Server (GUI) (EXTERNALLY LOADED) -POSIX -- [ ] Unix Filesystem "proc, bin etc" -- [ ] Unix System Calls -- [ ] Other posix stuff OS Functionality - -- [ ] POSIX - [ ] ext2 Filesystem - [ ] GUI Theming, More GUI Widgets - [ ] Game Ports (DOOM etc..) diff --git a/docs/commit.md b/docs/commit.md index fde81eab..1ef66968 100644 --- a/docs/commit.md +++ b/docs/commit.md @@ -1,3 +1,2 @@ -# Input Box - 20/10/23 -- Added Input Boxes -- Will need to fix focusing and stuff tho \ No newline at end of file +# Windows Fix - 20/10/23 +- \ No newline at end of file diff --git a/kernel/include/common/vector.h b/kernel/include/common/vector.h index 0e5df3df..56bc35e6 100644 --- a/kernel/include/common/vector.h +++ b/kernel/include/common/vector.h @@ -21,8 +21,6 @@ namespace maxOS{ }; - - template class Vector { protected: @@ -57,9 +55,9 @@ namespace maxOS{ //______________________________________Implementation__________________________________________________ /** - * Base Template for VectorIterationHandler - * @tparam Type Type of the Vector - */ + * Base Template for VectorIterationHandler + * @tparam Type Type of the Vector + */ template Vector::Vector() { MaxSize = 100; @@ -192,12 +190,14 @@ namespace maxOS{ * @return The iterator of the element */ - template - typename Vector::iterator Vector::pushFront(Type element) { - if (Size >= MaxSize) // if the Vector is full - return end(); // return the end of the Vector + template typename Vector::iterator Vector::pushFront(Type element) { + + // Make sure the Vector is not full + if (Size >= MaxSize) + return end(); - for (iterator i = end(); i > begin(); --i) // for each element in the Vector + // for each element in the Vector + for (iterator i = end(); i > begin(); --i) *i = *(i - 1); // move the element one index to the right elements[0] = element; // add the element to front of the Vector @@ -211,8 +211,7 @@ namespace maxOS{ * @tparam Type Type of the Vector */ - template - void Vector::popFront() { + template void Vector::popFront() { if (Size > 0) //If the Vector is not empty { for (iterator i = begin() + 1; i != end(); ++i) // for each element in the Vector @@ -226,18 +225,21 @@ namespace maxOS{ * @tparam Type The type of the Vector * @param element The element to remove */ - template - void Vector::erase(Type element) { - int hits = 0; // number of hits - for (iterator i = begin(); i != end(); ++i) // for each element in the Vector + template void Vector::erase(Type element) { + + // Search for the element + int hits = 0; + for (iterator i = begin(); i != end(); ++i) { - if (*i == - element) // if the element is equal to the element we are looking for + // If it is the element we are looking for + if (*i == element) { - ++hits; // increase the number of hits + ++hits; } else { - if (hits > 0) // if we have hits - *(i - hits) = *i; // move the element one index to the left + + // if we have hits + if (hits > 0) + *(i - hits) = *i; // move the element to the left } } @@ -297,6 +299,27 @@ namespace maxOS{ for (iterator i = begin(); i != end(); ++i) // for each element in the Vector callback(*i); // call the callback function } + + template + void VectorIterationHandler::OnEndOfStream() { + + } + + template + void VectorIterationHandler::OnRead(Type) { + + } + + template + VectorIterationHandler::~VectorIterationHandler() { + + } + + template + VectorIterationHandler::VectorIterationHandler() { + + } + } } diff --git a/kernel/include/drivers/clock/clock.h b/kernel/include/drivers/clock/clock.h index fb144506..f2b0fbe8 100644 --- a/kernel/include/drivers/clock/clock.h +++ b/kernel/include/drivers/clock/clock.h @@ -58,7 +58,7 @@ namespace maxOS { common::uint16_t ticksUntilNextEvent; // Other functions - common::uint32_t HandleInterrupt(common::uint32_t esp); + void HandleInterrupt(); common::uint8_t readHardwareClock(common::uint8_t address); common::uint8_t binaryRepresentation(common::uint8_t number); diff --git a/kernel/include/drivers/ethernet/amd_am79c973.h b/kernel/include/drivers/ethernet/amd_am79c973.h index d0a77ed0..333e88bf 100644 --- a/kernel/include/drivers/ethernet/amd_am79c973.h +++ b/kernel/include/drivers/ethernet/amd_am79c973.h @@ -96,7 +96,7 @@ namespace maxOS{ common::string getDeviceName(); //Override Interrupt default methods - common::uint32_t HandleInterrupt(common::uint32_t esp); + void HandleInterrupt(); //Ethernet Driver functions void DoSend(common::uint8_t* buffer, common::uint32_t size); diff --git a/kernel/include/drivers/ethernet/intel_i217.h b/kernel/include/drivers/ethernet/intel_i217.h index 45cb162c..ecaeb78d 100644 --- a/kernel/include/drivers/ethernet/intel_i217.h +++ b/kernel/include/drivers/ethernet/intel_i217.h @@ -119,7 +119,7 @@ namespace maxOS{ void deactivate(); //Override Interrupt default methods - common::uint32_t HandleInterrupt(common::uint32_t esp); + void HandleInterrupt(); //Ethernet Driver functions diff --git a/kernel/include/drivers/peripherals/keyboard.h b/kernel/include/drivers/peripherals/keyboard.h index 233e790c..58d7d19f 100644 --- a/kernel/include/drivers/peripherals/keyboard.h +++ b/kernel/include/drivers/peripherals/keyboard.h @@ -400,7 +400,7 @@ namespace maxOS KeyboardDriver(hardwarecommunication::InterruptManager *manager); ~KeyboardDriver(); - virtual common::uint32_t HandleInterrupt(common::uint32_t esp); + void HandleInterrupt(); virtual void activate(); common::string getDeviceName(); diff --git a/kernel/include/drivers/peripherals/mouse.h b/kernel/include/drivers/peripherals/mouse.h index 85f255a0..cf0b3a8b 100644 --- a/kernel/include/drivers/peripherals/mouse.h +++ b/kernel/include/drivers/peripherals/mouse.h @@ -63,7 +63,7 @@ namespace maxOS { hardwarecommunication::Port8Bit dataPort; hardwarecommunication::Port8Bit commandPort; - common::uint32_t HandleInterrupt(common::uint32_t esp); + void HandleInterrupt(); common::uint8_t buffer[3]; common::uint8_t offest; diff --git a/kernel/include/hardwarecommunication/interrupts.h b/kernel/include/hardwarecommunication/interrupts.h index 2cb0790b..1d1a5a98 100644 --- a/kernel/include/hardwarecommunication/interrupts.h +++ b/kernel/include/hardwarecommunication/interrupts.h @@ -23,12 +23,11 @@ namespace maxOS { common::uint8_t interrupNumber; InterruptManager *interruptManager; - InterruptHandler(common::uint8_t interrupNumber, InterruptManager *interruptManager); - + InterruptHandler(common::uint8_t interrupNumber, InterruptManager *interruptManager = 0); ~InterruptHandler(); public: - virtual common::uint32_t HandleInterrupt(common::uint32_t esp); + virtual void HandleInterrupt(); }; @@ -38,7 +37,9 @@ namespace maxOS { protected: static InterruptManager *ActiveInterruptManager; - InterruptHandler *interruptHandlers[256]; + static common::OutputStream* errorMessages; + common::uint16_t hardwareInterruptOffset; + InterruptHandler *interruptHandlers[256]; // Make vector? ThreadManager* threadManager; struct GateDescriptor { @@ -56,9 +57,6 @@ namespace maxOS { common::uint32_t base; } __attribute__((packed)); - common::uint16_t hardwareInterruptOffset; - common::OutputStream* errorMessages; - static void SetInterruptDescriptorTableEntry(common::uint8_t interrupt, common::uint16_t codeSegmentSelectorOffset, void (*handler)(), @@ -122,8 +120,8 @@ namespace maxOS { static common::uint32_t HandleInterrupt(common::uint8_t interrupt, common::uint32_t esp); - - common::uint32_t DoHandleInterrupt(common::uint8_t interrupt, common::uint32_t esp); + static common::uint32_t HandleInterruptRequest(common::uint32_t esp); + common::uint32_t DoHandleInterruptRequest(common::uint8_t interrupt, common::uint32_t esp); //PIC Cominunication Port8BitSlow programmableInterruptControllerMasterCommandPort; @@ -134,13 +132,14 @@ namespace maxOS { public: InterruptManager(common::uint16_t hardwareInterruptOffset, system::GlobalDescriptorTable *globalDescriptorTable, ThreadManager* threadManage, common::OutputStream* handler); - ~InterruptManager(); common::uint16_t HardwareInterruptOffset(); - void Activate(); + void setInterruptHandler(common::uint8_t interrupt, InterruptHandler *handler); + void removeInterruptHandler(common::uint8_t interrupt); + void Activate(); void Deactivate(); }; diff --git a/kernel/include/hardwarecommunication/serial.h b/kernel/include/hardwarecommunication/serial.h index 6f8d72a4..1b401917 100644 --- a/kernel/include/hardwarecommunication/serial.h +++ b/kernel/include/hardwarecommunication/serial.h @@ -106,7 +106,7 @@ namespace maxOS{ serial(InterruptManager* interruptManager); ~serial(); - common::uint32_t HandleInterrupt(common::uint32_t esp); + void HandleInterrupt(); void Test(); char Read(); diff --git a/kernel/include/system/syscalls.h b/kernel/include/system/syscalls.h index 26a5ac83..bb0ce1da 100644 --- a/kernel/include/system/syscalls.h +++ b/kernel/include/system/syscalls.h @@ -16,7 +16,7 @@ namespace maxOS{ SyscallHandler(hardwarecommunication::InterruptManager* interruptManager, common::uint8_t interruptNumber); ~SyscallHandler(); - virtual common::uint32_t HandleInterrupt(common::uint32_t esp); + virtual void HandleInterrupt(); }; diff --git a/kernel/src/drivers/clock/clock.cpp b/kernel/src/drivers/clock/clock.cpp index 4eeadbdd..ee4c0876 100644 --- a/kernel/src/drivers/clock/clock.cpp +++ b/kernel/src/drivers/clock/clock.cpp @@ -68,7 +68,7 @@ Clock::~Clock() { * @details Handle the RTC interrupt, It increments the number of ticks and calls the event clockEventHandlers if the number of ticks is equal to the number of ticks between events * @param esp The stack pointer */ -uint32_t Clock::HandleInterrupt(uint32_t esp) { +void Clock::HandleInterrupt() { // Increment the number of ticks and decrement the number of ticks until the next event ticks++; @@ -76,7 +76,7 @@ uint32_t Clock::HandleInterrupt(uint32_t esp) { // If the number of ticks until the next event is not 0 then return if(ticksUntilNextEvent != 0) - return esp; + return; // Otherwise, reset the number of ticks until the next event ticksUntilNextEvent = ticksBetweenEvents; @@ -96,8 +96,6 @@ uint32_t Clock::HandleInterrupt(uint32_t esp) { TimeEvent* event = new TimeEvent(&time); raiseEvent(event); //TODO: delete event; - - return esp; } diff --git a/kernel/src/drivers/console/console.cpp b/kernel/src/drivers/console/console.cpp index f5babe63..bcd6cd2d 100644 --- a/kernel/src/drivers/console/console.cpp +++ b/kernel/src/drivers/console/console.cpp @@ -416,7 +416,7 @@ void ConsoleStream::writeChar(char c) { cursorY = console->getHeight()-1; } - // dont break here, we want to go to the next case because of the \r + // don't break here, we want to go to the next case because of the \r // Carriage return case '\r': diff --git a/kernel/src/drivers/ethernet/amd_am79c973.cpp b/kernel/src/drivers/ethernet/amd_am79c973.cpp index 6f4db13d..b39d5414 100644 --- a/kernel/src/drivers/ethernet/amd_am79c973.cpp +++ b/kernel/src/drivers/ethernet/amd_am79c973.cpp @@ -154,8 +154,8 @@ uint32_t amd_am79c973::reset() { * @details This function handles the interrupt for the device * * @param esp The stack pointer (where to return to) - */ -common::uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp) { +*/ +void amd_am79c973::HandleInterrupt() { // Similar to PIC, data needs to be read when a interrupt is sent, or it hangs @@ -179,11 +179,6 @@ common::uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp) { // Reply that it was received registerAddressPort.Write(0); // Tell device to write to register 0 registerDataPort.Write(temp); // Tell device that the interrupt was received - - - - return esp; - } diff --git a/kernel/src/drivers/ethernet/intel_i217.cpp b/kernel/src/drivers/ethernet/intel_i217.cpp index b4b9cede..34e4df9b 100644 --- a/kernel/src/drivers/ethernet/intel_i217.cpp +++ b/kernel/src/drivers/ethernet/intel_i217.cpp @@ -307,7 +307,7 @@ void intel_i217::activate() { } -common::uint32_t intel_i217::HandleInterrupt(common::uint32_t esp) { +void intel_i217::HandleInterrupt() { Write(interruptMaskRegister, 0x1); //Clear the interrupt or it will hang uint32_t temp = Read(0xc0); //Read the interrupt status register @@ -317,10 +317,6 @@ common::uint32_t intel_i217::HandleInterrupt(common::uint32_t esp) { if(temp & 0x04) driverMessageStream -> write("INTEL i217 START LINK");//initDone = true; if(temp & 0x10) driverMessageStream -> write("INTEL i217 GOOD THRESHOLD"); if(temp & 0x80) FetchDataReceived(); - - - return esp; - } void intel_i217::FetchDataReceived() { diff --git a/kernel/src/drivers/peripherals/keyboard.cpp b/kernel/src/drivers/peripherals/keyboard.cpp index 2d7b3a8f..c369f8ad 100644 --- a/kernel/src/drivers/peripherals/keyboard.cpp +++ b/kernel/src/drivers/peripherals/keyboard.cpp @@ -90,7 +90,7 @@ void KeyboardDriver::activate() { * @param esp The stack pointer * @return returns the passed esp */ -uint32_t KeyboardDriver::HandleInterrupt(uint32_t esp){ +void KeyboardDriver::HandleInterrupt(){ // Read the scancode from the keyboard uint8_t key = dataPort.Read(); //NOTE: The 8th bit is set to 1 if key is released and cleared to 0 if key is pressed @@ -98,9 +98,6 @@ uint32_t KeyboardDriver::HandleInterrupt(uint32_t esp){ // Pass the scan code to the handlers for(Vector*>::iterator streamEventHandler = inputStreamEventHandlers.begin(); streamEventHandler != inputStreamEventHandlers.end(); streamEventHandler++) (*streamEventHandler)->onStreamRead(key); - - return esp; - } string KeyboardDriver::getDeviceName() { diff --git a/kernel/src/drivers/peripherals/mouse.cpp b/kernel/src/drivers/peripherals/mouse.cpp index cd2684c7..5735edac 100644 --- a/kernel/src/drivers/peripherals/mouse.cpp +++ b/kernel/src/drivers/peripherals/mouse.cpp @@ -103,7 +103,7 @@ void MouseDriver::activate() { * @param esp * @return always returns esp */ -uint32_t MouseDriver::HandleInterrupt(uint32_t esp){ +void MouseDriver::HandleInterrupt(){ //The mouse triggers 3 interrupts , one for each byte . //Byte 1 : Y overflow | X overflow | Y sign bit | X sign bit | Reserved (1) | Middle button pressed | Right button pressed | Left button pressed @@ -112,7 +112,7 @@ uint32_t MouseDriver::HandleInterrupt(uint32_t esp){ uint8_t status = commandPort.Read(); if(!(status & 0x20)) //Only if the 6th bit of data is one then there is data to handle - return esp; //Otherwise don't bother handling this input + return; //Otherwise don't bother handling this input buffer[offest] = dataPort.Read(); //Read mouse info into buffer @@ -120,7 +120,7 @@ uint32_t MouseDriver::HandleInterrupt(uint32_t esp){ //If the mouse data transmission is incomplete (3rd piece of data isn't through) if(offest != 0) - return esp; + return; // If the mouse is moved (buffer 1 and 2 store x and y) if(buffer[1] != 0 || buffer[2] != 0) @@ -143,8 +143,6 @@ uint32_t MouseDriver::HandleInterrupt(uint32_t esp){ // Update the buttons buttons = buffer[0]; - - return esp; } string MouseDriver::getDeviceName() { diff --git a/kernel/src/gui/desktop.cpp b/kernel/src/gui/desktop.cpp index b3c5b057..faefdba5 100644 --- a/kernel/src/gui/desktop.cpp +++ b/kernel/src/gui/desktop.cpp @@ -75,12 +75,18 @@ void Desktop::setFocus(Widget* widget) { */ void Desktop::bringToFront(Widget* frontWidget) { + /* + * 0x563200 + start = {elements = {0x563844, 0x563200, 0x563680, 0x56303c, 0x0 }, Size = 4, + erased = {elements = {0x563844, 0x563680, 0x56303c, 0x56303c, 0x0 }, Size = 3, + pushed front = {elements = {0x563200, 0x563844, 0x563680, 0x56303c, 0x0 }, Size = 4, + */ + // Remove the widget from where ever it already is children.erase(frontWidget); // Add it back in the front children.pushFront(frontWidget); - } /** @@ -214,7 +220,7 @@ void Desktop::onTime(const Time &time) { while (!invalidAreas.empty()) { // Get the first invalid area - Rectangle invalidArea = *(invalidAreas.begin()); //get the pointer to the first element + Rectangle invalidArea = *(invalidAreas.begin()); //get the pointer to the first element // Remove the area from the invalid areas invalidAreas.popFront(); diff --git a/kernel/src/gui/widgets/inputbox.cpp b/kernel/src/gui/widgets/inputbox.cpp index e692c7a2..aaa64ffa 100644 --- a/kernel/src/gui/widgets/inputbox.cpp +++ b/kernel/src/gui/widgets/inputbox.cpp @@ -126,12 +126,14 @@ void InputBox::onFocus() { // Make the border black on focus borderColour = Colour(0x00, 0x00, 0x00); + invalidate(); } void InputBox::onFocusLost() { // Reset the border colour borderColour = Colour(0x57, 0x57, 0x57); + invalidate(); } void InputBox::onKeyDown(KeyCode keyDownCode, KeyboardState keyDownState) { diff --git a/kernel/src/gui/window.cpp b/kernel/src/gui/window.cpp index cabae3b7..2b260d15 100644 --- a/kernel/src/gui/window.cpp +++ b/kernel/src/gui/window.cpp @@ -208,9 +208,6 @@ void Window::drawSelf(common::GraphicsContext* gc, common::Rectangle& area) gc -> fillRectangle(windowX + windowFrameRightAreaToDraw.left, windowY + windowFrameRightAreaToDraw.top, windowX + windowFrameRightAreaToDraw.left + windowFrameRightAreaToDraw.width, windowY + windowFrameRightAreaToDraw.top + windowFrameRightAreaToDraw.height, windowFrameColour); } - - // TODO: This is a hack to get the window border to draw correctly, should make it so that the window border is drawn in the correct place - gc -> drawRectangle(windowX+1, windowY+1, windowX + windowPosition.width -1, windowY + windowPosition.height -1, windowFrameBorderColour); } /** diff --git a/kernel/src/hardwarecommunication/interrupts.cpp b/kernel/src/hardwarecommunication/interrupts.cpp index 49f4886d..7cc908ff 100644 --- a/kernel/src/hardwarecommunication/interrupts.cpp +++ b/kernel/src/hardwarecommunication/interrupts.cpp @@ -9,8 +9,11 @@ using namespace maxOS::common; using namespace maxOS::hardwarecommunication; using namespace maxOS::system; +// Define the static variables - +InterruptManager* InterruptManager::ActiveInterruptManager = 0; +OutputStream* InterruptManager::errorMessages = 0; +InterruptManager::GateDescriptor InterruptManager::interruptDescriptorTable[256]; ///__Handler__ @@ -18,29 +21,32 @@ InterruptHandler::InterruptHandler(uint8_t interrupNumber, InterruptManager *int //Store values given this->interrupNumber = interrupNumber; + + if(interruptManager == 0) { + this->interruptManager = InterruptManager::ActiveInterruptManager; + } + this->interruptManager = interruptManager; - //Put itself into handlers array - interruptManager->interruptHandlers[interrupNumber] = this; + // Set the handler in the array + this->interruptManager->setInterruptHandler(interrupNumber, this); } + InterruptHandler::~InterruptHandler(){ - //Remove self from handlers array - if(interruptManager->interruptHandlers[interrupNumber] == this){ - interruptManager->interruptHandlers[interrupNumber] = 0; - } -} -uint32_t InterruptHandler::HandleInterrupt(uint32_t esp){ - //Standard for the handlers, specifics will be created when init each type - return esp; + // Unset the handler in the array + if(this->interruptManager != 0) + this->interruptManager->removeInterruptHandler(interrupNumber); + } +void InterruptHandler::HandleInterrupt() { -///__Manger__ +} -InterruptManager::GateDescriptor InterruptManager::interruptDescriptorTable[256]; -InterruptManager* InterruptManager::ActiveInterruptManager = 0; + +///__Manger__ /** * @details This function is used to set an entry in the IDT @@ -78,7 +84,6 @@ InterruptManager::InterruptManager(uint16_t hardwareInterruptOffset, system::Glo { this->threadManager = threadManager; this->hardwareInterruptOffset = hardwareInterruptOffset; - this->errorMessages = handler; uint32_t CodeSegment = globalDescriptorTable->CodeSegmentSelector(); //Set all the entry's to Ignore so that the ones we don't specify aren't run as there won't be a handler for these and therefore would have caused a protection error @@ -185,7 +190,7 @@ InterruptManager::~InterruptManager() */ void InterruptManager::Activate() { - if(ActiveInterruptManager != 0){ //There shouldn't be another interrupt manager, but for saftey delete anyother ones. This is becuase the processor only has 1 IDT + if(ActiveInterruptManager != 0){ //There shouldn't be another interrupt manager, but for safety delete another ones. This is because the processor only has 1 IDT ActiveInterruptManager->Deactivate(); } @@ -218,7 +223,7 @@ uint32_t InterruptManager::HandleInterrupt(uint8_t interrupt, uint32_t esp) { if(ActiveInterruptManager != 0){ - return ActiveInterruptManager->DoHandleInterrupt(interrupt, esp); //Handle the interrupt in OOP mode instead of Static + return ActiveInterruptManager->DoHandleInterruptRequest(interrupt, esp); //Handle the interrupt in OOP mode instead of Static } return esp; @@ -231,11 +236,12 @@ uint32_t InterruptManager::HandleInterrupt(uint8_t interrupt, uint32_t esp) * @param esp The stack pointer * @return The stack pointer */ -uint32_t InterruptManager::DoHandleInterrupt(uint8_t interrupt, uint32_t esp) +uint32_t InterruptManager::DoHandleInterruptRequest(uint8_t interrupt, uint32_t esp) { if(interruptHandlers[interrupt] != 0){ //If it has a handler for it - esp = interruptHandlers[interrupt]->HandleInterrupt(esp); //Run the handler - }else{ + interruptHandlers[interrupt]->HandleInterrupt(); //Run the handler + } + else{ if(interrupt != 0x20){ //If not the timer interrupt switch (interrupt) { @@ -378,8 +384,6 @@ uint32_t InterruptManager::DoHandleInterrupt(uint8_t interrupt, uint32_t esp) break; } - - } } @@ -389,22 +393,21 @@ uint32_t InterruptManager::DoHandleInterrupt(uint8_t interrupt, uint32_t esp) if(interrupt == hardwareInterruptOffset) { esp = (uint32_t)threadManager->Schedule((CPUState_Thread*)esp); - //printf("task switched", true); - } - if(hardwareInterruptOffset <= interrupt && interrupt < hardwareInterruptOffset+16) //Only if it is hardware (keep in mind that around line: 90, the hardware interrupt was remapped at 0x20) the hardware ranges from 0x20 to 0x30 + // Acknowledge the interrupt (if it is a hardware interrupt) + if(hardwareInterruptOffset <= interrupt && interrupt < hardwareInterruptOffset+16) { //Send Answer to tell PIC the interrupt was received - programmableInterruptControllerMasterCommandPort.Write(0x20); //0x20 is the answer the PIC wants for master - if(0x28 <= interrupt) //Answer the master always, but don't answer the slave unless the slave called the interrupt - programmableInterruptControllerSlaveCommandPort.Write(0x20); //0x20 is the answer the PIC wants for slave + programmableInterruptControllerMasterCommandPort.Write(0x20); + + //Answer the master always, but don't answer the slave unless the slave called the interrupt + if(0x28 <= interrupt) + programmableInterruptControllerSlaveCommandPort.Write(0x20); } CPUState_Thread cpuStateThread = *((CPUState_Thread*)esp); - - return esp; } @@ -416,3 +419,11 @@ uint32_t InterruptManager::DoHandleInterrupt(uint8_t interrupt, uint32_t esp) uint16_t InterruptManager::HardwareInterruptOffset() { return hardwareInterruptOffset; } + +void InterruptManager::setInterruptHandler(common::uint8_t interrupt, InterruptHandler *handler) { + interruptHandlers[interrupt] = handler; +} + +void InterruptManager::removeInterruptHandler(common::uint8_t interrupt) { + interruptHandlers[interrupt] = 0; +} diff --git a/kernel/src/hardwarecommunication/serial.cpp b/kernel/src/hardwarecommunication/serial.cpp index 64761a4b..b8369d25 100644 --- a/kernel/src/hardwarecommunication/serial.cpp +++ b/kernel/src/hardwarecommunication/serial.cpp @@ -240,9 +240,6 @@ void serial::Write(char* str, int type) { * @param esp The stack pointer * @return The stack pointer (where the processor will go when the interrupt is finished) (always will be what is passed in) */ -uint32_t serial::HandleInterrupt(common::uint32_t esp) { +void serial::HandleInterrupt() { //Handle reading from the serial port - - - return esp; } diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 50dc6eb4..66da4886 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,4 +1,4 @@ -int buildCount = 398; +int buildCount = 421; // This is the build counter, it is incremented every time the build script is run. Started 27/09/2023, Commit 129 //Common diff --git a/kernel/src/system/syscalls.cpp b/kernel/src/system/syscalls.cpp index b22a3224..7c0fd025 100644 --- a/kernel/src/system/syscalls.cpp +++ b/kernel/src/system/syscalls.cpp @@ -25,23 +25,10 @@ SyscallHandler::~SyscallHandler() * * @param esp The stack frame */ -uint32_t SyscallHandler::HandleInterrupt(uint32_t esp) +void SyscallHandler::HandleInterrupt() { - CPUState_Thread* cpu = (CPUState_Thread*)esp; - - - switch(cpu->eax) - { - case 4: //Write - //printf((char*)cpu->ebx); - break; - - default: - break; - } - - - return (uint32_t)cpu; + // TODO: Get the CPU state from the stack frame + return; } ///__Syscall__///