├── .gitignore ├── .gitmodules ├── Cargo.toml ├── build.rs ├── src ├── lib.rs └── tlsf │ └── lib.rs └── x86_64-solrs.json /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | **/*.rs.bk 3 | Cargo.lock 4 | *.swp 5 | *.swo 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "solo5"] 2 | path = solo5 3 | url = https://github.com/Solo5/solo5 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "solo5" 3 | version = "0.1.0" 4 | authors = ["Nikita Nazarenko "] 5 | publish = false 6 | 7 | [features] 8 | ukvm = [] 9 | virtio = [] 10 | 11 | [dependencies] 12 | rlibc="1.0" 13 | volatile = "0.1.0" 14 | spin = "0.4" 15 | wee_alloc={git="https://github.com/savant2212/wee_alloc", features=["ptr_array_backend"]} 16 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::process::Command; 3 | 4 | #[cfg(feature = "ukvm")] 5 | fn get_variant() -> &'static str { 6 | return "ukvm"; 7 | } 8 | 9 | #[cfg(feature = "virtio")] 10 | fn get_variant() -> &'static str { 11 | return "virtio"; 12 | } 13 | 14 | 15 | fn main() { 16 | let out_dir = env::var("OUT_DIR").unwrap(); 17 | 18 | let variant = get_variant(); 19 | 20 | // make solo5 virtio 21 | Command::new("make").args(&[ "-C", "solo5", &variant ]).status().unwrap(); 22 | Command::new("cp").arg(&format!("solo5/kernel/{}/solo5.lds", variant)).arg(&format!("{}/solo5.lds",out_dir)).status().unwrap(); 23 | // create static lib 24 | Command::new("ar").arg(&"crus").arg(&format!("{}/libsolo5.a", out_dir)).arg(&format!("solo5/kernel/{}/solo5.o", variant)).status().unwrap(); 25 | println!("cargo:rustc-link-search=native={}", out_dir); 26 | println!("cargo:rustc-link-lib=static=solo5"); 27 | } 28 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | 3 | #![allow(non_upper_case_globals)] 4 | #![allow(non_camel_case_types)] 5 | #![allow(non_snake_case)] 6 | #![feature(const_fn)] 7 | #![feature(compiler_builtins_lib)] 8 | #![feature(lang_items)] 9 | #![feature(linkage)] 10 | #![feature(alloc, global_allocator, allocator_api,allocator_internals)] 11 | 12 | pub extern crate spin; 13 | pub extern crate alloc; 14 | 15 | //extern crate alloc_cortex_m; 16 | extern crate rlibc; 17 | 18 | use core::{fmt,ptr}; 19 | use spin::Mutex; 20 | extern crate wee_alloc; 21 | 22 | #[global_allocator] 23 | static GLOBAL: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; 24 | 25 | #[no_mangle] 26 | pub extern "C" fn __floatundisf() { 27 | panic!() 28 | } 29 | 30 | #[lang = "oom"] 31 | #[no_mangle] 32 | pub fn rust_oom() -> ! { 33 | loop{} 34 | } 35 | 36 | #[allow(improper_ctypes)] 37 | extern { pub fn rust_main(cmdline : &str) -> isize; } 38 | 39 | unsafe fn strlen(buf : *const u8) -> usize { 40 | let mut idx = 0; 41 | while *buf.offset(idx) != 0 { 42 | idx += 1; 43 | } 44 | 45 | return idx as usize; 46 | } 47 | 48 | pub enum solo5_result { 49 | SOLO5_R_OK = 0, 50 | SOLO5_R_AGAIN = 1, 51 | SOLO5_R_EINVAL = 2, 52 | SOLO5_R_EUNSPEC = 3 53 | } 54 | 55 | #[repr(C)] 56 | #[derive(Debug)] 57 | pub struct solo5_start_info { 58 | pub cmdline: *const u8, 59 | pub heap_start: usize, 60 | pub heap_size: usize 61 | } 62 | 63 | 64 | #[no_mangle] 65 | extern "C" { 66 | pub fn solo5_net_write_sync(data: *mut u8, len: isize) -> isize; 67 | pub fn solo5_net_read_sync(data: *mut u8, len: *mut isize) -> isize; 68 | pub fn solo5_net_mac_str() -> *const u8; 69 | 70 | pub fn solo5_blk_write_sync(sec: u64, data: *mut u8, n: isize)-> isize; 71 | pub fn solo5_blk_read_sync(sec:u64, data : *mut u8, n : *mut isize) -> isize; 72 | pub fn solo5_blk_sector_size() -> isize; 73 | pub fn solo5_blk_sectors() -> u64; 74 | pub fn solo5_blk_rw() -> isize; 75 | 76 | pub fn solo5_console_write(buf : *const u8, len : usize ) -> isize; 77 | pub fn solo5_exit(result: isize) -> !; 78 | 79 | pub fn solo5_clock_monotonic() -> u64; 80 | pub fn solo5_clock_wall() -> u64; 81 | pub fn solo5_poll(nsec:u64) -> isize; 82 | } 83 | 84 | pub struct Console; 85 | 86 | impl fmt::Write for Console { 87 | fn write_str(&mut self, s: &str) -> fmt::Result { 88 | unsafe { 89 | solo5_console_write(s.as_ptr(), s.len()); 90 | }; 91 | Ok(()) 92 | } 93 | } 94 | 95 | pub static CONSOLE : Mutex = Mutex::new(Console{}); 96 | 97 | #[macro_export] 98 | macro_rules! print { 99 | ($($arg:tt)*) => ({ 100 | use core::fmt::Write; 101 | let mut cn = $crate::CONSOLE.lock(); 102 | (*cn).write_fmt(format_args!($($arg)*)).unwrap(); 103 | }); 104 | } 105 | 106 | #[macro_export] 107 | macro_rules! println { 108 | ($fmt:expr) => (print!(concat!($fmt, "\n"))); 109 | ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); 110 | } 111 | 112 | #[lang = "eh_personality"] extern fn eh_personality() {} 113 | #[lang = "panic_fmt"] 114 | #[no_mangle] 115 | pub extern fn panic_fmt( 116 | _args: ::core::fmt::Arguments, 117 | _file: &'static str, 118 | _line: u32 ) -> ! { 119 | println!("panic {} occured at {}:{}", _args, _file, _line); 120 | unsafe {solo5_exit(1);} 121 | } 122 | 123 | #[no_mangle] 124 | pub unsafe fn solo5_app_main(info : *const solo5_start_info) -> isize { 125 | // init allocator 126 | println!("{:?}",*info); 127 | GLOBAL.init((*info).heap_start,(*info).heap_size); 128 | let p = core::str::from_utf8(core::slice::from_raw_parts((*info).cmdline, strlen((*info).cmdline) as usize)).unwrap(); 129 | solo5_exit(rust_main(p)) 130 | } 131 | 132 | -------------------------------------------------------------------------------- /src/tlsf/lib.rs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savant2212/solo5-rs/33022a1a062d0a60bf8dac243321874ca0beb7b2/src/tlsf/lib.rs -------------------------------------------------------------------------------- /x86_64-solrs.json: -------------------------------------------------------------------------------- 1 | { 2 | "llvm-target": "x86_64-unknown-none", 3 | "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", 4 | "linker-flavor": "gcc", 5 | "target-endian": "little", 6 | "target-pointer-width": "64", 7 | "target-c-int-width": "32", 8 | "arch": "x86_64", 9 | "no-compiler-rt" : false, 10 | "os": "none", 11 | "disable-redzone": true, 12 | "features": "-mmx,-sse,+soft-float" 13 | } 14 | 15 | --------------------------------------------------------------------------------