Files
termOS/Runtime/rust/rterm/src/lib.rs
T
2026-04-13 23:40:41 +04:00

36 lines
727 B
Rust

#![no_std]
extern crate alloc;
use core::panic::PanicInfo;
use core::alloc::{GlobalAlloc, Layout};
unsafe extern "C" {
fn MemoryAllocate(size: usize) -> *mut u8;
fn MemoryFree(ptr: *mut u8);
fn ConsolePrintString(s: *const u8);
}
struct TermosAllocator;
unsafe impl GlobalAlloc for TermosAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
MemoryAllocate(layout.size())
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
MemoryFree(ptr);
}
}
#[global_allocator]
static ALLOCATOR: TermosAllocator = TermosAllocator;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
pub unsafe fn print_str(s: &str) {
ConsolePrintString(s.as_ptr());
}