Barebones rust example working in user space.

Requires manually copying the executable over to the image.
This commit is contained in:
Drew Galbraith 2024-06-08 15:47:58 -07:00
parent 844f55c7d0
commit b0048b0a4f
13 changed files with 707 additions and 1 deletions

3
.gitignore vendored
View File

@ -5,3 +5,6 @@ compile_commands.json
sysroot/bin
sysroot/usr/bin
rust/target
yunq/venv

View File

@ -69,7 +69,14 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
reinterpret_cast<Elf64ProgramHeader*>(base + header->phoff);
for (uint64_t i = 0; i < header->phnum; i++) {
Elf64ProgramHeader& program = programs[i];
if (program.type != 1) {
// Only load loadable types.
// TODO: This may break if the stack is far away?
continue;
}
#if MAM_PROC_DEBUG
dbgln(glcr::StrFormat("Program:\n\tType: {}\n\tFlags: {}\n\t", program.type,
program.flags));
dbgln("Create mem object");
#endif
uint64_t page_offset = program.vaddr & 0xFFF;
@ -93,7 +100,8 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
memcpy(base + program.offset, program.filesz, vaddr + page_offset);
#if MAM_PROC_DEBUG
dbgln("Map Foreign");
dbgln(glcr::StrFormat("Map Foreign: {x} {x} {x}",
program.vaddr - page_offset, size, vaddr));
#endif
check(ZAddressSpaceMap(as_cap, program.vaddr - page_offset, mem_cap, 0,
&vaddr));
@ -124,6 +132,10 @@ glcr::ErrorOr<z_cap_t> SpawnProcessFromElfRegion(uint64_t program,
uint64_t entry_point = LoadElfProgram(program, as_cap);
if (entry_point == 0) {
crash("Entry Point == 0", glcr::INTERNAL);
}
#if MAM_PROC_DEBUG
dbgln("Thread Create");
#endif

6
rust/.cargo/config.toml Normal file
View File

@ -0,0 +1,6 @@
[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]
[build]
target = "x86_64-acadia-os.json"

14
rust/Cargo.lock generated Normal file
View File

@ -0,0 +1,14 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "mammoth"
version = "0.1.0"
[[package]]
name = "testbed"
version = "0.1.0"
dependencies = [
"mammoth",
]

14
rust/Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[workspace]
members = [
"lib/mammoth", "usr/testbed",
]
# the profile used for `cargo build`
[profile.dev]
panic = "abort" # disable stack unwinding on panic
# the profile used for `cargo build --release`
[profile.release]
panic = "abort" # disable stack unwinding on panic

View File

@ -0,0 +1,8 @@
[package]
name = "mammoth"
version = "0.1.0"
edition = "2021"
[dependencies]
[build-dependencies]

18
rust/lib/mammoth/build.rs Normal file
View File

@ -0,0 +1,18 @@
use std::env;
fn main() {
let mut curr_directory = env::current_dir().unwrap();
println!("{:?}", curr_directory);
assert!(curr_directory.pop());
assert!(curr_directory.pop());
assert!(curr_directory.pop());
curr_directory.push("builddbg");
curr_directory.push("zion");
println!(
"cargo:rustc-link-search={}",
curr_directory.to_str().unwrap()
);
println!("cargo:rustc-link-lib=zion_stub");
}

View File

@ -0,0 +1,571 @@
/* automatically generated by rust-bindgen 0.69.4 */
pub const _STDINT_H: u32 = 1;
pub const _FEATURES_H: u32 = 1;
pub const _ISOC95_SOURCE: u32 = 1;
pub const _ISOC99_SOURCE: u32 = 1;
pub const _ISOC11_SOURCE: u32 = 1;
pub const _ISOC2X_SOURCE: u32 = 1;
pub const _POSIX_SOURCE: u32 = 1;
pub const _POSIX_C_SOURCE: u32 = 200809;
pub const _XOPEN_SOURCE: u32 = 700;
pub const _XOPEN_SOURCE_EXTENDED: u32 = 1;
pub const _LARGEFILE64_SOURCE: u32 = 1;
pub const _DEFAULT_SOURCE: u32 = 1;
pub const _ATFILE_SOURCE: u32 = 1;
pub const _DYNAMIC_STACK_SIZE_SOURCE: u32 = 1;
pub const __GLIBC_USE_ISOC2X: u32 = 1;
pub const __USE_ISOC11: u32 = 1;
pub const __USE_ISOC99: u32 = 1;
pub const __USE_ISOC95: u32 = 1;
pub const __USE_ISOCXX11: u32 = 1;
pub const __USE_POSIX: u32 = 1;
pub const __USE_POSIX2: u32 = 1;
pub const __USE_POSIX199309: u32 = 1;
pub const __USE_POSIX199506: u32 = 1;
pub const __USE_XOPEN2K: u32 = 1;
pub const __USE_XOPEN2K8: u32 = 1;
pub const __USE_XOPEN: u32 = 1;
pub const __USE_XOPEN_EXTENDED: u32 = 1;
pub const __USE_UNIX98: u32 = 1;
pub const _LARGEFILE_SOURCE: u32 = 1;
pub const __USE_XOPEN2K8XSI: u32 = 1;
pub const __USE_XOPEN2KXSI: u32 = 1;
pub const __USE_LARGEFILE: u32 = 1;
pub const __USE_LARGEFILE64: u32 = 1;
pub const __WORDSIZE: u32 = 64;
pub const __WORDSIZE_TIME64_COMPAT32: u32 = 1;
pub const __SYSCALL_WORDSIZE: u32 = 64;
pub const __TIMESIZE: u32 = 64;
pub const __USE_MISC: u32 = 1;
pub const __USE_ATFILE: u32 = 1;
pub const __USE_DYNAMIC_STACK_SIZE: u32 = 1;
pub const __USE_GNU: u32 = 1;
pub const __USE_FORTIFY_LEVEL: u32 = 0;
pub const __GLIBC_USE_DEPRECATED_GETS: u32 = 0;
pub const __GLIBC_USE_DEPRECATED_SCANF: u32 = 0;
pub const __GLIBC_USE_C2X_STRTOL: u32 = 1;
pub const _STDC_PREDEF_H: u32 = 1;
pub const __STDC_IEC_559__: u32 = 1;
pub const __STDC_IEC_60559_BFP__: u32 = 201404;
pub const __STDC_IEC_559_COMPLEX__: u32 = 1;
pub const __STDC_IEC_60559_COMPLEX__: u32 = 201404;
pub const __STDC_ISO_10646__: u32 = 201706;
pub const __GNU_LIBRARY__: u32 = 6;
pub const __GLIBC__: u32 = 2;
pub const __GLIBC_MINOR__: u32 = 39;
pub const _SYS_CDEFS_H: u32 = 1;
pub const __glibc_c99_flexarr_available: u32 = 1;
pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI: u32 = 0;
pub const __HAVE_GENERIC_SELECTION: u32 = 0;
pub const __GLIBC_USE_LIB_EXT2: u32 = 1;
pub const __GLIBC_USE_IEC_60559_BFP_EXT: u32 = 1;
pub const __GLIBC_USE_IEC_60559_BFP_EXT_C2X: u32 = 1;
pub const __GLIBC_USE_IEC_60559_EXT: u32 = 1;
pub const __GLIBC_USE_IEC_60559_FUNCS_EXT: u32 = 1;
pub const __GLIBC_USE_IEC_60559_FUNCS_EXT_C2X: u32 = 1;
pub const __GLIBC_USE_IEC_60559_TYPES_EXT: u32 = 1;
pub const _BITS_TYPES_H: u32 = 1;
pub const _BITS_TYPESIZES_H: u32 = 1;
pub const __OFF_T_MATCHES_OFF64_T: u32 = 1;
pub const __INO_T_MATCHES_INO64_T: u32 = 1;
pub const __RLIM_T_MATCHES_RLIM64_T: u32 = 1;
pub const __STATFS_MATCHES_STATFS64: u32 = 1;
pub const __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64: u32 = 1;
pub const __FD_SETSIZE: u32 = 1024;
pub const _BITS_TIME64_H: u32 = 1;
pub const _BITS_WCHAR_H: u32 = 1;
pub const _BITS_STDINT_INTN_H: u32 = 1;
pub const _BITS_STDINT_UINTN_H: u32 = 1;
pub const _BITS_STDINT_LEAST_H: u32 = 1;
pub const INT8_MIN: i32 = -128;
pub const INT16_MIN: i32 = -32768;
pub const INT32_MIN: i32 = -2147483648;
pub const INT8_MAX: u32 = 127;
pub const INT16_MAX: u32 = 32767;
pub const INT32_MAX: u32 = 2147483647;
pub const UINT8_MAX: u32 = 255;
pub const UINT16_MAX: u32 = 65535;
pub const UINT32_MAX: u32 = 4294967295;
pub const INT_LEAST8_MIN: i32 = -128;
pub const INT_LEAST16_MIN: i32 = -32768;
pub const INT_LEAST32_MIN: i32 = -2147483648;
pub const INT_LEAST8_MAX: u32 = 127;
pub const INT_LEAST16_MAX: u32 = 32767;
pub const INT_LEAST32_MAX: u32 = 2147483647;
pub const UINT_LEAST8_MAX: u32 = 255;
pub const UINT_LEAST16_MAX: u32 = 65535;
pub const UINT_LEAST32_MAX: u32 = 4294967295;
pub const INT_FAST8_MIN: i32 = -128;
pub const INT_FAST16_MIN: i64 = -9223372036854775808;
pub const INT_FAST32_MIN: i64 = -9223372036854775808;
pub const INT_FAST8_MAX: u32 = 127;
pub const INT_FAST16_MAX: u64 = 9223372036854775807;
pub const INT_FAST32_MAX: u64 = 9223372036854775807;
pub const UINT_FAST8_MAX: u32 = 255;
pub const UINT_FAST16_MAX: i32 = -1;
pub const UINT_FAST32_MAX: i32 = -1;
pub const INTPTR_MIN: i64 = -9223372036854775808;
pub const INTPTR_MAX: u64 = 9223372036854775807;
pub const UINTPTR_MAX: i32 = -1;
pub const PTRDIFF_MIN: i64 = -9223372036854775808;
pub const PTRDIFF_MAX: u64 = 9223372036854775807;
pub const SIG_ATOMIC_MIN: i32 = -2147483648;
pub const SIG_ATOMIC_MAX: u32 = 2147483647;
pub const SIZE_MAX: i32 = -1;
pub const WINT_MIN: u32 = 0;
pub const WINT_MAX: u32 = 4294967295;
pub const INT8_WIDTH: u32 = 8;
pub const UINT8_WIDTH: u32 = 8;
pub const INT16_WIDTH: u32 = 16;
pub const UINT16_WIDTH: u32 = 16;
pub const INT32_WIDTH: u32 = 32;
pub const UINT32_WIDTH: u32 = 32;
pub const INT64_WIDTH: u32 = 64;
pub const UINT64_WIDTH: u32 = 64;
pub const INT_LEAST8_WIDTH: u32 = 8;
pub const UINT_LEAST8_WIDTH: u32 = 8;
pub const INT_LEAST16_WIDTH: u32 = 16;
pub const UINT_LEAST16_WIDTH: u32 = 16;
pub const INT_LEAST32_WIDTH: u32 = 32;
pub const UINT_LEAST32_WIDTH: u32 = 32;
pub const INT_LEAST64_WIDTH: u32 = 64;
pub const UINT_LEAST64_WIDTH: u32 = 64;
pub const INT_FAST8_WIDTH: u32 = 8;
pub const UINT_FAST8_WIDTH: u32 = 8;
pub const INT_FAST16_WIDTH: u32 = 64;
pub const UINT_FAST16_WIDTH: u32 = 64;
pub const INT_FAST32_WIDTH: u32 = 64;
pub const UINT_FAST32_WIDTH: u32 = 64;
pub const INT_FAST64_WIDTH: u32 = 64;
pub const UINT_FAST64_WIDTH: u32 = 64;
pub const INTPTR_WIDTH: u32 = 64;
pub const UINTPTR_WIDTH: u32 = 64;
pub const INTMAX_WIDTH: u32 = 64;
pub const UINTMAX_WIDTH: u32 = 64;
pub const PTRDIFF_WIDTH: u32 = 64;
pub const SIG_ATOMIC_WIDTH: u32 = 32;
pub const SIZE_WIDTH: u32 = 64;
pub const WCHAR_WIDTH: u32 = 32;
pub const WINT_WIDTH: u32 = 32;
pub type __u_char = ::core::ffi::c_uchar;
pub type __u_short = ::core::ffi::c_ushort;
pub type __u_int = ::core::ffi::c_uint;
pub type __u_long = ::core::ffi::c_ulong;
pub type __int8_t = ::core::ffi::c_schar;
pub type __uint8_t = ::core::ffi::c_uchar;
pub type __int16_t = ::core::ffi::c_short;
pub type __uint16_t = ::core::ffi::c_ushort;
pub type __int32_t = ::core::ffi::c_int;
pub type __uint32_t = ::core::ffi::c_uint;
pub type __int64_t = ::core::ffi::c_long;
pub type __uint64_t = ::core::ffi::c_ulong;
pub type __int_least8_t = __int8_t;
pub type __uint_least8_t = __uint8_t;
pub type __int_least16_t = __int16_t;
pub type __uint_least16_t = __uint16_t;
pub type __int_least32_t = __int32_t;
pub type __uint_least32_t = __uint32_t;
pub type __int_least64_t = __int64_t;
pub type __uint_least64_t = __uint64_t;
pub type __quad_t = ::core::ffi::c_long;
pub type __u_quad_t = ::core::ffi::c_ulong;
pub type __intmax_t = ::core::ffi::c_long;
pub type __uintmax_t = ::core::ffi::c_ulong;
pub type __dev_t = ::core::ffi::c_ulong;
pub type __uid_t = ::core::ffi::c_uint;
pub type __gid_t = ::core::ffi::c_uint;
pub type __ino_t = ::core::ffi::c_ulong;
pub type __ino64_t = ::core::ffi::c_ulong;
pub type __mode_t = ::core::ffi::c_uint;
pub type __nlink_t = ::core::ffi::c_ulong;
pub type __off_t = ::core::ffi::c_long;
pub type __off64_t = ::core::ffi::c_long;
pub type __pid_t = ::core::ffi::c_int;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __fsid_t {
pub __val: [::core::ffi::c_int; 2usize],
}
pub type __clock_t = ::core::ffi::c_long;
pub type __rlim_t = ::core::ffi::c_ulong;
pub type __rlim64_t = ::core::ffi::c_ulong;
pub type __id_t = ::core::ffi::c_uint;
pub type __time_t = ::core::ffi::c_long;
pub type __useconds_t = ::core::ffi::c_uint;
pub type __suseconds_t = ::core::ffi::c_long;
pub type __suseconds64_t = ::core::ffi::c_long;
pub type __daddr_t = ::core::ffi::c_int;
pub type __key_t = ::core::ffi::c_int;
pub type __clockid_t = ::core::ffi::c_int;
pub type __timer_t = *mut ::core::ffi::c_void;
pub type __blksize_t = ::core::ffi::c_long;
pub type __blkcnt_t = ::core::ffi::c_long;
pub type __blkcnt64_t = ::core::ffi::c_long;
pub type __fsblkcnt_t = ::core::ffi::c_ulong;
pub type __fsblkcnt64_t = ::core::ffi::c_ulong;
pub type __fsfilcnt_t = ::core::ffi::c_ulong;
pub type __fsfilcnt64_t = ::core::ffi::c_ulong;
pub type __fsword_t = ::core::ffi::c_long;
pub type __ssize_t = ::core::ffi::c_long;
pub type __syscall_slong_t = ::core::ffi::c_long;
pub type __syscall_ulong_t = ::core::ffi::c_ulong;
pub type __loff_t = __off64_t;
pub type __caddr_t = *mut ::core::ffi::c_char;
pub type __intptr_t = ::core::ffi::c_long;
pub type __socklen_t = ::core::ffi::c_uint;
pub type __sig_atomic_t = ::core::ffi::c_int;
pub type int_least8_t = __int_least8_t;
pub type int_least16_t = __int_least16_t;
pub type int_least32_t = __int_least32_t;
pub type int_least64_t = __int_least64_t;
pub type uint_least8_t = __uint_least8_t;
pub type uint_least16_t = __uint_least16_t;
pub type uint_least32_t = __uint_least32_t;
pub type uint_least64_t = __uint_least64_t;
pub type int_fast8_t = ::core::ffi::c_schar;
pub type int_fast16_t = ::core::ffi::c_long;
pub type int_fast32_t = ::core::ffi::c_long;
pub type int_fast64_t = ::core::ffi::c_long;
pub type uint_fast8_t = ::core::ffi::c_uchar;
pub type uint_fast16_t = ::core::ffi::c_ulong;
pub type uint_fast32_t = ::core::ffi::c_ulong;
pub type uint_fast64_t = ::core::ffi::c_ulong;
pub type intmax_t = __intmax_t;
pub type uintmax_t = __uintmax_t;
pub type z_err_t = u64;
pub const kZionProcessExit: u64 = 1;
pub const kZionProcessSpawn: u64 = 2;
pub const kZionProcessWait: u64 = 3;
pub const kZionThreadCreate: u64 = 16;
pub const kZionThreadStart: u64 = 17;
pub const kZionThreadExit: u64 = 18;
pub const kZionThreadWait: u64 = 19;
pub const kZionThreadSleep: u64 = 20;
pub const kZionAddressSpaceMap: u64 = 33;
pub const kZionAddressSpaceUnmap: u64 = 34;
pub const kZionMemoryObjectCreate: u64 = 48;
pub const kZionMemoryObjectCreatePhysical: u64 = 49;
pub const kZionMemoryObjectCreateContiguous: u64 = 50;
pub const kZionMemoryObjectDuplicate: u64 = 56;
pub const kZionMemoryObjectInspect: u64 = 57;
pub const kZionChannelCreate: u64 = 64;
pub const kZionChannelSend: u64 = 65;
pub const kZionChannelRecv: u64 = 66;
pub const kZionChannelSendRecv: u64 = 67;
pub const kZionPortCreate: u64 = 80;
pub const kZionPortSend: u64 = 81;
pub const kZionPortRecv: u64 = 82;
pub const kZionPortPoll: u64 = 83;
pub const kZionIrqRegister: u64 = 88;
pub const kZionEndpointCreate: u64 = 96;
pub const kZionEndpointSend: u64 = 97;
pub const kZionEndpointRecv: u64 = 98;
pub const kZionReplyPortSend: u64 = 99;
pub const kZionReplyPortRecv: u64 = 100;
pub const kZionEndpointCall: u64 = 101;
pub const kZionCapDuplicate: u64 = 112;
pub const kZionCapRelease: u64 = 113;
pub const kZionMutexCreate: u64 = 128;
pub const kZionMutexLock: u64 = 129;
pub const kZionMutexRelease: u64 = 130;
pub const kZionSemaphoreCreate: u64 = 131;
pub const kZionSemaphoreWait: u64 = 132;
pub const kZionSemaphoreSignal: u64 = 133;
pub const kZionDebug: u64 = 65536;
pub const kZIrqKbd: u64 = 34;
pub const kZIrqPci1: u64 = 48;
pub const kZIrqPci2: u64 = 49;
pub const kZIrqPci3: u64 = 50;
pub const kZIrqPci4: u64 = 51;
pub type z_cap_t = u64;
pub type z_perm_t = u64;
pub const kZionInvalidCapability: u64 = 0;
pub const kZionPerm_Write: u64 = 1;
pub const kZionPerm_Read: u64 = 2;
pub const kZionPerm_Transmit: u64 = 16;
pub const kZionPerm_Duplicate: u64 = 32;
pub const kZionPerm_SpawnProcess: u64 = 256;
pub const kZionPerm_SpawnThread: u64 = 512;
pub const kZionPerm_Lock: u64 = 256;
pub const kZionPerm_Release: u64 = 512;
pub const kZionPerm_Wait: u64 = 256;
pub const kZionPerm_Signal: u64 = 512;
pub const kZionPerm_None: z_perm_t = 0;
pub const kZionPerm_All: z_perm_t = 18446744073709551615;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZFramebufferInfo {
pub address_phys: u64,
pub width: u64,
pub height: u64,
pub pitch: u64,
pub bpp: u16,
pub memory_model: u8,
pub red_mask_size: u8,
pub red_mask_shift: u8,
pub green_mask_size: u8,
pub green_mask_shift: u8,
pub blue_mask_size: u8,
pub blue_mask_shift: u8,
}
extern "C" {
#[link_name = "\u{1}_Z8SysCall1mPKv"]
pub fn SysCall1(code: u64, req: *const ::core::ffi::c_void) -> z_err_t;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZProcessExitReq {
pub code: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZProcessSpawnReq {
pub proc_cap: z_cap_t,
pub bootstrap_cap: z_cap_t,
pub new_proc_cap: *mut z_cap_t,
pub new_vmas_cap: *mut z_cap_t,
pub new_bootstrap_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZProcessWaitReq {
pub proc_cap: z_cap_t,
pub exit_code: *mut z_err_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZThreadCreateReq {
pub proc_cap: z_cap_t,
pub thread_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZThreadStartReq {
pub thread_cap: z_cap_t,
pub entry: u64,
pub arg1: u64,
pub arg2: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZThreadExitReq {
pub _address: u8,
}
extern "C" {
#[link_name = "\u{1}_Z11ZThreadExitv"]
pub fn ZThreadExit() -> z_err_t;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZThreadWaitReq {
pub thread_cap: z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZThreadSleepReq {
pub millis: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZAddressSpaceMapReq {
pub vmas_cap: z_cap_t,
pub vmas_offset: u64,
pub vmmo_cap: z_cap_t,
pub align: u64,
pub vaddr: *mut u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZAddressSpaceUnmapReq {
pub vmas_cap: z_cap_t,
pub lower_addr: u64,
pub upper_addr: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMemoryObjectCreateReq {
pub size: u64,
pub vmmo_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMemoryObjectCreatePhysicalReq {
pub paddr: u64,
pub size: u64,
pub vmmo_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMemoryObjectCreateContiguousReq {
pub size: u64,
pub vmmo_cap: *mut z_cap_t,
pub paddr: *mut u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMemoryObjectDuplicateReq {
pub vmmo_cap: z_cap_t,
pub base_offset: u64,
pub length: u64,
pub new_vmmo_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMemoryObjectInspectReq {
pub vmmo_cap: z_cap_t,
pub size: *mut u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZChannelCreateReq {
pub channel1: *mut z_cap_t,
pub channel2: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZChannelSendReq {
pub chan_cap: z_cap_t,
pub num_bytes: u64,
pub data: *const ::core::ffi::c_void,
pub num_caps: u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZChannelRecvReq {
pub chan_cap: z_cap_t,
pub num_bytes: *mut u64,
pub data: *mut ::core::ffi::c_void,
pub num_caps: *mut u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZPortCreateReq {
pub port_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZPortSendReq {
pub port_cap: z_cap_t,
pub num_bytes: u64,
pub data: *const ::core::ffi::c_void,
pub num_caps: u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZPortRecvReq {
pub port_cap: z_cap_t,
pub num_bytes: *mut u64,
pub data: *mut ::core::ffi::c_void,
pub num_caps: *mut u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZPortPollReq {
pub port_cap: z_cap_t,
pub num_bytes: *mut u64,
pub data: *mut ::core::ffi::c_void,
pub num_caps: *mut u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZIrqRegisterReq {
pub irq_num: u64,
pub port_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZEndpointCreateReq {
pub endpoint_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZEndpointSendReq {
pub endpoint_cap: z_cap_t,
pub num_bytes: u64,
pub data: *const ::core::ffi::c_void,
pub num_caps: u64,
pub caps: *const z_cap_t,
pub reply_port_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZEndpointRecvReq {
pub endpoint_cap: z_cap_t,
pub num_bytes: *mut u64,
pub data: *mut ::core::ffi::c_void,
pub num_caps: *mut u64,
pub caps: *mut z_cap_t,
pub reply_port_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZReplyPortSendReq {
pub reply_port_cap: z_cap_t,
pub num_bytes: u64,
pub data: *const ::core::ffi::c_void,
pub num_caps: u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZReplyPortRecvReq {
pub reply_port_cap: z_cap_t,
pub num_bytes: *mut u64,
pub data: *mut ::core::ffi::c_void,
pub num_caps: *mut u64,
pub caps: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZCapDuplicateReq {
pub cap_in: z_cap_t,
pub perm_mask: z_perm_t,
pub cap_out: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZCapReleaseReq {
pub cap: z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMutexCreateReq {
pub mutex_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMutexLockReq {
pub mutex_cap: z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZMutexReleaseReq {
pub mutex_cap: z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSemaphoreCreateReq {
pub semaphore_cap: *mut z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSemaphoreWaitReq {
pub semaphore_cap: z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZSemaphoreSignalReq {
pub semaphore_cap: z_cap_t,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct ZDebugReq {
pub message: *const ::core::ffi::c_char,
pub size: u64,
}

View File

@ -0,0 +1,28 @@
#![no_std]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use core::ffi::c_void;
use core::panic::PanicInfo;
include!("bindings.rs");
fn syscall<T>(id: u64, req: &T) -> u64 {
unsafe { SysCall1(id, req as *const T as *const c_void) }
}
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
let req = ZProcessExitReq { code: 1 };
syscall(kZionProcessExit, &req);
unreachable!()
}
pub fn debug(msg: &str) {
let req = ZDebugReq {
message: msg.as_ptr() as *const i8,
size: msg.len() as u64,
};
syscall(kZionDebug, &req);
}

2
rust/rust-toolchain.toml Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

View File

@ -0,0 +1,7 @@
[package]
name = "testbed"
version = "0.1.0"
edition = "2021"
[dependencies]
mammoth = { path = "../../lib/mammoth" }

View File

@ -0,0 +1,10 @@
#![no_std]
#![no_main]
use mammoth::debug;
#[no_mangle]
pub extern "C" fn _start() -> ! {
debug("Test!");
panic!()
}

View File

@ -0,0 +1,13 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort"
}