Skip to content

Commit

Permalink
acpi: Parse the AML tables after free memory pool has been setup.
Browse files Browse the repository at this point in the history
- Dont call parseAMLTables() when all of the other ACPI tables are
  parsed as it requires too much memory so move the parse to the
  DeviceManager init().

- Convert ACPI from a struct to a class since there should only be
  a singleton instance anyway.

- Reduce the stack size from 6 pages down to 4. Also reduce the
  initial heap set in the linker script from 2048 pages (8MB) down
  to 64 pages (256k).
  • Loading branch information
spevans committed Dec 30, 2017
1 parent 3fc6874 commit b3d111f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion acpitest/main.swift
Expand Up @@ -72,7 +72,7 @@ func loadData(_ fileSet: Int) -> ACPI {
var testDir = Bundle.main.resourcePath!
testDir.append("/acpitest.xctest/Contents/Resources/")

var acpi = ACPI()
let acpi = ACPI()
for file in files[fileSet] {
//print("Filename:", file)
let data = openOrQuit(filename: testDir + "/" + file)
Expand Down
10 changes: 4 additions & 6 deletions kernel/devices/acpi/acpi.swift
Expand Up @@ -113,7 +113,7 @@ struct RSDP2: CustomStringConvertible {
}


struct ACPI {
final class ACPI {
private(set) var mcfg: MCFG?
private(set) var facp: FACP?
private(set) var madt: MADT?
Expand All @@ -135,13 +135,11 @@ struct ACPI {
parseEntry(rawSDTPtr: rawSDTPtr, vendor: vendor, product: product)
}

print("Parsing AML")
if dsdt == nil, let dsdtAddr = facp?.dsdtAddress {
print("Found DSDT address in FACP: 0x\(asHex(dsdtAddr.value))")
parseEntry(rawSDTPtr: mkSDTPtr(dsdtAddr),
vendor: vendor, product: product)
}
globalObjects = parseAMLTables()
}


Expand All @@ -150,7 +148,8 @@ struct ACPI {
}


mutating func parseAMLTables() -> ACPIGlobalObjects? {
func parseAMLTables() {
print("Parsing AML")
guard let ptr = dsdt else {
fatalError("ACPI: No valid DSDT found")
}
Expand All @@ -171,11 +170,10 @@ struct ACPI {
//parser.parseMethods()
globalObjects = parser.acpiGlobalObjects
print("End of AML code")
return acpiGlobalObjects
}


mutating func parseEntry(rawSDTPtr: UnsafeRawPointer, vendor: String,
func parseEntry(rawSDTPtr: UnsafeRawPointer, vendor: String,
product: String) {

let signature = tableSignature(ptr: rawSDTPtr)
Expand Down
1 change: 1 addition & 0 deletions kernel/devices/devicemanager.swift
Expand Up @@ -117,6 +117,7 @@ final class DeviceManager {


init(acpiTables: ACPI) {
acpiTables.parseAMLTables()
guard let (sb, sbFullName) = acpiTables.globalObjects.getGlobalObject(currentScope: AMLNameString("\\"),
name: AMLNameString("_SB")) else {
fatalError("No \\_SB system bus node")
Expand Down
4 changes: 2 additions & 2 deletions linker.script
Expand Up @@ -3,7 +3,7 @@ OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")

PAGE_SIZE = 0x1000;
/* Needs to be bigger for DEBUG mode, can be 2 for non debug */
STACK_SIZE = 6 * PAGE_SIZE;
STACK_SIZE = 4 * PAGE_SIZE;

PHDRS {
text PT_LOAD FLAGS(5); /* R_E */
Expand Down Expand Up @@ -102,7 +102,7 @@ SECTIONS {
. += PAGE_SIZE;
_ist1_stack_top = .;
_heap_start = .;
. += PAGE_SIZE * 2048;
. += PAGE_SIZE * 64;
_heap_end = .;

_bss_end = .;
Expand Down

0 comments on commit b3d111f

Please sign in to comment.