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;
pub fn init() {
#[repr(align(4096))]
#[repr(align(4096))] // align the PageData struct to 4096 bytes
struct PageData([u8; PAGE_SIZE]);
static PAGE_TABLE_ROOT: PageData = PageData([0; PAGE_SIZE]);
unsafe { sstatus::set_sum(); } // Allow user memory access
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();
remap_the_kernel();
init_heap();
@ -23,9 +24,19 @@ fn init_frame_allocator() {
let mut ba = FRAME_ALLOCATOR.lock();
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));
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> {
let page_start = (start - MEMORY_OFFSET) / PAGE_SIZE;
let page_end = (end - MEMORY_OFFSET - 1) / PAGE_SIZE + 1;
@ -35,6 +46,7 @@ fn init_frame_allocator() {
fn remap_the_kernel() {
use consts::{KERNEL_HEAP_OFFSET, KERNEL_HEAP_SIZE};
// set up kernel stack
let kstack = Stack {
top: bootstacktop as usize,
bottom: bootstack as usize + PAGE_SIZE,

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

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

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

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

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