Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
809021d748 |
No files matched your search
+6
-4
@@ -1,10 +1,12 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use kos::fs::read_file;
|
||||
use kos::fs::fs_read;
|
||||
|
||||
#[no_mangle]
|
||||
pub fn kol_main() {
|
||||
let mut buf = [0u8; 256];
|
||||
let _ = read_file(c"/rd/1/readme.txt", &mut buf);
|
||||
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 {}
|
||||
}
|
||||
+83
-1
@@ -6,10 +6,23 @@ pub struct Console {
|
||||
con_init: extern "stdcall" fn(u32, u32, u32, u32, *const u8),
|
||||
con_write_string: extern "stdcall" fn(*const u8, u32),
|
||||
con_exit: extern "stdcall" fn(bool),
|
||||
con_set_title: extern "stdcall" fn(*const u8),
|
||||
con_get_flags: extern "stdcall" fn() -> u32,
|
||||
con_set_flags: extern "stdcall" fn(u32) -> u32,
|
||||
con_get_font_height: extern "stdcall" fn() -> u32,
|
||||
con_get_cursor_height: extern "stdcall" fn() -> u32,
|
||||
con_set_cursor_height: extern "stdcall" fn(u32) -> u32,
|
||||
con_getch: extern "stdcall" fn() -> u32,
|
||||
con_getch2: extern "stdcall" fn() -> u16,
|
||||
con_kbhit: extern "stdcall" fn() -> u32,
|
||||
con_gets: extern "stdcall" fn(*mut u8, u32) -> *mut u8,
|
||||
con_cls: extern "stdcall" fn(),
|
||||
con_get_cursor_pos: extern "stdcall" fn(*mut u32, *mut u32),
|
||||
con_set_cursor_pos: extern "stdcall" fn(u32, u32),
|
||||
}
|
||||
|
||||
impl Console {
|
||||
pub fn import(path: Option<&CStr>) -> Result<Self, &str> {
|
||||
pub fn import(path: Option<&CStr>) -> Result<Self, &'static str> {
|
||||
let lib = DLL::load_dll(path.unwrap_or(c"/sys/lib/console.obj"));
|
||||
match lib {
|
||||
Err(e) => return Err(e),
|
||||
@@ -18,6 +31,19 @@ impl Console {
|
||||
con_init: transmute(dll.get_func(c"con_init").ok().unwrap()),
|
||||
con_write_string: transmute(dll.get_func(c"con_write_string").ok().unwrap()),
|
||||
con_exit: transmute(dll.get_func(c"con_exit").ok().unwrap()),
|
||||
con_set_title: transmute(dll.get_func(c"con_set_title").ok().unwrap()),
|
||||
con_get_flags: transmute(dll.get_func(c"con_get_flags").ok().unwrap()),
|
||||
con_set_flags: transmute(dll.get_func(c"con_set_flags").ok().unwrap()),
|
||||
con_get_font_height: transmute(dll.get_func(c"con_get_font_height").ok().unwrap()),
|
||||
con_get_cursor_height: transmute(dll.get_func(c"con_get_cursor_height").ok().unwrap()),
|
||||
con_set_cursor_height: transmute(dll.get_func(c"con_set_cursor_height").ok().unwrap()),
|
||||
con_getch: transmute(dll.get_func(c"con_getch").ok().unwrap()),
|
||||
con_getch2: transmute(dll.get_func(c"con_getch2").ok().unwrap()),
|
||||
con_kbhit: transmute(dll.get_func(c"con_kbhit").ok().unwrap()),
|
||||
con_gets: transmute(dll.get_func(c"con_gets").ok().unwrap()),
|
||||
con_cls: transmute(dll.get_func(c"con_cls").ok().unwrap()),
|
||||
con_get_cursor_pos: transmute(dll.get_func(c"con_get_cursor_pos").ok().unwrap()),
|
||||
con_set_cursor_pos: transmute(dll.get_func(c"con_set_cursor_pos").ok().unwrap()),
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -34,4 +60,60 @@ impl Console {
|
||||
pub fn exit(self, close_window: bool) {
|
||||
(self.con_exit)(close_window);
|
||||
}
|
||||
|
||||
pub fn set_title(&self, title: &CStr) {
|
||||
(self.con_set_title)(title.as_ptr() as *const u8);
|
||||
}
|
||||
|
||||
pub fn get_flags(&self) -> u32 {
|
||||
(self.con_get_flags)()
|
||||
}
|
||||
|
||||
pub fn set_flags(&self, flags: u32) -> u32 {
|
||||
(self.con_set_flags)(flags)
|
||||
}
|
||||
|
||||
pub fn get_font_height(&self) -> u32 {
|
||||
(self.con_get_font_height)()
|
||||
}
|
||||
|
||||
pub fn get_cursor_height(&self) -> u32 {
|
||||
(self.con_get_cursor_height)()
|
||||
}
|
||||
|
||||
pub fn set_cursor_height(&self, height: u32) -> u32 {
|
||||
(self.con_set_cursor_height)(height)
|
||||
}
|
||||
|
||||
pub fn getch(&self) -> u32 {
|
||||
(self.con_getch)()
|
||||
}
|
||||
|
||||
pub fn getch2(&self) -> u16 {
|
||||
(self.con_getch2)()
|
||||
}
|
||||
|
||||
pub fn kbhit(&self) -> u32 {
|
||||
(self.con_kbhit)()
|
||||
}
|
||||
|
||||
pub fn gets<'a>(&self, buf: &'a mut [u8]) -> Option<&'a [u8]> {
|
||||
let ptr = (self.con_gets)(buf.as_mut_ptr(), buf.len() as u32);
|
||||
if ptr.is_null() { None } else { Some(buf) }
|
||||
}
|
||||
|
||||
pub fn cls(&self) {
|
||||
(self.con_cls)();
|
||||
}
|
||||
|
||||
pub fn get_cursor_pos(&self) -> (u32, u32) {
|
||||
let mut x = 0u32;
|
||||
let mut y = 0u32;
|
||||
(self.con_get_cursor_pos)(&mut x, &mut y);
|
||||
(x, y)
|
||||
}
|
||||
|
||||
pub fn set_cursor_pos(&self, x: u32, y: u32) {
|
||||
(self.con_set_cursor_pos)(x, y);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +1,14 @@
|
||||
use core::ffi::CStr;
|
||||
use crate::sys::{fs_execute, FsBlock};
|
||||
use crate::sys::{syscall_fs, FileSystemRequest};
|
||||
|
||||
fn execute(op: u32, offset: u32, offset_hi: u32, count: u32, buf: *mut u8, path: &CStr) -> Result<(), u32> {
|
||||
let info = FsBlock {
|
||||
operation: op,
|
||||
offset,
|
||||
offset_hi,
|
||||
byte_count: count,
|
||||
buffer: buf,
|
||||
_pad: 0,
|
||||
path: path.as_ptr() as *const u8,
|
||||
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,
|
||||
};
|
||||
match unsafe { fs_execute(&info) } {
|
||||
0 => Ok(()),
|
||||
e => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_file(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
||||
execute(0, 0, 0, buf.len() as u32, buf.as_mut_ptr(), path)
|
||||
}
|
||||
|
||||
pub fn read_folder(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
||||
execute(1, 0, 0, buf.len() as u32, buf.as_mut_ptr(), path)
|
||||
}
|
||||
|
||||
pub fn create_file(path: &CStr, buf: &[u8]) -> Result<(), u32> {
|
||||
execute(2, 0, 0, buf.len() as u32, buf.as_ptr() as *mut u8, path)
|
||||
}
|
||||
|
||||
pub fn write_file(path: &CStr, buf: &[u8]) -> Result<(), u32> {
|
||||
execute(3, 0, 0, buf.len() as u32, buf.as_ptr() as *mut u8, path)
|
||||
}
|
||||
|
||||
pub fn set_size(path: &CStr, size: u64) -> Result<(), u32> {
|
||||
execute(4, size as u32, (size >> 32) as u32, 0, core::ptr::null_mut(), path)
|
||||
}
|
||||
|
||||
pub fn get_attributes(path: &CStr, buf: &mut [u8]) -> Result<(), u32> {
|
||||
execute(5, 0, 0, buf.len() as u32, buf.as_mut_ptr(), path)
|
||||
}
|
||||
|
||||
pub fn set_attributes(path: &CStr, buf: &[u8]) -> Result<(), u32> {
|
||||
execute(6, 0, 0, buf.len() as u32, buf.as_ptr() as *mut u8, path)
|
||||
}
|
||||
|
||||
pub fn run(path: &CStr) -> Result<(), u32> {
|
||||
execute(7, 0, 0, 0, core::ptr::null_mut(), path)
|
||||
}
|
||||
|
||||
pub fn delete(path: &CStr) -> Result<(), u32> {
|
||||
execute(8, 0, 0, 0, core::ptr::null_mut(), path)
|
||||
}
|
||||
|
||||
pub fn create_folder(path: &CStr) -> Result<(), u32> {
|
||||
execute(9, 0, 0, 0, core::ptr::null_mut(), path)
|
||||
unsafe { syscall_fs(&req) }
|
||||
}
|
||||
@@ -20,4 +20,3 @@ SF_SYS_MISC = 68
|
||||
SSF_MEM_ALLOC = 12
|
||||
SSF_MEM_FREE = 13
|
||||
SSF_LOAD_DLL = 19
|
||||
SF_FILE = 70
|
||||
+20
-12
@@ -67,19 +67,27 @@ extern "C" {
|
||||
// 68.19
|
||||
#[link_name = "_load_dll"]
|
||||
pub fn load_dll(name: *const u8) -> *const u32;
|
||||
|
||||
// 70
|
||||
#[link_name = "_fs_execute"]
|
||||
pub fn fs_execute(info: *const FsBlock) -> u32;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub(crate) struct FsBlock {
|
||||
pub operation: u32,
|
||||
pub offset: u32,
|
||||
pub offset_hi: u32,
|
||||
pub byte_count: u32,
|
||||
pub buffer: *mut u8,
|
||||
pub _pad: u8,
|
||||
pub path: *const u8,
|
||||
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)
|
||||
}
|
||||
@@ -20,7 +20,6 @@ section '.text'
|
||||
public _get_lang
|
||||
public _load_dll
|
||||
public _set_event_mask
|
||||
public _fs_execute
|
||||
|
||||
_exit:
|
||||
mov eax, SF_TERMINATE_PROCESS
|
||||
@@ -144,10 +143,3 @@ _set_event_mask:
|
||||
int 0x40
|
||||
ret
|
||||
|
||||
_fs_execute:
|
||||
push ebx
|
||||
mov eax, SF_FILE
|
||||
mov ebx, [esp + 4 * 2]
|
||||
int 0x40
|
||||
pop ebx
|
||||
ret
|
||||
Reference in new issue
Block a user