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