|
11 | 11 |
|
12 | 12 |
|
13 | 13 | init_acpi: |
| 14 | + mov rbx, 'RSD PTR ' ; This in the Signature for the ACPI Structure Table (0x2052545020445352) |
14 | 15 | mov al, [p_BootMode] ; Check how the system was booted |
15 | 16 | cmp al, 'U' ; UEFI? |
16 | 17 | je foundACPIfromUEFI ; If so, jump - otherwise fall thru for BIOS |
17 | 18 |
|
18 | 19 | ; 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 |
21 | 22 | searchingforACPI: |
| 23 | + sub esi, 0x7 |
22 | 24 | lodsq ; Load a quad word from RSI and store in RAX, then increment RSI by 8 |
23 | 25 | cmp rax, rbx ; Verify the Signature |
24 | 26 | 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 |
27 | 29 | jmp searchingforACPI |
28 | 30 |
|
29 | 31 | ; Find the ACPI RSDP Structure on a UEFI system |
30 | 32 | foundACPIfromUEFI: |
31 | 33 | mov rsi, [0x400830] ; TODO This should be passed properly |
32 | | - mov rbx, 'RSD PTR ' ; This in the Signature for the ACPI Structure Table (0x2052545020445352) |
33 | 34 | lodsq ; Signature |
34 | 35 | cmp rax, rbx ; Verify the Signature |
35 | 36 | jne noACPI ; If it isn't a match then fail |
36 | 37 |
|
37 | 38 | ; Parse the Root System Description Pointer (RSDP) Structure (5.2.5.3) |
38 | 39 | foundACPI: ; Found a Pointer Structure, verify the checksum |
39 | 40 | push rsi ; Save the RSDP location - currently pointing to the checksum |
| 41 | + push rbx |
40 | 42 | xor ebx, ebx |
41 | 43 | 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 |
43 | 45 | nextchecksum: |
44 | 46 | lodsb ; Get a byte |
45 | 47 | 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 |
49 | 52 | 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 |
52 | 55 |
|
53 | 56 | lodsb ; Checksum |
54 | 57 | lodsd ; OEMID (First 4 bytes) |
|
0 commit comments