mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 19:33:23 +00:00
format files
This commit is contained in:
@ -1,6 +1,9 @@
|
|||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields, DataEnum, punctuated::Punctuated, token::Comma, Field};
|
use syn::{
|
||||||
|
parse_macro_input, punctuated::Punctuated, token::Comma, Data, DataEnum, DataStruct,
|
||||||
|
DeriveInput, Field, Fields,
|
||||||
|
};
|
||||||
|
|
||||||
#[proc_macro_derive(Pod)]
|
#[proc_macro_derive(Pod)]
|
||||||
pub fn derive_pod(input_token: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
pub fn derive_pod(input_token: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||||
@ -16,9 +19,9 @@ fn expand_derive_pod(input: DeriveInput) -> TokenStream {
|
|||||||
Fields::Unnamed(fields_unnamed) => fields_unnamed.unnamed,
|
Fields::Unnamed(fields_unnamed) => fields_unnamed.unnamed,
|
||||||
Fields::Unit => Punctuated::new(),
|
Fields::Unit => Punctuated::new(),
|
||||||
},
|
},
|
||||||
Data::Enum(DataEnum{variants,..})=>{
|
Data::Enum(DataEnum { variants, .. }) => {
|
||||||
let mut fields : Punctuated<Field,Comma> = Punctuated::new();
|
let mut fields: Punctuated<Field, Comma> = Punctuated::new();
|
||||||
for var in variants{
|
for var in variants {
|
||||||
fields.extend(match var.fields {
|
fields.extend(match var.fields {
|
||||||
Fields::Named(fields_named) => fields_named.named,
|
Fields::Named(fields_named) => fields_named.named,
|
||||||
Fields::Unnamed(fields_unnamed) => fields_unnamed.unnamed,
|
Fields::Unnamed(fields_unnamed) => fields_unnamed.unnamed,
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
pub mod framebuffer;
|
pub mod framebuffer;
|
||||||
mod io_port;
|
mod io_port;
|
||||||
pub mod pci;
|
pub mod pci;
|
||||||
pub mod serial;
|
|
||||||
mod pic;
|
mod pic;
|
||||||
|
pub mod serial;
|
||||||
|
|
||||||
pub use pic::{TimerCallback, TIMER_FREQ};
|
|
||||||
pub(crate) use pic::{add_timeout_list,TICK};
|
|
||||||
pub use self::io_port::IoPort;
|
pub use self::io_port::IoPort;
|
||||||
|
pub(crate) use pic::{add_timeout_list, TICK};
|
||||||
|
pub use pic::{TimerCallback, TIMER_FREQ};
|
||||||
|
|
||||||
pub(crate) fn init(framebuffer: &'static mut bootloader::boot_info::FrameBuffer) {
|
pub(crate) fn init(framebuffer: &'static mut bootloader::boot_info::FrameBuffer) {
|
||||||
framebuffer::init(framebuffer);
|
framebuffer::init(framebuffer);
|
||||||
|
@ -78,7 +78,7 @@ fn timer_callback(trap_frame: &TrapFrame) {
|
|||||||
TICK += 1;
|
TICK += 1;
|
||||||
}
|
}
|
||||||
let timeout_list = TIMEOUT_LIST.get();
|
let timeout_list = TIMEOUT_LIST.get();
|
||||||
let mut callbacks : Vec<Arc<TimerCallback>>= Vec::new();
|
let mut callbacks: Vec<Arc<TimerCallback>> = Vec::new();
|
||||||
while let Some(t) = timeout_list.peek() {
|
while let Some(t) = timeout_list.peek() {
|
||||||
if t.expire_ms <= current_ms {
|
if t.expire_ms <= current_ms {
|
||||||
callbacks.push(timeout_list.pop().unwrap());
|
callbacks.push(timeout_list.pop().unwrap());
|
||||||
@ -86,8 +86,8 @@ fn timer_callback(trap_frame: &TrapFrame) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for callback in callbacks{
|
for callback in callbacks {
|
||||||
if callback.is_enable(){
|
if callback.is_enable() {
|
||||||
callback.callback.call((&callback,));
|
callback.callback.call((&callback,));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ fn timer_callback(trap_frame: &TrapFrame) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TIMEOUT_LIST: Cell<BinaryHeap<Arc<TimerCallback>>> = Cell::new(BinaryHeap::new()) ;
|
static ref TIMEOUT_LIST: Cell<BinaryHeap<Arc<TimerCallback>>> = Cell::new(BinaryHeap::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TimerCallback {
|
pub struct TimerCallback {
|
||||||
@ -115,7 +115,7 @@ impl TimerCallback {
|
|||||||
expire_ms: timeout_ms,
|
expire_ms: timeout_ms,
|
||||||
data,
|
data,
|
||||||
callback,
|
callback,
|
||||||
enable:Cell::new(true),
|
enable: Cell::new(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,19 +124,18 @@ impl TimerCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// disable this timeout
|
/// disable this timeout
|
||||||
pub fn disable(&self){
|
pub fn disable(&self) {
|
||||||
*self.enable.get() = false;
|
*self.enable.get() = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// enable this timeout
|
/// enable this timeout
|
||||||
pub fn enable(&self){
|
pub fn enable(&self) {
|
||||||
*self.enable.get() = true;
|
*self.enable.get() = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_enable(&self) -> bool{
|
pub fn is_enable(&self) -> bool {
|
||||||
*self.enable
|
*self.enable
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for TimerCallback {
|
impl PartialEq for TimerCallback {
|
||||||
@ -167,14 +166,9 @@ pub fn add_timeout_list<F, T>(timeout: u64, data: T, callback: F) -> Arc<TimerCa
|
|||||||
where
|
where
|
||||||
F: Fn(&TimerCallback) + Send + Sync + 'static,
|
F: Fn(&TimerCallback) + Send + Sync + 'static,
|
||||||
T: Any + Send + Sync,
|
T: Any + Send + Sync,
|
||||||
|
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let timer_callback = TimerCallback::new(
|
let timer_callback = TimerCallback::new(TICK + timeout, Arc::new(data), Box::new(callback));
|
||||||
TICK + timeout,
|
|
||||||
Arc::new(data),
|
|
||||||
Box::new(callback),
|
|
||||||
);
|
|
||||||
let arc = Arc::new(timer_callback);
|
let arc = Arc::new(timer_callback);
|
||||||
TIMEOUT_LIST.get().push(arc.clone());
|
TIMEOUT_LIST.get().push(arc.clone());
|
||||||
arc
|
arc
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
//! Timer.
|
//! Timer.
|
||||||
|
|
||||||
use crate::{prelude::*, device::{TimerCallback, TICK,TIMER_FREQ}};
|
use crate::{
|
||||||
use spin::Mutex;
|
device::{TimerCallback, TICK, TIMER_FREQ},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
|
use spin::Mutex;
|
||||||
|
|
||||||
/// A timer invokes a callback function after a specified span of time elapsed.
|
/// A timer invokes a callback function after a specified span of time elapsed.
|
||||||
///
|
///
|
||||||
@ -13,57 +16,67 @@ use core::time::Duration;
|
|||||||
/// Timers are one-shot. If the time is out, one has to set the timer again
|
/// Timers are one-shot. If the time is out, one has to set the timer again
|
||||||
/// in order to trigger the callback again.
|
/// in order to trigger the callback again.
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
function: Arc<dyn Fn(Arc<Self>)+Send+Sync>,
|
function: Arc<dyn Fn(Arc<Self>) + Send + Sync>,
|
||||||
inner: Mutex<TimerInner>,
|
inner: Mutex<TimerInner>,
|
||||||
}
|
}
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TimerInner{
|
struct TimerInner {
|
||||||
start_tick: u64,
|
start_tick: u64,
|
||||||
timeout_tick:u64,
|
timeout_tick: u64,
|
||||||
timer_callback:Option<Arc<TimerCallback>>,
|
timer_callback: Option<Arc<TimerCallback>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timer_callback(callback:&TimerCallback){
|
fn timer_callback(callback: &TimerCallback) {
|
||||||
let data = callback.data();
|
let data = callback.data();
|
||||||
if data.is::<Arc<Timer>>(){
|
if data.is::<Arc<Timer>>() {
|
||||||
let timer = data.downcast_ref::<Arc<Timer>>().unwrap();
|
let timer = data.downcast_ref::<Arc<Timer>>().unwrap();
|
||||||
timer.function.call((timer.clone(),));
|
timer.function.call((timer.clone(),));
|
||||||
}else{
|
} else {
|
||||||
panic!("the timer callback is not Timer structure");
|
panic!("the timer callback is not Timer structure");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const NANOS_DIVIDE : u64 = 1_000_000_000/TIMER_FREQ;
|
const NANOS_DIVIDE: u64 = 1_000_000_000 / TIMER_FREQ;
|
||||||
|
|
||||||
impl Timer {
|
impl Timer {
|
||||||
/// Creates a new instance, given a callback function.
|
/// Creates a new instance, given a callback function.
|
||||||
pub fn new<F>(f: F) -> Result<Arc<Self>>
|
pub fn new<F>(f: F) -> Result<Arc<Self>>
|
||||||
where
|
where
|
||||||
F: Fn(Arc<Timer>) +Send+Sync+'static,
|
F: Fn(Arc<Timer>) + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
Ok(Arc::new(Self { function: Arc::new(f),inner:Mutex::new(TimerInner::default()) }))
|
Ok(Arc::new(Self {
|
||||||
|
function: Arc::new(f),
|
||||||
|
inner: Mutex::new(TimerInner::default()),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a timeout value.
|
/// Set a timeout value.
|
||||||
///
|
///
|
||||||
/// If a timeout value is already set, the timeout value will be refreshed.
|
/// If a timeout value is already set, the timeout value will be refreshed.
|
||||||
///
|
///
|
||||||
pub fn set(self : Arc<Self>, timeout: Duration) {
|
pub fn set(self: Arc<Self>, timeout: Duration) {
|
||||||
let mut lock = self.inner.lock();
|
let mut lock = self.inner.lock();
|
||||||
match &lock.timer_callback{
|
match &lock.timer_callback {
|
||||||
Some(callback) => {
|
Some(callback) => {
|
||||||
callback.disable();
|
callback.disable();
|
||||||
},
|
|
||||||
None => {},
|
|
||||||
}
|
}
|
||||||
let tick_count = timeout.as_secs()*TIMER_FREQ
|
None => {}
|
||||||
+ if timeout.subsec_nanos() !=0{(timeout.subsec_nanos() as u64 - 1)/NANOS_DIVIDE + 1} else {0};
|
}
|
||||||
unsafe{
|
let tick_count = timeout.as_secs() * TIMER_FREQ
|
||||||
|
+ if timeout.subsec_nanos() != 0 {
|
||||||
|
(timeout.subsec_nanos() as u64 - 1) / NANOS_DIVIDE + 1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
unsafe {
|
||||||
lock.start_tick = TICK;
|
lock.start_tick = TICK;
|
||||||
lock.timeout_tick = TICK+tick_count;
|
lock.timeout_tick = TICK + tick_count;
|
||||||
}
|
}
|
||||||
lock.timer_callback = Some(crate::device::add_timeout_list(tick_count, self.clone(), timer_callback));
|
lock.timer_callback = Some(crate::device::add_timeout_list(
|
||||||
|
tick_count,
|
||||||
|
self.clone(),
|
||||||
|
timer_callback,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the remaining timeout value.
|
/// Returns the remaining timeout value.
|
||||||
@ -72,22 +85,22 @@ impl Timer {
|
|||||||
pub fn remain(&self) -> Duration {
|
pub fn remain(&self) -> Duration {
|
||||||
let lock = self.inner.lock();
|
let lock = self.inner.lock();
|
||||||
let tick_remain;
|
let tick_remain;
|
||||||
unsafe{
|
unsafe {
|
||||||
tick_remain = lock.timeout_tick as i64-TICK as i64;
|
tick_remain = lock.timeout_tick as i64 - TICK as i64;
|
||||||
}
|
}
|
||||||
if tick_remain<=0{
|
if tick_remain <= 0 {
|
||||||
Duration::new(0,0)
|
Duration::new(0, 0)
|
||||||
}else{
|
} else {
|
||||||
let second_count = tick_remain as u64/TIMER_FREQ;
|
let second_count = tick_remain as u64 / TIMER_FREQ;
|
||||||
let remain_count = tick_remain as u64 % TIMER_FREQ;
|
let remain_count = tick_remain as u64 % TIMER_FREQ;
|
||||||
Duration::new(second_count,(remain_count * NANOS_DIVIDE) as u32)
|
Duration::new(second_count, (remain_count * NANOS_DIVIDE) as u32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear the timeout value.
|
/// Clear the timeout value.
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
let mut lock = self.inner.lock();
|
let mut lock = self.inner.lock();
|
||||||
if let Some(callback) = &lock.timer_callback{
|
if let Some(callback) = &lock.timer_callback {
|
||||||
callback.disable();
|
callback.disable();
|
||||||
}
|
}
|
||||||
lock.timeout_tick = 0;
|
lock.timeout_tick = 0;
|
||||||
|
@ -41,7 +41,7 @@ pub(crate) extern "C" fn trap_handler(f: &mut TrapFrame) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if is_cpu_fault(f){
|
if is_cpu_fault(f) {
|
||||||
panic!("cannot handle kernel cpu fault now");
|
panic!("cannot handle kernel cpu fault now");
|
||||||
}
|
}
|
||||||
let irq_line = IRQ_LIST.get(f.id as usize).unwrap();
|
let irq_line = IRQ_LIST.get(f.id as usize).unwrap();
|
||||||
|
@ -22,7 +22,7 @@ pub struct MSIXEntry {
|
|||||||
pub irq_handle: IrqAllocateHandle,
|
pub irq_handle: IrqAllocateHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq,Pod)]
|
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Pod)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct MSIXTableEntry {
|
pub struct MSIXTableEntry {
|
||||||
pub msg_addr: u32,
|
pub msg_addr: u32,
|
||||||
|
@ -4,9 +4,9 @@ use crate::process::Process;
|
|||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use kxos_frame::info;
|
use kxos_frame::info;
|
||||||
|
use kxos_frame_pod_derive::Pod;
|
||||||
use kxos_pci::PCIDevice;
|
use kxos_pci::PCIDevice;
|
||||||
use kxos_virtio::PCIVirtioDevice;
|
use kxos_virtio::PCIVirtioDevice;
|
||||||
use kxos_frame_pod_derive::Pod;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use spin::mutex::Mutex;
|
use spin::mutex::Mutex;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ pub struct VirtioBlockDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Copy, Clone,Pod)]
|
#[derive(Debug, Copy, Clone, Pod)]
|
||||||
pub struct BlkReq {
|
pub struct BlkReq {
|
||||||
pub type_: ReqType,
|
pub type_: ReqType,
|
||||||
pub reserved: u32,
|
pub reserved: u32,
|
||||||
@ -28,13 +28,13 @@ pub struct BlkReq {
|
|||||||
|
|
||||||
/// Response of a VirtIOBlk request.
|
/// Response of a VirtIOBlk request.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Copy, Clone,Pod)]
|
#[derive(Debug, Copy, Clone, Pod)]
|
||||||
pub struct BlkResp {
|
pub struct BlkResp {
|
||||||
pub status: RespStatus,
|
pub status: RespStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Debug, Copy, Clone,Pod)]
|
#[derive(Debug, Copy, Clone, Pod)]
|
||||||
pub enum ReqType {
|
pub enum ReqType {
|
||||||
In = 0,
|
In = 0,
|
||||||
Out = 1,
|
Out = 1,
|
||||||
@ -44,7 +44,7 @@ pub enum ReqType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone,Pod)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Pod)]
|
||||||
pub enum RespStatus {
|
pub enum RespStatus {
|
||||||
/// Ok.
|
/// Ok.
|
||||||
Ok = 0,
|
Ok = 0,
|
||||||
|
@ -23,11 +23,11 @@ pub mod fs;
|
|||||||
mod memory;
|
mod memory;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod process;
|
mod process;
|
||||||
|
pub mod rights;
|
||||||
pub mod syscall;
|
pub mod syscall;
|
||||||
mod user_apps;
|
mod user_apps;
|
||||||
mod util;
|
mod util;
|
||||||
pub mod vm;
|
pub mod vm;
|
||||||
pub mod rights;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate kxos_frame_pod_derive;
|
extern crate kxos_frame_pod_derive;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use kxos_typeflags::type_flags;
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use kxos_typeflags::type_flags;
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
/// Value-based access rights.
|
/// Value-based access rights.
|
||||||
@ -54,10 +54,4 @@ type_flags! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The full set of access rights.
|
/// The full set of access rights.
|
||||||
pub type Full = TRights![
|
pub type Full = TRights![Dup, Read, Write, Exec, Signal];
|
||||||
Dup,
|
|
||||||
Read,
|
|
||||||
Write,
|
|
||||||
Exec,
|
|
||||||
Signal
|
|
||||||
];
|
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use kxos_frame::{vm::VmIo, Error};
|
|
||||||
use kxos_frame::prelude::Result;
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::{vm::VmIo, Error};
|
||||||
|
|
||||||
use crate::{rights::Rights, vm::vmo::Vmo};
|
use crate::{rights::Rights, vm::vmo::Vmo};
|
||||||
|
|
||||||
use super::{Vmar, VmPerms, options::{VmarChildOptions, VmarMapOptions}, Vmar_};
|
use super::{
|
||||||
|
options::{VmarChildOptions, VmarMapOptions},
|
||||||
|
VmPerms, Vmar, Vmar_,
|
||||||
|
};
|
||||||
|
|
||||||
impl Vmar<Rights> {
|
impl Vmar<Rights> {
|
||||||
/// Creates a root VMAR.
|
/// Creates a root VMAR.
|
||||||
@ -52,7 +55,11 @@ impl Vmar<Rights> {
|
|||||||
/// Memory permissions may be changed through the `protect` method,
|
/// Memory permissions may be changed through the `protect` method,
|
||||||
/// which ensures that any updated memory permissions do not go beyond
|
/// which ensures that any updated memory permissions do not go beyond
|
||||||
/// the access rights of the underlying VMOs.
|
/// the access rights of the underlying VMOs.
|
||||||
pub fn new_map(&self, vmo: Vmo<Rights>, perms: VmPerms) -> Result<VmarMapOptions<Rights,Rights>> {
|
pub fn new_map(
|
||||||
|
&self,
|
||||||
|
vmo: Vmo<Rights>,
|
||||||
|
perms: VmPerms,
|
||||||
|
) -> Result<VmarMapOptions<Rights, Rights>> {
|
||||||
let dup_self = self.dup()?;
|
let dup_self = self.dup()?;
|
||||||
Ok(VmarMapOptions::new(dup_self, vmo, perms))
|
Ok(VmarMapOptions::new(dup_self, vmo, perms))
|
||||||
}
|
}
|
||||||
@ -143,7 +150,6 @@ impl Vmar<Rights> {
|
|||||||
Err(Error::AccessDenied)
|
Err(Error::AccessDenied)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VmIo for Vmar<Rights> {
|
impl VmIo for Vmar<Rights> {
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
//! Virtual Memory Address Regions (VMARs).
|
//! Virtual Memory Address Regions (VMARs).
|
||||||
|
|
||||||
mod static_cap;
|
|
||||||
mod dyn_cap;
|
mod dyn_cap;
|
||||||
mod options;
|
mod options;
|
||||||
|
mod static_cap;
|
||||||
|
|
||||||
use core::ops::Range;
|
|
||||||
use kxos_frame::vm::VmSpace;
|
|
||||||
use kxos_frame::vm::Vaddr;
|
|
||||||
use spin::Mutex;
|
|
||||||
use alloc::sync::Arc;
|
|
||||||
use kxos_frame::prelude::Result;
|
|
||||||
use kxos_frame::Error;
|
|
||||||
use crate::rights::Rights;
|
use crate::rights::Rights;
|
||||||
|
use alloc::sync::Arc;
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use core::ops::Range;
|
||||||
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::vm::Vaddr;
|
||||||
|
use kxos_frame::vm::VmSpace;
|
||||||
|
use kxos_frame::Error;
|
||||||
|
use spin::Mutex;
|
||||||
|
|
||||||
/// Virtual Memory Address Regions (VMARs) are a type of capability that manages
|
/// Virtual Memory Address Regions (VMARs) are a type of capability that manages
|
||||||
/// user address spaces.
|
/// user address spaces.
|
||||||
@ -91,8 +91,6 @@ impl<R> Vmar<R> {
|
|||||||
pub fn base(&self) -> Vaddr {
|
pub fn base(&self) -> Vaddr {
|
||||||
self.0.base
|
self.0.base
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
//! Options for allocating child VMARs and creating mappings.
|
//! Options for allocating child VMARs and creating mappings.
|
||||||
|
|
||||||
use kxos_frame::{config::PAGE_SIZE, vm::Vaddr};
|
|
||||||
use kxos_frame::prelude::Result;
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::{config::PAGE_SIZE, vm::Vaddr};
|
||||||
|
|
||||||
use crate::vm::vmo::Vmo;
|
use crate::vm::vmo::Vmo;
|
||||||
|
|
||||||
use super::{Vmar, VmPerms};
|
use super::{VmPerms, Vmar};
|
||||||
|
|
||||||
/// Options for allocating a child VMAR, which must not overlap with any
|
/// Options for allocating a child VMAR, which must not overlap with any
|
||||||
/// existing mappings or child VMARs.
|
/// existing mappings or child VMARs.
|
||||||
@ -46,7 +46,7 @@ pub struct VmarChildOptions<R> {
|
|||||||
parent: Vmar<R>,
|
parent: Vmar<R>,
|
||||||
size: usize,
|
size: usize,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
align:usize,
|
align: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> VmarChildOptions<R> {
|
impl<R> VmarChildOptions<R> {
|
||||||
@ -102,7 +102,7 @@ impl<R> VmarChildOptions<R> {
|
|||||||
/// Options for creating a new mapping. The mapping is not allowed to overlap
|
/// Options for creating a new mapping. The mapping is not allowed to overlap
|
||||||
/// with any child VMARs. And unless specified otherwise, it is not allowed
|
/// with any child VMARs. And unless specified otherwise, it is not allowed
|
||||||
/// to overlap with any existing mapping, either.
|
/// to overlap with any existing mapping, either.
|
||||||
pub struct VmarMapOptions<R1,R2> {
|
pub struct VmarMapOptions<R1, R2> {
|
||||||
parent: Vmar<R1>,
|
parent: Vmar<R1>,
|
||||||
vmo: Vmo<R2>,
|
vmo: Vmo<R2>,
|
||||||
perms: VmPerms,
|
perms: VmPerms,
|
||||||
@ -113,7 +113,7 @@ pub struct VmarMapOptions<R1,R2> {
|
|||||||
can_overwrite: bool,
|
can_overwrite: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R1,R2> VmarMapOptions<R1,R2> {
|
impl<R1, R2> VmarMapOptions<R1, R2> {
|
||||||
/// Creates a default set of options with the VMO and the memory access
|
/// Creates a default set of options with the VMO and the memory access
|
||||||
/// permissions.
|
/// permissions.
|
||||||
///
|
///
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
|
use kxos_frame::prelude::Result;
|
||||||
use kxos_frame::{vm::VmIo, Error};
|
use kxos_frame::{vm::VmIo, Error};
|
||||||
use kxos_rights_proc::require;
|
use kxos_rights_proc::require;
|
||||||
use kxos_frame::prelude::Result;
|
|
||||||
|
|
||||||
use crate::{rights::*, vm::vmo::Vmo};
|
use crate::{rights::*, vm::vmo::Vmo};
|
||||||
|
|
||||||
use super::{Vmar, Vmar_, VmPerms, options::{VmarMapOptions, VmarChildOptions}};
|
use super::{
|
||||||
|
options::{VmarChildOptions, VmarMapOptions},
|
||||||
|
VmPerms, Vmar, Vmar_,
|
||||||
|
};
|
||||||
|
|
||||||
impl<R: TRights> Vmar<R> {
|
impl<R: TRights> Vmar<R> {
|
||||||
/// Creates a root VMAR.
|
/// Creates a root VMAR.
|
||||||
@ -58,9 +61,9 @@ impl<R: TRights> Vmar<R> {
|
|||||||
/// which ensures that any updated memory permissions do not go beyond
|
/// which ensures that any updated memory permissions do not go beyond
|
||||||
/// the access rights of the underlying VMOs.
|
/// the access rights of the underlying VMOs.
|
||||||
#[require(R > Dup)]
|
#[require(R > Dup)]
|
||||||
pub fn new_map(&self, vmo: Vmo<Rights>, perms: VmPerms) -> Result<VmarMapOptions<R,Rights>> {
|
pub fn new_map(&self, vmo: Vmo<Rights>, perms: VmPerms) -> Result<VmarMapOptions<R, Rights>> {
|
||||||
let dup_self = self.dup()?;
|
let dup_self = self.dup()?;
|
||||||
Ok(VmarMapOptions::new(dup_self, vmo,perms))
|
Ok(VmarMapOptions::new(dup_self, vmo, perms))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new child VMAR through a set of VMAR child options.
|
/// Creates a new child VMAR through a set of VMAR child options.
|
||||||
@ -156,10 +159,9 @@ impl<R: TRights> Vmar<R> {
|
|||||||
Err(Error::AccessDenied)
|
Err(Error::AccessDenied)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R:TRights> VmIo for Vmar<R> {
|
impl<R: TRights> VmIo for Vmar<R> {
|
||||||
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()> {
|
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()> {
|
||||||
// self.check_rights!(Rights::READ)?;
|
// self.check_rights!(Rights::READ)?;
|
||||||
self.0.read(offset, buf)
|
self.0.read(offset, buf)
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use kxos_frame::{vm::VmIo, Error};
|
|
||||||
use kxos_frame::prelude::Result;
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::{vm::VmIo, Error};
|
||||||
|
|
||||||
use crate::rights::{Rights, TRights};
|
use crate::rights::{Rights, TRights};
|
||||||
|
|
||||||
use super::{VmoChildOptions, options::{VmoSliceChild, VmoCowChild}, Vmo};
|
use super::{
|
||||||
|
options::{VmoCowChild, VmoSliceChild},
|
||||||
|
Vmo, VmoChildOptions,
|
||||||
|
};
|
||||||
|
|
||||||
impl Vmo<Rights> {
|
impl Vmo<Rights> {
|
||||||
/// Creates a new slice VMO through a set of VMO child options.
|
/// Creates a new slice VMO through a set of VMO child options.
|
||||||
@ -27,7 +30,10 @@ impl Vmo<Rights> {
|
|||||||
///
|
///
|
||||||
/// The new VMO child will be of the same capability flavor as the parent;
|
/// The new VMO child will be of the same capability flavor as the parent;
|
||||||
/// so are the access rights.
|
/// so are the access rights.
|
||||||
pub fn new_slice_child(&self, range: Range<usize>) -> Result<VmoChildOptions<Rights, VmoSliceChild>> {
|
pub fn new_slice_child(
|
||||||
|
&self,
|
||||||
|
range: Range<usize>,
|
||||||
|
) -> Result<VmoChildOptions<Rights, VmoSliceChild>> {
|
||||||
let dup_self = self.dup()?;
|
let dup_self = self.dup()?;
|
||||||
Ok(VmoChildOptions::new_slice_rights(dup_self, range))
|
Ok(VmoChildOptions::new_slice_rights(dup_self, range))
|
||||||
}
|
}
|
||||||
@ -52,7 +58,10 @@ impl Vmo<Rights> {
|
|||||||
/// The new VMO child will be of the same capability flavor as the parent.
|
/// The new VMO child will be of the same capability flavor as the parent.
|
||||||
/// The child will be given the access rights of the parent
|
/// The child will be given the access rights of the parent
|
||||||
/// plus the Write right.
|
/// plus the Write right.
|
||||||
pub fn new_cow_child(&self, range: Range<usize>) -> Result<VmoChildOptions<Rights, VmoCowChild>> {
|
pub fn new_cow_child(
|
||||||
|
&self,
|
||||||
|
range: Range<usize>,
|
||||||
|
) -> Result<VmoChildOptions<Rights, VmoCowChild>> {
|
||||||
let dup_self = self.dup()?;
|
let dup_self = self.dup()?;
|
||||||
Ok(VmoChildOptions::new_cow(dup_self, range))
|
Ok(VmoChildOptions::new_cow(dup_self, range))
|
||||||
}
|
}
|
||||||
|
@ -2,22 +2,20 @@
|
|||||||
|
|
||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use kxos_frame::{prelude::Result, vm::Paddr, Error};
|
|
||||||
use crate::rights::Rights;
|
use crate::rights::Rights;
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use kxos_frame::{prelude::Result, vm::Paddr, Error};
|
||||||
|
|
||||||
mod static_cap;
|
|
||||||
mod dyn_cap;
|
mod dyn_cap;
|
||||||
mod options;
|
mod options;
|
||||||
mod pager;
|
mod pager;
|
||||||
|
mod static_cap;
|
||||||
|
|
||||||
pub use options::{VmoOptions, VmoChildOptions};
|
pub use options::{VmoChildOptions, VmoOptions};
|
||||||
pub use pager::Pager;
|
pub use pager::Pager;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Virtual Memory Objects (VMOs) are a type of capability that represents a
|
/// Virtual Memory Objects (VMOs) are a type of capability that represents a
|
||||||
/// range of memory pages.
|
/// range of memory pages.
|
||||||
///
|
///
|
||||||
@ -148,7 +146,6 @@ impl Vmo_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<R> Vmo<R> {
|
impl<R> Vmo<R> {
|
||||||
/// Returns the size (in bytes) of a VMO.
|
/// Returns the size (in bytes) of a VMO.
|
||||||
pub fn size(&self) -> usize {
|
pub fn size(&self) -> usize {
|
||||||
@ -165,5 +162,4 @@ impl<R> Vmo<R> {
|
|||||||
pub fn flags(&self) -> VmoFlags {
|
pub fn flags(&self) -> VmoFlags {
|
||||||
self.0.flags()
|
self.0.flags()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,13 +4,13 @@ use core::marker::PhantomData;
|
|||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use kxos_frame::vm::Paddr;
|
|
||||||
use kxos_frame::prelude::Result;
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::vm::Paddr;
|
||||||
use kxos_rights_proc::require;
|
use kxos_rights_proc::require;
|
||||||
|
|
||||||
use crate::rights::{Dup,TRights,Rights};
|
use crate::rights::{Dup, Rights, TRights};
|
||||||
|
|
||||||
use super::{Vmo, VmoFlags, Pager};
|
use super::{Pager, Vmo, VmoFlags};
|
||||||
|
|
||||||
/// Options for allocating a root VMO.
|
/// Options for allocating a root VMO.
|
||||||
///
|
///
|
||||||
@ -201,7 +201,7 @@ pub struct VmoChildOptions<R, C> {
|
|||||||
marker: PhantomData<C>,
|
marker: PhantomData<C>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R:TRights> VmoChildOptions<R, VmoSliceChild> {
|
impl<R: TRights> VmoChildOptions<R, VmoSliceChild> {
|
||||||
/// Creates a default set of options for creating a slice VMO child.
|
/// Creates a default set of options for creating a slice VMO child.
|
||||||
///
|
///
|
||||||
/// A slice child of a VMO, which has direct access to a range of memory
|
/// A slice child of a VMO, which has direct access to a range of memory
|
||||||
@ -231,7 +231,9 @@ impl VmoChildOptions<Rights, VmoSliceChild> {
|
|||||||
///
|
///
|
||||||
/// The range of a child must be within that of the parent.
|
/// The range of a child must be within that of the parent.
|
||||||
pub fn new_slice_rights(parent: Vmo<Rights>, range: Range<usize>) -> Self {
|
pub fn new_slice_rights(parent: Vmo<Rights>, range: Range<usize>) -> Self {
|
||||||
parent.check_rights(Rights::DUP).expect("function new_slice_rights should called with rights Dup");
|
parent
|
||||||
|
.check_rights(Rights::DUP)
|
||||||
|
.expect("function new_slice_rights should called with rights Dup");
|
||||||
Self {
|
Self {
|
||||||
flags: parent.flags() & Self::PARENT_FLAGS_MASK,
|
flags: parent.flags() & Self::PARENT_FLAGS_MASK,
|
||||||
parent,
|
parent,
|
||||||
@ -263,7 +265,8 @@ impl<R> VmoChildOptions<R, VmoCowChild> {
|
|||||||
|
|
||||||
impl<R, C> VmoChildOptions<R, C> {
|
impl<R, C> VmoChildOptions<R, C> {
|
||||||
/// Flags that a VMO child inherits from its parent.
|
/// Flags that a VMO child inherits from its parent.
|
||||||
pub const PARENT_FLAGS_MASK: VmoFlags = VmoFlags::from_bits(VmoFlags::CONTIGUOUS.bits | VmoFlags::DMA.bits).unwrap();
|
pub const PARENT_FLAGS_MASK: VmoFlags =
|
||||||
|
VmoFlags::from_bits(VmoFlags::CONTIGUOUS.bits | VmoFlags::DMA.bits).unwrap();
|
||||||
/// Flags that a VMO child may differ from its parent.
|
/// Flags that a VMO child may differ from its parent.
|
||||||
pub const CHILD_FLAGS_MASK: VmoFlags = VmoFlags::RESIZABLE;
|
pub const CHILD_FLAGS_MASK: VmoFlags = VmoFlags::RESIZABLE;
|
||||||
|
|
||||||
@ -311,8 +314,7 @@ impl<R: TRights> VmoChildOptions<R, VmoCowChild> {
|
|||||||
/// The child VMO is initially assigned all the parent's access rights
|
/// The child VMO is initially assigned all the parent's access rights
|
||||||
/// plus the Write right.
|
/// plus the Write right.
|
||||||
pub fn alloc<TRights>(mut self) -> Result<Vmo<TRights>>
|
pub fn alloc<TRights>(mut self) -> Result<Vmo<TRights>>
|
||||||
where
|
// TODO: R1 must contain the Write right. To do so at the type level,
|
||||||
// TODO: R1 must contain the Write right. To do so at the type level,
|
|
||||||
// we need to implement a type-level operator
|
// we need to implement a type-level operator
|
||||||
// (say, `TRightsExtend(L, F)`)
|
// (say, `TRightsExtend(L, F)`)
|
||||||
// that may extend a list (`L`) of type-level flags with an extra flag `F`.
|
// that may extend a list (`L`) of type-level flags with an extra flag `F`.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use kxos_frame::vm::VmFrame;
|
|
||||||
use kxos_frame::prelude::Result;
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::vm::VmFrame;
|
||||||
|
|
||||||
/// Pagers provide frame to a VMO.
|
/// Pagers provide frame to a VMO.
|
||||||
///
|
///
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
use core::ops::Range;
|
use core::ops::Range;
|
||||||
|
|
||||||
use kxos_frame::{vm::VmIo, Error};
|
|
||||||
use kxos_frame::prelude::Result;
|
use kxos_frame::prelude::Result;
|
||||||
|
use kxos_frame::{vm::VmIo, Error};
|
||||||
use kxos_rights_proc::require;
|
use kxos_rights_proc::require;
|
||||||
|
|
||||||
use crate::rights::*;
|
use crate::rights::*;
|
||||||
|
|
||||||
use super::{Vmo, VmoChildOptions, options::{VmoSliceChild, VmoCowChild}};
|
use super::{
|
||||||
|
options::{VmoCowChild, VmoSliceChild},
|
||||||
|
Vmo, VmoChildOptions,
|
||||||
|
};
|
||||||
|
|
||||||
impl<R: TRights> Vmo<R> {
|
impl<R: TRights> Vmo<R> {
|
||||||
/// Creates a new slice VMO through a set of VMO child options.
|
/// Creates a new slice VMO through a set of VMO child options.
|
||||||
@ -29,7 +32,10 @@ impl<R: TRights> Vmo<R> {
|
|||||||
/// The new VMO child will be of the same capability flavor as the parent;
|
/// The new VMO child will be of the same capability flavor as the parent;
|
||||||
/// so are the access rights.
|
/// so are the access rights.
|
||||||
#[require(R > Dup)]
|
#[require(R > Dup)]
|
||||||
pub fn new_slice_child(&self, range: Range<usize>) -> Result<VmoChildOptions<R, VmoSliceChild>> {
|
pub fn new_slice_child(
|
||||||
|
&self,
|
||||||
|
range: Range<usize>,
|
||||||
|
) -> Result<VmoChildOptions<R, VmoSliceChild>> {
|
||||||
let dup_self = self.dup()?;
|
let dup_self = self.dup()?;
|
||||||
Ok(VmoChildOptions::new_slice(dup_self, range))
|
Ok(VmoChildOptions::new_slice(dup_self, range))
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use kxos_frame::Pod;
|
use kxos_frame::Pod;
|
||||||
|
use kxos_frame_pod_derive::Pod;
|
||||||
use kxos_pci::capability::vendor::virtio::CapabilityVirtioData;
|
use kxos_pci::capability::vendor::virtio::CapabilityVirtioData;
|
||||||
use kxos_pci::util::BAR;
|
use kxos_pci::util::BAR;
|
||||||
use kxos_util::frame_ptr::InFramePtr;
|
use kxos_util::frame_ptr::InFramePtr;
|
||||||
use kxos_frame_pod_derive::Pod;
|
|
||||||
|
|
||||||
pub const BLK_SIZE: usize = 512;
|
pub const BLK_SIZE: usize = 512;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone,Pod)]
|
#[derive(Debug, Copy, Clone, Pod)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct VirtioBLKConfig {
|
pub struct VirtioBLKConfig {
|
||||||
capacity: u64,
|
capacity: u64,
|
||||||
@ -25,7 +25,7 @@ pub struct VirtioBLKConfig {
|
|||||||
unused1: [u8; 3],
|
unused1: [u8; 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone,Pod)]
|
#[derive(Debug, Copy, Clone, Pod)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct VirtioBLKGeometry {
|
pub struct VirtioBLKGeometry {
|
||||||
cylinders: u16,
|
cylinders: u16,
|
||||||
@ -33,7 +33,7 @@ pub struct VirtioBLKGeometry {
|
|||||||
sectors: u8,
|
sectors: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone,Pod)]
|
#[derive(Debug, Copy, Clone, Pod)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct VirtioBLKTopology {
|
pub struct VirtioBLKTopology {
|
||||||
physical_block_exp: u8,
|
physical_block_exp: u8,
|
||||||
|
@ -7,13 +7,12 @@ extern crate alloc;
|
|||||||
use alloc::{sync::Arc, vec::Vec};
|
use alloc::{sync::Arc, vec::Vec};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use kxos_frame::{info, offset_of, TrapFrame};
|
use kxos_frame::{info, offset_of, TrapFrame};
|
||||||
|
use kxos_frame_pod_derive::Pod;
|
||||||
use kxos_pci::util::{PCIDevice, BAR};
|
use kxos_pci::util::{PCIDevice, BAR};
|
||||||
use kxos_util::frame_ptr::InFramePtr;
|
use kxos_util::frame_ptr::InFramePtr;
|
||||||
use kxos_frame_pod_derive::Pod;
|
|
||||||
|
|
||||||
use spin::{mutex::Mutex, MutexGuard};
|
use spin::{mutex::Mutex, MutexGuard};
|
||||||
|
|
||||||
|
|
||||||
use self::{block::VirtioBLKConfig, queue::VirtQueue};
|
use self::{block::VirtioBLKConfig, queue::VirtQueue};
|
||||||
|
|
||||||
use kxos_frame::Pod;
|
use kxos_frame::Pod;
|
||||||
@ -57,7 +56,7 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Copy, Clone,Pod)]
|
#[derive(Debug, Default, Copy, Clone, Pod)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct VitrioPciCommonCfg {
|
pub struct VitrioPciCommonCfg {
|
||||||
device_feature_select: u32,
|
device_feature_select: u32,
|
||||||
|
@ -6,8 +6,8 @@ use bitflags::bitflags;
|
|||||||
use core::sync::atomic::{fence, Ordering};
|
use core::sync::atomic::{fence, Ordering};
|
||||||
use kxos_frame::offset_of;
|
use kxos_frame::offset_of;
|
||||||
use kxos_frame::Pod;
|
use kxos_frame::Pod;
|
||||||
use kxos_util::frame_ptr::InFramePtr;
|
|
||||||
use kxos_frame_pod_derive::Pod;
|
use kxos_frame_pod_derive::Pod;
|
||||||
|
use kxos_util::frame_ptr::InFramePtr;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum QueueError {
|
pub enum QueueError {
|
||||||
InvalidArgs,
|
InvalidArgs,
|
||||||
@ -231,7 +231,7 @@ impl VirtQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C, align(16))]
|
#[repr(C, align(16))]
|
||||||
#[derive(Debug, Default, Copy, Clone,Pod)]
|
#[derive(Debug, Default, Copy, Clone, Pod)]
|
||||||
struct Descriptor {
|
struct Descriptor {
|
||||||
addr: u64,
|
addr: u64,
|
||||||
len: u32,
|
len: u32,
|
||||||
@ -274,7 +274,7 @@ impl Default for DescFlags {
|
|||||||
/// each ring entry refers to the head of a descriptor chain.
|
/// each ring entry refers to the head of a descriptor chain.
|
||||||
/// It is only written by the driver and read by the device.
|
/// It is only written by the driver and read by the device.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Copy, Clone,Pod)]
|
#[derive(Debug, Default, Copy, Clone, Pod)]
|
||||||
struct AvailRing {
|
struct AvailRing {
|
||||||
flags: u16,
|
flags: u16,
|
||||||
/// A driver MUST NOT decrement the idx.
|
/// A driver MUST NOT decrement the idx.
|
||||||
@ -286,7 +286,7 @@ struct AvailRing {
|
|||||||
/// The used ring is where the device returns buffers once it is done with them:
|
/// The used ring is where the device returns buffers once it is done with them:
|
||||||
/// it is only written to by the device, and read by the driver.
|
/// it is only written to by the device, and read by the driver.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Copy, Clone,Pod)]
|
#[derive(Debug, Default, Copy, Clone, Pod)]
|
||||||
struct UsedRing {
|
struct UsedRing {
|
||||||
flags: u16,
|
flags: u16,
|
||||||
idx: u16,
|
idx: u16,
|
||||||
@ -295,7 +295,7 @@ struct UsedRing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Default, Copy, Clone,Pod)]
|
#[derive(Debug, Default, Copy, Clone, Pod)]
|
||||||
struct UsedElem {
|
struct UsedElem {
|
||||||
id: u32,
|
id: u32,
|
||||||
len: u32,
|
len: u32,
|
||||||
|
@ -7,8 +7,8 @@ use bootloader::{entry_point, BootInfo};
|
|||||||
use kxos_frame::timer::Timer;
|
use kxos_frame::timer::Timer;
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
use core::time::Duration;
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
use core::time::Duration;
|
||||||
use kxos_frame::println;
|
use kxos_frame::println;
|
||||||
|
|
||||||
static mut TICK: usize = 0;
|
static mut TICK: usize = 0;
|
||||||
@ -28,7 +28,9 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn test_timer() {
|
fn test_timer() {
|
||||||
println!("If you want to pass this test, you may need to enable the interrupt in kxos_frame/lib.rs");
|
println!(
|
||||||
|
"If you want to pass this test, you may need to enable the interrupt in kxos_frame/lib.rs"
|
||||||
|
);
|
||||||
println!("make sure the Timer irq number 32 handler won't panic");
|
println!("make sure the Timer irq number 32 handler won't panic");
|
||||||
unsafe {
|
unsafe {
|
||||||
let timer = Timer::new(timer_callback).unwrap();
|
let timer = Timer::new(timer_callback).unwrap();
|
||||||
@ -39,8 +41,8 @@ fn test_timer() {
|
|||||||
|
|
||||||
pub fn timer_callback(timer: Arc<Timer>) {
|
pub fn timer_callback(timer: Arc<Timer>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
TICK+=1;
|
TICK += 1;
|
||||||
println!("TICK:{}",TICK);
|
println!("TICK:{}", TICK);
|
||||||
timer.set(Duration::from_secs(1));
|
timer.set(Duration::from_secs(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user