1
0
mirror of https://github.com/taigrr/gopher-os synced 2026-03-24 13:22:23 -07:00

acpi: implement AML parser for all AML opcodes in the ACPI 6.2 spec

This commit is contained in:
Achilleas Anagnostopoulos
2017-09-06 10:47:57 +01:00
parent 4dd7c0b077
commit 2a84c75d8e
7 changed files with 1183 additions and 15 deletions

View File

@@ -0,0 +1,69 @@
package aml
import (
"gopheros/device/acpi/table"
"io/ioutil"
"path/filepath"
"runtime"
"strings"
"testing"
"unsafe"
)
func TestParser(t *testing.T) {
specs := [][]string{
[]string{"DSDT.aml", "SSDT.aml"},
[]string{"parser-testsuite-DSDT.aml"},
}
for specIndex, spec := range specs {
var resolver = mockResolver{
tableFiles: spec,
}
// Create default scopes
rootNS := &scopeEntity{op: opScope, name: `\`}
rootNS.Append(&scopeEntity{op: opScope, name: `_GPE`}) // General events in GPE register block
rootNS.Append(&scopeEntity{op: opScope, name: `_PR_`}) // ACPI 1.0 processor namespace
rootNS.Append(&scopeEntity{op: opScope, name: `_SB_`}) // System bus with all device objects
rootNS.Append(&scopeEntity{op: opScope, name: `_SI_`}) // System indicators
rootNS.Append(&scopeEntity{op: opScope, name: `_TZ_`}) // ACPI 1.0 thermal zone namespace
p := NewParser(ioutil.Discard, rootNS)
for _, tableName := range spec {
tableName := strings.Replace(tableName, ".aml", "", -1)
if err := p.ParseAML(tableName, resolver.LookupTable(tableName)); err != nil {
t.Errorf("[spec %d] [%s]: %v", specIndex, tableName, err)
break
}
}
}
}
func pkgDir() string {
_, f, _, _ := runtime.Caller(1)
return filepath.Dir(f)
}
type mockResolver struct {
tableFiles []string
}
func (m mockResolver) LookupTable(name string) *table.SDTHeader {
pathToDumps := pkgDir() + "/../table/tabletest/"
for _, f := range m.tableFiles {
if !strings.Contains(f, name) {
continue
}
data, err := ioutil.ReadFile(pathToDumps + f)
if err != nil {
panic(err)
}
return (*table.SDTHeader)(unsafe.Pointer(&data[0]))
}
return nil
}