mirror of
https://github.com/sgmarz/osblog.git
synced 2024-11-24 02:16:19 +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},
|
use crate::{kmem::{kfree, kmalloc, talloc, tfree},
|
||||||
page::{zalloc, PAGE_SIZE},
|
page::{zalloc, PAGE_SIZE},
|
||||||
|
process::{add_kernel_process_args, set_running, set_waiting},
|
||||||
|
syscall::syscall_exit,
|
||||||
virtio,
|
virtio,
|
||||||
virtio::{Descriptor, MmioOffsets, Queue, StatusField, VIRTIO_RING_SIZE}};
|
virtio::{Descriptor, MmioOffsets, Queue, StatusField, VIRTIO_RING_SIZE}};
|
||||||
use crate::process::{set_running, set_waiting, get_by_pid, add_kernel_process_args};
|
|
||||||
use core::mem::size_of;
|
use core::mem::size_of;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -131,7 +132,7 @@ pub enum BlockErrors {
|
|||||||
Success = 0,
|
Success = 0,
|
||||||
BlockDeviceNotFound,
|
BlockDeviceNotFound,
|
||||||
InvalidArgument,
|
InvalidArgument,
|
||||||
ReadOnly
|
ReadOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Much like with processes, Rust requires some initialization
|
// 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.
|
/// 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
|
/// 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.
|
/// 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 {
|
unsafe {
|
||||||
if let Some(bdev) = BLOCK_DEVICES[dev - 1].as_mut() {
|
if let Some(bdev) = BLOCK_DEVICES[dev - 1].as_mut() {
|
||||||
// Check to see if we are trying to write to a read only device.
|
// 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,
|
flags: virtio::VIRTIO_DESC_F_WRITE,
|
||||||
next: 0, };
|
next: 0, };
|
||||||
let _status_idx = fill_next_descriptor(bdev, desc);
|
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);
|
(*bdev.queue).avail.idx = (*bdev.queue).avail.idx.wrapping_add(1);
|
||||||
// The only queue a block device has is 0, which is the request
|
// The only queue a block device has is 0, which is the request
|
||||||
// queue.
|
// queue.
|
||||||
@ -376,23 +385,24 @@ pub fn handle_interrupt(idx: usize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ///////////////////////////////////////////////
|
// ///////////////////////////////////////////////
|
||||||
// // BLOCK PROCESSES (KERNEL PROCESSES)
|
// // BLOCK PROCESSES (KERNEL PROCESSES)
|
||||||
// ///////////////////////////////////////////////
|
// ///////////////////////////////////////////////
|
||||||
struct ProcArgs {
|
struct ProcArgs {
|
||||||
pub pid: u16,
|
pub pid: u16,
|
||||||
pub dev: usize,
|
pub dev: usize,
|
||||||
pub buffer: *mut u8,
|
pub buffer: *mut u8,
|
||||||
pub size: u32,
|
pub size: u32,
|
||||||
pub offset: u64,
|
pub offset: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This will be a
|
||||||
fn read_proc(args_addr: usize) {
|
fn read_proc(args_addr: usize) {
|
||||||
let args_ptr = args_addr as *mut ProcArgs;
|
let args_ptr = args_addr as *mut ProcArgs;
|
||||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||||
let _ = block_op(args.dev, args.buffer, args.size, args.offset, false, args.pid);
|
let _ = block_op(args.dev, args.buffer, args.size, args.offset, false, args.pid);
|
||||||
tfree(args_ptr);
|
tfree(args_ptr);
|
||||||
|
syscall_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_read(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u64) {
|
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 args = unsafe { args_ptr.as_ref().unwrap() };
|
||||||
|
|
||||||
let _ = block_op(args.dev, args.buffer, args.size, args.offset, true, args.pid);
|
let _ = block_op(args.dev, args.buffer, args.size, args.offset, true, args.pid);
|
||||||
|
|
||||||
tfree(args_ptr);
|
tfree(args_ptr);
|
||||||
|
syscall_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_write(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u64) {
|
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;
|
args.offset = offset;
|
||||||
set_waiting(pid);
|
set_waiting(pid);
|
||||||
let _ = add_kernel_process_args(write_proc, args as *mut ProcArgs as usize);
|
let _ = add_kernel_process_args(write_proc, args as *mut ProcArgs as usize);
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
// Stephen Marz
|
// Stephen Marz
|
||||||
// 16 March 2020
|
// 16 March 2020
|
||||||
|
|
||||||
use crate::{block,
|
use crate::{fs::{Descriptor, FileSystem, FsError, Stat},
|
||||||
fs::{Descriptor, FileSystem, FsError, Stat},
|
kmem::{kfree, kmalloc, talloc, tfree},
|
||||||
kmem::{kfree, kmalloc, talloc, tfree}};
|
process::{add_kernel_process_args, set_waiting},
|
||||||
use crate::process::{set_waiting, set_running, add_kernel_process_args};
|
syscall::syscall_exit};
|
||||||
|
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use core::{mem::size_of, ptr::null_mut};
|
use core::{mem::size_of, ptr::null_mut};
|
||||||
@ -122,7 +122,11 @@ impl MinixFileSystem {
|
|||||||
let inode = unsafe { &*(buffer.get_mut() as *mut Inode) };
|
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
|
// 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.
|
// 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);
|
syc_read(desc, buffer.get_mut(), 512, 1024);
|
||||||
println!("Magic is {:x}", super_block.magic);
|
println!("Magic is {:x}", super_block.magic);
|
||||||
if super_block.magic == 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 {
|
struct ProcArgs {
|
||||||
pub pid: u16,
|
pub pid: u16,
|
||||||
pub dev: usize,
|
pub dev: usize,
|
||||||
pub buffer: *mut u8,
|
pub buffer: *mut u8,
|
||||||
pub size: u32,
|
pub size: u32,
|
||||||
pub offset: u32
|
pub offset: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_proc(args_addr: usize) {
|
fn read_proc(args_addr: usize) {
|
||||||
let args_ptr = args_addr as *mut ProcArgs;
|
let args_ptr = args_addr as *mut ProcArgs;
|
||||||
let args = unsafe { args_ptr.as_ref().unwrap() };
|
let args = unsafe { args_ptr.as_ref().unwrap() };
|
||||||
|
|
||||||
let desc = Descriptor {
|
let desc = Descriptor { blockdev: args.dev,
|
||||||
blockdev: args.dev,
|
node: 1,
|
||||||
node: 1,
|
loc: 0,
|
||||||
loc: 0,
|
size: 500,
|
||||||
size: 500,
|
pid: args.pid, };
|
||||||
pid: args.pid
|
|
||||||
};
|
|
||||||
|
|
||||||
MinixFileSystem::read(&desc, args.buffer, args.offset, args.size);
|
MinixFileSystem::read(&desc, args.buffer, args.offset, args.size);
|
||||||
tfree(args_ptr);
|
tfree(args_ptr);
|
||||||
unsafe {
|
syscall_exit();
|
||||||
extern "C" {
|
|
||||||
fn make_syscall(no: usize);
|
|
||||||
}
|
|
||||||
make_syscall(93);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_read(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u32) {
|
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;
|
fn make_syscall(sysno: usize, duration: usize) -> usize;
|
||||||
}
|
}
|
||||||
println!("Init is still here :), alright, back to sleep.");
|
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
|
// These system call numbers come from libgloss so that we can use newlib
|
||||||
// for our system calls.
|
// for our system calls.
|
||||||
// Libgloss wants the system call number in A7 and arguments in A0..A6
|
// Libgloss wants the system call number in A7 and arguments in A0..A6
|
||||||
|
Loading…
Reference in New Issue
Block a user