break monster VM into small pieces :D
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
use super::CapFlags;
|
||||
|
||||
pub const NONE: CapFlags = 0;
|
||||
pub const SYSTEM: CapFlags = 1 << 0;
|
||||
pub const GFX: CapFlags = 1 << 1;
|
||||
pub const INPUT: CapFlags = 1 << 2;
|
||||
pub const AUDIO: CapFlags = 1 << 3;
|
||||
pub const FS: CapFlags = 1 << 4;
|
||||
pub const LOG: CapFlags = 1 << 5;
|
||||
pub const ASSET: CapFlags = 1 << 6;
|
||||
pub const BANK: CapFlags = 1 << 7;
|
||||
pub const ALL: CapFlags = SYSTEM | GFX | INPUT | AUDIO | FS | LOG | ASSET | BANK;
|
||||
@@ -0,0 +1,53 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::AssetLoad,
|
||||
"asset",
|
||||
"load",
|
||||
1,
|
||||
3,
|
||||
1,
|
||||
caps::ASSET,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::AssetStatus,
|
||||
"asset",
|
||||
"status",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::ASSET,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::AssetCommit,
|
||||
"asset",
|
||||
"commit",
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
caps::ASSET,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::AssetCancel,
|
||||
"asset",
|
||||
"cancel",
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
caps::ASSET,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::AudioPlaySample,
|
||||
"audio",
|
||||
"play_sample",
|
||||
1,
|
||||
5,
|
||||
0,
|
||||
caps::AUDIO,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::AudioPlay,
|
||||
"audio",
|
||||
"play",
|
||||
1,
|
||||
7,
|
||||
0,
|
||||
caps::AUDIO,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::BankInfo,
|
||||
"bank",
|
||||
"info",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::BANK,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::BankSlotInfo,
|
||||
"bank",
|
||||
"slot_info",
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
caps::BANK,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,78 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::FsOpen,
|
||||
"fs",
|
||||
"open",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::FS,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::FsRead,
|
||||
"fs",
|
||||
"read",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::FS,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::FsWrite,
|
||||
"fs",
|
||||
"write",
|
||||
1,
|
||||
2,
|
||||
1,
|
||||
caps::FS,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(Syscall::FsClose, "fs", "close", 1, 1, 0, caps::FS, Determinism::Deterministic, false, 5),
|
||||
entry(
|
||||
Syscall::FsListDir,
|
||||
"fs",
|
||||
"list_dir",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::FS,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::FsExists,
|
||||
"fs",
|
||||
"exists",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::FS,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::FsDelete,
|
||||
"fs",
|
||||
"delete",
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
caps::FS,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,113 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::GfxClear,
|
||||
"gfx",
|
||||
"clear",
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxFillRect,
|
||||
"gfx",
|
||||
"fill_rect",
|
||||
1,
|
||||
5,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxDrawLine,
|
||||
"gfx",
|
||||
"draw_line",
|
||||
1,
|
||||
5,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxDrawCircle,
|
||||
"gfx",
|
||||
"draw_circle",
|
||||
1,
|
||||
4,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxDrawDisc,
|
||||
"gfx",
|
||||
"draw_disc",
|
||||
1,
|
||||
5,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxDrawSquare,
|
||||
"gfx",
|
||||
"draw_square",
|
||||
1,
|
||||
6,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxSetSprite,
|
||||
"gfx",
|
||||
"set_sprite",
|
||||
1,
|
||||
10,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxDrawText,
|
||||
"gfx",
|
||||
"draw_text",
|
||||
1,
|
||||
4,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
entry(
|
||||
Syscall::GfxClear565,
|
||||
"gfx",
|
||||
"clear_565",
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
caps::GFX,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
20,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,305 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::InputGetPad,
|
||||
"input",
|
||||
"get_pad",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::InputGetPadPressed,
|
||||
"input",
|
||||
"get_pad_pressed",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::InputGetPadReleased,
|
||||
"input",
|
||||
"get_pad_released",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::InputGetPadHold,
|
||||
"input",
|
||||
"get_pad_hold",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::InputPadSnapshot,
|
||||
"input",
|
||||
"pad_snapshot",
|
||||
1,
|
||||
0,
|
||||
48,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::InputTouchSnapshot,
|
||||
"input",
|
||||
"touch_snapshot",
|
||||
1,
|
||||
0,
|
||||
6,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchGetX,
|
||||
"input",
|
||||
"touch_get_x",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchGetY,
|
||||
"input",
|
||||
"touch_get_y",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchIsDown,
|
||||
"input",
|
||||
"touch_is_down",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchIsPressed,
|
||||
"input",
|
||||
"touch_is_pressed",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchIsReleased,
|
||||
"input",
|
||||
"touch_is_released",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchGetHold,
|
||||
"input",
|
||||
"touch_get_hold",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::TouchGetFinger,
|
||||
"input",
|
||||
"touch_get_finger",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetUp,
|
||||
"input",
|
||||
"pad_get_up",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetDown,
|
||||
"input",
|
||||
"pad_get_down",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetLeft,
|
||||
"input",
|
||||
"pad_get_left",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetRight,
|
||||
"input",
|
||||
"pad_get_right",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetA,
|
||||
"input",
|
||||
"pad_get_a",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetB,
|
||||
"input",
|
||||
"pad_get_b",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetX,
|
||||
"input",
|
||||
"pad_get_x",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetY,
|
||||
"input",
|
||||
"pad_get_y",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetL,
|
||||
"input",
|
||||
"pad_get_l",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetR,
|
||||
"input",
|
||||
"pad_get_r",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetStart,
|
||||
"input",
|
||||
"pad_get_start",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::PadGetSelect,
|
||||
"input",
|
||||
"pad_get_select",
|
||||
1,
|
||||
0,
|
||||
4,
|
||||
caps::INPUT,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::LogWrite,
|
||||
"log",
|
||||
"write",
|
||||
1,
|
||||
2,
|
||||
0,
|
||||
caps::LOG,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
entry(
|
||||
Syscall::LogWriteTag,
|
||||
"log",
|
||||
"write_tag",
|
||||
1,
|
||||
3,
|
||||
0,
|
||||
caps::LOG,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
5,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,51 @@
|
||||
mod asset;
|
||||
mod audio;
|
||||
mod bank;
|
||||
mod fs;
|
||||
mod gfx;
|
||||
mod input;
|
||||
mod log;
|
||||
mod system;
|
||||
|
||||
use super::{CapFlags, Determinism, Syscall, SyscallMeta, SyscallRegistryEntry};
|
||||
|
||||
pub(crate) const fn entry(
|
||||
syscall: Syscall,
|
||||
module: &'static str,
|
||||
name: &'static str,
|
||||
version: u16,
|
||||
arg_slots: u8,
|
||||
ret_slots: u16,
|
||||
caps: CapFlags,
|
||||
determinism: Determinism,
|
||||
may_allocate: bool,
|
||||
cost_hint: u32,
|
||||
) -> SyscallRegistryEntry {
|
||||
SyscallRegistryEntry {
|
||||
syscall,
|
||||
meta: SyscallMeta {
|
||||
id: syscall as u32,
|
||||
module,
|
||||
name,
|
||||
version,
|
||||
arg_slots,
|
||||
ret_slots,
|
||||
caps,
|
||||
determinism,
|
||||
may_allocate,
|
||||
cost_hint,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn all_entries() -> impl Iterator<Item = &'static SyscallRegistryEntry> {
|
||||
system::ENTRIES
|
||||
.iter()
|
||||
.chain(gfx::ENTRIES.iter())
|
||||
.chain(input::ENTRIES.iter())
|
||||
.chain(audio::ENTRIES.iter())
|
||||
.chain(fs::ENTRIES.iter())
|
||||
.chain(log::ENTRIES.iter())
|
||||
.chain(asset::ENTRIES.iter())
|
||||
.chain(bank::ENTRIES.iter())
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
use super::entry;
|
||||
use crate::syscalls::{Determinism, Syscall, SyscallRegistryEntry, caps};
|
||||
|
||||
pub(crate) const ENTRIES: &[SyscallRegistryEntry] = &[
|
||||
entry(
|
||||
Syscall::SystemHasCart,
|
||||
"system",
|
||||
"has_cart",
|
||||
1,
|
||||
0,
|
||||
1,
|
||||
caps::SYSTEM,
|
||||
Determinism::Deterministic,
|
||||
false,
|
||||
1,
|
||||
),
|
||||
entry(
|
||||
Syscall::SystemRunCart,
|
||||
"system",
|
||||
"run_cart",
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
caps::SYSTEM,
|
||||
Determinism::NonDeterministic,
|
||||
false,
|
||||
50,
|
||||
),
|
||||
];
|
||||
@@ -0,0 +1,137 @@
|
||||
use super::{Syscall, SyscallMeta, domains};
|
||||
|
||||
pub(crate) fn meta_for(syscall: Syscall) -> &'static SyscallMeta {
|
||||
for entry in domains::all_entries() {
|
||||
if entry.syscall == syscall {
|
||||
return &entry.meta;
|
||||
}
|
||||
}
|
||||
panic!("Missing SyscallMeta for {:?}", syscall);
|
||||
}
|
||||
|
||||
impl Syscall {
|
||||
pub fn from_u32(id: u32) -> Option<Self> {
|
||||
match id {
|
||||
0x0001 => Some(Self::SystemHasCart),
|
||||
0x0002 => Some(Self::SystemRunCart),
|
||||
0x1001 => Some(Self::GfxClear),
|
||||
0x1002 => Some(Self::GfxFillRect),
|
||||
0x1003 => Some(Self::GfxDrawLine),
|
||||
0x1004 => Some(Self::GfxDrawCircle),
|
||||
0x1005 => Some(Self::GfxDrawDisc),
|
||||
0x1006 => Some(Self::GfxDrawSquare),
|
||||
0x1007 => Some(Self::GfxSetSprite),
|
||||
0x1008 => Some(Self::GfxDrawText),
|
||||
0x1010 => Some(Self::GfxClear565),
|
||||
0x2001 => Some(Self::InputGetPad),
|
||||
0x2002 => Some(Self::InputGetPadPressed),
|
||||
0x2003 => Some(Self::InputGetPadReleased),
|
||||
0x2004 => Some(Self::InputGetPadHold),
|
||||
0x2010 => Some(Self::InputPadSnapshot),
|
||||
0x2011 => Some(Self::InputTouchSnapshot),
|
||||
0x2101 => Some(Self::TouchGetX),
|
||||
0x2102 => Some(Self::TouchGetY),
|
||||
0x2103 => Some(Self::TouchIsDown),
|
||||
0x2104 => Some(Self::TouchIsPressed),
|
||||
0x2105 => Some(Self::TouchIsReleased),
|
||||
0x2106 => Some(Self::TouchGetHold),
|
||||
0x2107 => Some(Self::TouchGetFinger),
|
||||
0x2200 => Some(Self::PadGetUp),
|
||||
0x2201 => Some(Self::PadGetDown),
|
||||
0x2202 => Some(Self::PadGetLeft),
|
||||
0x2203 => Some(Self::PadGetRight),
|
||||
0x2204 => Some(Self::PadGetA),
|
||||
0x2205 => Some(Self::PadGetB),
|
||||
0x2206 => Some(Self::PadGetX),
|
||||
0x2207 => Some(Self::PadGetY),
|
||||
0x2208 => Some(Self::PadGetL),
|
||||
0x2209 => Some(Self::PadGetR),
|
||||
0x220A => Some(Self::PadGetStart),
|
||||
0x220B => Some(Self::PadGetSelect),
|
||||
0x3001 => Some(Self::AudioPlaySample),
|
||||
0x3002 => Some(Self::AudioPlay),
|
||||
0x4001 => Some(Self::FsOpen),
|
||||
0x4002 => Some(Self::FsRead),
|
||||
0x4003 => Some(Self::FsWrite),
|
||||
0x4004 => Some(Self::FsClose),
|
||||
0x4005 => Some(Self::FsListDir),
|
||||
0x4006 => Some(Self::FsExists),
|
||||
0x4007 => Some(Self::FsDelete),
|
||||
0x5001 => Some(Self::LogWrite),
|
||||
0x5002 => Some(Self::LogWriteTag),
|
||||
0x6001 => Some(Self::AssetLoad),
|
||||
0x6002 => Some(Self::AssetStatus),
|
||||
0x6003 => Some(Self::AssetCommit),
|
||||
0x6004 => Some(Self::AssetCancel),
|
||||
0x6101 => Some(Self::BankInfo),
|
||||
0x6102 => Some(Self::BankSlotInfo),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn args_count(&self) -> usize {
|
||||
super::meta_for(*self).arg_slots as usize
|
||||
}
|
||||
|
||||
pub fn results_count(&self) -> usize {
|
||||
super::meta_for(*self).ret_slots as usize
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::SystemHasCart => "SystemHasCart",
|
||||
Self::SystemRunCart => "SystemRunCart",
|
||||
Self::GfxClear => "GfxClear",
|
||||
Self::GfxFillRect => "GfxFillRect",
|
||||
Self::GfxDrawLine => "GfxDrawLine",
|
||||
Self::GfxDrawCircle => "GfxDrawCircle",
|
||||
Self::GfxDrawDisc => "GfxDrawDisc",
|
||||
Self::GfxDrawSquare => "GfxDrawSquare",
|
||||
Self::GfxSetSprite => "GfxSetSprite",
|
||||
Self::GfxDrawText => "GfxDrawText",
|
||||
Self::GfxClear565 => "GfxClear565",
|
||||
Self::InputGetPad => "InputGetPad",
|
||||
Self::InputGetPadPressed => "InputGetPadPressed",
|
||||
Self::InputGetPadReleased => "InputGetPadReleased",
|
||||
Self::InputGetPadHold => "InputGetPadHold",
|
||||
Self::InputPadSnapshot => "InputPadSnapshot",
|
||||
Self::InputTouchSnapshot => "InputTouchSnapshot",
|
||||
Self::TouchGetX => "TouchGetX",
|
||||
Self::TouchGetY => "TouchGetY",
|
||||
Self::TouchIsDown => "TouchIsDown",
|
||||
Self::TouchIsPressed => "TouchIsPressed",
|
||||
Self::TouchIsReleased => "TouchIsReleased",
|
||||
Self::TouchGetHold => "TouchGetHold",
|
||||
Self::TouchGetFinger => "TouchGetFinger",
|
||||
Self::PadGetUp => "PadGetUp",
|
||||
Self::PadGetDown => "PadGetDown",
|
||||
Self::PadGetLeft => "PadGetLeft",
|
||||
Self::PadGetRight => "PadGetRight",
|
||||
Self::PadGetA => "PadGetA",
|
||||
Self::PadGetB => "PadGetB",
|
||||
Self::PadGetX => "PadGetX",
|
||||
Self::PadGetY => "PadGetY",
|
||||
Self::PadGetL => "PadGetL",
|
||||
Self::PadGetR => "PadGetR",
|
||||
Self::PadGetStart => "PadGetStart",
|
||||
Self::PadGetSelect => "PadGetSelect",
|
||||
Self::AudioPlaySample => "AudioPlaySample",
|
||||
Self::AudioPlay => "AudioPlay",
|
||||
Self::FsOpen => "FsOpen",
|
||||
Self::FsRead => "FsRead",
|
||||
Self::FsWrite => "FsWrite",
|
||||
Self::FsClose => "FsClose",
|
||||
Self::FsListDir => "FsListDir",
|
||||
Self::FsExists => "FsExists",
|
||||
Self::FsDelete => "FsDelete",
|
||||
Self::LogWrite => "LogWrite",
|
||||
Self::LogWriteTag => "LogWriteTag",
|
||||
Self::AssetLoad => "AssetLoad",
|
||||
Self::AssetStatus => "AssetStatus",
|
||||
Self::AssetCommit => "AssetCommit",
|
||||
Self::AssetCancel => "AssetCancel",
|
||||
Self::BankInfo => "BankInfo",
|
||||
Self::BankSlotInfo => "BankSlotInfo",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
use super::{CapFlags, SyscallMeta, domains};
|
||||
|
||||
/// Canonical identity triple for a syscall.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct SyscallIdentity {
|
||||
pub module: &'static str,
|
||||
pub name: &'static str,
|
||||
pub version: u16,
|
||||
}
|
||||
|
||||
impl SyscallIdentity {
|
||||
pub fn key(&self) -> (&'static str, &'static str, u16) {
|
||||
(self.module, self.name, self.version)
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolved syscall information provided to the loader/VM.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct SyscallResolved {
|
||||
pub id: u32,
|
||||
pub meta: SyscallMeta,
|
||||
}
|
||||
|
||||
/// Load-time error for syscall resolution.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum LoadError {
|
||||
UnknownSyscall {
|
||||
module: &'static str,
|
||||
name: &'static str,
|
||||
version: u16,
|
||||
},
|
||||
MissingCapability {
|
||||
required: CapFlags,
|
||||
provided: CapFlags,
|
||||
module: &'static str,
|
||||
name: &'static str,
|
||||
version: u16,
|
||||
},
|
||||
}
|
||||
|
||||
/// Load-time error for PBX-declared syscall resolution.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum DeclaredLoadError {
|
||||
UnknownSyscall {
|
||||
module: String,
|
||||
name: String,
|
||||
version: u16,
|
||||
},
|
||||
MissingCapability {
|
||||
required: CapFlags,
|
||||
provided: CapFlags,
|
||||
module: String,
|
||||
name: String,
|
||||
version: u16,
|
||||
},
|
||||
AbiMismatch {
|
||||
module: String,
|
||||
name: String,
|
||||
version: u16,
|
||||
declared_arg_slots: u16,
|
||||
declared_ret_slots: u16,
|
||||
expected_arg_slots: u16,
|
||||
expected_ret_slots: u16,
|
||||
},
|
||||
}
|
||||
|
||||
fn resolve_syscall_impl(module: &str, name: &str, version: u16) -> Option<SyscallResolved> {
|
||||
for entry in domains::all_entries() {
|
||||
if entry.meta.module == module && entry.meta.name == name && entry.meta.version == version {
|
||||
return Some(SyscallResolved { id: entry.meta.id, meta: entry.meta });
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn resolve_syscall(
|
||||
module: &'static str,
|
||||
name: &'static str,
|
||||
version: u16,
|
||||
) -> Option<SyscallResolved> {
|
||||
resolve_syscall_impl(module, name, version)
|
||||
}
|
||||
|
||||
pub fn resolve_program_syscalls(
|
||||
declared: &[SyscallIdentity],
|
||||
caps: CapFlags,
|
||||
) -> Result<Vec<SyscallResolved>, LoadError> {
|
||||
let mut out = Vec::with_capacity(declared.len());
|
||||
for ident in declared {
|
||||
let Some(res) = resolve_syscall(ident.module, ident.name, ident.version) else {
|
||||
return Err(LoadError::UnknownSyscall {
|
||||
module: ident.module,
|
||||
name: ident.name,
|
||||
version: ident.version,
|
||||
});
|
||||
};
|
||||
let missing = res.meta.caps & !caps;
|
||||
if missing != 0 {
|
||||
return Err(LoadError::MissingCapability {
|
||||
required: res.meta.caps,
|
||||
provided: caps,
|
||||
module: ident.module,
|
||||
name: ident.name,
|
||||
version: ident.version,
|
||||
});
|
||||
}
|
||||
out.push(res);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn resolve_declared_program_syscalls(
|
||||
declared: &[prometeu_bytecode::SyscallDecl],
|
||||
caps: CapFlags,
|
||||
) -> Result<Vec<SyscallResolved>, DeclaredLoadError> {
|
||||
let mut out = Vec::with_capacity(declared.len());
|
||||
|
||||
for decl in declared {
|
||||
let Some(res) = resolve_syscall_impl(&decl.module, &decl.name, decl.version) else {
|
||||
return Err(DeclaredLoadError::UnknownSyscall {
|
||||
module: decl.module.clone(),
|
||||
name: decl.name.clone(),
|
||||
version: decl.version,
|
||||
});
|
||||
};
|
||||
|
||||
let missing = res.meta.caps & !caps;
|
||||
if missing != 0 {
|
||||
return Err(DeclaredLoadError::MissingCapability {
|
||||
required: res.meta.caps,
|
||||
provided: caps,
|
||||
module: decl.module.clone(),
|
||||
name: decl.name.clone(),
|
||||
version: decl.version,
|
||||
});
|
||||
}
|
||||
|
||||
let expected_arg_slots = u16::from(res.meta.arg_slots);
|
||||
let expected_ret_slots = res.meta.ret_slots;
|
||||
if decl.arg_slots != expected_arg_slots || decl.ret_slots != expected_ret_slots {
|
||||
return Err(DeclaredLoadError::AbiMismatch {
|
||||
module: decl.module.clone(),
|
||||
name: decl.name.clone(),
|
||||
version: decl.version,
|
||||
declared_arg_slots: decl.arg_slots,
|
||||
declared_ret_slots: decl.ret_slots,
|
||||
expected_arg_slots,
|
||||
expected_ret_slots,
|
||||
});
|
||||
}
|
||||
|
||||
out.push(res);
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
use super::*;
|
||||
|
||||
fn all_syscalls() -> Vec<Syscall> {
|
||||
domains::all_entries().map(|entry| entry.syscall).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_syscall_has_metadata() {
|
||||
for sc in all_syscalls() {
|
||||
let m = meta_for(sc);
|
||||
assert_eq!(m.id, sc as u32, "id mismatch for {:?}", sc);
|
||||
assert!(!m.module.is_empty(), "module must be non-empty for id=0x{:08X}", m.id);
|
||||
assert!(!m.name.is_empty(), "name must be non-empty for id=0x{:08X}", m.id);
|
||||
assert!(m.version > 0, "version must be > 0 for id=0x{:08X}", m.id);
|
||||
}
|
||||
|
||||
use std::collections::HashSet;
|
||||
let mut ids = HashSet::new();
|
||||
let mut identities = HashSet::new();
|
||||
let mut count = 0usize;
|
||||
for entry in domains::all_entries() {
|
||||
count += 1;
|
||||
assert!(ids.insert(entry.meta.id), "duplicate syscall id 0x{:08X}", entry.meta.id);
|
||||
let parsed = Syscall::from_u32(entry.meta.id).expect("id not recognized by enum mapping");
|
||||
assert_eq!(parsed as u32, entry.meta.id);
|
||||
|
||||
let key = (entry.meta.module, entry.meta.name, entry.meta.version);
|
||||
assert!(
|
||||
identities.insert(key),
|
||||
"duplicate canonical identity: ({}.{}, v{})",
|
||||
entry.meta.module,
|
||||
entry.meta.name,
|
||||
entry.meta.version
|
||||
);
|
||||
}
|
||||
|
||||
assert_eq!(count, all_syscalls().len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolver_returns_expected_id_for_known_identity() {
|
||||
let id = resolve_syscall("gfx", "clear", 1).expect("known identity must resolve");
|
||||
assert_eq!(id.id, 0x1001);
|
||||
assert_eq!(id.meta.module, "gfx");
|
||||
assert_eq!(id.meta.name, "clear");
|
||||
assert_eq!(id.meta.version, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolver_rejects_unknown_identity() {
|
||||
let res = resolve_syscall("gfx", "nonexistent", 1);
|
||||
assert!(res.is_none());
|
||||
|
||||
let requested = [SyscallIdentity { module: "gfx", name: "nonexistent", version: 1 }];
|
||||
let err = resolve_program_syscalls(&requested, 0).unwrap_err();
|
||||
match err {
|
||||
LoadError::UnknownSyscall { module, name, version } => {
|
||||
assert_eq!(module, "gfx");
|
||||
assert_eq!(name, "nonexistent");
|
||||
assert_eq!(version, 1);
|
||||
}
|
||||
_ => panic!("expected UnknownSyscall error"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolver_enforces_capabilities() {
|
||||
let requested = [SyscallIdentity { module: "gfx", name: "clear", version: 1 }];
|
||||
let err = resolve_program_syscalls(&requested, 0).unwrap_err();
|
||||
match err {
|
||||
LoadError::MissingCapability { required, provided, module, name, version } => {
|
||||
assert_eq!(module, "gfx");
|
||||
assert_eq!(name, "clear");
|
||||
assert_eq!(version, 1);
|
||||
assert_ne!(required, 0);
|
||||
assert_eq!(provided, 0);
|
||||
}
|
||||
_ => panic!("expected MissingCapability error"),
|
||||
}
|
||||
|
||||
let ok = resolve_program_syscalls(&requested, caps::GFX).expect("must resolve with caps");
|
||||
assert_eq!(ok.len(), 1);
|
||||
assert_eq!(ok[0].id, 0x1001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declared_resolver_returns_expected_id_for_known_identity() {
|
||||
let declared = [prometeu_bytecode::SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
ret_slots: 0,
|
||||
}];
|
||||
|
||||
let ok =
|
||||
resolve_declared_program_syscalls(&declared, caps::GFX).expect("must resolve with ABI");
|
||||
assert_eq!(ok.len(), 1);
|
||||
assert_eq!(ok[0].id, 0x1001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declared_resolver_rejects_unknown_identity() {
|
||||
let declared = [prometeu_bytecode::SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
name: "nonexistent".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
ret_slots: 0,
|
||||
}];
|
||||
|
||||
let err = resolve_declared_program_syscalls(&declared, caps::GFX).unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
DeclaredLoadError::UnknownSyscall {
|
||||
module: "gfx".into(),
|
||||
name: "nonexistent".into(),
|
||||
version: 1,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declared_resolver_rejects_missing_capability() {
|
||||
let declared = [prometeu_bytecode::SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
arg_slots: 1,
|
||||
ret_slots: 0,
|
||||
}];
|
||||
|
||||
let err = resolve_declared_program_syscalls(&declared, caps::NONE).unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
DeclaredLoadError::MissingCapability {
|
||||
required: caps::GFX,
|
||||
provided: caps::NONE,
|
||||
module: "gfx".into(),
|
||||
name: "clear".into(),
|
||||
version: 1,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn declared_resolver_rejects_abi_mismatch() {
|
||||
let declared = [prometeu_bytecode::SyscallDecl {
|
||||
module: "gfx".into(),
|
||||
name: "draw_line".into(),
|
||||
version: 1,
|
||||
arg_slots: 4,
|
||||
ret_slots: 0,
|
||||
}];
|
||||
|
||||
let err = resolve_declared_program_syscalls(&declared, caps::GFX).unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
DeclaredLoadError::AbiMismatch {
|
||||
module: "gfx".into(),
|
||||
name: "draw_line".into(),
|
||||
version: 1,
|
||||
declared_arg_slots: 4,
|
||||
declared_ret_slots: 0,
|
||||
expected_arg_slots: 5,
|
||||
expected_ret_slots: 0,
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user