1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#[cfg(not(feature = "std"))]
#[lang = "eh_personality"]
extern fn eh_personality() {}

#[cfg(not(feature = "std"))]
#[macro_export] macro_rules! install_panic_handler {
    ($module_name:expr) => {
        #[panic_handler]
        fn panic(panic_info: &core::panic::PanicInfo) -> ! {
            $crate::println!("{} panicked: {}", $module_name, panic_info);


            loop {
                unsafe {
                    $crate::nn::os::SleepThread(
                        $crate::nn::TimeSpan::milli(100)
                    )
                }
            }
        }
    };
}

#[cfg(feature = "std")]
#[macro_export] macro_rules! install_panic_handler {
    ($module_name:expr) => {};
}

#[cfg(not(feature = "std"))]
global_asm!(include_str!("mod0.s"));

#[macro_export] macro_rules! set_module_name {
    ($lit:literal) => {
        ::skyline::install_panic_handler!($lit);

        const __SKYLINE_INTERNAL_MODULE_LEN: usize = $lit.len() + 1;

        #[used]
        #[link_section = ".rodata.module_name"]
        pub static __MODULE_NAME: ::skyline::build::ModuleName<__SKYLINE_INTERNAL_MODULE_LEN> =
            ::skyline::build::ModuleName::new(
                ::skyline::skyline_macro::to_null_term_bytes!($lit)
            );
    };
}

#[repr(packed)]
#[allow(unused_variables)]
pub struct ModuleName<const LEN: usize> {
    pub unk: u32,
    pub name_length: u32,
    pub name: [u8; LEN],
}

impl<const LEN: usize> ModuleName<LEN> {
    pub const fn new(bytes: &[u8; LEN]) -> Self {
        Self {
            unk: 0,
            name_length: LEN as u32 - 1,
            name: *bytes,
        }
    }
}

/// one-time setup for skyline
#[cfg(not(feature = "std"))]
#[doc(hidden)]
#[macro_export] macro_rules! setup {
    () => {
        #[global_allocator]
        pub static ALLOCATOR: $crate::extern_alloc::Allocator = $crate::extern_alloc::Allocator;

        #[no_mangle] pub unsafe extern "C" fn __custom_init() {}
        #[no_mangle] pub extern "C" fn __custom_fini() {}
    };
}

#[cfg(feature = "std")]
#[macro_export] macro_rules! setup {
    () => {
        #[no_mangle] pub unsafe extern "C" fn __custom_init() {}
        #[no_mangle] pub extern "C" fn __custom_fini() {}
    };
}