Finish comment for ristv boot.

master
lcy1996 6 years ago
parent 528c919626
commit 4e0b510895

@ -0,0 +1,4 @@
[[package]]
name = "bbl"
version = "0.1.0"

@ -0,0 +1,14 @@
[[package]]
name = "bit-allocator"
version = "0.1.0"
dependencies = [
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bit_field"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"

@ -0,0 +1,4 @@
[[package]]
name = "ucore-memory"
version = "0.1.0"

@ -0,0 +1,23 @@
[[package]]
name = "cfg-if"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ucore-process"
version = "0.1.0"
dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"

@ -0,0 +1,4 @@
[[package]]
name = "ucore-sync"
version = "0.1.0"

@ -4,13 +4,14 @@ use super::riscv::{addr::*, register::sstatus};
use ucore_memory::PAGE_SIZE; use ucore_memory::PAGE_SIZE;
pub fn init() { pub fn init() {
#[repr(align(4096))] #[repr(align(4096))] // align the PageData struct to 4096 bytes
struct PageData([u8; PAGE_SIZE]); struct PageData([u8; PAGE_SIZE]);
static PAGE_TABLE_ROOT: PageData = PageData([0; PAGE_SIZE]); static PAGE_TABLE_ROOT: PageData = PageData([0; PAGE_SIZE]);
unsafe { sstatus::set_sum(); } // Allow user memory access unsafe { sstatus::set_sum(); } // Allow user memory access
let frame = Frame::of_addr(PhysAddr::new(&PAGE_TABLE_ROOT as *const _ as u32)); let frame = Frame::of_addr(PhysAddr::new(&PAGE_TABLE_ROOT as *const _ as u32));
super::paging::setup_page_table(frame); super::paging::setup_page_table(frame); // set up page table
// initialize heap and Frame allocator
init_frame_allocator(); init_frame_allocator();
remap_the_kernel(); remap_the_kernel();
init_heap(); init_heap();
@ -23,9 +24,19 @@ fn init_frame_allocator() {
let mut ba = FRAME_ALLOCATOR.lock(); let mut ba = FRAME_ALLOCATOR.lock();
use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE}; use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
// keep memory for the kernel heap and set other physical memory available in BitAlloc
ba.insert(to_range(KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE, MEMORY_END)); ba.insert(to_range(KERNEL_HEAP_OFFSET + KERNEL_HEAP_SIZE, MEMORY_END));
info!("FrameAllocator init end"); info!("FrameAllocator init end");
/*
* @param:
* start: start address
* end: end address
* @brief:
* transform the memory address to the page number
* @retval:
* the page number range from start address to end address
*/
fn to_range(start: usize, end: usize) -> Range<usize> { fn to_range(start: usize, end: usize) -> Range<usize> {
let page_start = (start - MEMORY_OFFSET) / PAGE_SIZE; let page_start = (start - MEMORY_OFFSET) / PAGE_SIZE;
let page_end = (end - MEMORY_OFFSET - 1) / PAGE_SIZE + 1; let page_end = (end - MEMORY_OFFSET - 1) / PAGE_SIZE + 1;
@ -35,6 +46,7 @@ fn init_frame_allocator() {
fn remap_the_kernel() { fn remap_the_kernel() {
use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE}; use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
// set up kernel stack
let kstack = Stack { let kstack = Stack {
top: bootstacktop as usize, top: bootstacktop as usize,
bottom: bootstack as usize + PAGE_SIZE, bottom: bootstack as usize + PAGE_SIZE,

@ -11,10 +11,15 @@ pub mod compiler_rt;
#[no_mangle] #[no_mangle]
pub extern fn rust_main() -> ! { pub extern fn rust_main() -> ! {
println!("Hello RISCV! {}", 123); println!("Hello RISCV! {}", 123);
// First init log mod, so that we can print log info.
::logging::init(); ::logging::init();
// Init interrupt handling.
interrupt::init(); interrupt::init();
// Init physical memory management and heap
memory::init(); memory::init();
// Init timer interrupt
timer::init(); timer::init();
::kmain(); ::kmain();
} }

@ -10,6 +10,12 @@ use ucore_memory::memory_set::*;
use ucore_memory::PAGE_SIZE; use ucore_memory::PAGE_SIZE;
use ucore_memory::paging::*; use ucore_memory::paging::*;
/*
* @param:
* Frame: page table root frame
* @brief:
* setup page table in the frame
*/
// need 1 page // need 1 page
pub fn setup_page_table(frame: Frame) { pub fn setup_page_table(frame: Frame) {
let p2 = unsafe { &mut *(frame.start_address().as_u32() as *mut RvPageTable) }; let p2 = unsafe { &mut *(frame.start_address().as_u32() as *mut RvPageTable) };

@ -26,12 +26,14 @@ pub fn init() {
info!("timer: init end"); info!("timer: init end");
} }
// set the next timer interrupt
pub fn set_next() { pub fn set_next() {
// 100Hz @ QEMU // 100Hz @ QEMU
let timebase = 250000; let timebase = 250000;
set_timer(get_cycle() + timebase); set_timer(get_cycle() + timebase);
} }
// set time for timer interrupt
fn set_timer(t: u64) { fn set_timer(t: u64) {
#[cfg(feature = "no_bbl")] #[cfg(feature = "no_bbl")]
unsafe { unsafe {

@ -8,6 +8,7 @@ pub use self::x86_64::*;
pub const MAX_CPU_NUM: usize = 8; pub const MAX_CPU_NUM: usize = 8;
pub const MAX_PROCESS_NUM: usize = 48; pub const MAX_PROCESS_NUM: usize = 48;
// Memory address for riscv32
#[cfg(target_arch = "riscv32")] #[cfg(target_arch = "riscv32")]
mod riscv { mod riscv {
// Physical address available on THINPAD: // Physical address available on THINPAD:
@ -26,6 +27,7 @@ mod riscv {
pub const USER32_STACK_OFFSET: usize = USER_STACK_OFFSET; pub const USER32_STACK_OFFSET: usize = USER_STACK_OFFSET;
} }
// Memory address for x86_64
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
mod x86_64 { mod x86_64 {
// Copy from Redox consts.rs: // Copy from Redox consts.rs:

@ -0,0 +1,4 @@
[[package]]
name = "ucore-ulib"
version = "0.1.0"
Loading…
Cancel
Save