@@ -17,45 +17,59 @@ init_acpi:
1717 je foundACPIfromUEFI ; If so, jump - otherwise fall thru for BIOS
1818
1919; Find the ACPI RSDP Structure on a BIOS system
20- ; It's supposed to be somewhere in the first MiB of memory but some systems don't adhere to that
21- mov esi , 0x00000007 ; Start looking for the Root System Description Pointer Structure
22- searchingforACPI:
23- sub esi , 0x7
24- lodsq ; Load a quad word from RSI and store in RAX, then increment RSI by 8
25- cmp rax , rbx ; Verify the Signature
20+ ; The RSDP is potentially located in 2 places:
21+ ; 1) Within the first 1 KiB of the EBDA (Extended BIOS Data Area; a 2 byte address to the start of it is located at 0x40E)
22+ ; 2) In the BIOS ROM memory region from 0x000E0000 to 0x000FFFFF
23+ ; The signature always starts on a 16 byte boundary.
24+ ; If the system does not adhere to the standard then this will fail.
25+
26+ ; ; Check EBDA (first 1KB)
27+ ; mov rsi, [p_EBDA]
28+ ; mov ecx, 64 ; 0x400 / 16 = 64 iterations
29+ ;acpi_search_ebda:
30+ ; cmp qword [rsi], rbx ; Compare the Signature
31+ ; je foundACPI
32+ ; add esi, 16
33+ ; dec ecx
34+ ; jnz acpi_search_ebda
35+
36+ ; Check BIOS ROM area (0xE0000–0xFFFFF)
37+ mov esi , 0xE0000 ; Start of BIOS ROM
38+ mov ecx , 8192 ; 0x20000 / 16 = 8192 iterations
39+ acpi_search_rom:
40+ cmp qword [ rsi ], rbx ; Compare the Signature
2641 je foundACPI
27- cmp esi , 0xFFFFFFF8 ; Keep looking until we get here
28- ja noACPI ; ACPI tables couldn't be found, fail
29- jmp searchingforACPI
42+ add esi , 16
43+ dec ecx
44+ jnz acpi_search_rom
45+ jmp noACPI ; ACPI tables couldn't be found, fail
3046
3147; Find the ACPI RSDP Structure on a UEFI system
3248foundACPIfromUEFI:
3349 mov rsi , [ 0x400830 ] ; TODO This should be passed properly
34- lodsq ; Signature
50+ mov rax , [ rsi ] ; Signature
3551 cmp rax , rbx ; Verify the Signature
3652 jne noACPI ; If it isn't a match then fail
3753
3854; Parse the Root System Description Pointer (RSDP) Structure (5.2.5.3)
55+ ; 8 bytes - Signature
56+ ; 1 byte - Checksum
57+ ; 6 bytes - OEMID
58+ ; 1 byte - Revision
59+ ; 4 bytes - Address
3960foundACPI: ; Found a Pointer Structure, verify the checksum
40- push rsi ; Save the RSDP location - currently pointing to the checksum
41- push rbx
61+ push rsi ; Save the RSDP location
4262 xor ebx , ebx
43- mov ecx , 20 ; As per the spec only the first 20 bytes matter
44- sub esi , 8 ; Bytes 0 thru 19 must sum to zero
63+ mov ecx , 20 ; As per the spec only the first 20 bytes matter for checksum
4564nextchecksum:
4665 lodsb ; Get a byte
4766 add bl , al ; Add it to the running total
4867 dec cl
4968 jnz nextchecksum ; 'dec' will set the zero flag
50- mov al , bl ; Save the value to AL before RBX gets popped
51- pop rbx
5269 pop rsi ; Restore the RSDP location
53- cmp al , 0 ; Verify the checksum is zero
54- jne searchingforACPI ; Checksum didn't check out? Keep looking for a valid record
55-
56- lodsb ; Checksum
57- lodsd ; OEMID (First 4 bytes)
58- lodsw ; OEMID (Last 2 bytes)
70+ cmp bl , 0 ; Verify the checksum is zero
71+ jne noACPI ; Checksum didn't check out? Keep looking for a valid record
72+ add rsi , 15 ; Add offset to revision byte
5973 lodsb ; Revision (0 is v1.0, 1 is v2.0, 2 is v3.0, etc)
6074 cmp al , 0
6175 je foundACPIv1 ; If AL is 0 then the system is using ACPI v1.0
0 commit comments