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.
This commit is contained in:
Eric-Paul Ickhorn 2024-08-17 16:52:17 +02:00
parent 21ba34f526
commit 2923a300b5
Signed by: epickh
GPG Key ID: 1358818BAA38B104
3 changed files with 168 additions and 49 deletions

View File

@ -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"

View File

@ -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 "

View File

@ -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 "