mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-24 02:16:19 +04:00
Added formatting, made syscall.rs clearer to read.
This commit is contained in:
parent
056ef5bb2d
commit
84e5126d29
@ -228,7 +228,11 @@ impl FileSystem for MinixFileSystem {
|
||||
// Once again, here we actually copy the bytes into the final destination, the buffer. This memcpy
|
||||
// is written in cpu.rs.
|
||||
unsafe {
|
||||
memcpy(buffer.add(bytes_read as usize), block_buffer.get().add(offset_byte as usize), read_this_many as usize);
|
||||
memcpy(
|
||||
buffer.add(bytes_read as usize,),
|
||||
block_buffer.get().add(offset_byte as usize,),
|
||||
read_this_many as usize,
|
||||
);
|
||||
}
|
||||
// Regardless of whether we have an offset or not, we reset the offset byte back to 0. This
|
||||
// probably will get set to 0 many times, but who cares?
|
||||
@ -261,14 +265,23 @@ impl FileSystem for MinixFileSystem {
|
||||
unsafe {
|
||||
if izones.add(i).read() != 0 {
|
||||
if offset_block <= blocks_seen {
|
||||
syc_read(desc, block_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * izones.add(i).read());
|
||||
syc_read(
|
||||
desc,
|
||||
block_buffer.get_mut(),
|
||||
BLOCK_SIZE,
|
||||
BLOCK_SIZE * izones.add(i,).read(),
|
||||
);
|
||||
let read_this_many = if BLOCK_SIZE - offset_byte > bytes_left {
|
||||
bytes_left
|
||||
}
|
||||
else {
|
||||
BLOCK_SIZE - offset_byte
|
||||
};
|
||||
memcpy(buffer.add(bytes_read as usize), block_buffer.get().add(offset_byte as usize), read_this_many as usize);
|
||||
memcpy(
|
||||
buffer.add(bytes_read as usize,),
|
||||
block_buffer.get().add(offset_byte as usize,),
|
||||
read_this_many as usize,
|
||||
);
|
||||
bytes_read += read_this_many;
|
||||
bytes_left -= read_this_many;
|
||||
offset_byte = 0;
|
||||
@ -297,7 +310,12 @@ impl FileSystem for MinixFileSystem {
|
||||
for j in 0..num_indirect_pointers {
|
||||
if iizones.add(j).read() != 0 {
|
||||
if offset_block <= blocks_seen {
|
||||
syc_read(desc, block_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * iizones.add(j).read());
|
||||
syc_read(
|
||||
desc,
|
||||
block_buffer.get_mut(),
|
||||
BLOCK_SIZE,
|
||||
BLOCK_SIZE * iizones.add(j,).read(),
|
||||
);
|
||||
let read_this_many = if BLOCK_SIZE - offset_byte > bytes_left {
|
||||
bytes_left
|
||||
}
|
||||
@ -340,20 +358,32 @@ impl FileSystem for MinixFileSystem {
|
||||
syc_read(desc, iindirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * izones.add(i).read());
|
||||
for j in 0..num_indirect_pointers {
|
||||
if iizones.add(j).read() != 0 {
|
||||
syc_read(desc, iiindirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * iizones.add(j).read());
|
||||
syc_read(
|
||||
desc,
|
||||
iiindirect_buffer.get_mut(),
|
||||
BLOCK_SIZE,
|
||||
BLOCK_SIZE * iizones.add(j,).read(),
|
||||
);
|
||||
for k in 0..num_indirect_pointers {
|
||||
if iiizones.add(k).read() != 0 {
|
||||
if offset_block <= blocks_seen {
|
||||
syc_read(desc, block_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * iiizones.add(k).read());
|
||||
let read_this_many = if BLOCK_SIZE - offset_byte > bytes_left {
|
||||
bytes_left
|
||||
}
|
||||
else {
|
||||
BLOCK_SIZE - offset_byte
|
||||
};
|
||||
syc_read(
|
||||
desc,
|
||||
block_buffer.get_mut(),
|
||||
BLOCK_SIZE,
|
||||
BLOCK_SIZE * iiizones.add(k,).read(),
|
||||
);
|
||||
let read_this_many =
|
||||
if BLOCK_SIZE - offset_byte > bytes_left {
|
||||
bytes_left
|
||||
}
|
||||
else {
|
||||
BLOCK_SIZE - offset_byte
|
||||
};
|
||||
memcpy(
|
||||
buffer.add(bytes_read as usize,),
|
||||
block_buffer.get().add(offset_byte as usize,),
|
||||
block_buffer.get()
|
||||
.add(offset_byte as usize,),
|
||||
read_this_many as usize,
|
||||
);
|
||||
bytes_read += read_this_many;
|
||||
|
@ -4,7 +4,7 @@
|
||||
// 3 Jan 2020
|
||||
|
||||
use crate::{block::block_op,
|
||||
cpu::{TrapFrame, dump_registers},
|
||||
cpu::{dump_registers, TrapFrame},
|
||||
minixfs,
|
||||
page::{virt_to_phys, Table},
|
||||
process::{delete_process, get_by_pid, set_sleeping, set_waiting}};
|
||||
@ -13,15 +13,16 @@ use crate::{block::block_op,
|
||||
/// made here whether this is a U-mode, S-mode, or M-mode system call.
|
||||
/// Since we can't do anything unless we dereference the passed pointer,
|
||||
/// I went ahead and made the entire function unsafe.
|
||||
/// If we return 0 from this function, the m_trap function will schedule
|
||||
/// the next process--consider this a yield. A non-0 is the program counter
|
||||
/// we want to go back to.
|
||||
pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
let syscall_number;
|
||||
// Libgloss expects the system call number in A7, so let's follow
|
||||
// their lead.
|
||||
// A7 is X17, so it's register number 17.
|
||||
syscall_number = (*frame).regs[17];
|
||||
|
||||
let syscall_number = (*frame).regs[17];
|
||||
match syscall_number {
|
||||
0 | 93 => {
|
||||
0 | 93 => {
|
||||
// Exit
|
||||
// Currently, we cannot kill a process, it runs forever. We will delete
|
||||
// the process later and free the resources, but for now, we want to get
|
||||
@ -84,7 +85,14 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
// (*frame).regs[13]
|
||||
// );
|
||||
set_waiting((*frame).pid as u16);
|
||||
let _ = block_op((*frame).regs[10], (*frame).regs[11] as *mut u8, (*frame).regs[12] as u32, (*frame).regs[13] as u64, false, (*frame).pid as u16);
|
||||
let _ = block_op(
|
||||
(*frame).regs[10],
|
||||
(*frame).regs[11] as *mut u8,
|
||||
(*frame).regs[12] as u32,
|
||||
(*frame).regs[13] as u64,
|
||||
false,
|
||||
(*frame).pid as u16,
|
||||
);
|
||||
0
|
||||
},
|
||||
_ => {
|
||||
|
Loading…
Reference in New Issue
Block a user