runtime alloc for virtio + fix some stack stuff
This commit is contained in:
parent
0b0a2afd6d
commit
e090331c23
3 changed files with 14 additions and 13 deletions
|
|
@ -51,8 +51,6 @@ SECTIONS {
|
|||
PROVIDE(_stack_end = _stack_start + 16384);
|
||||
PROVIDE(_tstack_start = _stack_end);
|
||||
PROVIDE(_tstack_end = _tstack_start + 16384);
|
||||
PROVIDE(_virtio_virtqueue_start = _tstack_end);
|
||||
PROVIDE(_virtio_virtqueue_end = _virtio_virtqueue_start + 32768);
|
||||
PROVIDE(_heap_start = _virtio_virtqueue_end);
|
||||
PROVIDE(_heap_start = _tstack_end);
|
||||
PROVIDE(_heap_size = _MEM_END - _heap_start);
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
use crate::dev::virtio::{Descriptor, VIRTIO_DESC_F_NEXT, VIRTIO_DESC_F_WRITE, VIRTIO_MMIO_GUEST_FEATURES, VIRTIO_MMIO_GUEST_PAGE_SIZE, VIRTIO_MMIO_HOST_FEATURES, VIRTIO_MMIO_QUEUE_NOTIFY, VIRTIO_MMIO_QUEUE_NUM, VIRTIO_MMIO_QUEUE_NUM_MAX, VIRTIO_MMIO_QUEUE_PFN, VIRTIO_MMIO_QUEUE_SEL, VIRTIO_MMIO_STATUS, VIRTIO_MMIO_STATUS_ACKNOWLEDGE, VIRTIO_MMIO_STATUS_DRIVER, VIRTIO_MMIO_STATUS_DRIVER_OK, VIRTIO_MMIO_STATUS_FAILED, VIRTIO_MMIO_STATUS_FEATURES_OK, VIRTIO_QUEUE_SIZE, VirtQueue, Used};
|
||||
use crate::trafficcontrol::{TaskWait, TrafficControl};
|
||||
|
||||
unsafe extern "C" {
|
||||
fn _virtio_virtqueue_start();
|
||||
}
|
||||
#[repr(C)]
|
||||
pub struct Status {
|
||||
pub status: u8,
|
||||
|
|
@ -96,8 +93,12 @@ impl VirtIoBlockDevice {
|
|||
unsafe {
|
||||
((addr + VIRTIO_MMIO_QUEUE_SEL) as *mut u32).write_volatile(0);
|
||||
}
|
||||
let queue_ptr= _virtio_virtqueue_start as usize;
|
||||
unsafe { ((addr + VIRTIO_MMIO_GUEST_PAGE_SIZE) as *mut u32).write_volatile(4096) }; // who knows if this actually works :p
|
||||
let num_blocks = size_of::<VirtQueue>().div_ceil(512) + 8; // 8 extra blocks will assert that the queue is aligned to 4096 bytes
|
||||
let queue_block= unsafe { tc.memory_manager.as_mut().unwrap_unchecked().alloc_n_blocks(num_blocks) };
|
||||
let queue_ptr = unsafe { tc.memory_manager.as_mut().unwrap_unchecked().block_to_addr(queue_block) };
|
||||
// align up to 4096
|
||||
let queue_ptr = queue_ptr.wrapping_add(4095) & !(4095);
|
||||
unsafe { ((addr + VIRTIO_MMIO_GUEST_PAGE_SIZE) as *mut u32).write_volatile(4096) };
|
||||
unsafe {
|
||||
((addr + VIRTIO_MMIO_QUEUE_PFN) as *mut u32).write_volatile(queue_ptr as u32 / 4096)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ pub enum TaskWait {
|
|||
WaitForTaskExit = 1 << 2,
|
||||
}
|
||||
|
||||
pub const STACK_SIZE_IN_BLOCKS: usize = 16;
|
||||
|
||||
pub const MAX_TASKS: usize = 8;
|
||||
|
||||
pub static TC: Spinlock<TrafficControl> = Spinlock::new(TrafficControl::empty());
|
||||
|
|
@ -71,14 +73,14 @@ pub fn handle_syscall(
|
|||
tc.memory_manager
|
||||
.as_mut()
|
||||
.unwrap_unchecked()
|
||||
.alloc_n_blocks(16)
|
||||
.alloc_n_blocks(STACK_SIZE_IN_BLOCKS)
|
||||
};
|
||||
let sp = unsafe {
|
||||
tc.memory_manager
|
||||
.as_mut()
|
||||
.unwrap_unchecked()
|
||||
.block_to_addr(blockalloc)
|
||||
+ BLOCK_SIZE
|
||||
+ (BLOCK_SIZE * STACK_SIZE_IN_BLOCKS)
|
||||
};
|
||||
|
||||
#[cfg(feature = "arch_virt")]
|
||||
|
|
@ -352,17 +354,17 @@ pub fn context_switch<'a>(tc: &'a mut TrafficControl, current: Task) -> Option<&
|
|||
tc.memory_manager
|
||||
.as_mut()
|
||||
.unwrap_unchecked()
|
||||
.addr_to_block(sp - BLOCK_SIZE)
|
||||
.addr_to_block(sp - (BLOCK_SIZE * STACK_SIZE_IN_BLOCKS))
|
||||
};
|
||||
unsafe {
|
||||
tc.memory_manager
|
||||
.as_mut()
|
||||
.unwrap_unchecked()
|
||||
.free_n_blocks(stackblock, 4)
|
||||
.free_n_blocks(stackblock, STACK_SIZE_IN_BLOCKS)
|
||||
};
|
||||
unsafe {
|
||||
tc.memory_manager.as_mut().unwrap_unchecked()
|
||||
.free_n_blocks(ddi_start_block as usize, ddi_blocks_count as usize)
|
||||
.free_n_blocks(ddi_start_block, ddi_blocks_count)
|
||||
}
|
||||
}
|
||||
tc.tasks[i] = None;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue