Skip to content

Commit 390280c

Browse files
author
Ian Seyler
committed
Fix #96
1 parent e755548 commit 390280c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/init/acpi.asm

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,47 @@
1111

1212

1313
init_acpi:
14+
mov rbx, 'RSD PTR ' ; This in the Signature for the ACPI Structure Table (0x2052545020445352)
1415
mov al, [p_BootMode] ; Check how the system was booted
1516
cmp al, 'U' ; UEFI?
1617
je foundACPIfromUEFI ; If so, jump - otherwise fall thru for BIOS
1718

1819
; Find the ACPI RSDP Structure on a BIOS system
19-
mov esi, 0x000E0000 ; Start looking for the Root System Description Pointer Structure
20-
mov rbx, 'RSD PTR ' ; This in the Signature for the ACPI Structure Table (0x2052545020445352)
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
2122
searchingforACPI:
23+
sub esi, 0x7
2224
lodsq ; Load a quad word from RSI and store in RAX, then increment RSI by 8
2325
cmp rax, rbx ; Verify the Signature
2426
je foundACPI
25-
cmp esi, 0x000FFFFF ; Keep looking until we get here
26-
jae noACPI ; ACPI tables couldn't be found, fail
27+
cmp esi, 0xFFFFFFF8 ; Keep looking until we get here
28+
ja noACPI ; ACPI tables couldn't be found, fail
2729
jmp searchingforACPI
2830

2931
; Find the ACPI RSDP Structure on a UEFI system
3032
foundACPIfromUEFI:
3133
mov rsi, [0x400830] ; TODO This should be passed properly
32-
mov rbx, 'RSD PTR ' ; This in the Signature for the ACPI Structure Table (0x2052545020445352)
3334
lodsq ; Signature
3435
cmp rax, rbx ; Verify the Signature
3536
jne noACPI ; If it isn't a match then fail
3637

3738
; Parse the Root System Description Pointer (RSDP) Structure (5.2.5.3)
3839
foundACPI: ; Found a Pointer Structure, verify the checksum
3940
push rsi ; Save the RSDP location - currently pointing to the checksum
41+
push rbx
4042
xor ebx, ebx
4143
mov ecx, 20 ; As per the spec only the first 20 bytes matter
42-
sub rsi, 8 ; Bytes 0 thru 19 must sum to zero
44+
sub esi, 8 ; Bytes 0 thru 19 must sum to zero
4345
nextchecksum:
4446
lodsb ; Get a byte
4547
add bl, al ; Add it to the running total
46-
sub cl, 1
47-
cmp cl, 0
48-
jne nextchecksum
48+
dec cl
49+
jnz nextchecksum ; 'dec' will set the zero flag
50+
mov al, bl ; Save the value to AL before RBX gets popped
51+
pop rbx
4952
pop rsi ; Restore the RSDP location
50-
cmp bl, 0 ; Verify the checksum is zero
51-
jne noACPI ; Checksum didn't check out? Fail
53+
cmp al, 0 ; Verify the checksum is zero
54+
jne searchingforACPI ; Checksum didn't check out? Keep looking for a valid record
5255

5356
lodsb ; Checksum
5457
lodsd ; OEMID (First 4 bytes)

0 commit comments

Comments
 (0)