diff options
| author | amlal <amlal@el-mahrouss-logic.com> | 2024-03-23 10:22:31 +0100 |
|---|---|---|
| committer | amlal <amlal@el-mahrouss-logic.com> | 2024-03-23 10:22:31 +0100 |
| commit | 57834666259af373d19b560108ed7bb322b68adb (patch) | |
| tree | fdf1d4fdced47b0ebf8c90d8f8d9f54e852ad75f | |
| parent | 77bf7cab39fef40797e8832aaef91abbdf0098f5 (diff) | |
Kernel: PS2 mouse builtin works now.
- But doesnt draw at the exact position, we need to fix that.
Signed-off-by: amlal <amlal@el-mahrouss-logic.com>
| -rw-r--r-- | Private/ArchKit/ArchKit.hpp | 2 | ||||
| -rw-r--r-- | Private/Builtins/PS2/PS2MouseInterface.hxx | 17 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalDescriptorLoader.cpp | 34 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalInterruptRouting.asm | 43 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMain.cxx | 11 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/HalKernelMouse.cxx | 43 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Processor.hpp | 3 | ||||
| -rw-r--r-- | Private/KernelKit/DebugOutput.hpp | 36 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 2 | ||||
| -rw-r--r-- | Private/Source/KernelCheck.cxx | 9 | ||||
| -rw-r--r-- | Private/Source/KernelHeap.cxx | 4 |
11 files changed, 116 insertions, 88 deletions
diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp index 7f5624c1..e9e09577 100644 --- a/Private/ArchKit/ArchKit.hpp +++ b/Private/ArchKit/ArchKit.hpp @@ -20,8 +20,6 @@ #error Unknown architecture #endif -#define kVirtualAddressStartOffset 0x100 - namespace HCore { constexpr static inline SSizeT rt_hash_seed(const char *seed, int mul) { SSizeT hash = 0; diff --git a/Private/Builtins/PS2/PS2MouseInterface.hxx b/Private/Builtins/PS2/PS2MouseInterface.hxx index f37d294e..beb98665 100644 --- a/Private/Builtins/PS2/PS2MouseInterface.hxx +++ b/Private/Builtins/PS2/PS2MouseInterface.hxx @@ -28,7 +28,9 @@ class PS2MouseInterface final { public: Void Init() noexcept { - HCore::kcout << "NewKernel.exe: Enabling PS/2 mouse...\r\n"; + HAL::rt_cli(); + + HCore::kcout << "HCoreKrnl.exe: Enabling PS/2 mouse...\r\n"; this->Write(0xFF); @@ -54,16 +56,20 @@ class PS2MouseInterface final { this->Write(0xF4); auto f4Dat = this->Read(); - HCore::kcout << "NewKernel.exe: PS/2 mouse is OK: " << hex_number(f6Dat); + HCore::kcout << "HCoreKrnl.exe: PS/2 mouse is OK: " << hex_number(f6Dat); HCore::kcout << ", " << hex_number(f4Dat) << end_line(); + + HAL::Out8(0x64, 0xAD); + + HAL::rt_sti(); } - private: + public: Bool WaitInput() noexcept { UInt64 timeout = 100000; while (timeout) { - if ((HAL::In8(0x64) & 0x1)) { + if ((HAL::In8(0x64) & 0x1) == 0x0) { HCore::kcout << "NewKernel.exe: Wait: OK\r\n"; return true; } @@ -94,11 +100,10 @@ class PS2MouseInterface final { } Void Write(UInt8 val) { - this->Wait(); HAL::Out8(0x64, 0xD4); this->Wait(); - HAL::Out8(0x60, val); + this->Wait(); } UInt8 Read() { diff --git a/Private/HALKit/AMD64/HalDescriptorLoader.cpp b/Private/HALKit/AMD64/HalDescriptorLoader.cpp index a5f445e5..df6caf7a 100644 --- a/Private/HALKit/AMD64/HalDescriptorLoader.cpp +++ b/Private/HALKit/AMD64/HalDescriptorLoader.cpp @@ -15,35 +15,21 @@ STATIC ::HCore::Detail::AMD64::InterruptDescriptorAMD64 kInterruptVectorTable[kKernelIdtSize]; STATIC Void RemapPIC(Void) noexcept { - UInt8 a1, a2; - - a1 = HAL::In8(0x21); // save masks - a2 = HAL::In8(0xA1); - // Remap PIC. HAL::Out8(0x20, 0x10 | 0x01); - HAL::rt_wait_400ns(); HAL::Out8(0xA0, 0x10 | 0x01); - HAL::rt_wait_400ns(); - - HAL::Out8(0x21, 0x28); - HAL::rt_wait_400ns(); - HAL::Out8(0xA1, 0x30); - HAL::rt_wait_400ns(); + HAL::Out8(0x21, 32); + HAL::Out8(0xA1, 40); - HAL::Out8(0x21, 0x04); - HAL::rt_wait_400ns(); - HAL::Out8(0xA1, 0x02); + HAL::Out8(0x21, 4); + HAL::Out8(0xA1, 2); - HAL::rt_wait_400ns(); HAL::Out8(0x21, 0x01); - HAL::rt_wait_400ns(); HAL::Out8(0xA1, 0x01); - HAL::rt_wait_400ns(); - HAL::Out8(0x21, a1); - HAL::rt_wait_400ns(); - HAL::Out8(0xA1, a2); + + HAL::Out8(0x21, 0x00); + HAL::Out8(0xA1, 0x00); } } // namespace Detail @@ -64,7 +50,9 @@ Void IDTLoader::Load(Register64 &idt) { MUST_PASS(baseIdt); - for (UInt16 i = 0; i < kKernelIdtSize; i++) { + Detail::RemapPIC(); + + for (UInt16 i = 0; i < kKernelIdtSize; ++i) { MUST_PASS(baseIdt[i]); Detail::kInterruptVectorTable[i].Selector = kGdtCodeSelector; @@ -82,8 +70,6 @@ Void IDTLoader::Load(Register64 &idt) { (kKernelIdtSize - 1); hal_load_idt(Detail::kRegIdt); - - Detail::RemapPIC(); } void GDTLoader::Load(Ref<RegisterGDT> &gdt) { GDTLoader::Load(gdt.Leak()); } diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm index 384f775c..05f14e36 100644 --- a/Private/HALKit/AMD64/HalInterruptRouting.asm +++ b/Private/HALKit/AMD64/HalInterruptRouting.asm @@ -104,21 +104,17 @@ IntNormal 29 IntExp 30 IntNormal 31 -IntNormal 32 - -__HCR_INT_33: - cli +;; Mapped according to PIC remap. +__HCR_INT_32: push rax - mov rcx, kSystemCallLabel - call ke_io_print + call _hal_mouse_handler pop rax - - sti iretq +IntNormal 33 IntNormal 34 IntNormal 35 IntNormal 36 @@ -128,29 +124,30 @@ IntNormal 39 IntNormal 40 IntNormal 41 IntNormal 42 + IntNormal 43 -;; Mapped according to PIC remap. -__HCR_INT_44: +IntNormal 44 + +IntNormal 45 +IntNormal 46 +IntNormal 47 +IntNormal 48 +IntNormal 49 + +__HCR_INT_50: cli push rax - call _hal_mouse_handler + mov rcx, kSystemCallLabel + call ke_io_print pop rax sti iretq - -IntNormal 45 - -IntNormal 46 -IntNormal 47 -IntNormal 48 -IntNormal 49 -IntNormal 50 IntNormal 51 IntNormal 52 IntNormal 53 @@ -171,10 +168,10 @@ IntNormal 60 ;; this one is doing a POST for us. ;; testing interrupts. _ke_power_on_self_test: - int 0x21 - int 0x21 - int 0x21 - int 0x21 + int 50 + int 50 + int 50 + int 50 ret diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx index c2b6dfbb..e78be6ec 100644 --- a/Private/HALKit/AMD64/HalKernelMain.cxx +++ b/Private/HALKit/AMD64/HalKernelMain.cxx @@ -8,19 +8,20 @@ #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> +#include <KernelKit/KernelHeap.hpp> #include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessScheduler.hpp> #include <KernelKit/Rsrc/Splash.rsrc> #include <KernelKit/Rsrc/Util.hxx> -#include <NewKit/Json.hpp> -#include <KernelKit/KernelHeap.hpp> #include <KernelKit/UserHeap.hpp> +#include <NewKit/Json.hpp> ///! @brief Disk contains HCore files. #define kInstalledMedia 0xDD -EXTERN_C HCore::Void _hal_draw_mouse(); EXTERN_C HCore::Void _hal_init_mouse(); +EXTERN_C HCore::Void _hal_draw_mouse(); +EXTERN_C HCore::Void _hal_mouse_handler(); EXTERN_C HCore::VoidPtr kInterruptVectorTable[]; @@ -30,7 +31,9 @@ EXTERN_C void RuntimeMain( /// Setup kernel globals. kKernelVirtualSize = HandoverHeader->f_VirtualSize; - kKernelVirtualStart = (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; diff --git a/Private/HALKit/AMD64/HalKernelMouse.cxx b/Private/HALKit/AMD64/HalKernelMouse.cxx index b71c00ed..cafebc9e 100644 --- a/Private/HALKit/AMD64/HalKernelMouse.cxx +++ b/Private/HALKit/AMD64/HalKernelMouse.cxx @@ -10,6 +10,12 @@ #include <KernelKit/Rsrc/Util.hxx> #include <NewKit/Defines.hpp> +// forward decl. +EXTERN_C HCore::Void _hal_draw_mouse(); +EXTERN_C HCore::Void _hal_init_mouse(); + +EXTERN_C void ke_io_print(const char* bytes); + STATIC HCore::Int32 kPrevX = 0; STATIC HCore::Int32 kPrevY = 0; STATIC HCore::Int32 kX = 0; @@ -30,10 +36,8 @@ STATIC HCore::Boolean kMousePacketReady = false; using namespace HCore; -/// @brief Interrupt handler for the mouse. -/// @return -EXTERN_C Void _hal_mouse_handler() { - HCore::UInt8 data = HCore::HAL::In8(0x60); +Void hal_handle_mouse() { + HCore::UInt8 data = HAL::In8(0x60); switch (kMouseCycle) { case 0: { @@ -57,7 +61,7 @@ EXTERN_C Void _hal_mouse_handler() { if (kMousePacketReady) break; kMousePacket[2] = data; - ++kMouseCycle; + kMousePacketReady = true; kMouseCycle = 0; @@ -69,12 +73,14 @@ EXTERN_C Void _hal_mouse_handler() { // Notify PIC controller that we're done with it's interrupt. - HCore::HAL::Out8(0x20, 0x20); HCore::HAL::Out8(0xA0, 0x20); + HCore::HAL::Out8(0x20, 0x20); } +/// @brief Interrupt handler for the mouse. +EXTERN_C Void _hal_mouse_handler() { hal_handle_mouse(); } + /// @brief Draws the kernel's mouse. -/// @return void EXTERN_C Void _hal_draw_mouse() { if (!kMousePacketReady) return; @@ -86,23 +92,16 @@ EXTERN_C Void _hal_draw_mouse() { 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 (xOvf) { - kX += xNeg ? 255 : -255; - } - - if (yOvf) { - kY += yNeg ? 255 : -255; - } + 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; } if (kX > kHandoverHeader->f_GOP.f_Width) { + kX = 0; return; } @@ -112,11 +111,13 @@ EXTERN_C Void _hal_draw_mouse() { KeDrawRsrc(Pointer, POINTER_HEIGHT, POINTER_WIDTH, kX, kY); KeClearRsrc(); - kPrevX = kMousePacket[1]; - kPrevY = kMousePacket[2]; + kPrevX = kX; + kPrevY = kY; kMousePacketReady = false; } /// @brief Init kernel mouse. -EXTERN_C Void _hal_init_mouse() { kMousePS2.Init(); }
\ No newline at end of file +EXTERN_C Void _hal_init_mouse() { + kMousePS2.Init(); +}
\ No newline at end of file diff --git a/Private/HALKit/AMD64/Processor.hpp b/Private/HALKit/AMD64/Processor.hpp index 2c4a1c67..bbda5edc 100644 --- a/Private/HALKit/AMD64/Processor.hpp +++ b/Private/HALKit/AMD64/Processor.hpp @@ -30,6 +30,7 @@ #define kTrapGate 0xEF #define kTaskGate 0b10001100 #define kGdtCodeSelector 0x08 +#define kVirtualAddressStartOffset 0x100 namespace HCore { namespace Detail::AMD64 { @@ -182,4 +183,4 @@ EXTERN_C void hal_load_gdt(HCore::HAL::RegisterGDT ptr); /// @brief Maximum size of the IDT. #define kKernelIdtSize 0x100 -#define kKernelInterruptId 0x21 +#define kKernelInterruptId 50 diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp index 0eb59da2..457bc9d1 100644 --- a/Private/KernelKit/DebugOutput.hpp +++ b/Private/KernelKit/DebugOutput.hpp @@ -45,7 +45,7 @@ class TerminalDevice final : public DeviceInterface<const Char *> { inline TerminalDevice end_line() { TerminalDevice selfTerm = TerminalDevice::Shared(); - selfTerm << "\n"; + selfTerm << "\r\n"; return selfTerm; } @@ -56,6 +56,30 @@ inline TerminalDevice carriage_return() { } namespace Detail { +inline TerminalDevice _write_number(const Long &x, TerminalDevice& term) { + int y = x / 10; + int h = x % 10; + + if (y) _write_number(y, term); + + /* fail if the number is not base-10 */ + if (h > 9) { + _write_number('?', term); + return term; + } + + if (y < 0) y = -y; + + const char NUMBERS[11] = "0123456789"; + + Char buf[2]; + buf[0] = NUMBERS[h]; + buf[1] = 0; + + term << buf; + return term; +} + inline TerminalDevice _write_number_hex(const Long &x, TerminalDevice& term) { int y = x / 16; int h = x % 16; @@ -70,7 +94,7 @@ inline TerminalDevice _write_number_hex(const Long &x, TerminalDevice& term) { if (y < 0) y = -y; - const char NUMBERS[17] = "0123456789ABCDEF"; + const char NUMBERS[17] = "0123456789"; Char buf[2]; buf[0] = NUMBERS[h]; @@ -90,6 +114,14 @@ inline TerminalDevice hex_number(const Long &x) { return selfTerm; } +inline TerminalDevice number(const Long &x) { + TerminalDevice selfTerm = TerminalDevice::Shared(); + + Detail::_write_number(x, selfTerm); + + return selfTerm; +} + inline TerminalDevice get_console_in(Char* buf) { TerminalDevice selfTerm = TerminalDevice::Shared(); selfTerm >> buf; diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index e4ed6cbe..0bded801 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -17,7 +17,7 @@ EMU=qemu-system-x86_64w.exe endif IMG=epm.img -EMU_FLAGS=-net none -smp 2 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -serial stdio +EMU_FLAGS=-net none -smp 2 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int LD_FLAGS=-e efi_main --subsystem=10 OBJ=$(wildcard *.o) $(wildcard ../../Objects/*.obj) $(wildcard HEL/AMD64/*.obj) diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx index 40833a87..bf7ac939 100644 --- a/Private/Source/KernelCheck.cxx +++ b/Private/Source/KernelCheck.cxx @@ -69,6 +69,11 @@ void ke_stop(const HCore::Int &id) { kcout << "*** WHAT: CATASROPHIC FAILURE! *** \r\n"; break; } + case RUNTIME_CHECK_FAILED: { + kcout << "*** CAUSE: RUNTIME_CHECK_FAILED *** \r\n"; + kcout << "*** WHAT: ASSERTION FAILED! *** \r\n"; + break; + } default: { kcout << "*** CAUSE: RUNTIME_CHECK_GENERIC *** \r\n"; break; @@ -86,8 +91,8 @@ void ke_stop(const HCore::Int &id) { void ke_runtime_check(bool expr, const char *file, const char *line) { if (!expr) { #ifdef __DEBUG__ - kcout << "Krnl: File: " << file << "\n"; - kcout << "Krnl: Line: " << line << "\n"; + kcout << "NewKernel: File: " << file << "\n"; + kcout << "NewKernel: Line: " << line << "\n"; #endif // __DEBUG__ diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index f5cb01da..03e5f250 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -66,7 +66,7 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) { if (kHeapCount < 1) return -kErrorInternal; Detail::HeapInformationBlockPtr virtualAddress = - reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr - + reinterpret_cast<Detail::HeapInformationBlockPtr>((UIntPtr)ptr - sizeof(Detail::HeapInformationBlock)); if (virtualAddress && virtualAddress->hMagic == kHeapMagic) { @@ -98,7 +98,7 @@ Boolean ke_is_valid_ptr(VoidPtr ptr) { if (ptr) { Detail::HeapInformationBlockPtr virtualAddress = - reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr - + reinterpret_cast<Detail::HeapInformationBlockPtr>((UIntPtr)ptr - sizeof(Detail::HeapInformationBlock)); if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) { |
