From 2923a300b5248b588c9c44b4eb9cbc87d077de06 Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Sat, 17 Aug 2024 16:52:17 +0200 Subject: [PATCH] Write some ACPI stubs The ACPI driver is not required yet, but some stubs have already been added to the sources; only to test the driver initialization function of the driver manager. --- .../src-asm/drivers/acpi/driver.asm | 45 +++++++ .../src-asm/drivers/acpi/search-rsdp.asm | 49 ------- .../src-asm/drivers/acpi/utility.asm | 123 ++++++++++++++++++ 3 files changed, 168 insertions(+), 49 deletions(-) create mode 100644 i386/legacy-boot/src-asm/drivers/acpi/driver.asm delete mode 100644 i386/legacy-boot/src-asm/drivers/acpi/search-rsdp.asm create mode 100644 i386/legacy-boot/src-asm/drivers/acpi/utility.asm diff --git a/i386/legacy-boot/src-asm/drivers/acpi/driver.asm b/i386/legacy-boot/src-asm/drivers/acpi/driver.asm new file mode 100644 index 0000000..9c8f18b --- /dev/null +++ b/i386/legacy-boot/src-asm/drivers/acpi/driver.asm @@ -0,0 +1,45 @@ + +initialize_acpi_driver: + push dword esi + sub esp, 64 + mov esi, esp + + mov [esi + (64 - 4)], eax + mov [esi + (64 - 8)], ebx + mov [esi + (64 - 12)], ecx + mov [esi + (64 - 16)], edx + mov [esi + (64 - 20)], edi + +.get_rsdt: + push ebp + mov ebp, esp + call acpi_search_rsdt + mov esp, ebp + pop ebp + + push ebp + mov ebp, esp + push eax + call acpi_enumerate_tables + mov esp, ebp + pop ebp + + cmp eax, 0 + je .rsdp_not_found + +.success: + mov eax, [esi + (64 - 4)] + mov ebx, [esi + (64 - 8)] + mov ecx, [esi + (64 - 12)] + mov edx, [esi + (64 - 16)] + mov edi, [esi + (64 - 20)] + + add esp, 64 + pop dword esi + ret + +.rsdp_not_found: + ; todo(debug): Write warning + hlt + +%include "drivers/acpi/utility.asm" diff --git a/i386/legacy-boot/src-asm/drivers/acpi/search-rsdp.asm b/i386/legacy-boot/src-asm/drivers/acpi/search-rsdp.asm deleted file mode 100644 index 72c4ab4..0000000 --- a/i386/legacy-boot/src-asm/drivers/acpi/search-rsdp.asm +++ /dev/null @@ -1,49 +0,0 @@ - -MAIN_BIOS_AREA_START equ 0xe0000 - -; Arguments: -; -- None -- -acpi_search_rsdp: -.prolog: - push esi - sub esp, 8 - mov esi, esp - - mov [esi], dword 0 - mov [esi + 4], ecx - -.search_loop_header: - mov ecx, MAIN_BIOS_AREA_START - -.search_loop: - push ebp - mov ebp, esp - push ecx - push dword .signature - push dword 8 - call mem_equal - mov esp, ebp - pop ebp - - cmp ax, 0 - jne .rsdp_found - - add ecx, 16 - cmp ecx, 0x100000 - jb .search_loop - - ; If no "RSD PTR "-signature could be found - xor ecx, ecx - -.rsdp_found: - mov eax, ecx - -.epilog: - mov ecx, [esi + 4] - add esp, 8 - pop esi - - ret - -.signature: - db "RSD PTR " diff --git a/i386/legacy-boot/src-asm/drivers/acpi/utility.asm b/i386/legacy-boot/src-asm/drivers/acpi/utility.asm new file mode 100644 index 0000000..425bd2f --- /dev/null +++ b/i386/legacy-boot/src-asm/drivers/acpi/utility.asm @@ -0,0 +1,123 @@ + +MAIN_BIOS_AREA_START equ 0xe0000 + +; Arguments: +; [Furthest from EBP] +; 1. Pointer to RSDT +; 0. Pointer to driver area of 65536 bytes +; [Nearest to EBP] +acpi_enumerate_tables: +.prolog: + push esi + sub esp, 32 + mov esi, esp + + mov [esi + (32 - 4)], eax + mov [esi + (32 - 8)], ebx + mov [esi + (32 - 12)], ecx + mov [esi + (32 - 16)], edx + mov [esi + (32 - 20)], edi + + ; ESI + 4: Number of RSDT entries + ; ESI + 8: Start of RSDT's entries + +.get_table_metrics: + ; First, get the length of the full RSDT with header + mov ebx, [ebp + 8] + mov eax, [ebx + 4] + + ; Subtract the length of the RSDT's header to just get + ; the length of all the table + sub eax, 36 + + ; Save the value for later, to get the start of the entries. + mov edx, eax + + ; Divide through 4 to get the number of entries + shr eax, 2 + mov [esi + 4], eax + + ; Save the table entries' start + add edx, [ebp + 4] + mov [esi + 4], edx + +.initialize_enumeration_loop: + xor ecx, ecx + +.enumeration_loop: + cmp ecx, [esi + 4] + + ; Calculate the address of the current entry + mov eax, ecx + shl eax, 2 + mov ebx, [esi + 8] + add ebx, eax + + mov eax, [ebx]Z + + inc ecx + jmp .enumeration_loop + +.epilog: + mov edi, [esi + (32 - 20)] + mov edx, [esi + (32 - 16)] + mov ecx, [esi + (32 - 12)] + mov ebx, [esi + (32 - 8)] + mov eax, [esi + (32 - 4)] + + add esp, 32 + pop esi + + ret + + + +; Arguments: +; -- None -- +acpi_search_rsdt: +.prolog: + push esi + sub esp, 8 + mov esi, esp + + mov [esi], dword 0 + mov [esi + 4], ecx + +.search_loop_header: + mov ecx, MAIN_BIOS_AREA_START + +.search_loop: + push ebp + mov ebp, esp + push ecx + push dword .signature + push dword 8 + call mem_equal + mov esp, ebp + pop ebp + + cmp ax, 0 + jne .rsdp_found + + add ecx, 16 + cmp ecx, 0x100000 + jb .search_loop + + ; If no "RSD PTR "-signature could be found + xor ecx, ecx + +.resolve_rsdp: + ; The 4-byte RSDT-pointer is at byte-offset 4 into the RSDP strucfture. + mov eax, ecx + add eax, 4 + mov eax, [eax] + +.epilog: + mov ecx, [esi + 4] + add esp, 8 + pop esi + + ret + +.signature: + db "RSD PTR "