From 34d4c44cc60683c47ef31499791d27872fa358e7 Mon Sep 17 00:00:00 2001 From: andromeda Date: Sat, 24 Oct 2026 09:51:50 -0400 Subject: add acpi.c3l --- acpi.c3l/acpi.c3 | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 acpi.c3l/acpi.c3 (limited to 'acpi.c3l/acpi.c3') diff --git a/acpi.c3l/acpi.c3 b/acpi.c3l/acpi.c3 new file mode 100644 index 0000000..1842866 --- /dev/null +++ b/acpi.c3l/acpi.c3 @@ -0,0 +1,61 @@ +/** + * Copyright (C) 2026 andromeda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +**/ + +module acpi; + +import c3os::util; + +extern fn int memcmp(void*, void*, usz); + +fn bool RootSystemDescriptionPointer.is_valid(&self) +{ + if (memcmp(&self.signature, "RSD PTR ", 8) != 0) return false; + if (self.revision != 2) return false; + char sum = 0; + for (int i = 0; i < 20; i++) sum += ((char*)self)[i]; + if (sum != 0) return false; + for (int i = 0; i < RootSystemDescriptionPointer::size; i++) sum += ((char*)self)[i]; + return (sum == 0); +} + +fn bool ExtendedSystemDescriptionTable.is_valid(&self) +{ + if (memcmp(&self.signature, "XSDT", 4) != 0) return false; + if (self.revision != 1) return false; + char sum = 0; + for (uint i = 0; i < self.length; i++) sum += ((char*)self)[i]; + if (sum != 0) return false; + return true; +} + +fn bool DescriptionHeader.is_valid(&self) +{ + if (catch excuse = self.sig()) return false; + char sum = 0; + for (uint i = 0; i < self.length; i++) sum += ((char*)self)[i]; + if (sum != 0) return false; + return true; +} + +fn DescriptionHeaderSignature? DescriptionHeader.sig(&self) +{ + foreach (i, name : DescriptionHeaderSignature::names) + { + if (memcmp(name, &self.signature, 4) == 0) return (DescriptionHeaderSignature)i; + } + return INVALID_DESCRIPTION_HEADER~; +} -- cgit v1.3.1