interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / pi5 / klog-lib.sh

40 lines · 2291 bytes Raw Blame History
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# klog-lib.sh -- KLOG slot helpers for pi5-run.sh (sourced). Formats:
17# aienos native/kernel/core/klog_slot.h (struct ck_klog_map, ck_klog_hdr).
18le32() { local v=$1; printf '\\x%02x\\x%02x\\x%02x\\x%02x' $((v&255)) $(((v>>8)&255)) $(((v>>16)&255)) $(((v>>24)&255)); }
19le64() { le32 $(( $1 & 0xffffffff )); le32 $(( ($1 >> 32) & 0xffffffff )); }
20hexbytes() { local h=$1 out="" i; for ((i=0;i<${#h};i+=2)); do out+="\\x${h:i:2}"; done; printf '%s' "$out"; }
21# klog_struct <magic8> <lba> <count> <nonce-hex32> <out> ; map or empty header
22klog_map() { # magic version sector_size lba count nonce pad
23 { printf "AIENKLM1$(le32 1)$(le32 512)$(le64 $1)$(le64 $2)$(hexbytes $3)"; head -c $((512-48)) /dev/zero; } > "$4"
24}
25klog_hdr_empty() { # magic version state nonce lba count, rest zero
26 { printf "AIENKLG1$(le32 1)$(le32 0)$(hexbytes $3)$(le64 $1)$(le64 $2)"; head -c $((512-48)) /dev/zero; } > "$4"
27}
28# klog_extract <KLOG.BIN> <out.txt> : prints the header fields, writes the text
29klog_extract() {
30 local f=$1 out=$2
31 [[ "$(head -c 8 "$f")" == AIENKLG1 ]] || { echo "klog: no header"; return 1; }
32 local state len total
33 state=$(od -An -tu4 -j12 -N4 "$f" | tr -d ' ')
34 len=$(od -An -tu8 -j48 -N8 "$f" | tr -d ' ')
35 total=$(od -An -tu8 -j56 -N8 "$f" | tr -d ' ')
36 echo "klog: state=${state} log_len=${len} log_total=${total} stage=$(dd if="$f" bs=1 skip=72 count=32 status=none | tr -d '\0')"
37 [[ ${state} == 1 ]] || return 2
38 { tail -c +513 "$f" | head -c "${len}" > "$out"; } || true # head stops tail early (SIGPIPE under pipefail)
39 [[ $(stat -c %s "$out") == "${len}" ]] || { echo "klog: short extract"; return 3; }
40}