aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / crates / aienos-accel / src / registers.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Source-backed GB10 register inventory. |
| 17 | //! |
| 18 | //! This is a knowledge ledger, not a driver. It records only registers the |
| 19 | //! repository can point at a source for. At present that is exactly two: the |
| 20 | //! PMC registers `BOOT_0` and `BOOT_42`, whose offsets the existing UEFI |
| 21 | //! handoff already reads. Their semantic meaning is not established here, and |
| 22 | //! an absent entry is not an inferred register: unknown registers stay |
| 23 | //! unknown. |
| 24 | //! |
| 25 | //! Nothing in this module reads or writes a register. It carries metadata. |
| 26 | |
| 27 | use core::fmt::Write; |
| 28 | |
| 29 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 30 | pub enum RegisterAccess { |
| 31 | ReadOnly, |
| 32 | ReadWrite, |
| 33 | Unknown, |
| 34 | } |
| 35 | |
| 36 | /// Whether reading the register is inside the established safe set. |
| 37 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 38 | pub enum RegisterSafety { |
| 39 | /// The repository already reads it through an established path. |
| 40 | EstablishedRead, |
| 41 | /// A read would need explicit, separate approval before it is attempted. |
| 42 | RequiresApproval, |
| 43 | } |
| 44 | |
| 45 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] |
| 46 | pub struct RegisterSpec { |
| 47 | pub block: &'static str, |
| 48 | pub name: &'static str, |
| 49 | pub offset: u64, |
| 50 | pub width_bits: u8, |
| 51 | pub access: RegisterAccess, |
| 52 | /// Where the offset is recorded. A repository or public source, never a |
| 53 | /// guess from the register name. |
| 54 | pub evidence: &'static str, |
| 55 | /// A value observed by any AIENOS path, if one exists. |
| 56 | pub observed_value: Option<u32>, |
| 57 | /// The path that observed `observed_value`, if any. |
| 58 | pub observed_by: Option<&'static str>, |
| 59 | pub safe_to_read: RegisterSafety, |
| 60 | /// Native AIENOS has decoded this register on hardware. |
| 61 | pub native_observed: bool, |
| 62 | /// The register's meaning is established. |
| 63 | pub semantics_known: bool, |
| 64 | } |
| 65 | |
| 66 | pub const PMC_BLOCK: &str = "GB10 PMC"; |
| 67 | const PMC_EVIDENCE: &str = |
| 68 | "crates/aienos-accel PMC_BOOT_0/PMC_BOOT_42 offsets used by the UEFI handoff; meaning not established"; |
| 69 | |
| 70 | /// The complete known-register set. It has two entries by design. |
| 71 | pub const GB10_REGISTERS: [RegisterSpec; 2] = [ |
| 72 | RegisterSpec { |
| 73 | block: PMC_BLOCK, |
| 74 | name: "BOOT_0", |
| 75 | offset: 0x0000, |
| 76 | width_bits: 32, |
| 77 | access: RegisterAccess::ReadOnly, |
| 78 | evidence: PMC_EVIDENCE, |
| 79 | observed_value: None, |
| 80 | observed_by: None, |
| 81 | safe_to_read: RegisterSafety::EstablishedRead, |
| 82 | native_observed: false, |
| 83 | semantics_known: false, |
| 84 | }, |
| 85 | RegisterSpec { |
| 86 | block: PMC_BLOCK, |
| 87 | name: "BOOT_42", |
| 88 | offset: 0x0a00, |
| 89 | width_bits: 32, |
| 90 | access: RegisterAccess::ReadOnly, |
| 91 | evidence: PMC_EVIDENCE, |
| 92 | observed_value: None, |
| 93 | observed_by: None, |
| 94 | safe_to_read: RegisterSafety::EstablishedRead, |
| 95 | native_observed: false, |
| 96 | semantics_known: false, |
| 97 | }, |
| 98 | ]; |
| 99 | |
| 100 | pub fn find(name: &str) -> Option<&'static RegisterSpec> { |
| 101 | GB10_REGISTERS.iter().find(|spec| spec.name == name) |
| 102 | } |
| 103 | |
| 104 | /// Write the ledger deterministically. One line per register. |
| 105 | pub fn write_ledger(out: &mut impl Write) { |
| 106 | for spec in &GB10_REGISTERS { |
| 107 | let _ = write!( |
| 108 | out, |
| 109 | "gb10.register {}.{}: offset {:#06x} width {} access {:?} safety {:?} native_observed {} semantics_known {}", |
| 110 | spec.block, |
| 111 | spec.name, |
| 112 | spec.offset, |
| 113 | spec.width_bits, |
| 114 | spec.access, |
| 115 | spec.safe_to_read, |
| 116 | spec.native_observed, |
| 117 | spec.semantics_known, |
| 118 | ); |
| 119 | match spec.observed_value { |
| 120 | Some(value) => { |
| 121 | let _ = write!(out, " observed_value {value:#010x}"); |
| 122 | } |
| 123 | None => { |
| 124 | let _ = write!(out, " observed_value unknown"); |
| 125 | } |
| 126 | } |
| 127 | match spec.observed_by { |
| 128 | Some(path) => { |
| 129 | let _ = writeln!(out, " observed_by {path:?} evidence {:?}", spec.evidence); |
| 130 | } |
| 131 | None => { |
| 132 | let _ = writeln!(out, " observed_by none evidence {:?}", spec.evidence); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | #[cfg(test)] |
| 139 | mod tests { |
| 140 | use super::*; |
| 141 | |
| 142 | #[test] |
| 143 | fn ledger_is_exactly_the_two_established_offsets() { |
| 144 | assert_eq!(GB10_REGISTERS.len(), 2); |
| 145 | assert_eq!(find("BOOT_0").unwrap().offset, crate::PMC_BOOT_0); |
| 146 | assert_eq!(find("BOOT_42").unwrap().offset, crate::PMC_BOOT_42); |
| 147 | assert!(find("BOOT_1").is_none()); |
| 148 | for spec in &GB10_REGISTERS { |
| 149 | assert_eq!(spec.safe_to_read, RegisterSafety::EstablishedRead); |
| 150 | assert!(!spec.native_observed); |
| 151 | assert!(!spec.semantics_known); |
| 152 | assert!(spec.observed_value.is_none()); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | #[test] |
| 157 | fn ledger_renders_without_claiming_semantics() { |
| 158 | extern crate std; |
| 159 | use std::string::String; |
| 160 | let mut text = String::new(); |
| 161 | write_ledger(&mut text); |
| 162 | assert_eq!(text.lines().count(), 2); |
| 163 | assert!(text.contains("GB10 PMC.BOOT_0: offset 0x0000")); |
| 164 | assert!(text.contains("semantics_known false")); |
| 165 | assert!(text.contains("native_observed false")); |
| 166 | } |
| 167 | } |