mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2025-03-14 02:16:10 +00:00
Move required build objects to skyline subcrate
This commit is contained in:
parent
7bc01022f5
commit
4e05ea1e95
6 changed files with 95 additions and 86 deletions
5
skyline/Cargo.lock
generated
5
skyline/Cargo.lock
generated
|
@ -1,5 +1,6 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "extern_alloc"
|
||||
version = "0.1.0"
|
||||
name = "skyline"
|
||||
version = "0.0.1"
|
||||
|
||||
|
|
39
skyline/src/alloc.rs
Normal file
39
skyline/src/alloc.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ffi::c_void;
|
||||
|
||||
extern "C" {
|
||||
fn malloc(size: usize) -> *const c_void;
|
||||
fn free(ptr: *const c_void);
|
||||
fn calloc(num: usize, size: usize) -> *const c_void;
|
||||
fn realloc(ptr: *const c_void, size: usize) -> *const c_void;
|
||||
// fn aligned_alloc(align: usize, size: usize) -> *const c_void;
|
||||
}
|
||||
|
||||
pub struct Allocator;
|
||||
|
||||
unsafe impl GlobalAlloc for Allocator {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
malloc(layout.size()) as *mut u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
calloc(layout.size(), 1) as *mut u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||
free(ptr as *mut c_void)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 {
|
||||
realloc(ptr as *mut c_void, new_size) as *mut u8
|
||||
}
|
||||
}
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn _alloc_error(_layout: Layout) -> ! {
|
||||
panic!("Allocation error");
|
||||
}
|
41
skyline/src/build.rs
Normal file
41
skyline/src/build.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use core::any::Any;
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern fn eh_personality() {
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
crate::log("Panic at the Rust lib!\n");
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
global_asm!(include_str!("mod0.s"));
|
||||
|
||||
#[no_mangle] pub extern "C" fn __custom_init() {}
|
||||
#[no_mangle] pub extern "C" fn __custom_fini() {}
|
||||
|
||||
#[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,
|
||||
name: *bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[link_section = ".rodata.module_name"]
|
||||
pub static MODULE_NAME: impl Any = ModuleName::new(b"no_std_test\0");
|
||||
|
||||
|
|
@ -1,41 +1,19 @@
|
|||
#![no_std]
|
||||
#![feature(alloc_error_handler)]
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ffi::c_void;
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(alloc_error_handler, lang_items, start, global_asm, const_generics, impl_trait_in_bindings)]
|
||||
|
||||
pub mod alloc;
|
||||
pub use alloc::Allocator;
|
||||
|
||||
pub mod build;
|
||||
|
||||
extern "C" {
|
||||
fn malloc(size: usize) -> *const c_void;
|
||||
fn free(ptr: *const c_void);
|
||||
fn calloc(num: usize, size: usize) -> *const c_void;
|
||||
fn realloc(ptr: *const c_void, size: usize) -> *const c_void;
|
||||
// fn aligned_alloc(align: usize, size: usize) -> *const c_void;
|
||||
fn skyline_tcp_send_raw(bytes: *const u8, usize: u64);
|
||||
}
|
||||
|
||||
pub struct Allocator;
|
||||
|
||||
unsafe impl GlobalAlloc for Allocator {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||
malloc(layout.size()) as *mut u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
calloc(layout.size(), 1) as *mut u8
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||
free(ptr as *mut c_void)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 {
|
||||
realloc(ptr as *mut c_void, new_size) as *mut u8
|
||||
pub fn log(message: &str) {
|
||||
unsafe {
|
||||
skyline_tcp_send_raw(message.as_bytes().as_ptr(), message.as_bytes().len() as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn _alloc_error(_layout: Layout) -> ! {
|
||||
panic!("Allocation error");
|
||||
}
|
||||
|
|
52
src/lib.rs
52
src/lib.rs
|
@ -1,9 +1,5 @@
|
|||
#![no_std]
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(lang_items, start, global_asm, const_generics, impl_trait_in_bindings)]
|
||||
|
||||
use core::any::Any;
|
||||
use skyline::Allocator;
|
||||
use skyline::{Allocator, log};
|
||||
|
||||
#[global_allocator]
|
||||
pub static ALLOCATOR: Allocator = Allocator;
|
||||
|
@ -11,26 +7,6 @@ pub static ALLOCATOR: Allocator = Allocator;
|
|||
extern crate alloc;
|
||||
use alloc::vec;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
log("Panic at the Rust lib!\n");
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] extern fn eh_personality() {}
|
||||
|
||||
extern "C" {
|
||||
fn skyline_tcp_send_raw(bytes: *const u8, usize: u64);
|
||||
}
|
||||
|
||||
fn log(message: &str) {
|
||||
unsafe {
|
||||
skyline_tcp_send_raw(message.as_bytes().as_ptr(), message.as_bytes().len() as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() {
|
||||
let x = vec![1, 2, 3];
|
||||
|
@ -42,29 +18,3 @@ pub fn main() {
|
|||
log("x[1] != 2\n");
|
||||
}
|
||||
}
|
||||
|
||||
global_asm!(include_str!("mod0.s"));
|
||||
|
||||
#[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,
|
||||
name: *bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[link_section = ".rodata.module_name"]
|
||||
pub static MODULE_NAME: impl Any = ModuleName::new(b"no_std_test\0");
|
||||
|
||||
#[no_mangle] pub extern "C" fn __custom_init() {}
|
||||
#[no_mangle] pub extern "C" fn __custom_fini() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue