1 # bend-osdev-acpi, dsdt.bend: the Differentiated and Secondary System 2 # Description Tables, "DSDT" and "SSDT" (ACPI 6.5, sections 5.2.11.1 and 3 # 5.2.11.2): a header, then a definition block of AML byte code (chapter 4 # 20), kept here as its bytes; aml_*.bend read and run it. A definition 5 # block whose header revision is below 2 uses 32-bit integers (chapter 19, 6 # DefinitionBlock: ComplianceRevision), 64-bit otherwise. 7 import Base 8 import bend-osdev-bytes@0.1.1.1/bytes.bend as B 9 import ./error.bend as E 10 import ./header.bend as H 11 12 type AcpiAml is Data: 13 AcpiAml{header: H.AcpiHeader, aml: B.Octets} 14 15 def AcpiAml.header(t: AcpiAml) -> H.AcpiHeader: 16 match t: 17 case AcpiAml{h, a}: 18 h 19 20 def AcpiAml.aml(t: AcpiAml) -> B.Octets: 21 match t: 22 case AcpiAml{h, a}: 23 a 24 25 # true when the block's integers are 64 bits wide 26 def AcpiAml.wide(t: AcpiAml) -> Bool: 27 U32.is_le(2, H.AcpiHeader.revision(AcpiAml.header(t))) 28 29 def AcpiAml.of_sdt(t: H.AcpiSdt) -> Result<&2, &2, E.AcpiError, AcpiAml>: 30 match t: 31 case H.AcpiSdt{h, body}: 32 Done{AcpiAml{h, body}} 33 34 def aml.parse(r: Result<&2, &2, E.AcpiError, H.AcpiSdt>) -> Result<&2, &2, E.AcpiError, AcpiAml>: 35 match r: 36 case Fail{e}: 37 Fail{e} 38 case Done{t}: 39 AcpiAml.of_sdt(t) 40 41 # a DSDT or SSDT at the front of o (checked; either signature) 42 def AcpiAml.parse(+o: B.Octets) -> Result<&2, &2, E.AcpiError, AcpiAml>: 43 aml.parse(H.AcpiSdt.parse(o)) 44 45 def AcpiAml.parse_dsdt(+o: B.Octets) -> Result<&2, &2, E.AcpiError, AcpiAml>: 46 aml.parse(H.AcpiSdt.parse_sig(B.Octets.of_string("DSDT"), o)) 47 48 # the table: the header's signature as given (DSDT or SSDT), length and 49 # checksum computed 50 def AcpiAml.build(t: AcpiAml) -> B.Octets: 51 match t: 52 case AcpiAml{h, a}: 53 H.AcpiSdt.build(h, a)