mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-23 18:06:20 +04:00
Don't let init sleep. This will cause us to hang in the scheduler.
This commit is contained in:
parent
73636c1de1
commit
58ab3f3b6f
@ -5,9 +5,10 @@
|
||||
|
||||
use crate::{kmem::{kfree, kmalloc, talloc, tfree},
|
||||
page::{zalloc, PAGE_SIZE},
|
||||
process::{add_kernel_process_args, set_running, set_waiting},
|
||||
syscall::syscall_exit,
|
||||
virtio,
|
||||
virtio::{Descriptor, MmioOffsets, Queue, StatusField, VIRTIO_RING_SIZE}};
|
||||
use crate::process::{set_running, set_waiting, get_by_pid, add_kernel_process_args};
|
||||
virtio::{Descriptor, MmioOffsets, Queue, StatusField, VIRTIO_RING_SIZE}};
|
||||
use core::mem::size_of;
|
||||
|
||||
#[repr(C)]
|
||||
@ -131,7 +132,7 @@ pub enum BlockErrors {
|
||||
Success = 0,
|
||||
BlockDeviceNotFound,
|
||||
InvalidArgument,
|
||||
ReadOnly
|
||||
ReadOnly,
|
||||
}
|
||||
|
||||
// Much like with processes, Rust requires some initialization
|
||||
@ -263,7 +264,14 @@ pub fn fill_next_descriptor(bd: &mut BlockDevice, desc: Descriptor) -> u16 {
|
||||
/// a multiple of 512, but we don't really check that.
|
||||
/// We DO however, check that we aren't writing to an R/O device. This would
|
||||
/// cause a I/O error if we tried to write to a R/O device.
|
||||
pub fn block_op(dev: usize, buffer: *mut u8, size: u32, offset: u64, write: bool, watcher: u16) -> Result<u32, BlockErrors> {
|
||||
pub fn block_op(dev: usize,
|
||||
buffer: *mut u8,
|
||||
size: u32,
|
||||
offset: u64,
|
||||
write: bool,
|
||||
watcher: u16)
|
||||
-> Result<u32, BlockErrors>
|
||||
{
|
||||
unsafe {
|
||||
if let Some(bdev) = BLOCK_DEVICES[dev - 1].as_mut() {
|
||||
// Check to see if we are trying to write to a read only device.
|
||||
@ -316,7 +324,8 @@ pub fn block_op(dev: usize, buffer: *mut u8, size: u32, offset: u64, write: bool
|
||||
flags: virtio::VIRTIO_DESC_F_WRITE,
|
||||
next: 0, };
|
||||
let _status_idx = fill_next_descriptor(bdev, desc);
|
||||
(*bdev.queue).avail.ring[(*bdev.queue).avail.idx as usize % virtio::VIRTIO_RING_SIZE] = head_idx;
|
||||
(*bdev.queue).avail.ring[(*bdev.queue).avail.idx as usize % virtio::VIRTIO_RING_SIZE] =
|
||||
head_idx;
|
||||
(*bdev.queue).avail.idx = (*bdev.queue).avail.idx.wrapping_add(1);
|
||||
// The only queue a block device has is 0, which is the request
|
||||
// queue.
|
||||
@ -376,23 +385,24 @@ pub fn handle_interrupt(idx: usize) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ///////////////////////////////////////////////
|
||||
// // BLOCK PROCESSES (KERNEL PROCESSES)
|
||||
// ///////////////////////////////////////////////
|
||||
struct ProcArgs {
|
||||
pub pid: u16,
|
||||
pub dev: usize,
|
||||
pub pid: u16,
|
||||
pub dev: usize,
|
||||
pub buffer: *mut u8,
|
||||
pub size: u32,
|
||||
pub size: u32,
|
||||
pub offset: u64,
|
||||
}
|
||||
|
||||
/// This will be a
|
||||
fn read_proc(args_addr: usize) {
|
||||
let args_ptr = args_addr as *mut ProcArgs;
|
||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||
let _ = block_op(args.dev, args.buffer, args.size, args.offset, false, args.pid);
|
||||
tfree(args_ptr);
|
||||
syscall_exit();
|
||||
}
|
||||
|
||||
pub fn process_read(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u64) {
|
||||
@ -412,8 +422,8 @@ fn write_proc(args_addr: usize) {
|
||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||
|
||||
let _ = block_op(args.dev, args.buffer, args.size, args.offset, true, args.pid);
|
||||
|
||||
tfree(args_ptr);
|
||||
syscall_exit();
|
||||
}
|
||||
|
||||
pub fn process_write(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u64) {
|
||||
@ -425,4 +435,4 @@ pub fn process_write(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u
|
||||
args.offset = offset;
|
||||
set_waiting(pid);
|
||||
let _ = add_kernel_process_args(write_proc, args as *mut ProcArgs as usize);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@
|
||||
// Stephen Marz
|
||||
// 16 March 2020
|
||||
|
||||
use crate::{block,
|
||||
fs::{Descriptor, FileSystem, FsError, Stat},
|
||||
kmem::{kfree, kmalloc, talloc, tfree}};
|
||||
use crate::process::{set_waiting, set_running, add_kernel_process_args};
|
||||
use crate::{fs::{Descriptor, FileSystem, FsError, Stat},
|
||||
kmem::{kfree, kmalloc, talloc, tfree},
|
||||
process::{add_kernel_process_args, set_waiting},
|
||||
syscall::syscall_exit};
|
||||
|
||||
use alloc::string::String;
|
||||
use core::{mem::size_of, ptr::null_mut};
|
||||
@ -122,7 +122,11 @@ impl MinixFileSystem {
|
||||
let inode = unsafe { &*(buffer.get_mut() as *mut Inode) };
|
||||
// Read from the block device. The size is 1 sector (512 bytes) and our offset is past
|
||||
// the boot block (first 1024 bytes). This is where the superblock sits.
|
||||
println!("DO READ, magic should be next, buffer is at {:p}, desc is at {:p}", buffer.get(), desc as *const Descriptor);
|
||||
println!(
|
||||
"DO READ, magic should be next, buffer is at {:p}, desc is at {:p}",
|
||||
buffer.get(),
|
||||
desc as *const Descriptor
|
||||
);
|
||||
syc_read(desc, buffer.get_mut(), 512, 1024);
|
||||
println!("Magic is {:x}", super_block.magic);
|
||||
if super_block.magic == MAGIC {
|
||||
@ -234,33 +238,26 @@ pub fn syc_read(desc: &Descriptor, buffer: *mut u8, size: u32, offset: u32) {
|
||||
}
|
||||
|
||||
struct ProcArgs {
|
||||
pub pid: u16,
|
||||
pub dev: usize,
|
||||
pub pid: u16,
|
||||
pub dev: usize,
|
||||
pub buffer: *mut u8,
|
||||
pub size: u32,
|
||||
pub offset: u32
|
||||
pub size: u32,
|
||||
pub offset: u32,
|
||||
}
|
||||
|
||||
fn read_proc(args_addr: usize) {
|
||||
let args_ptr = args_addr as *mut ProcArgs;
|
||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||
|
||||
let desc = Descriptor {
|
||||
blockdev: args.dev,
|
||||
node: 1,
|
||||
loc: 0,
|
||||
size: 500,
|
||||
pid: args.pid
|
||||
};
|
||||
let desc = Descriptor { blockdev: args.dev,
|
||||
node: 1,
|
||||
loc: 0,
|
||||
size: 500,
|
||||
pid: args.pid, };
|
||||
|
||||
MinixFileSystem::read(&desc, args.buffer, args.offset, args.size);
|
||||
tfree(args_ptr);
|
||||
unsafe {
|
||||
extern "C" {
|
||||
fn make_syscall(no: usize);
|
||||
}
|
||||
make_syscall(93);
|
||||
}
|
||||
syscall_exit();
|
||||
}
|
||||
|
||||
pub fn process_read(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u32) {
|
||||
|
@ -157,7 +157,7 @@ fn init_process() {
|
||||
fn make_syscall(sysno: usize, duration: usize) -> usize;
|
||||
}
|
||||
println!("Init is still here :), alright, back to sleep.");
|
||||
make_syscall(2, 60000000);
|
||||
for _ in 0..100000000 {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,20 @@ pub fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn make_syscall(sysno: usize, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize;
|
||||
}
|
||||
|
||||
fn do_make_syscall(sysno: usize, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
|
||||
unsafe {
|
||||
make_syscall(sysno, arg0, arg1, arg2, arg3, arg4, arg5)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn syscall_exit() {
|
||||
let _ = do_make_syscall(93, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// These system call numbers come from libgloss so that we can use newlib
|
||||
// for our system calls.
|
||||
// Libgloss wants the system call number in A7 and arguments in A0..A6
|
||||
|
Loading…
Reference in New Issue
Block a user