omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / native / v2 / dev / hdev.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Fake-device only: no NVIDIA device is opened. Linux ABI constants are checked against libc in dcall.c. |
| 3 | om2 |
| 4 | export fn nread fd long to long |
| 5 | b = new uchar 4 0 |
| 6 | r = devctl int fd uint 21531 b 0 4 |
| 7 | if lt r 0 |
| 8 | ret r |
| 9 | end |
| 10 | ret long or or or uint get b 0 shl uint get b 1 8 shl uint get b 2 16 shl uint get b 3 24 |
| 11 | end |
| 12 | export fn ctl fd long to long |
| 13 | b = new uchar 48 0 |
| 14 | ret devctl int fd uint 3224389163 b 0 48 |
| 15 | end |
| 16 | export fn call fd long to long |
| 17 | h = new uchar 32 0 |
| 18 | p = new uchar 16 0 |
| 19 | ret devcall int fd uint 3223340587 h 0 32 p 0 16 |
| 20 | end |
| 21 | export fn uvm fd long to long |
| 22 | b = new uchar 8 0 |
| 23 | ret uvmctl int fd uint 75 b 0 8 |
| 24 | end |
| 25 | export fn mapping fd long to long |
| 26 | ret mapnew int fd 0 4096 3 1 |
| 27 | end |
| 28 | export fn anon to long |
| 29 | ret mapnew neg int 1 0 4096 3 34 |
| 30 | end |
| 31 | export fn address h long to ulong |
| 32 | ret mapaddr h |
| 33 | end |
| 34 | export fn drop h long to long |
| 35 | ret mapdrop h |
| 36 | end |
| 37 | export fn publish h long v ulong to long |
| 38 | p = new uchar 16 7 |
| 39 | w = mapwrite h 16 p 0 16 |
| 40 | cpufence |
| 41 | w = mapset h 8 8 v |
| 42 | w = mapset h 0 4 1 |
| 43 | ret w |
| 44 | end |
| 45 | export fn fetch h long to long |
| 46 | p = new uchar 16 0 |
| 47 | n = mapread h 16 p 0 16 |
| 48 | v = mapget h 8 8 |
| 49 | ret add long v long get p 15 |
| 50 | end |
| 51 | export fn rd h long to ulong |
| 52 | ret mapget h 0 4 |
| 53 | end |
| 54 | export fn mono to long |
| 55 | ret monons |
| 56 | end |
| 57 | export fn wall to long |
| 58 | ret realns |
| 59 | end |
| 60 | export fn pause n long to long |
| 61 | ret sleepns n |
| 62 | end |
| 63 | export fn reserve addr ulong bytes ulong to long |
| 64 | ret maphold addr bytes |
| 65 | end |
| 66 | export fn attach h long fd long to long |
| 67 | ret mapbind h int fd 0 3 |
| 68 | end |
| 69 | export fn store h long to long |
| 70 | ret mapset h 0 4 1 |
| 71 | end |
| 72 | note Exact ABI1 requests from the Wolfram-checked compiler aien-ioctl matrix. |
| 73 | note The oversized backing view leaves the exact-length guard, not bounds, as the short/long oracle. |
| 74 | export fn aiinfo fd long count ulong to long |
| 75 | b = new uchar 4096 0 |
| 76 | ret devctl int fd uint 2154840336 b 0 count |
| 77 | end |
| 78 | export fn aialloc fd long count ulong to long |
| 79 | b = new uchar 4096 0 |
| 80 | ret devctl int fd uint 3224387873 b 0 count |
| 81 | end |
| 82 | export fn aifree fd long count ulong to long |
| 83 | b = new uchar 4096 0 |
| 84 | ret devctl int fd uint 3222815010 b 0 count |
| 85 | end |
| 86 | export fn aicreate fd long count ulong to long |
| 87 | b = new uchar 4096 0 |
| 88 | ret devctl int fd uint 3225960739 b 0 count |
| 89 | end |
| 90 | export fn aidrop fd long count ulong to long |
| 91 | b = new uchar 4096 0 |
| 92 | ret devctl int fd uint 3222815012 b 0 count |
| 93 | end |