1
0
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:
Stephen Marz 2020-04-25 18:48:23 -04:00
parent 056ef5bb2d
commit 84e5126d29
2 changed files with 57 additions and 19 deletions

View File

@ -228,7 +228,11 @@ impl FileSystem for MinixFileSystem {
// Once again, here we actually copy the bytes into the final destination, the buffer. This memcpy // Once again, here we actually copy the bytes into the final destination, the buffer. This memcpy
// is written in cpu.rs. // is written in cpu.rs.
unsafe { 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 // 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? // probably will get set to 0 many times, but who cares?
@ -261,14 +265,23 @@ impl FileSystem for MinixFileSystem {
unsafe { unsafe {
if izones.add(i).read() != 0 { if izones.add(i).read() != 0 {
if offset_block <= blocks_seen { 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 { let read_this_many = if BLOCK_SIZE - offset_byte > bytes_left {
bytes_left bytes_left
} }
else { else {
BLOCK_SIZE - offset_byte 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_read += read_this_many;
bytes_left -= read_this_many; bytes_left -= read_this_many;
offset_byte = 0; offset_byte = 0;
@ -297,7 +310,12 @@ impl FileSystem for MinixFileSystem {
for j in 0..num_indirect_pointers { for j in 0..num_indirect_pointers {
if iizones.add(j).read() != 0 { if iizones.add(j).read() != 0 {
if offset_block <= blocks_seen { 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 { let read_this_many = if BLOCK_SIZE - offset_byte > bytes_left {
bytes_left bytes_left
} }
@ -340,12 +358,23 @@ impl FileSystem for MinixFileSystem {
syc_read(desc, iindirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * izones.add(i).read()); syc_read(desc, iindirect_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * izones.add(i).read());
for j in 0..num_indirect_pointers { for j in 0..num_indirect_pointers {
if iizones.add(j).read() != 0 { 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 { for k in 0..num_indirect_pointers {
if iiizones.add(k).read() != 0 { if iiizones.add(k).read() != 0 {
if offset_block <= blocks_seen { if offset_block <= blocks_seen {
syc_read(desc, block_buffer.get_mut(), BLOCK_SIZE, BLOCK_SIZE * iiizones.add(k).read()); syc_read(
let read_this_many = if BLOCK_SIZE - offset_byte > bytes_left { 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 bytes_left
} }
else { else {
@ -353,7 +382,8 @@ impl FileSystem for MinixFileSystem {
}; };
memcpy( memcpy(
buffer.add(bytes_read as usize,), 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, read_this_many as usize,
); );
bytes_read += read_this_many; bytes_read += read_this_many;

View File

@ -4,7 +4,7 @@
// 3 Jan 2020 // 3 Jan 2020
use crate::{block::block_op, use crate::{block::block_op,
cpu::{TrapFrame, dump_registers}, cpu::{dump_registers, TrapFrame},
minixfs, minixfs,
page::{virt_to_phys, Table}, page::{virt_to_phys, Table},
process::{delete_process, get_by_pid, set_sleeping, set_waiting}}; process::{delete_process, get_by_pid, set_sleeping, set_waiting}};
@ -13,13 +13,14 @@ use crate::{block::block_op,
/// made here whether this is a U-mode, S-mode, or M-mode system call. /// 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, /// Since we can't do anything unless we dereference the passed pointer,
/// I went ahead and made the entire function unsafe. /// 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 { 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 // Libgloss expects the system call number in A7, so let's follow
// their lead. // their lead.
// A7 is X17, so it's register number 17. // A7 is X17, so it's register number 17.
syscall_number = (*frame).regs[17]; let syscall_number = (*frame).regs[17];
match syscall_number { match syscall_number {
0 | 93 => { 0 | 93 => {
// Exit // Exit
@ -84,7 +85,14 @@ pub unsafe fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
// (*frame).regs[13] // (*frame).regs[13]
// ); // );
set_waiting((*frame).pid as u16); 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 0
}, },
_ => { _ => {