Added Write system call
This commit is contained in:
parent
dc33c857a6
commit
5c7979b746
@ -1,3 +1,5 @@
|
|||||||
|
use libc::printf;
|
||||||
|
|
||||||
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
|
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
|
||||||
|
|
||||||
|
|
||||||
@ -37,7 +39,9 @@ pub const SC_SYS_TIME: u8 = 32 ;
|
|||||||
pub const SC_MMAP: u8 = 33;
|
pub const SC_MMAP: u8 = 33;
|
||||||
pub const SC_DEBUG: u8 = 34;
|
pub const SC_DEBUG: u8 = 34;
|
||||||
|
|
||||||
|
pub const CONSOLE_OUTPUT: u8 = 1;
|
||||||
|
|
||||||
|
// todo : returns new types, not just machine errors and machine ok
|
||||||
pub fn call(exception: ExceptionType, machine: &Machine) -> Result<MachineOk, MachineError> {
|
pub fn call(exception: ExceptionType, machine: &Machine) -> Result<MachineOk, MachineError> {
|
||||||
|
|
||||||
match exception {
|
match exception {
|
||||||
@ -64,7 +68,30 @@ fn syscall(machine: &Machine) -> Result<MachineOk, MachineError> {
|
|||||||
SC_CREATE => todo!(),
|
SC_CREATE => todo!(),
|
||||||
SC_OPEN => todo!(),
|
SC_OPEN => todo!(),
|
||||||
SC_READ => todo!(),
|
SC_READ => todo!(),
|
||||||
SC_WRITE => todo!(),
|
SC_WRITE => {
|
||||||
|
|
||||||
|
let address = machine.read_int_register(10);
|
||||||
|
let size = machine.read_int_register(11);
|
||||||
|
// openfileid or 1 (console)
|
||||||
|
let f = machine.read_int_register(12);
|
||||||
|
|
||||||
|
// load buffer
|
||||||
|
let mut buffer = "".to_string();
|
||||||
|
for i in 0..size {
|
||||||
|
match char::from_digit(machine.read_memory(1, (address + i) as usize) as u32, 2) {
|
||||||
|
Some(c) => buffer.push(c),
|
||||||
|
None => todo!() // Throw a proper error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if f as u8 == CONSOLE_OUTPUT {
|
||||||
|
println!("{}", buffer); // todo replace with console driver in the future
|
||||||
|
} else {
|
||||||
|
todo!("SC_WRITE to file is not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(MachineOk::Ok)
|
||||||
|
},
|
||||||
SC_SEEK => todo!(),
|
SC_SEEK => todo!(),
|
||||||
SC_CLOSE => todo!(),
|
SC_CLOSE => todo!(),
|
||||||
SC_NEW_THREAD => todo!(),
|
SC_NEW_THREAD => todo!(),
|
||||||
|
Loading…
Reference in New Issue
Block a user