mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 16:16:16 +04:00
Bump rust version to newer nightly and use acpi crate to print acpi info
This commit is contained in:
parent
087e18b202
commit
96357e63df
@ -110,7 +110,7 @@ impl<T: PageTable> CowExt<T> {
|
||||
return true;
|
||||
}
|
||||
use core::mem::MaybeUninit;
|
||||
let mut temp_data: [u8; PAGE_SIZE] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut temp_data: [u8; PAGE_SIZE] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
temp_data[..].copy_from_slice(self.get_page_slice_mut(addr));
|
||||
|
||||
self.unmap_shared(addr);
|
||||
|
@ -147,7 +147,7 @@ impl MockPageTable {
|
||||
use core::mem::MaybeUninit;
|
||||
MockPageTable {
|
||||
entries: [MockEntry::default(); PAGE_COUNT],
|
||||
data: unsafe { MaybeUninit::uninitialized().into_initialized() },
|
||||
data: unsafe { MaybeUninit::zeroed().assume_init() },
|
||||
page_fault_handler: None,
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub struct MockSwapper {
|
||||
impl Swapper for MockSwapper {
|
||||
fn swap_out(&mut self, data: &[u8]) -> Result<usize, ()> {
|
||||
let id = self.alloc_id();
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
slice.copy_from_slice(data);
|
||||
self.map.insert(id, slice);
|
||||
Ok(id)
|
||||
@ -27,7 +27,7 @@ impl Swapper for MockSwapper {
|
||||
if !self.map.contains_key(&token) {
|
||||
return Err(());
|
||||
}
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut slice: [u8; PAGE_SIZE] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
slice.copy_from_slice(data);
|
||||
self.map.insert(token, slice);
|
||||
Ok(())
|
||||
@ -64,8 +64,8 @@ mod test {
|
||||
#[test]
|
||||
fn swap_out_in() {
|
||||
let mut swapper = MockSwapper::default();
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let data1: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
let data1: [u8; 4096] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
let token = swapper.swap_out(&data1).unwrap();
|
||||
swapper.swap_in(token, &mut data).unwrap();
|
||||
assert_data_eq(&data, &data1);
|
||||
@ -74,9 +74,9 @@ mod test {
|
||||
#[test]
|
||||
fn swap_update() {
|
||||
let mut swapper = MockSwapper::default();
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let data1: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let data2: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
let data1: [u8; 4096] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
let data2: [u8; 4096] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
let token = swapper.swap_out(&data1).unwrap();
|
||||
swapper.swap_update(token, &data2).unwrap();
|
||||
swapper.swap_in(token, &mut data).unwrap();
|
||||
@ -86,7 +86,7 @@ mod test {
|
||||
#[test]
|
||||
fn invalid_token() {
|
||||
let mut swapper = MockSwapper::default();
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut data: [u8; 4096] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
assert_eq!(swapper.swap_in(0, &mut data), Err(()));
|
||||
}
|
||||
}
|
||||
|
11
kernel/Cargo.lock
generated
11
kernel/Cargo.lock
generated
@ -13,6 +13,15 @@ dependencies = [
|
||||
"ux 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "acpi"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "apic"
|
||||
version = "0.1.0"
|
||||
@ -397,6 +406,7 @@ name = "rcore"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)",
|
||||
"acpi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)",
|
||||
"bcm2837 1.0.0 (git+https://github.com/rcore-os/bcm2837)",
|
||||
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -709,6 +719,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum aarch64 2.6.1 (git+https://github.com/rcore-os/aarch64)" = "<none>"
|
||||
"checksum acpi 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "78e6a32e8cfd10171d029c68aba977ddd83a6b598dec2816d27d32890c63c164"
|
||||
"checksum apic 0.1.0 (git+https://github.com/rcore-os/apic-rs)" = "<none>"
|
||||
"checksum array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72"
|
||||
"checksum as-slice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "293dac66b274fab06f95e7efb05ec439a6b70136081ea522d270bc351ae5bb27"
|
||||
|
@ -77,6 +77,7 @@ x86_64 = "0.6"
|
||||
raw-cpuid = "6.0"
|
||||
uart_16550 = "0.2"
|
||||
pc-keyboard = "0.5"
|
||||
acpi = "0.2"
|
||||
|
||||
[target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies]
|
||||
riscv = { git = "https://github.com/rcore-os/riscv", features = ["inline-asm"] }
|
||||
|
@ -213,7 +213,7 @@ impl PageTableImpl {
|
||||
ManuallyDrop::new(PageTableImpl {
|
||||
page_table: MappedPageTable::new(table, frame_to_page_table),
|
||||
root_frame: frame,
|
||||
entry: core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
entry: core::mem::MaybeUninit::zeroed().assume_init(),
|
||||
})
|
||||
}
|
||||
/// The method for getting the kernel page table.
|
||||
@ -224,7 +224,7 @@ impl PageTableImpl {
|
||||
ManuallyDrop::new(PageTableImpl {
|
||||
page_table: MappedPageTable::new(table, frame_to_page_table),
|
||||
root_frame: frame,
|
||||
entry: core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
entry: core::mem::MaybeUninit::zeroed().assume_init(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -239,7 +239,7 @@ impl PageTableExt for PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: MappedPageTable::new(table, frame_to_page_table),
|
||||
root_frame: frame,
|
||||
entry: core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
entry: core::mem::MaybeUninit::zeroed().assume_init(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ impl PageTableImpl {
|
||||
ManuallyDrop::new(PageTableImpl {
|
||||
page_table: TwoLevelPageTable::new(table),
|
||||
root_frame: frame,
|
||||
entry: unsafe { core::mem::MaybeUninit::uninitialized().into_initialized() },
|
||||
entry: unsafe { core::mem::MaybeUninit::zeroed().assume_init() },
|
||||
})
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ impl PageTableExt for PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: TwoLevelPageTable::new(table),
|
||||
root_frame: frame,
|
||||
entry: unsafe { core::mem::MaybeUninit::uninitialized().into_initialized() },
|
||||
entry: unsafe { core::mem::MaybeUninit::zeroed().assume_init() },
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ impl PageTableImpl {
|
||||
ManuallyDrop::new(PageTableImpl {
|
||||
page_table: TopLevelPageTable::new(table, PHYSICAL_MEMORY_OFFSET),
|
||||
root_frame: frame,
|
||||
entry: unsafe { core::mem::MaybeUninit::uninitialized().into_initialized() },
|
||||
entry: unsafe { core::mem::MaybeUninit::zeroed().assume_init() },
|
||||
})
|
||||
}
|
||||
/// The method for getting the kernel page table.
|
||||
@ -180,7 +180,7 @@ impl PageTableExt for PageTableImpl {
|
||||
PageTableImpl {
|
||||
page_table: TopLevelPageTable::new(table, PHYSICAL_MEMORY_OFFSET),
|
||||
root_frame: frame,
|
||||
entry: unsafe { core::mem::uninitialized() },
|
||||
entry: unsafe { core::mem::zeroed() },
|
||||
}
|
||||
}
|
||||
|
||||
|
31
kernel/src/arch/x86_64/acpi.rs
Normal file
31
kernel/src/arch/x86_64/acpi.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use crate::arch::consts::PHYSICAL_MEMORY_OFFSET;
|
||||
use acpi::{search_for_rsdp_bios, AcpiHandler, PhysicalMapping};
|
||||
use core::ptr::NonNull;
|
||||
|
||||
struct Handler;
|
||||
|
||||
impl AcpiHandler for Handler {
|
||||
fn map_physical_region<T>(
|
||||
&mut self,
|
||||
physical_address: usize,
|
||||
size: usize,
|
||||
) -> PhysicalMapping<T> {
|
||||
PhysicalMapping {
|
||||
physical_start: physical_address,
|
||||
virtual_start: NonNull::new((physical_address + PHYSICAL_MEMORY_OFFSET) as *mut T)
|
||||
.unwrap(),
|
||||
region_length: size,
|
||||
mapped_length: size,
|
||||
}
|
||||
}
|
||||
|
||||
fn unmap_physical_region<T>(&mut self, region: PhysicalMapping<T>) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
let mut handler = Handler {};
|
||||
let res = unsafe { search_for_rsdp_bios(&mut handler) };
|
||||
debug!("ACPI {:#x?}", res);
|
||||
}
|
@ -2,6 +2,7 @@ use bootloader::bootinfo::{BootInfo, MemoryRegionType};
|
||||
use core::sync::atomic::*;
|
||||
use log::*;
|
||||
|
||||
pub mod acpi;
|
||||
pub mod board;
|
||||
pub mod consts;
|
||||
pub mod cpu;
|
||||
@ -64,6 +65,8 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
|
||||
crate::drivers::init();
|
||||
// init cpu scheduler and process manager, and add user shell app in process manager
|
||||
crate::process::init();
|
||||
// load acpi
|
||||
acpi::init();
|
||||
|
||||
// wake up other CPUs
|
||||
AP_CAN_INIT.store(true, Ordering::Relaxed);
|
||||
|
@ -203,7 +203,7 @@ impl PageTableImpl {
|
||||
let table = &mut *frame_to_page_table(frame);
|
||||
ManuallyDrop::new(PageTableImpl(
|
||||
MappedPageTable::new(table, frame_to_page_table),
|
||||
core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
core::mem::MaybeUninit::zeroed().assume_init(),
|
||||
frame,
|
||||
))
|
||||
}
|
||||
@ -223,7 +223,7 @@ impl PageTableExt for PageTableImpl {
|
||||
unsafe {
|
||||
PageTableImpl(
|
||||
MappedPageTable::new(table, frame_to_page_table),
|
||||
core::mem::MaybeUninit::uninitialized().into_initialized(),
|
||||
core::mem::MaybeUninit::zeroed().assume_init(),
|
||||
frame,
|
||||
)
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#![feature(global_asm)]
|
||||
#![feature(fnbox)]
|
||||
#![feature(maybe_uninit)]
|
||||
#![feature(alloc_prelude)]
|
||||
#![deny(unused_must_use)]
|
||||
#![no_std]
|
||||
|
||||
|
@ -191,7 +191,7 @@ pub fn copy_from_user<T>(addr: *const T) -> Option<T> {
|
||||
if !access_ok(addr as usize, size_of::<T>()) {
|
||||
return None;
|
||||
}
|
||||
let mut dst: T = unsafe { core::mem::uninitialized() };
|
||||
let mut dst: T = unsafe { core::mem::zeroed() };
|
||||
match unsafe { read_user(&mut dst, addr) } {
|
||||
0 => Some(dst),
|
||||
_ => None,
|
||||
|
@ -103,7 +103,7 @@ impl Thread {
|
||||
Box::new(Thread {
|
||||
context: Context::null(),
|
||||
// safety: other fields will never be used
|
||||
..core::mem::MaybeUninit::uninitialized().into_initialized()
|
||||
..core::mem::MaybeUninit::zeroed().assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ impl Thread {
|
||||
) -> Result<(MemorySet, usize, usize), &'static str> {
|
||||
// Read ELF header
|
||||
// 0x3c0: magic number from ld-musl.so
|
||||
let mut data: [u8; 0x3c0] = unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut data: [u8; 0x3c0] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
inode
|
||||
.read_at(0, &mut data)
|
||||
.map_err(|_| "failed to read from INode")?;
|
||||
@ -197,8 +197,7 @@ impl Thread {
|
||||
.lookup_follow(loader_path, FOLLOW_MAX_DEPTH)
|
||||
.map_err(|_| "interpreter not found")?;
|
||||
// load loader by bias and set aux vector.
|
||||
let mut interp_data: [u8; 0x3c0] =
|
||||
unsafe { MaybeUninit::uninitialized().into_initialized() };
|
||||
let mut interp_data: [u8; 0x3c0] = unsafe { MaybeUninit::zeroed().assume_init() };
|
||||
interp_inode
|
||||
.read_at(0, &mut interp_data)
|
||||
.map_err(|_| "failed to read from INode")?;
|
||||
|
@ -1 +1 @@
|
||||
nightly-2019-03-05
|
||||
nightly-2019-06-15
|
||||
|
Loading…
Reference in New Issue
Block a user