1use crate::balloc::Allocator;
2use alloc::string::{String, ToString};
3use alloc::vec::Vec;
4
5#[global_allocator]
6pub static LALC: Allocator = Allocator::global();
7pub static mut ARGS: Vec<String> = Vec::new();
8
9#[panic_handler]
10pub fn panic_handler(i: &core::panic::PanicInfo) -> ! {
11 crate::syscall::debug(&i.to_string());
14 crate::syscall::exit(101)
15}
16
17#[allow(clippy::missing_safety_doc)]
18#[unsafe(no_mangle)]
19pub unsafe extern "C" fn _start() {
20 unsafe {
21 core::arch::asm!(
22 "lw a0,0(sp)", "add a1,sp,8", "li a2,0", "call _entry",
26 "li a7, 93",
27 "ecall",
28 );
29 }
30}
31
32#[allow(clippy::missing_safety_doc)]
33#[unsafe(no_mangle)]
34pub unsafe extern "C" fn _entry(argc: u64, argv: *const *const u8) {
35 unsafe {
36 for i in 0..argc {
37 let argn = core::ffi::CStr::from_ptr(argv.add(i as usize).read());
38 let argn = String::from(argn.to_string_lossy());
39 #[allow(static_mut_refs)]
40 ARGS.push(argn);
41 }
42 core::arch::asm!("call main");
43 }
44}