1#[cfg(target_os = "none")]
2use core::{ffi::CStr, ptr::slice_from_raw_parts};
3
4#[cfg(target_os = "none")]
5use alloc::borrow::ToOwned;
6#[cfg(target_os = "none")]
7pub use irid_syscall::ffi::thread::syscall_exit as entrypoint_exit;
8
9#[cfg(target_os = "none")]
10use crate::{env::arg_lock, println};
11
12#[cfg(target_os = "none")]
13#[macro_export]
14macro_rules! entrypoint {
15 () => {
16 core::arch::global_asm!(r#"
17 .global _start
18 _start:
19 mov rbp,0
20 mov rdi,[rsp]
21 lea rsi,[rsp + 0x8]
22 call _std_entry
23 "#);
24
25 #[unsafe(no_mangle)]
26 unsafe extern "C" fn _std_entry(argc: usize, argv: *const *const u8) -> ! {
27 $crate::start::_std_init(argc, argv);
28
29 main();
30
31 $crate::start::entrypoint_exit(0);
32 }
33 };
34}
35
36#[cfg(target_os = "none")]
37#[unsafe(no_mangle)]
38pub extern "C" fn _std_init(argc: usize, argv: *const *const u8) {
39 let mut arg_lock = arg_lock();
40
41 let args = unsafe { slice_from_raw_parts(argv, argc).as_ref_unchecked() };
44
45 for arg in args {
46 let arg = unsafe { CStr::from_ptr(*arg as *const i8) }.to_str().expect("failed to parse program argument");
47
48 arg_lock.push(arg.to_owned().into_boxed_str());
51 }
52}
53
54#[cfg(not(target_os = "none"))]
55#[macro_export]
56macro_rules! entrypoint {
57 () => {}
58}
59