Skip to main content

dirty/
syscall.rs

1// https://github.com/SCLorentz/UwU/blob/main/ARM64/src/main.s
2
3/// This will get our ASM bindings
4mod bindings {
5	unsafe extern "C" {
6		pub(crate) fn exit(code: crate::f8) -> !;
7	}
8}
9
10/// Exits the program with a specified exit code
11#[allow(unused)]
12#[inline]
13pub fn exit(code: crate::f8) -> ! { unsafe { bindings::exit(code) } }
14
15/// write attribute to print strings into the terminal
16#[macro_export]
17macro_rules! write {
18	($($x:expr),+ $(,)?) => {
19		let s = alloc::format!($($x),+);
20		let ptr = s.as_ptr();
21		let len = s.len();
22
23		#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
24		unsafe {
25			core::arch::asm!(
26				"syscall",
27				in("rax") 1,		// SYS_write
28				in("rdi") 1,		// stdout
29				in("rsi") ptr,
30				in("rdx") len,
31			)
32		}
33
34		#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
35		unsafe {
36			core::arch::asm!(
37				"mov x16, #4",
38				"mov x0, #1",
39				"svc #0x80",
40				in("x1") ptr,
41				in("x2") len,
42				options(nostack)
43			)
44		}
45	};
46}