interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / aienux / kernel / arm64 / uart.om

124 lines · 2643 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/kernel/arm64/uart.om: Polled bare-metal UART console (Spark 16550 @ 0x16A00000 & QEMU PL011)
3note plus post-EBS panic hook (panichk) that NEVER calls dead UEFI Boot/Runtime Services.
4
5const UART_KIND_NONE ulong 0
6const UART_KIND_16550_32 ulong 1
7const UART_KIND_PL011 ulong 2
8const UART_SPARK_16550_PA ulong 0x16a00000
9const UART_QEMU_PL011_PA ulong 0x09000000
10
11note uart_state: 0=base_pa, 1=kind (1=16550 dword-stride, 2=PL011), 2=psci_conduit
12global uart_state ulong 4
13
14text u_hex "0123456789abcdef"
15text u_panic_hdr "\nPANIC post-EBS code=0x"
16text u_panic_esr " esr=0x"
17text u_panic_elr " elr=0x"
18text u_panic_far " far=0x"
19text u_nl "\n"
20
21fn uart_init base_pa ulong kind ulong conduit ulong to void
22put uart_state 0 base_pa
23put uart_state 1 kind
24put uart_state 2 conduit
25end
26
27fn uart_base to ulong
28ret get uart_state 0
29end
30
31fn uart_kind to ulong
32ret get uart_state 1
33end
34
35fn uart_putc ch ulong to void
36base = get uart_state 0
37kind = get uart_state 1
38if or eq base 0 eq kind UART_KIND_NONE
39ret
40end
41if eq kind UART_KIND_PL011
42note PL011: FR at +0x18, TXFF = bit 5 (0x20); DR at +0x00
43i = ulong 0
44while lt i 100000 bound 100000
45fr = fwld add base 0x18 4
46if eq and fr 0x20 0
47break
48end
49i = add i 1
50end
51x = fwst base 4 and ch 0xff
52ret
53end
54note 16550 dword-spaced (Spark MTKI0511:00 @ 0x16A00000): LSR at +0x14 (5*4), THRE = bit 5 (0x20); THR at +0x00
55i = ulong 0
56while lt i 100000 bound 100000
57lsr = fwld add base 0x14 4
58if ne and lsr 0x20 0
59break
60end
61i = add i 1
62end
63x = fwst base 4 and ch 0xff
64end
65
66fn uart_puts s view uchar * to void
67n = len s
68i = ulong 0
69while lt i n bound 4096
70b = ulong get s i
71if eq b 10
72uart_putc 13
73end
74uart_putc b
75i = add i 1
76end
77end
78
79fn uart_puthex v ulong to void
80i = ulong 0
81while lt i 16 bound 16
82sh = mul sub 15 i 4
83d = and shr v sh 15
84uart_putc ulong get u_hex d
85i = add i 1
86end
87end
88
89fn uart_putdec v ulong to void
90if eq v 0
91uart_putc 48
92ret
93end
94buf = new uchar 24 0
95k = ulong 0
96cur = v
97while gt cur 0 bound 24
98put buf k uchar add 48 rem cur 10
99cur = div cur 10
100k = add k 1
101end
102while gt k 0 bound 24
103k = sub k 1
104uart_putc ulong get buf k
105end
106end
107
108note panichk: invoked by aefx/vbar_el1 after ExitBootServices(). Logs crash state to UART;
109note aefx then invokes PSCI SYSTEM_RESET or parks in WFE. Never touches UEFI services.
110fn panichk code ulong esr ulong elr ulong far ulong to void
111if eq get uart_state 0 0
112put uart_state 0 UART_SPARK_16550_PA
113put uart_state 1 UART_KIND_16550_32
114end
115uart_puts u_panic_hdr
116uart_puthex code
117uart_puts u_panic_esr
118uart_puthex esr
119uart_puts u_panic_elr
120uart_puthex elr
121uart_puts u_panic_far
122uart_puthex far
123uart_puts u_nl
124end