mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: fixup use in kernel
This commit is contained in:
parent
4d090c0478
commit
f41664e7cd
29
kernel/Cargo.lock
generated
29
kernel/Cargo.lock
generated
@ -2,6 +2,16 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "allocator"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"spin 0.9.8",
|
||||||
|
"static_assertions",
|
||||||
|
"utils",
|
||||||
|
"vspace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "api"
|
name = "api"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -62,6 +72,7 @@ checksum = "784a4df722dc6267a04af36895398f59d21d07dce47232adf31ec0ff2fa45e67"
|
|||||||
name = "kernel"
|
name = "kernel"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"allocator",
|
||||||
"api",
|
"api",
|
||||||
"bitflags 2.5.0",
|
"bitflags 2.5.0",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
@ -75,6 +86,8 @@ dependencies = [
|
|||||||
"spin 0.9.8",
|
"spin 0.9.8",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"uart_16550",
|
"uart_16550",
|
||||||
|
"utils",
|
||||||
|
"vspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -235,6 +248,22 @@ version = "1.0.12"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"vspace",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "vspace"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.5.0",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "x86"
|
name = "x86"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||||||
[features]
|
[features]
|
||||||
default = ["riscv.board.virt", "log_color"]
|
default = ["riscv.board.virt", "log_color"]
|
||||||
|
|
||||||
legacy = []
|
legacy = ["utils/legacy", "vspace/legacy"]
|
||||||
|
|
||||||
riscv = []
|
riscv = []
|
||||||
|
|
||||||
@ -33,9 +33,12 @@ panic = "abort"
|
|||||||
lto = "thin"
|
lto = "thin"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
allocator = { path = "../lib/allocator" }
|
||||||
api = { path = "../api" }
|
api = { path = "../api" }
|
||||||
|
utils = { path = "../lib/utils", default-features = false }
|
||||||
|
vspace = { path = "../lib/vspace", default-features = false }
|
||||||
|
|
||||||
bitflags = "2.4"
|
bitflags = "2.5"
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
fdt = "0.1"
|
fdt = "0.1"
|
||||||
lazy_static = { version = "1.4", features = ["spin_no_std"] }
|
lazy_static = { version = "1.4", features = ["spin_no_std"] }
|
||||||
|
@ -9,7 +9,7 @@ fn main() {
|
|||||||
const TARGET_LDS: &[TargetConfig] = &[
|
const TARGET_LDS: &[TargetConfig] = &[
|
||||||
TargetConfig {
|
TargetConfig {
|
||||||
target: "riscv64",
|
target: "riscv64",
|
||||||
lds: "src/arch/riscv/linker.ld",
|
lds: "src/arch/riscv/linker64.ld",
|
||||||
},
|
},
|
||||||
TargetConfig {
|
TargetConfig {
|
||||||
target: "riscv32",
|
target: "riscv32",
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
pub use arch::*;
|
|
||||||
|
|
||||||
// Arch Level
|
|
||||||
#[cfg(feature = "riscv")]
|
#[cfg(feature = "riscv")]
|
||||||
#[path = "riscv/mod.rs"]
|
mod riscv;
|
||||||
#[allow(clippy::module_inception)]
|
#[cfg(feature = "riscv")]
|
||||||
mod arch;
|
pub use riscv::*;
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
use super::board::console::init_early_console;
|
|
||||||
use super::vspace::utils::setup_kernel_paging;
|
|
||||||
use crate::arch::layout::zero_bss;
|
use crate::arch::layout::zero_bss;
|
||||||
use crate::arch::vspace::utils::setup_memory;
|
use crate::arch::vspace::utils::{setup_kernel_paging, setup_memory};
|
||||||
use crate::vspace::allocator::RamBlock;
|
use allocator::RamBlock;
|
||||||
use fdt::Fdt;
|
|
||||||
|
|
||||||
#[naked]
|
#[naked]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::utils::extern_addr::ExternSymbol;
|
|
||||||
use crate::utils::size::KIB;
|
|
||||||
use crate::vspace::addr::{AddressOps, PhysAddr, VirtAddr};
|
|
||||||
use core::alloc::Layout;
|
use core::alloc::Layout;
|
||||||
|
use utils::extern_addr::ExternSymbol;
|
||||||
|
use utils::size::KIB;
|
||||||
|
use vspace::addr::{AddressOps, PhysAddr, VirtAddr};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub static KERNEL_START: ExternSymbol;
|
pub static KERNEL_START: ExternSymbol;
|
||||||
|
@ -12,6 +12,7 @@ cfg_if! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Console: plat/console.rs
|
// Console: plat/console.rs
|
||||||
|
pub use board::console::init_early_console;
|
||||||
pub use board::console::EarlyConsole;
|
pub use board::console::EarlyConsole;
|
||||||
|
|
||||||
mod entry;
|
mod entry;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::vspace::addr::{AddressOps, PhysAddr};
|
use super::traits::PhysAddrPaging;
|
||||||
use crate::vspace::paging::{EntryOps, MapAttr};
|
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use vspace::addr::PhysAddr;
|
||||||
|
use vspace::paging::{EntryOps, MapAttr};
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -79,45 +80,6 @@ assert_eq_size!(Entry, u64);
|
|||||||
#[cfg(feature = "riscv.pagetable.sv32")]
|
#[cfg(feature = "riscv.pagetable.sv32")]
|
||||||
assert_eq_size!(Entry, u32);
|
assert_eq_size!(Entry, u32);
|
||||||
|
|
||||||
#[cfg(feature = "riscv.pagetable.sv32")]
|
|
||||||
impl PhysAddr {
|
|
||||||
const PA_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PG_OFFSET;
|
|
||||||
const PG_OFFSET: usize = 12;
|
|
||||||
const PPN_BITS: usize = 22;
|
|
||||||
const PPN_OFFSET: usize = 10;
|
|
||||||
const PTE_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PPN_OFFSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "riscv.pagetable.sv39")]
|
|
||||||
impl PhysAddr {
|
|
||||||
const PA_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PG_OFFSET;
|
|
||||||
const PG_OFFSET: usize = 12;
|
|
||||||
const PPN_BITS: usize = 44;
|
|
||||||
const PPN_OFFSET: usize = 10;
|
|
||||||
const PTE_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PPN_OFFSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PhysAddr {
|
|
||||||
pub fn to_ppn(self) -> usize {
|
|
||||||
(self.as_usize() & Self::PA_PPN_MASK) >> Self::PG_OFFSET
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_ppn_shifted(self) -> usize {
|
|
||||||
self.to_ppn() << Self::PPN_OFFSET
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_pte(pte: usize) -> Self {
|
|
||||||
let ppn = (pte & Self::PTE_PPN_MASK) >> Self::PPN_OFFSET;
|
|
||||||
let paddr = ppn << Self::PG_OFFSET;
|
|
||||||
PhysAddr::from(paddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn merge_pte(self, pte: usize) -> usize {
|
|
||||||
let ppn = self.to_ppn_shifted();
|
|
||||||
(pte & !Self::PTE_PPN_MASK) | ppn
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default)]
|
#[derive(Clone, Copy, Default)]
|
||||||
pub struct Entry(usize);
|
pub struct Entry(usize);
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
mod entry;
|
mod entry;
|
||||||
mod table;
|
mod table;
|
||||||
|
mod traits;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
pub use entry::Entry;
|
|
||||||
pub use table::Table;
|
|
||||||
|
@ -1,63 +1,9 @@
|
|||||||
|
use super::entry::Entry;
|
||||||
|
use super::traits::{TableLevelSize, VirtAddrPaging};
|
||||||
use crate::arch::layout::{kernel_phys_to_virt, PAGE_SIZE};
|
use crate::arch::layout::{kernel_phys_to_virt, PAGE_SIZE};
|
||||||
use crate::utils::size::*;
|
|
||||||
use crate::vspace::addr::*;
|
|
||||||
use crate::vspace::paging::*;
|
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
use vspace::addr::*;
|
||||||
#[cfg(feature = "riscv.pagetable.sv32")]
|
use vspace::paging::*;
|
||||||
impl VirtAddr {
|
|
||||||
const PG_OFFSET: usize = 12;
|
|
||||||
const VPN_BITS: usize = 10;
|
|
||||||
const VPN_MASK: usize = (1 << Self::VPN_BITS) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "riscv.pagetable.sv39")]
|
|
||||||
impl VirtAddr {
|
|
||||||
const PG_OFFSET: usize = 12;
|
|
||||||
const VPN_BITS: usize = 9;
|
|
||||||
const VPN_MASK: usize = (1 << Self::VPN_BITS) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VirtAddr {
|
|
||||||
fn to_vpn(self, level: TableLevel) -> usize {
|
|
||||||
self.0 >> (Self::PG_OFFSET + Self::VPN_BITS * level.to_usize().unwrap()) & Self::VPN_MASK
|
|
||||||
}
|
|
||||||
|
|
||||||
fn merge_vpn(&self, vpn: usize, size: TableLevel) -> Self {
|
|
||||||
let shift = Self::PG_OFFSET + Self::VPN_BITS * size.to_usize().unwrap();
|
|
||||||
let mask = Self::VPN_MASK << shift;
|
|
||||||
VirtAddr((self.0 & !mask) | ((vpn & Self::VPN_MASK) << shift))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lower_bits(self, level: usize) -> usize {
|
|
||||||
self.0 & ((1 << (Self::PG_OFFSET + Self::VPN_BITS * (level + 1))) - 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TableLevel {
|
|
||||||
pub fn level_size(&self) -> usize {
|
|
||||||
match self {
|
|
||||||
Self::Level0 => 4 * KIB,
|
|
||||||
#[cfg(feature = "riscv.pagetable.sv32")]
|
|
||||||
Self::Level1 => 4 * MIB,
|
|
||||||
#[cfg(not(feature = "riscv.pagetable.sv32"))]
|
|
||||||
Self::Level1 => 2 * MIB,
|
|
||||||
Self::Level2 => 1 * GIB,
|
|
||||||
#[cfg(not(feature = "legacy"))]
|
|
||||||
Self::Level3 => 512 * GIB,
|
|
||||||
#[cfg(not(feature = "legacy"))]
|
|
||||||
Self::Level4 => 256 * TIB,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn align<A: AddressOps>(&self, addr: A) -> A {
|
|
||||||
addr.align_down(self.level_size())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_aligned<A: AddressOps>(&self, addr: A) -> bool {
|
|
||||||
self.align(addr) == addr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C, align(4096))]
|
#[repr(C, align(4096))]
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
@ -84,6 +30,17 @@ impl Table {
|
|||||||
table = unsafe { Self::new(kernel_phys_to_virt(entry.addr()).as_usize().into()) };
|
table = unsafe { Self::new(kernel_phys_to_virt(entry.addr()).as_usize().into()) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mode() -> riscv::register::satp::Mode {
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv32")]
|
||||||
|
return riscv::register::satp::Mode::Sv32;
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv39")]
|
||||||
|
return riscv::register::satp::Mode::Sv39;
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv48")]
|
||||||
|
return riscv::register::satp::Mode::Sv48;
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv57")]
|
||||||
|
return riscv::register::satp::Mode::Sv57;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableOps for Table {
|
impl TableOps for Table {
|
||||||
|
113
kernel/src/arch/riscv/vspace/traits.rs
Normal file
113
kernel/src/arch/riscv/vspace/traits.rs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
use num_traits::ToPrimitive;
|
||||||
|
use utils::size::{GIB, KIB, MIB, TIB};
|
||||||
|
use vspace::addr::{AddressOps, PhysAddr, VirtAddr};
|
||||||
|
use vspace::paging::TableLevel;
|
||||||
|
|
||||||
|
pub trait PhysAddrPaging {
|
||||||
|
const PG_OFFSET: usize;
|
||||||
|
const PPN_BITS: usize;
|
||||||
|
const PPN_OFFSET: usize;
|
||||||
|
|
||||||
|
const PA_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PG_OFFSET;
|
||||||
|
const PTE_PPN_MASK: usize = ((1 << Self::PPN_BITS) - 1) << Self::PPN_OFFSET;
|
||||||
|
|
||||||
|
fn to_ppn(&self) -> usize
|
||||||
|
where Self: AddressOps {
|
||||||
|
(self.as_usize() & Self::PA_PPN_MASK) >> Self::PG_OFFSET
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_ppn_shifted(&self) -> usize
|
||||||
|
where Self: PhysAddrPaging + AddressOps {
|
||||||
|
self.to_ppn() << Self::PPN_OFFSET
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_pte(pte: usize) -> PhysAddr {
|
||||||
|
let ppn = (pte & Self::PTE_PPN_MASK) >> Self::PPN_OFFSET;
|
||||||
|
let paddr = ppn << Self::PG_OFFSET;
|
||||||
|
PhysAddr::from(paddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn merge_pte(&self, pte: usize) -> usize
|
||||||
|
where Self: PhysAddrPaging + AddressOps {
|
||||||
|
let ppn = self.to_ppn_shifted();
|
||||||
|
(pte & !Self::PTE_PPN_MASK) | ppn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv32")]
|
||||||
|
impl PhysAddrPaging for PhysAddr {
|
||||||
|
const PG_OFFSET: usize = 12;
|
||||||
|
const PPN_BITS: usize = 22;
|
||||||
|
const PPN_OFFSET: usize = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv39")]
|
||||||
|
impl PhysAddrPaging for PhysAddr {
|
||||||
|
const PG_OFFSET: usize = 12;
|
||||||
|
const PPN_BITS: usize = 44;
|
||||||
|
const PPN_OFFSET: usize = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait VirtAddrPaging {
|
||||||
|
const PG_OFFSET: usize;
|
||||||
|
const VPN_BITS: usize;
|
||||||
|
|
||||||
|
const VPN_MASK: usize = (1 << Self::VPN_BITS) - 1;
|
||||||
|
|
||||||
|
fn to_vpn(&self, level: TableLevel) -> usize
|
||||||
|
where Self: AddressOps {
|
||||||
|
self.as_usize() >> (Self::PG_OFFSET + Self::VPN_BITS * level.to_usize().unwrap())
|
||||||
|
& Self::VPN_MASK
|
||||||
|
}
|
||||||
|
|
||||||
|
fn merge_vpn(&self, vpn: usize, size: TableLevel) -> VirtAddr
|
||||||
|
where Self: AddressOps {
|
||||||
|
let shift = Self::PG_OFFSET + Self::VPN_BITS * size.to_usize().unwrap();
|
||||||
|
let mask = Self::VPN_MASK << shift;
|
||||||
|
VirtAddr((self.as_usize() & !mask) | ((vpn & Self::VPN_MASK) << shift))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lower_bits(&self, level: usize) -> usize
|
||||||
|
where Self: AddressOps {
|
||||||
|
self.as_usize() & ((1 << (Self::PG_OFFSET + Self::VPN_BITS * (level + 1))) - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv32")]
|
||||||
|
impl VirtAddrPaging for VirtAddr {
|
||||||
|
const PG_OFFSET: usize = 12;
|
||||||
|
const VPN_BITS: usize = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv39")]
|
||||||
|
impl VirtAddrPaging for VirtAddr {
|
||||||
|
const PG_OFFSET: usize = 12;
|
||||||
|
const VPN_BITS: usize = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait TableLevelSize {
|
||||||
|
fn level_size(&self) -> usize;
|
||||||
|
fn align<A: AddressOps>(&self, addr: A) -> A {
|
||||||
|
addr.align_down(self.level_size())
|
||||||
|
}
|
||||||
|
fn is_aligned<A: AddressOps>(&self, addr: A) -> bool {
|
||||||
|
self.align(addr) == addr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TableLevelSize for TableLevel {
|
||||||
|
fn level_size(&self) -> usize {
|
||||||
|
match self {
|
||||||
|
Self::Level0 => 4 * KIB,
|
||||||
|
#[cfg(feature = "riscv.pagetable.sv32")]
|
||||||
|
Self::Level1 => 4 * MIB,
|
||||||
|
#[cfg(not(feature = "riscv.pagetable.sv32"))]
|
||||||
|
Self::Level1 => 2 * MIB,
|
||||||
|
Self::Level2 => 1 * GIB,
|
||||||
|
#[cfg(not(feature = "legacy"))]
|
||||||
|
Self::Level3 => 512 * GIB,
|
||||||
|
#[cfg(not(feature = "legacy"))]
|
||||||
|
Self::Level4 => 256 * TIB,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,15 @@
|
|||||||
|
use super::table::Table;
|
||||||
|
use super::traits::{PhysAddrPaging, TableLevelSize};
|
||||||
use crate::arch::layout::*;
|
use crate::arch::layout::*;
|
||||||
use crate::utils::size::GIB;
|
use allocator::RamBlock;
|
||||||
use crate::vspace::addr::{align_up, AddressOps, PhysAddr, VirtAddr};
|
use fdt::Fdt;
|
||||||
use crate::vspace::allocator::RamBlock;
|
use utils::size::GIB;
|
||||||
use crate::vspace::paging::PageError::{AlreadyMapped, MissingEntry};
|
use vspace::addr::*;
|
||||||
use crate::vspace::paging::{MapAttr, Table, TableLevel, TableOps};
|
use vspace::paging::{MapAttr, PageError::*, TableLevel, TableOps};
|
||||||
|
|
||||||
|
pub unsafe fn setup_memory(fdt_addr: usize, mem: &mut RamBlock<8>) {
|
||||||
|
let fdt = unsafe { Fdt::from_ptr(fdt_addr as *const u8).unwrap() };
|
||||||
|
|
||||||
pub unsafe fn setup_memory<const N: usize>(fdt: &fdt::Fdt, fdt_addr: usize, mem: &mut RamBlock<N>) {
|
|
||||||
// Add main memory regions to allocator
|
// Add main memory regions to allocator
|
||||||
for region in fdt.memory().regions() {
|
for region in fdt.memory().regions() {
|
||||||
mem.dealloc(
|
mem.dealloc(
|
||||||
@ -46,7 +50,11 @@ pub unsafe fn setup_memory<const N: usize>(fdt: &fdt::Fdt, fdt_addr: usize, mem:
|
|||||||
mem.reserve(fdt_addr, fdt_size);
|
mem.reserve(fdt_addr, fdt_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn setup_kernel_paging<const N: usize>(allocator: &mut RamBlock<N>) {
|
pub unsafe fn setup_kernel_paging(
|
||||||
|
allocator: &mut RamBlock<8>,
|
||||||
|
hart_id: usize,
|
||||||
|
fdt_addr: usize,
|
||||||
|
) -> ! {
|
||||||
let mut alloc = || {
|
let mut alloc = || {
|
||||||
allocator
|
allocator
|
||||||
.alloc(PAGE_LAYOUT)
|
.alloc(PAGE_LAYOUT)
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
use core::cell::Cell;
|
use crate::arch::init_early_console;
|
||||||
use log::{debug, error, info, warn};
|
|
||||||
|
|
||||||
use crate::plat::console::{set_console, ConsoleDevice, ConsoleDriver, CONSOLE};
|
use crate::plat::console::{set_console, ConsoleDevice, ConsoleDriver, CONSOLE};
|
||||||
use crate::plat::lowlevel::{Hardware, LowLevel};
|
use crate::plat::lowlevel::{Hardware, LowLevel};
|
||||||
use crate::plat::timer::{Timer, TimerOps};
|
use crate::plat::timer::{Timer, TimerOps};
|
||||||
use crate::plat::trap::{Trap, TrapOps};
|
use crate::plat::trap::{Trap, TrapOps};
|
||||||
use crate::vspace::allocator::RamBlock;
|
use allocator::RamBlock;
|
||||||
|
use core::cell::Cell;
|
||||||
|
use fdt::Fdt;
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
|
|
||||||
#[thread_local]
|
#[thread_local]
|
||||||
pub static HART_ID: Cell<usize> = Cell::new(0);
|
pub static HART_ID: Cell<usize> = Cell::new(0);
|
||||||
|
|
||||||
pub fn rust_main<const N: usize>(hart_id: usize, fdt: fdt::Fdt, mut _allocator: RamBlock<N>) -> ! {
|
// NOTE: we will call rust_main through trap (stvec), make sure it is aligned
|
||||||
|
#[repr(align(4))]
|
||||||
|
pub extern "C" fn rust_main(hart_id: usize, fdt_addr: usize, allocator: &mut RamBlock<8>) -> ! {
|
||||||
HART_ID.set(hart_id);
|
HART_ID.set(hart_id);
|
||||||
|
|
||||||
info!("Kernel Started");
|
info!("Kernel Started");
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
#![feature(concat_idents)]
|
#![feature(concat_idents)]
|
||||||
#![feature(const_mut_refs)]
|
#![feature(const_mut_refs)]
|
||||||
#![feature(extern_types)]
|
#![feature(extern_types)]
|
||||||
|
#![feature(fn_align)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
#![feature(naked_functions)]
|
#![feature(naked_functions)]
|
||||||
#![feature(panic_info_message)]
|
#![feature(panic_info_message)]
|
||||||
#![feature(step_trait)]
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![feature(thread_local)]
|
#![feature(thread_local)]
|
||||||
// Test Infrastructure
|
// Test Infrastructure
|
||||||
@ -21,9 +21,6 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate num_derive;
|
|
||||||
|
|
||||||
mod arch;
|
mod arch;
|
||||||
mod drivers;
|
mod drivers;
|
||||||
mod entry;
|
mod entry;
|
||||||
@ -31,8 +28,6 @@ mod lang;
|
|||||||
mod logging;
|
mod logging;
|
||||||
mod objects;
|
mod objects;
|
||||||
mod plat;
|
mod plat;
|
||||||
mod utils;
|
|
||||||
mod vspace;
|
|
||||||
|
|
||||||
// test infrastructure
|
// test infrastructure
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
pub mod addr;
|
|
||||||
pub mod allocator;
|
|
||||||
pub mod paging;
|
|
Loading…
Reference in New Issue
Block a user