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 / bridge / shlib / nvrmfake.om

100 lines · 2977 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note bridge/shlib/nvrmfake.om: the test transport libomega-nvrm.so.1 (nvrmfake.tsv) behind the gate's
3note libnvidia-ml.so.1: the three omega2_nvrm_* entry points of native/nvrm/transport.om, answered by the RM fake
4note nvml_fake (bridge/shlib/rmfake.om, CUDApp's tests/nvml/rmfake.om unchanged) instead of /dev/nvidia*, plus
5note fake_reset, fake_get and fake_trapped; the same functions and answers as CUDApp's tests/nvml/transport.c.
6note Composed after rmfake.om. No device file is opened.
7note States (frame words 8..11): FkS the fake's 64 words, FkH the request header, FkP the payload, FkT the
8note violation count (0) and the result word copied out (1).
9note A trap inside nvml_fake returns the TRAP value 1 (a transport refusal) at once, without the C's count of
10note it as a violation: a path that is a bug in the fake.
11
12const UMAX ulong 4294967295
13
14extern fn memcpy d ulong s ulong n ulong to ulong
15
16note fk_step: one fake step; a refusal (nonzero) counts as a violation and answers status 1; otherwise the
17note fake's result goes to the caller's result word
18fn fk_step st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 fr view ulong 12 to uint
19v = nvml_fake st h p
20if ne v 0
21put t 0 add get t 0 1
22put st 13 add get st 13 1
23ret 1
24end
25put t 1 get st 6
26z = memcpy get fr 0 add get fr 11 8 8
27ret 0
28end
29
30export fn omega2_nvrm_open_file fr view ulong 12 st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 to uint
31n = get fr 2
32if or eq n 0 gt n PN
33ret 32
34end
35z = memcpy get fr 10 get fr 1 n
36put st 0 2
37put st 7 n
38ret fk_step st h p t fr
39end
40
41export fn omega2_nvrm_close_file fr view ulong 12 st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 to uint
42put st 0 3
43put st 1 get fr 1
44ret fk_step st h p t fr
45end
46
47note fault S: the transport itself refuses the GPU name control 0x20800110 (status 1)
48fn fk_srefuse st view ulong 64 h view uchar HN fr view ulong 12 to bool
49if or ne get st 5 83 ne get fr 2 42
50ret false
51end
52if lt get fr 4 12
53ret false
54end
55c = or or ulong get h 8 shl ulong get h 9 8 or shl ulong get h 10 16 shl ulong get h 11 24
56ret eq c 545259792
57end
58
59export fn omega2_nvrm_ioctl fr view ulong 12 st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 to uint
60hl = get fr 4
61pl = get fr 6
62if or gt hl HN gt pl PN
63ret 32
64end
65z = memcpy get fr 9 get fr 3 hl
66if fk_srefuse st h fr
67ret 1
68end
69z = memcpy get fr 10 get fr 5 pl
70put st 0 1
71put st 1 get fr 1
72put st 2 get fr 2
73put st 3 hl
74put st 4 pl
75r = fk_step st h p t fr
76z = memcpy get fr 3 get fr 9 hl
77z = memcpy get fr 5 get fr 10 pl
78ret r
79end
80
81export fn fake_reset fr view ulong 12 st edit ulong 64 t edit ulong 8 to ulong
82for i ulong 64
83put st i 0
84end
85put st 5 and get fr 0 255
86put t 0 0
87ret 0
88end
89
90export fn fake_get fr view ulong 12 st edit ulong 64 to ulong
91i = and get fr 0 UMAX
92if lt i 64
93ret get st i
94end
95ret 18446744073709551615
96end
97
98export fn fake_trapped fr view ulong 12 t edit ulong 8 to ulong
99ret get t 0
100end