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 / boot / model_map.om

111 lines · 2621 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/boot/model_map.om: Pure-Omega MODEL.MAP (AIENMDL1) 4096-byte Extent Map Validator.
3note Converted from upstream aienux native/boot/model_map.h.
4
5const MMAP_BYTES ulong 4096
6const MMAP_VERSION uint 1
7const MMAP_MAX_EXTENTS uint 128
8
9const MMAP_OFF_MAGIC ulong 0
10const MMAP_OFF_VERSION ulong 8
11const MMAP_OFF_SECTOR_SZ ulong 12
12const MMAP_OFF_DISK_GUID ulong 16
13const MMAP_OFF_MODEL_LEN ulong 32
14const MMAP_OFF_SHA256 ulong 40
15const MMAP_OFF_N_EXTENTS ulong 72
16const MMAP_OFF_FLAGS ulong 76
17const MMAP_OFF_EXTENTS ulong 80
18
19const MMAP_OK int 0
20const MMAP_ERR_SHORT int -1
21const MMAP_ERR_MAGIC int -2
22const MMAP_ERR_VERSION int -3
23const MMAP_ERR_SECTOR_SZ int -4
24const MMAP_ERR_BLK_MISMATCH int -5
25const MMAP_ERR_FLAGS int -6
26const MMAP_ERR_ZERO_LEN int -7
27const MMAP_ERR_EXT_COUNT int -8
28const MMAP_ERR_EXT_BAD int -9
29const MMAP_ERR_EXT_PAST_DISK int -10
30const MMAP_ERR_EXT_OVERFLOW int -11
31const MMAP_ERR_COVERAGE int -12
32
33text mmap_magic "AIENMDL1"
34
35fn model_map_sum_extents buf view uchar * nexts uint last_block ulong sec_out edit ulong 1 to int
36sectors = ulong 0
37i = ulong 0
38n = ulong nexts
39while lt i n bound 128
40eoff = add MMAP_OFF_EXTENTS mul i 16
41elba = boot_rd64_le buf eoff
42ecnt = boot_rd64_le buf add eoff 8
43if eq ecnt 0
44ret MMAP_ERR_EXT_BAD
45end
46if lt elba 2
47ret MMAP_ERR_EXT_BAD
48end
49eend = add elba ecnt
50if lt eend elba
51ret MMAP_ERR_EXT_PAST_DISK
52end
53if ne last_block 0
54if gt sub eend 1 last_block
55ret MMAP_ERR_EXT_PAST_DISK
56end
57end
58if lt add sectors ecnt sectors
59ret MMAP_ERR_EXT_OVERFLOW
60end
61sectors = add sectors ecnt
62i = add i 1
63end
64put sec_out 0 sectors
65ret MMAP_OK
66end
67
68fn model_map_check buf view uchar * block_size uint last_block ulong to int
69if lt len buf MMAP_BYTES
70ret MMAP_ERR_SHORT
71end
72if not boot_eq_bytes part buf MMAP_OFF_MAGIC 8 mmap_magic
73ret MMAP_ERR_MAGIC
74end
75if ne boot_rd32_le buf MMAP_OFF_VERSION MMAP_VERSION
76ret MMAP_ERR_VERSION
77end
78secsz = boot_rd32_le buf MMAP_OFF_SECTOR_SZ
79if and ne secsz 512 ne secsz 4096
80ret MMAP_ERR_SECTOR_SZ
81end
82if and ne block_size 0 ne secsz block_size
83ret MMAP_ERR_BLK_MISMATCH
84end
85if ne boot_rd32_le buf MMAP_OFF_FLAGS 0
86ret MMAP_ERR_FLAGS
87end
88mlen = boot_rd64_le buf MMAP_OFF_MODEL_LEN
89if eq mlen 0
90ret MMAP_ERR_ZERO_LEN
91end
92nexts = boot_rd32_le buf MMAP_OFF_N_EXTENTS
93if or eq nexts 0 gt nexts MMAP_MAX_EXTENTS
94ret MMAP_ERR_EXT_COUNT
95end
96sbox = new ulong 1 0
97rc = model_map_sum_extents buf nexts last_block sbox
98if ne rc MMAP_OK
99ret rc
100end
101ssz = ulong secsz
102rem_m = rem mlen ssz
103need = div mlen ssz
104if ne rem_m 0
105need = add need 1
106end
107if ne get sbox 0 need
108ret MMAP_ERR_COVERAGE
109end
110ret MMAP_OK
111end