Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
809021d748 | ||
|
|
922c05ceb6 | ||
|
|
1ea751f931 |
No files matched your search
@@ -21,3 +21,6 @@ path = "examples/dark.rs"
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = "thin"
|
||||
|
||||
[[example]]
|
||||
name = "fs_demo"
|
||||
@@ -0,0 +1,12 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use kos::fs::fs_read;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
let path = c"/rd/1/readme.txt";
|
||||
let mut buf = [0u8; 512];
|
||||
let (_status, _bytes) = fs_read(path, &mut buf);
|
||||
loop {}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use core::ffi::CStr;
|
||||
use crate::sys::{syscall_fs, FileSystemRequest};
|
||||
|
||||
pub fn fs_read(path: &CStr, buf: &mut [u8]) -> (u32, u32) {
|
||||
let req = FileSystemRequest {
|
||||
operation: 0,
|
||||
offset_low: 0,
|
||||
offset_high: 0,
|
||||
byte_count: buf.len() as u32,
|
||||
buffer: buf.as_mut_ptr() as u32,
|
||||
path: path.as_ptr() as u32,
|
||||
};
|
||||
unsafe { syscall_fs(&req) }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ mod nanolibc;
|
||||
pub mod allocation;
|
||||
pub mod dll;
|
||||
pub mod sys;
|
||||
pub mod fs;
|
||||
|
||||
pub use modules::*;
|
||||
|
||||
|
||||
+23
@@ -68,3 +68,26 @@ extern "C" {
|
||||
#[link_name = "_load_dll"]
|
||||
pub fn load_dll(name: *const u8) -> *const u32;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct FileSystemRequest {
|
||||
pub operation: u32,
|
||||
pub offset_low: u32,
|
||||
pub offset_high: u32,
|
||||
pub byte_count: u32,
|
||||
pub buffer: u32,
|
||||
pub path: u32,
|
||||
}
|
||||
|
||||
pub unsafe fn syscall_fs(req: *const FileSystemRequest) -> (u32, u32) {
|
||||
let eax_result: u32;
|
||||
let ebx_result: u32;
|
||||
core::arch::asm!(
|
||||
"int 0x40",
|
||||
inout("eax") 70u32 => eax_result,
|
||||
in("ebx") req,
|
||||
out("ebx") ebx_result,
|
||||
options(nostack)
|
||||
);
|
||||
(eax_result, ebx_result)
|
||||
}
|
||||
Reference in new issue
Block a user