Compare commits
No commits in common. "51d40f6db694cba162c0d19f6ffc48098862d0d3" and "32ccbedb7a686038b35e8876c7dedadb26dd2c7d" have entirely different histories.
51d40f6db6
...
32ccbedb7a
|
@ -32,7 +32,7 @@ pub fn parse_init_port(port_cap: syscall::zcap) {
|
||||||
num_caps: &mut num_caps as *mut u64,
|
num_caps: &mut num_caps as *mut u64,
|
||||||
};
|
};
|
||||||
let resp = syscall::syscall(syscall::kZionPortPoll, &req);
|
let resp = syscall::syscall(syscall::kZionPortPoll, &req);
|
||||||
if let Err(_) = resp {
|
if resp != 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -59,7 +59,7 @@ macro_rules! define_entry {
|
||||||
unsafe {
|
unsafe {
|
||||||
let err = main();
|
let err = main();
|
||||||
let req = mammoth::syscall::ZProcessExitReq { code: err };
|
let req = mammoth::syscall::ZProcessExitReq { code: err };
|
||||||
let _ = mammoth::syscall::syscall(mammoth::syscall::kZionProcessExit, &req);
|
mammoth::syscall::syscall(mammoth::syscall::kZionProcessExit, &req);
|
||||||
}
|
}
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ use linked_list_allocator::LockedHeap;
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
static ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||||
|
|
||||||
pub static mut CAN_ALLOC: bool = false;
|
|
||||||
|
|
||||||
pub fn init_heap() {
|
pub fn init_heap() {
|
||||||
// 1 MiB
|
// 1 MiB
|
||||||
let size = 0x10_0000;
|
let size = 0x10_0000;
|
||||||
|
@ -15,8 +13,7 @@ pub fn init_heap() {
|
||||||
size,
|
size,
|
||||||
vmmo_cap: &mut vmmo_cap as *mut u64,
|
vmmo_cap: &mut vmmo_cap as *mut u64,
|
||||||
};
|
};
|
||||||
syscall::syscall(syscall::kZionMemoryObjectCreate, &obj_req)
|
syscall::checked_syscall(syscall::kZionMemoryObjectCreate, &obj_req);
|
||||||
.expect("Failed to create memory object");
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut vaddr: u64 = 0;
|
let mut vaddr: u64 = 0;
|
||||||
|
@ -28,9 +25,7 @@ pub fn init_heap() {
|
||||||
vmas_offset: 0,
|
vmas_offset: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
syscall::syscall(syscall::kZionAddressSpaceMap, &vmas_req)
|
syscall::checked_syscall(syscall::kZionAddressSpaceMap, &vmas_req);
|
||||||
.expect("Failed to map memory object");
|
|
||||||
ALLOCATOR.lock().init(vaddr as *mut u8, size as usize);
|
ALLOCATOR.lock().init(vaddr as *mut u8, size as usize);
|
||||||
CAN_ALLOC = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,91 +1,24 @@
|
||||||
extern crate alloc;
|
|
||||||
|
|
||||||
use alloc::string::String;
|
|
||||||
use alloc::vec::Vec;
|
|
||||||
use core::ffi::c_void;
|
use core::ffi::c_void;
|
||||||
use core::fmt;
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
include!("bindings.rs");
|
include!("bindings.rs");
|
||||||
|
|
||||||
pub enum ZError {
|
pub fn syscall<T>(id: u64, req: &T) -> u64 {
|
||||||
UNKNOWN = 0x0,
|
unsafe { SysCall1(id, req as *const T as *const c_void) }
|
||||||
// First set of error codes generally indicate user errors.
|
|
||||||
INVALID_ARGUMENT = 0x1,
|
|
||||||
NOT_FOUND = 0x2,
|
|
||||||
PERMISSION_DENIED = 0x3,
|
|
||||||
NULL_PTR = 0x4,
|
|
||||||
EMPTY = 0x5,
|
|
||||||
ALREADY_EXISTS = 0x6,
|
|
||||||
BUFFER_SIZE = 0x7,
|
|
||||||
FAILED_PRECONDITION = 0x8,
|
|
||||||
|
|
||||||
// Second set of error codes generally indicate service errors.
|
|
||||||
INTERNAL = 0x100,
|
|
||||||
UNIMPLEMENTED = 0x101,
|
|
||||||
EXHAUSTED = 0x102,
|
|
||||||
INVALID_RESPONSE = 0x103,
|
|
||||||
|
|
||||||
// Kernel specific error codes (relating to capabilities).
|
|
||||||
CAP_NOT_FOUND = 0x1000,
|
|
||||||
CAP_WRONG_TYPE = 0x1001,
|
|
||||||
CAP_PERMISSION_DENIED = 0x1002,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u64> for ZError {
|
pub fn checked_syscall<T>(id: u64, req: &T) {
|
||||||
fn from(value: u64) -> Self {
|
if syscall(id, req) != 0 {
|
||||||
match value {
|
debug("Bad syscall response.");
|
||||||
0x1 => ZError::INVALID_ARGUMENT,
|
panic!();
|
||||||
0x2 => ZError::NOT_FOUND,
|
|
||||||
0x3 => ZError::PERMISSION_DENIED,
|
|
||||||
0x4 => ZError::NULL_PTR,
|
|
||||||
0x5 => ZError::EMPTY,
|
|
||||||
0x6 => ZError::ALREADY_EXISTS,
|
|
||||||
0x7 => ZError::BUFFER_SIZE,
|
|
||||||
0x8 => ZError::FAILED_PRECONDITION,
|
|
||||||
|
|
||||||
0x100 => ZError::INTERNAL,
|
|
||||||
0x101 => ZError::UNIMPLEMENTED,
|
|
||||||
0x102 => ZError::EXHAUSTED,
|
|
||||||
0x103 => ZError::INVALID_RESPONSE,
|
|
||||||
|
|
||||||
0x1000 => ZError::CAP_NOT_FOUND,
|
|
||||||
0x1001 => ZError::CAP_WRONG_TYPE,
|
|
||||||
0x1002 => ZError::CAP_PERMISSION_DENIED,
|
|
||||||
_ => ZError::UNKNOWN,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ZError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
f.write_str("ZError")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn syscall<T>(id: u64, req: &T) -> Result<(), ZError> {
|
|
||||||
unsafe {
|
|
||||||
let resp = SysCall1(id, req as *const T as *const c_void);
|
|
||||||
if resp != 0 {
|
|
||||||
return Err(ZError::from(resp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(_info: &PanicInfo) -> ! {
|
||||||
unsafe {
|
|
||||||
if crate::mem::CAN_ALLOC {
|
|
||||||
crate::debug!("Panic occured: {}", info);
|
|
||||||
} else {
|
|
||||||
debug("Panic occured before heap initialized.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Internal error.
|
// Internal error.
|
||||||
let req = ZProcessExitReq { code: 0x100 };
|
let req = ZProcessExitReq { code: 0x100 };
|
||||||
let _ = syscall(kZionProcessExit, &req);
|
syscall(kZionProcessExit, &req);
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,52 +27,5 @@ pub fn debug(msg: &str) {
|
||||||
message: msg.as_ptr() as *const i8,
|
message: msg.as_ptr() as *const i8,
|
||||||
size: msg.len() as u64,
|
size: msg.len() as u64,
|
||||||
};
|
};
|
||||||
syscall(kZionDebug, &req).expect("Failed to write");
|
syscall(kZionDebug, &req);
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Writer {
|
|
||||||
int_vec: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Writer {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
int_vec: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<String> for Writer {
|
|
||||||
fn into(self) -> String {
|
|
||||||
String::from_utf8(self.int_vec).expect("Failed to convert")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Write for Writer {
|
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
|
||||||
for c in s.bytes() {
|
|
||||||
self.int_vec.push(c);
|
|
||||||
}
|
|
||||||
fmt::Result::Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! debug {
|
|
||||||
() => {
|
|
||||||
debug("");
|
|
||||||
};
|
|
||||||
($fmt:literal) => {
|
|
||||||
debug($fmt);
|
|
||||||
};
|
|
||||||
($fmt:literal, $($val:expr),+) => {{
|
|
||||||
use core::fmt::Write as _;
|
|
||||||
use alloc::string::String;
|
|
||||||
// TODO: Find a way to do this so we don't have to import writer.
|
|
||||||
// We can't fully qualify this if we want to use it in this crate.
|
|
||||||
let mut w = Writer::new();
|
|
||||||
write!(&mut w, $fmt, $($val),*).expect("Failed to format");
|
|
||||||
let s: String = w.into();
|
|
||||||
debug(&s);
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,9 @@
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use mammoth::debug;
|
|
||||||
use mammoth::define_entry;
|
use mammoth::define_entry;
|
||||||
use mammoth::syscall::debug;
|
use mammoth::syscall::debug;
|
||||||
use mammoth::syscall::z_err_t;
|
use mammoth::syscall::z_err_t;
|
||||||
use mammoth::syscall::Writer;
|
|
||||||
|
|
||||||
define_entry!();
|
define_entry!();
|
||||||
|
|
||||||
|
@ -17,13 +15,5 @@ pub extern "C" fn main() -> z_err_t {
|
||||||
debug("Testing!");
|
debug("Testing!");
|
||||||
let x = Box::new("Heap str");
|
let x = Box::new("Heap str");
|
||||||
debug(&x);
|
debug(&x);
|
||||||
debug!("Formatted {}", "string");
|
|
||||||
let mut vmmo_cap: u64 = 0;
|
|
||||||
let obj_req = mammoth::syscall::ZMemoryObjectCreateReq {
|
|
||||||
size: 0,
|
|
||||||
vmmo_cap: &mut vmmo_cap as *mut u64,
|
|
||||||
};
|
|
||||||
mammoth::syscall::syscall(mammoth::syscall::kZionMemoryObjectCreate, &obj_req)
|
|
||||||
.expect("Failed to create memory object");
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue