From cdbdc1a822af83413f259187f33b955332a2149c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 10 Apr 2024 04:39:48 +0300 Subject: [PATCH] Kernel: Remove lai as a dependecy I don't think lai is needed anymore, since my own AML interpreter can do ACPI poweroff which was all that lai was used for. --- .gitmodules | 4 - README.md | 2 +- kernel/CMakeLists.txt | 8 -- kernel/include/kernel/InterruptController.h | 2 - kernel/kernel/ACPI/ACPI.cpp | 8 -- kernel/kernel/InterruptController.cpp | 10 -- kernel/kernel/Process.cpp | 17 +-- kernel/kernel/lai_host.cpp | 149 -------------------- kernel/lai | 1 - 9 files changed, 4 insertions(+), 197 deletions(-) delete mode 100644 kernel/kernel/lai_host.cpp delete mode 160000 kernel/lai diff --git a/.gitmodules b/.gitmodules index 30d88028eb..e69de29bb2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "kernel/lai"] - path = kernel/lai - url = https://github.com/managarm/lai.git - ignore = untracked diff --git a/README.md b/README.md index 7b07d8f675..4eb1c07fb9 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ This is my hobby operating system written in C++. Currently supports x86\_64 and - [x] Linear framebuffer (VESA and GOP) - [x] Network stack - [x] ELF executable loading +- [x] AML interpreter (partial) - [ ] ELF dynamic linking - [ ] Graphical desktop -- [ ] AML interpreter (currenly using [lai](https://github.com/managarm/lai)) #### Drivers - [x] NVMe disks diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 61666bbbdb..f0c14178d2 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -119,13 +119,6 @@ if("${BANAN_ARCH}" STREQUAL "x86_64") arch/x86_64/Syscall.S arch/x86_64/Thread.S ) - file(GLOB_RECURSE LAI_SOURCES - lai/*.c - ) - set(LAI_SOURCES - ${LAI_SOURCES} - kernel/lai_host.cpp - ) elseif("${BANAN_ARCH}" STREQUAL "i686") set(KERNEL_SOURCES ${KERNEL_SOURCES} @@ -197,7 +190,6 @@ set_source_files_properties(${LAI_SOURCES} PROPERTIES COMPILE_FLAGS -Wno-stack-u add_custom_target(kernel-headers COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/ - COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/lai/include/ ${BANAN_INCLUDE}/ DEPENDS sysroot ) diff --git a/kernel/include/kernel/InterruptController.h b/kernel/include/kernel/InterruptController.h index b430e9837f..47a53f84f6 100644 --- a/kernel/include/kernel/InterruptController.h +++ b/kernel/include/kernel/InterruptController.h @@ -30,8 +30,6 @@ namespace Kernel bool is_using_apic() const { return m_using_apic; } - void enter_acpi_mode(); - private: bool m_using_apic { false }; }; diff --git a/kernel/kernel/ACPI/ACPI.cpp b/kernel/kernel/ACPI/ACPI.cpp index 5ef6d6fce9..2d8cee63cb 100644 --- a/kernel/kernel/ACPI/ACPI.cpp +++ b/kernel/kernel/ACPI/ACPI.cpp @@ -10,8 +10,6 @@ #include #include -#include - #define RSPD_SIZE 20 #define RSPDv2_SIZE 36 @@ -42,9 +40,6 @@ namespace Kernel::ACPI ASSERT(dsdt); s_instance->m_namespace = AML::initialize_namespace(*dsdt); -#if ARCH(x86_64) - lai_create_namespace(); -#endif return {}; } @@ -106,9 +101,6 @@ namespace Kernel::ACPI const RSDP* rsdp = locate_rsdp(); if (rsdp == nullptr) return BAN::Error::from_error_code(ErrorCode::ACPI_NoRootSDT); -#if ARCH(x86_64) - lai_set_acpi_revision(rsdp->revision); -#endif uint32_t root_entry_count = 0; diff --git a/kernel/kernel/InterruptController.cpp b/kernel/kernel/InterruptController.cpp index 5aa8e19d17..b297a604b2 100644 --- a/kernel/kernel/InterruptController.cpp +++ b/kernel/kernel/InterruptController.cpp @@ -3,8 +3,6 @@ #include #include -#include - namespace Kernel { @@ -45,12 +43,4 @@ namespace Kernel return s_instance; } - void InterruptController::enter_acpi_mode() - { -#if ARCH(x86_64) - if (lai_enable_acpi(m_using_apic ? 1 : 0) != 0) -#endif - dwarnln("could not enter acpi mode"); - } - } diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 74bd73e489..c260b949a1 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -17,8 +18,6 @@ #include -#include - #include #include #include @@ -1191,11 +1190,7 @@ namespace Kernel [[noreturn]] static void reset_system() { -#if ARCH(x86_64) - lai_acpi_reset(); -#endif - - // acpi reset did not work + // TODO: ACPI reset dwarnln("Could not reset with ACPI, crashing the cpu"); @@ -1215,13 +1210,7 @@ namespace Kernel if (command == POWEROFF_REBOOT) reset_system(); -#if ARCH(x86_64) - auto error = lai_enter_sleep(5); - // If we reach here, there was an error - dprintln("{}", lai_api_error_to_string(error)); -#else - dprintln("poweroff available only on x86_64"); -#endif + ACPI::ACPI::get().poweroff(); return BAN::Error::from_errno(EUNKNOWN); } diff --git a/kernel/kernel/lai_host.cpp b/kernel/kernel/lai_host.cpp deleted file mode 100644 index 0390e97ed9..0000000000 --- a/kernel/kernel/lai_host.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include - -using namespace Kernel; - -void* laihost_malloc(size_t size) -{ - return kmalloc(size); -} - -void* laihost_realloc(void* ptr, size_t newsize, size_t oldsize) -{ - if (ptr == nullptr) - return laihost_malloc(newsize); - - void* new_ptr = laihost_malloc(newsize); - if (new_ptr == nullptr) - return nullptr; - - memcpy(new_ptr, ptr, BAN::Math::min(newsize, oldsize)); - kfree(ptr); - - return new_ptr; -} - -void laihost_free(void* ptr, size_t) -{ - kfree(ptr); -} - -void laihost_log(int level, const char* msg) -{ - if (level == LAI_DEBUG_LOG) - dprintln(msg); - else if (level == LAI_WARN_LOG) - dwarnln(msg); - else - ASSERT_NOT_REACHED(); -} - -void laihost_panic(const char* msg) -{ - Kernel::panic(msg); -} - -void* laihost_scan(const char* sig, size_t index) -{ - return (void*)ACPI::ACPI::get().get_header(sig, index); -} - -void* laihost_map(size_t address, size_t count) -{ - size_t needed_pages = range_page_count(address, count); - vaddr_t vaddr = PageTable::kernel().reserve_free_contiguous_pages(needed_pages, KERNEL_OFFSET); - ASSERT(vaddr); - - PageTable::kernel().map_range_at(address & PAGE_ADDR_MASK, vaddr, needed_pages * PAGE_SIZE, PageTable::Flags::ReadWrite | PageTable::Flags::Present); - - return (void*)(vaddr + (address % PAGE_SIZE)); -} - -void laihost_unmap(void* ptr, size_t count) -{ - PageTable::kernel().unmap_range((vaddr_t)ptr, count); -} - -void laihost_outb(uint16_t port, uint8_t val) -{ - IO::outb(port, val); -} - -void laihost_outw(uint16_t port, uint16_t val) -{ - IO::outw(port, val); -} - -void laihost_outd(uint16_t port, uint32_t val) -{ - IO::outl(port, val); -} - -uint8_t laihost_inb(uint16_t port) -{ - return IO::inb(port); -} - -uint16_t laihost_inw(uint16_t port) -{ - return IO::inw(port); -} - -uint32_t laihost_ind(uint16_t port) -{ - return IO::inl(port); -} - -void laihost_pci_writeb(uint16_t seg, uint8_t bus, uint8_t slot, uint8_t fun, uint16_t offset, uint8_t val) -{ - ASSERT(seg == 0); - PCI::PCIManager::write_config_byte(bus, slot, fun, offset, val); -} - -void laihost_pci_writew(uint16_t seg, uint8_t bus, uint8_t slot, uint8_t fun, uint16_t offset, uint16_t val) -{ - ASSERT(seg == 0); - PCI::PCIManager::write_config_word(bus, slot, fun, offset, val); -} - -void laihost_pci_writed(uint16_t seg, uint8_t bus, uint8_t slot, uint8_t fun, uint16_t offset, uint32_t val) -{ - ASSERT(seg == 0); - PCI::PCIManager::write_config_dword(bus, slot, fun, offset, val); -} - -uint8_t laihost_pci_readb(uint16_t seg, uint8_t bus, uint8_t slot, uint8_t fun, uint16_t offset) -{ - ASSERT(seg == 0); - return PCI::PCIManager::read_config_byte(bus, slot, fun, offset); -} - -uint16_t laihost_pci_readw(uint16_t seg, uint8_t bus, uint8_t slot, uint8_t fun, uint16_t offset) -{ - ASSERT(seg == 0); - return PCI::PCIManager::read_config_word(bus, slot, fun, offset); - -} - -uint32_t laihost_pci_readd(uint16_t seg, uint8_t bus, uint8_t slot, uint8_t fun, uint16_t offset) -{ - ASSERT(seg == 0); - return PCI::PCIManager::read_config_dword(bus, slot, fun, offset); -} - -void laihost_sleep(uint64_t ms) -{ - SystemTimer::get().sleep(ms); -} - -uint64_t laihost_timer(void) -{ - auto time = SystemTimer::get().time_since_boot(); - return (1'000'000'000ull * time.tv_sec + time.tv_nsec) / 100; -} diff --git a/kernel/lai b/kernel/lai deleted file mode 160000 index a228465314..0000000000 --- a/kernel/lai +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a228465314ee3a542f62d4bdefeb8fbe2b48da41