Skip to content

Commit 7185693

Browse files
authored
Merge pull request #105 from ReturnInfinity/qa
Adjustment of ACPI changes from dev branch
2 parents 429584a + 4c8194d commit 7185693

2 files changed

Lines changed: 45 additions & 31 deletions

File tree

src/init/acpi.asm

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3248
foundACPIfromUEFI:
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
3960
foundACPI: ; 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
4564
nextchecksum:
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

src/pure64.asm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ bootmode:
117117
stosw ; BitsPerPixel
118118
%endif
119119

120-
; Clear memory for the Page Descriptor Entries (0x10000 - 0x5FFFF)
120+
; Clear memory for the Page Descriptor Entries (0x210000 - 0x25FFFF)
121121
mov edi, 0x00210000
122-
mov ecx, 81920
122+
mov ecx, 320 * 1024 / 4
123123
rep stosd ; Write 320KiB
124124

125125
; Create the temporary Page Map Level 4 Entries (PML4E)
@@ -205,8 +205,8 @@ start64:
205205

206206
mov edi, 0x5000 ; Clear the info map and system variable memory
207207
xor eax, eax
208-
mov ecx, 960 ; 3840 bytes (Range is 0x5000 - 0x5EFF)
209-
rep stosd ; Don't overwrite the UEFI/BIOS data at 0x5F00
208+
mov ecx, 3840 / 8 ; 3840 bytes (Range is 0x5000 - 0x5EFF)
209+
rep stosq ; Don't overwrite the 256-byte UEFI/BIOS data at 0x5F00
210210

211211
mov [p_BootMode], bl
212212
mov [p_BootDisk], bh
@@ -300,15 +300,15 @@ msg_boot_done:
300300
%endif
301301

302302
; Clear out the first 20KiB of memory. This will store the 64-bit IDT, GDT, PML4, PDP Low, and PDP High
303-
mov ecx, 5120
304303
xor eax, eax
305-
mov edi, eax
306-
rep stosd
304+
mov edi, edi
305+
mov ecx, 20 * 1024 / 8
306+
rep stosq ; Write 20KiB
307307

308308
; Clear memory for the Page Descriptor Entries (0x10000 - 0x5FFFF)
309309
mov edi, 0x00010000
310-
mov ecx, 81920
311-
rep stosd ; Write 320KiB
310+
mov ecx, 320 * 1024 / 8
311+
rep stosq ; Write 320KiB
312312

313313
; Copy the GDT to its final location in memory
314314
mov esi, gdt64

0 commit comments

Comments
 (0)