diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-23 21:40:37 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-23 21:40:37 +0100 |
| commit | 09383c793fe953da6441902b4f66b1382df46738 (patch) | |
| tree | 9c4e4040ad28818c6f13c96375221609cfc773a5 /Private/HALKit | |
| parent | d9477b8a80ee0dc9a6d05c0353aa989ceaedae8a (diff) | |
Kernel: See below.
Fix BUG inside ATA driver: Due to bad cast on lba select.
Add ToolBox APIs for kernel GUI.
Userland: See below.
Worked a bit on System.Core, just wrapped Thread.hxx into the System namespace.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/HALKit')
| -rw-r--r-- | Private/HALKit/AMD64/HalInterruptRouting.asm | 21 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMain.cxx | 33 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMouse.cxx | 144 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Processor.hpp | 2 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/ATA.cxx | 20 |
5 files changed, 118 insertions, 102 deletions
diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm index 06e40161..c00ce375 100644 --- a/Private/HALKit/AMD64/HalInterruptRouting.asm +++ b/Private/HALKit/AMD64/HalInterruptRouting.asm @@ -105,16 +105,10 @@ IntExp 30 IntNormal 31 -;; Mapped according to PIC remap. -__HCR_INT_32: - push rax - - call _hal_handle_mouse - - pop rax - iretq +IntNormal 32 IntNormal 33 + IntNormal 34 IntNormal 35 IntNormal 36 @@ -124,11 +118,8 @@ IntNormal 39 IntNormal 40 IntNormal 41 IntNormal 42 - IntNormal 43 - IntNormal 44 - IntNormal 45 IntNormal 46 IntNormal 47 @@ -168,10 +159,10 @@ IntNormal 60 ;; this one is doing a POST for us. ;; testing interrupts. _ke_power_on_self_test: - int 50 - int 50 - int 50 - int 50 + int 0x32 + int 0x32 + int 0x32 + int 0x32 ret diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index 5ceb57bd..90a09556 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -5,6 +5,7 @@ ------------------------------------------- */ #include <ArchKit/ArchKit.hpp> +#include <Builtins/Toolbox/Toolbox.hxx> #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> @@ -19,10 +20,6 @@ ///! @brief Disk contains HCore files. #define kInstalledMedia 0xDD -EXTERN_C HCore::Void _hal_init_mouse(); -EXTERN_C HCore::Void _hal_draw_mouse(); -EXTERN_C HCore::Void _hal_handle_mouse(); - EXTERN_C HCore::VoidPtr kInterruptVectorTable[]; EXTERN_C void RuntimeMain( @@ -31,9 +28,9 @@ EXTERN_C void RuntimeMain( /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; - kKernelVirtualStart = - reinterpret_cast<HCore::VoidPtr>(reinterpret_cast<HCore::UIntPtr>( - HandoverHeader->f_VirtualStart) + kVirtualAddressStartOffset); + kKernelVirtualStart = reinterpret_cast<HCore::VoidPtr>( + reinterpret_cast<HCore::UIntPtr>(HandoverHeader->f_VirtualStart) + + kVirtualAddressStartOffset); kKernelPhysicalSize = HandoverHeader->f_PhysicalSize; kKernelPhysicalStart = HandoverHeader->f_PhysicalStart; @@ -66,14 +63,6 @@ EXTERN_C void RuntimeMain( HCore::HAL::IDTLoader idt; idt.Load(idtBase); - KeInitRsrc(); - - KeDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH, - ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2), - ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2)); - - KeClearRsrc(); - /// START POST HCore::HAL::Detail::_ke_power_on_self_test(); @@ -86,14 +75,20 @@ EXTERN_C void RuntimeMain( /// We already have an install of HCore. if (HandoverHeader->f_Bootloader == kInstalledMedia) { - /// TODO: Parse system configuration. + ToolboxInitRsrc(); + + ToolboxDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH, + ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2), + ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2)); + + ToolboxClearRsrc(); } else { /// TODO: Install hcore on host. _hal_init_mouse(); - while (true) { - _hal_draw_mouse(); - } + ToolboxDrawZone(kClearClr, kHandoverHeader->f_GOP.f_Height, kHandoverHeader->f_GOP.f_Width, 0, 0); + + TOOLBOX_LOOP() { _hal_draw_mouse(); } } HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP); diff --git a/Private/HALKit/AMD64/HalKernelMouse.cxx b/Private/HALKit/AMD64/HalKernelMouse.cxx index 2033badc..61e79845 100644 --- a/Private/HALKit/AMD64/HalKernelMouse.cxx +++ b/Private/HALKit/AMD64/HalKernelMouse.cxx @@ -11,22 +11,21 @@ #include <NewKit/Defines.hpp> // forward decl. -EXTERN_C HCore::Void _hal_draw_mouse(); +EXTERN_C HCore::Boolean _hal_draw_mouse(); EXTERN_C HCore::Void _hal_init_mouse(); -STATIC HCore::Int32 kPrevX = 0; -STATIC HCore::Int32 kPrevY = 0; -STATIC HCore::Int32 kX = 0; -STATIC HCore::Int32 kY = 0; +STATIC HCore::Int32 kPrevX = 10; +STATIC HCore::Int32 kPrevY = 10; +STATIC HCore::Int32 kX = 10; +STATIC HCore::Int32 kY = 10; STATIC HCore::Int32 kMouseCycle = 0; STATIC HCore::PS2MouseInterface kMousePS2; -STATIC HCore::Int32 kMousePacket[4]; +STATIC HCore::Char kMousePacket[4] = {}; STATIC HCore::Boolean kMousePacketReady = false; -#define kPS2LeftButton 0b00000001 -#define kPS2MiddleButton 0b00000010 -#define kPS2RightButton 0b00000100 - +#define kPS2Leftbutton 0b00000001 +#define kPS2Middlebutton 0b00000010 +#define kPS2Rightbutton 0b00000100 #define kPS2XSign 0b00010000 #define kPS2YSign 0b00100000 #define kPS2XOverflow 0b01000000 @@ -38,84 +37,119 @@ Void hal_handle_mouse() { HCore::UInt8 data = HAL::In8(0x60); switch (kMouseCycle) { - case 0: { + case 0: if (kMousePacketReady) break; - if ((data & 0b00001000) == 0) break; - + if (data & 0b00001000 == 0) break; kMousePacket[0] = data; - ++kMouseCycle; - + kMouseCycle++; break; - } - case 1: { + case 1: if (kMousePacketReady) break; - kMousePacket[1] = data; - ++kMouseCycle; - + kMouseCycle++; break; - } - case 2: { + case 2: if (kMousePacketReady) break; - kMousePacket[2] = data; - kMousePacketReady = true; kMouseCycle = 0; - - break; - } - default: break; } // Notify PIC controller that we're done with it's interrupt. - HCore::HAL::Out8(0xA0, 0x20); HCore::HAL::Out8(0x20, 0x20); + HCore::HAL::Out8(0xA0, 0x20); } /// @brief Interrupt handler for the mouse. EXTERN_C Void _hal_handle_mouse() { hal_handle_mouse(); } -/// @brief Draws the kernel's mouse. -EXTERN_C Void _hal_draw_mouse() { - if (!kMousePacketReady) return; - - bool xNeg, yNeg, xOvf, yOvf; - - xNeg = (kMousePacket[0] & kPS2XSign); - yNeg = (kMousePacket[0] & kPS2YSign); +EXTERN_C Boolean _hal_left_button_pressed() { return kMousePacket[0] & kPS2Leftbutton; } +EXTERN_C Boolean _hal_right_button_pressed() { return kMousePacket[0] & kPS2Rightbutton; } +EXTERN_C Boolean _hal_middle_button_pressed() { return kMousePacket[0] & kPS2Middlebutton; } - xOvf = (kMousePacket[0] & kPS2XOverflow); - yOvf = (kMousePacket[0] & kPS2YOverflow); - - kX = !xNeg ? (256 + kMousePacket[1]) : (256 - (-kMousePacket[1])); - kY = !yNeg ? (256 + kMousePacket[2]) : (256 - (-kMousePacket[2])); - - if (kY > kHandoverHeader->f_GOP.f_Height) { - kY = 0; - return; +/// @brief Draws the kernel's mouse. +EXTERN_C Boolean _hal_draw_mouse() { + if (!kMousePacketReady) return false; + + bool xNegative, yNegative, xOverflow, yOverflow; + + if (kMousePacket[0] & kPS2XSign) { + xNegative = true; + } else + xNegative = false; + + if (kMousePacket[0] & kPS2YSign) { + yNegative = true; + } else + yNegative = false; + + if (kMousePacket[0] & kPS2XOverflow) { + xOverflow = true; + } else + xOverflow = false; + + if (kMousePacket[0] & kPS2YOverflow) { + yOverflow = true; + } else + yOverflow = false; + + if (!xNegative) { + kX += kMousePacket[1]; + if (xOverflow) { + kX += 255; + } + } else { + kMousePacket[1] = 256 - kMousePacket[1]; + kX -= kMousePacket[1]; + if (xOverflow) { + kX -= 255; + } } - if (kX > kHandoverHeader->f_GOP.f_Width) { - kX = 0; - return; + if (!yNegative) { + kY -= kMousePacket[2]; + if (yOverflow) { + kY -= 255; + } + } else { + kMousePacket[2] = 256 - kMousePacket[2]; + kY += kMousePacket[2]; + if (yOverflow) { + kY += 255; + } } - KeClearZone(POINTER_HEIGHT, POINTER_WIDTH, kPrevX, kPrevY); + if (kX < 0) kX = 0; + if (kX > kHandoverHeader->f_GOP.f_Width - 8) + kX = kHandoverHeader->f_GOP.f_Width - 8; + + if (kY < 0) kY = 0; + if (kY > kHandoverHeader->f_GOP.f_Height - 16) + kY = kHandoverHeader->f_GOP.f_Height - 16; + + ToolboxInitRsrc(); + ToolboxClearZone(POINTER_HEIGHT, POINTER_WIDTH, kPrevX, kPrevY); + ToolboxDrawRsrc(Pointer, POINTER_HEIGHT, POINTER_WIDTH, kX, kY); + ToolboxClearRsrc(); - KeInitRsrc(); - KeDrawRsrc(Pointer, POINTER_HEIGHT, POINTER_WIDTH, kX, kY); - KeClearRsrc(); + HCore::kcout << number(kX); + HCore::kcout << "\r\n"; + HCore::kcout << number(kY); + HCore::kcout << "\r\n"; kPrevX = kX; kPrevY = kY; kMousePacketReady = false; + return true; } /// @brief Init kernel mouse. -EXTERN_C Void _hal_init_mouse() { - kMousePS2.Init(); +EXTERN_C Void _hal_init_mouse() { + kMousePS2.Init(); + + HAL::Out8(0x21, 0b11111001); + HAL::Out8(0xA1, 0b11101111); }
\ No newline at end of file diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index bbda5edc..4e104b40 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -183,4 +183,4 @@ EXTERN_C void hal_load_gdt(HCore::HAL::RegisterGDT ptr); /// @brief Maximum size of the IDT. #define kKernelIdtSize 0x100 -#define kKernelInterruptId 50 +#define kKernelInterruptId 0x32 diff --git a/Private/HALKit/AMD64/Storage/ATA.cxx b/Private/HALKit/AMD64/Storage/ATA.cxx index 854b166e..699876b7 100644 --- a/Private/HALKit/AMD64/Storage/ATA.cxx +++ b/Private/HALKit/AMD64/Storage/ATA.cxx @@ -18,8 +18,6 @@ #include <Builtins/ATA/Defines.hxx> #include <ArchKit/ArchKit.hpp> -#ifdef __KERNEL__ - using namespace HCore; using namespace HCore::HAL; @@ -130,16 +128,16 @@ ATAInit_Retry: return true; } -Void drv_ata_read(UInt32 Lba, UInt16 IO, UInt8 Master, Char* Buf, +Void drv_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { UInt8 Command = (!Master ? 0xE0 : 0xF0); Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF)); Out8(IO + ATA_REG_SEC_COUNT0, SectorSz); - Out8(IO + ATA_REG_LBA0, (UInt8)(Lba)); - Out8(IO + ATA_REG_LBA1, (UInt8)(Lba) >> 8); - Out8(IO + ATA_REG_LBA2, (UInt8)(Lba) >> 16); + Out8(IO + ATA_REG_LBA0, (Lba)); + Out8(IO + ATA_REG_LBA1, (Lba) >> 8); + Out8(IO + ATA_REG_LBA2, (Lba) >> 16); Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); @@ -152,16 +150,16 @@ Void drv_ata_read(UInt32 Lba, UInt16 IO, UInt8 Master, Char* Buf, } } -Void drv_ata_write(UInt32 Lba, UInt16 IO, UInt8 Master, Char* Buf, +Void drv_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { UInt8 Command = (!Master ? 0xE0 : 0xF0); Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF)); Out8(IO + ATA_REG_SEC_COUNT0, SectorSz); - Out8(IO + ATA_REG_LBA0, (UInt8)(Lba)); - Out8(IO + ATA_REG_LBA1, (UInt8)(Lba) >> 8); - Out8(IO + ATA_REG_LBA2, (UInt8)(Lba) >> 16); + Out8(IO + ATA_REG_LBA0, (Lba)); + Out8(IO + ATA_REG_LBA1, (Lba) >> 8); + Out8(IO + ATA_REG_LBA2, (Lba) >> 16); Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); @@ -175,5 +173,3 @@ Void drv_ata_write(UInt32 Lba, UInt16 IO, UInt8 Master, Char* Buf, /// @check is ATA detected? Boolean drv_ata_detected(Void) { return kATADetected; } - -#endif // ifdef __KERNEL__ |
