Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/kernel/core/klog.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / kernel / core / klog.om` 153 lines ยท 2668 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/kernel/core/klog.om: Pure-Omega RAM Console Log (head + tail ring with drop marker). 3 note Converted from upstream aienux native/kernel/core/klog.h and native/kernel/core/klog.c. 4 5 const KLOG_HEAD_CAP ulong 4096 6 const KLOG_TAIL_CAP ulong 1024 7 8 note klog_meta: 0=head_len, 1=tail_put, 2=total, 3=head_cap, 4=tail_cap 9 global klog_meta ulong 5 10 global klog_head uchar 4096 11 global klog_tail uchar 1024 12 13 text klog_drop_pre "\n[klog: " 14 text klog_drop_suf " bytes dropped]\n" 15 16 fn klog_clear_caps hcap ulong tcap ulong to void 17 hc = hcap 18 tc = tcap 19 if or eq hc 0 gt hc KLOG_HEAD_CAP 20 hc = KLOG_HEAD_CAP 21 end 22 if or eq tc 0 gt tc KLOG_TAIL_CAP 23 tc = KLOG_TAIL_CAP 24 end 25 put klog_meta 0 0 26 put klog_meta 1 0 27 put klog_meta 2 0 28 put klog_meta 3 hc 29 put klog_meta 4 tc 30 end 31 32 fn klog_clear to void 33 klog_clear_caps KLOG_HEAD_CAP KLOG_TAIL_CAP 34 end 35 36 fn klog_put src view uchar * to void 37 n = len src 38 hc = get klog_meta 3 39 tc = get klog_meta 4 40 if eq hc 0 41 klog_clear 42 hc = KLOG_HEAD_CAP 43 tc = KLOG_TAIL_CAP 44 end 45 put klog_meta 2 add get klog_meta 2 n 46 hlen = get klog_meta 0 47 tput = get klog_meta 1 48 i = ulong 0 49 while lt i n bound 65536 50 ch = get src i 51 if lt hlen hc 52 put klog_head hlen ch 53 hlen = add hlen 1 54 else 55 put klog_tail rem tput tc ch 56 tput = add tput 1 57 end 58 i = add i 1 59 end 60 put klog_meta 0 hlen 61 put klog_meta 1 tput 62 end 63 64 fn klog_total to ulong 65 ret get klog_meta 2 66 end 67 68 fn klog_dropped to ulong 69 tput = get klog_meta 1 70 tc = get klog_meta 4 71 if gt tput tc 72 ret sub tput tc 73 end 74 ret 0 75 end 76 77 fn klog_write_dec dst edit uchar * pos ulong cap ulong val ulong to ulong 78 digits = new uchar 24 0 79 nd = ulong 0 80 v = val 81 if eq v 0 82 put digits 0 48 83 nd = ulong 1 84 else 85 while gt v 0 bound 24 86 put digits nd uchar add 48 rem v 10 87 v = div v 10 88 nd = add nd 1 89 end 90 end 91 w = pos 92 i = nd 93 while gt i 0 bound 24 94 i = sub i 1 95 if lt w cap 96 put dst w get digits i 97 w = add w 1 98 end 99 end 100 ret w 101 end 102 103 fn klog_copy_text dst edit uchar * pos ulong cap ulong src view uchar * to ulong 104 w = pos 105 n = len src 106 i = ulong 0 107 while lt i n bound 64 108 if ge w cap 109 break 110 end 111 put dst w get src i 112 w = add w 1 113 i = add i 1 114 end 115 ret w 116 end 117 118 fn klog_read dst edit uchar * to ulong 119 cap = len dst 120 hlen = get klog_meta 0 121 tput = get klog_meta 1 122 tc = get klog_meta 4 123 w = ulong 0 124 i = ulong 0 125 while lt i hlen bound 4096 126 if ge w cap 127 break 128 end 129 put dst w get klog_head i 130 w = add w 1 131 i = add i 1 132 end 133 kept = tput 134 if gt kept tc 135 kept = tc 136 end 137 if gt tput tc 138 w = klog_copy_text dst w cap klog_drop_pre 139 w = klog_write_dec dst w cap sub tput tc 140 w = klog_copy_text dst w cap klog_drop_suf 141 end 142 start = sub tput kept 143 j = start 144 while lt j tput bound 1024 145 if ge w cap 146 break 147 end 148 put dst w get klog_tail rem j tc 149 w = add w 1 150 j = add j 1 151 end 152 ret w 153 end