fix merge compile error

master
WangRunji 6 years ago
parent 2afe8c731e
commit b5ced136f7

17
kernel/Cargo.lock generated

@ -1,3 +1,17 @@
[[package]]
name = "aarch64"
version = "2.2.2"
source = "git+https://github.com/equation314/aarch64#47bf5439f5a1379f0fef6272853cf684207a4e45"
dependencies = [
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"os_bootinfo 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"usize_conversions 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ux 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "apic" name = "apic"
version = "0.1.0" version = "0.1.0"
@ -302,6 +316,7 @@ dependencies = [
name = "ucore" name = "ucore"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"aarch64 2.2.2 (git+https://github.com/equation314/aarch64)",
"apic 0.1.0 (git+https://github.com/wangrunji0408/APIC-Rust)", "apic 0.1.0 (git+https://github.com/wangrunji0408/APIC-Rust)",
"atags 0.1.0", "atags 0.1.0",
"bbl 0.1.0", "bbl 0.1.0",
@ -311,7 +326,6 @@ dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"bootloader 0.3.4 (git+https://github.com/wangrunji0408/bootloader)", "bootloader 0.3.4 (git+https://github.com/wangrunji0408/bootloader)",
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-a 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "linked_list_allocator 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -431,6 +445,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum aarch64 2.2.2 (git+https://github.com/equation314/aarch64)" = "<none>"
"checksum apic 0.1.0 (git+https://github.com/wangrunji0408/APIC-Rust)" = "<none>" "checksum apic 0.1.0 (git+https://github.com/wangrunji0408/APIC-Rust)" = "<none>"
"checksum array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72" "checksum array-init 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72"
"checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a" "checksum bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3caf393d93b2d453e80638d0674597020cef3382ada454faacd43d1a55a735a"

@ -142,7 +142,7 @@ ifeq ($(arch), riscv32)
ifeq ($(board), fpga) ifeq ($(board), fpga)
@cp $(kernel) $@ @cp $(kernel) $@
else else
@cd ../tools/riscv-pk && \ @cd ../riscv-pk && \
mkdir -p build && \ mkdir -p build && \
cd build && \ cd build && \
../configure \ ../configure \
@ -152,7 +152,7 @@ else
--host=riscv64-unknown-elf \ --host=riscv64-unknown-elf \
--with-payload=$(abspath $(kernel)) && \ --with-payload=$(abspath $(kernel)) && \
make && \ make && \
cp bbl ../../../kernel/$@ cp bbl ../../kernel/$@
endif endif
else ifeq ($(arch), aarch64) else ifeq ($(arch), aarch64)
@$(objcopy) $(kernel) --strip-all -O binary $@ @$(objcopy) $(kernel) --strip-all -O binary $@

@ -1,5 +1,7 @@
//! Raspberry PI 3 Model B/B+ //! Raspberry PI 3 Model B/B+
use once::*;
pub mod irq; pub mod irq;
pub mod timer; pub mod timer;
pub mod serial; pub mod serial;

@ -1,6 +1,7 @@
use bcm2837::mini_uart::MiniUart; use bcm2837::mini_uart::MiniUart;
use core::fmt; use core::fmt;
use spin::Mutex; use spin::Mutex;
use once::*;
/// Struct to get a global SerialPort interface /// Struct to get a global SerialPort interface
pub struct SerialPort { pub struct SerialPort {

@ -1,11 +1,8 @@
//! TODO: replace unmiplemented consts with real value pub const RECURSIVE_INDEX: usize = 0o777;
const UNIMPLEMENTED: usize = 0; pub const KERNEL_OFFSET: usize = 0;
pub const KERNEL_OFFSET: usize = UNIMPLEMENTED; pub const KERNEL_PML4: usize = 0;
pub const KERNEL_PML4: usize = UNIMPLEMENTED;
pub const KERNEL_HEAP_OFFSET: usize = UNIMPLEMENTED;
pub const KERNEL_HEAP_SIZE: usize = 8 * 1024 * 1024; pub const KERNEL_HEAP_SIZE: usize = 8 * 1024 * 1024;
pub const MEMORY_OFFSET: usize = UNIMPLEMENTED; pub const MEMORY_OFFSET: usize = 0;
pub const MEMORY_END: usize = UNIMPLEMENTED; pub const USER_STACK_OFFSET: usize = 0xffff_8000_0000_0000;
pub const USER_STACK_OFFSET: usize = UNIMPLEMENTED; pub const USER_STACK_SIZE: usize = 1 * 1024 * 1024;
pub const USER_STACK_SIZE: usize = UNIMPLEMENTED; pub const USER32_STACK_OFFSET: usize = USER_STACK_OFFSET;
pub const USER32_STACK_OFFSET: usize = UNIMPLEMENTED;

@ -1,8 +1,7 @@
//! TrapFrame and context definitions for aarch64. //! TrapFrame and context definitions for aarch64.
extern crate aarch64; use spin::Mutex;
use lazy_static::lazy_static;
use spin::{Mutex};
use aarch64::barrier; use aarch64::barrier;
use aarch64::addr::PhysAddr; use aarch64::addr::PhysAddr;
use aarch64::paging::PhysFrame; use aarch64::paging::PhysFrame;
@ -169,7 +168,7 @@ impl Context {
/// Called at a new user context /// Called at a new user context
/// To get the init TrapFrame in sys_exec /// To get the init TrapFrame in sys_exec
pub unsafe fn get_init_tf(&self) -> TrapFrame { pub unsafe fn get_init_tf(&self) -> TrapFrame {
(*(self.0 as *const InitStack)).tf.clone() (*(self.stack_top as *const InitStack)).tf.clone()
} }
} }

@ -55,7 +55,7 @@ pub extern "C" fn rust_trap(info: Info, esr: u32, tf: &mut TrapFrame) {
Fault::Translation | Fault::AccessFlag | Fault::Permission => { Fault::Translation | Fault::AccessFlag | Fault::Permission => {
handle_page_fault(tf) handle_page_fault(tf)
} }
_ => ::trap::error(tf), _ => crate::trap::error(tf),
}, },
_ => crate::trap::error(tf), _ => crate::trap::error(tf),
} }
@ -73,7 +73,7 @@ fn handle_break(_num: u16, tf: &mut TrapFrame) {
fn handle_syscall(num: u16, tf: &mut TrapFrame) { fn handle_syscall(num: u16, tf: &mut TrapFrame) {
if num != 0 { if num != 0 {
::trap::error(tf); crate::trap::error(tf);
} }
// svc instruction has been skipped in syscall (ref: J1.1.2, page 6152) // svc instruction has been skipped in syscall (ref: J1.1.2, page 6152)
@ -96,5 +96,5 @@ fn handle_page_fault(tf: &mut TrapFrame) {
let addr = FAR_EL1.get(); let addr = FAR_EL1.get();
trace!("\nEXCEPTION: Page Fault @ {:#x}", addr); trace!("\nEXCEPTION: Page Fault @ {:#x}", addr);
::trap::error(tf); crate::trap::error(tf);
} }

@ -1,10 +1,11 @@
//! Memory initialization for aarch64. //! Memory initialization for aarch64.
use log::*;
use ucore_memory::PAGE_SIZE; use ucore_memory::PAGE_SIZE;
use memory::{FRAME_ALLOCATOR, init_heap, MemoryArea, MemoryAttr, MemorySet, Stack}; use atags::atags::Atags;
use super::atags::atags::Atags;
use aarch64::{barrier, regs::*, addr::*}; use aarch64::{barrier, regs::*, addr::*};
use aarch64::paging::{PhysFrame as Frame, memory_attribute::*}; use aarch64::paging::{PhysFrame as Frame, memory_attribute::*};
use crate::memory::{FRAME_ALLOCATOR, init_heap, MemoryArea, MemoryAttr, MemorySet};
/// Memory initialization. /// Memory initialization.
pub fn init() { pub fn init() {
@ -73,7 +74,7 @@ pub fn init_mmu_early() {
fn init_frame_allocator() { fn init_frame_allocator() {
use bit_allocator::BitAlloc; use bit_allocator::BitAlloc;
use core::ops::Range; use core::ops::Range;
use consts::MEMORY_OFFSET; use crate::consts::MEMORY_OFFSET;
let (start, end) = memory_map().expect("failed to find memory map"); let (start, end) = memory_map().expect("failed to find memory map");
let mut ba = FRAME_ALLOCATOR.lock(); let mut ba = FRAME_ALLOCATOR.lock();
@ -98,20 +99,14 @@ fn init_frame_allocator() {
/// remap kernel page table after all initialization. /// remap kernel page table after all initialization.
fn remap_the_kernel() { fn remap_the_kernel() {
let (bottom, top) = (0, bootstacktop as usize); let mut ms = unsafe { MemorySet::new_bare() };
let kstack = Stack { ms.push(MemoryArea::new_identity(0, bootstacktop as usize, MemoryAttr::default(), "kstack"));
top,
bottom,
};
static mut SPACE: [u8; 0x1000] = [0; 0x1000];
let mut ms = unsafe { MemorySet::new_from_raw_space(&mut SPACE, kstack) };
ms.push(MemoryArea::new_identity(bottom, top, MemoryAttr::default(), "kstack"));
ms.push(MemoryArea::new_identity(stext as usize, etext as usize, MemoryAttr::default().execute().readonly(), "text")); ms.push(MemoryArea::new_identity(stext as usize, etext as usize, MemoryAttr::default().execute().readonly(), "text"));
ms.push(MemoryArea::new_identity(sdata as usize, edata as usize, MemoryAttr::default(), "data")); ms.push(MemoryArea::new_identity(sdata as usize, edata as usize, MemoryAttr::default(), "data"));
ms.push(MemoryArea::new_identity(srodata as usize, erodata as usize, MemoryAttr::default().readonly(), "rodata")); ms.push(MemoryArea::new_identity(srodata as usize, erodata as usize, MemoryAttr::default().readonly(), "rodata"));
ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss")); ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss"));
use arch::board::{IO_REMAP_BASE, IO_REMAP_END}; use super::board::{IO_REMAP_BASE, IO_REMAP_END};
ms.push(MemoryArea::new_identity(IO_REMAP_BASE, IO_REMAP_END, MemoryAttr::default().mmio(), "io_remap")); ms.push(MemoryArea::new_identity(IO_REMAP_BASE, IO_REMAP_END, MemoryAttr::default().mmio(), "io_remap"));
unsafe { ms.activate(); } unsafe { ms.activate(); }

@ -23,30 +23,18 @@ pub extern "C" fn rust_main() -> ! {
// Init board to enable serial port. // Init board to enable serial port.
board::init(); board::init();
println!("{}", LOGO);
crate::logging::init(); crate::logging::init();
interrupt::init(); interrupt::init();
memory::init(); memory::init();
timer::init(); timer::init();
use crate::process::{processor, ContextImpl};
crate::process::init(); crate::process::init();
processor().manager().add(ContextImpl::new_kernel(kernel_proc2, 2333), 0);
processor().manager().add(ContextImpl::new_user_test(kernel_proc3), 0);
crate::kmain(); crate::kmain();
} }
extern fn kernel_proc2(arg: usize) -> ! {
use alloc::format;
test_shell(&format!("proc2-{}>> ", arg));
}
extern fn kernel_proc3(arg: usize) -> ! {
use alloc::format;
test_shell(&format!("proc3-{}$ ", arg));
}
const LOGO: &str = r#" const LOGO: &str = r#"
____ __ ____ _____ ____ __ ____ _____
/ __ \ __ __ _____ / /_ / __ \/ ___/ / __ \ __ __ _____ / /_ / __ \/ ___/
@ -54,50 +42,3 @@ const LOGO: &str = r#"
/ _, _// /_/ /(__ )/ /_ / /_/ /___/ / / _, _// /_/ /(__ )/ /_ / /_/ /___/ /
/_/ |_| \__,_//____/ \__/ \____//____/ /_/ |_| \__,_//____/ \__/ \____//____/
"#; "#;
pub fn show_logo() {
println!("{}", LOGO);
}
#[inline(always)]
fn sys_call(id: usize, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> i32 {
let ret: i32;
unsafe {
asm!("svc 0"
: "={x0}" (ret)
: "{x8}" (id), "{x0}" (arg0), "{x1}" (arg1), "{x2}" (arg2), "{x3}" (arg3), "{x4}" (arg4), "{x5}" (arg5)
: "memory"
: "volatile");
}
ret
}
pub fn test_shell(prefix: &str) -> ! {
show_logo();
loop {
print!("{}", prefix);
loop {
let c = io::getchar();
match c {
'\u{7f}' => {
print!("\u{7f}");
}
'c' => unsafe {
print!("sys_putc: ");
sys_call(30, 'A' as usize, 0, 0, 0, 0, 0);
},
't' => unsafe {
println!("sys_get_time: {}", sys_call(17, 0, 0, 0, 0, 0, 0));
},
' '...'\u{7e}' => {
print!("{}", c);
}
'\n' | '\r' => {
print!("\n");
break;
}
_ => {}
}
}
}
}

@ -1,7 +1,4 @@
//! Page table implementations for aarch64. //! Page table implementations for aarch64.
// Depends on kernel
use consts::{KERNEL_PML4, RECURSIVE_INDEX};
use memory::{active_table, alloc_frame, alloc_stack, dealloc_frame};
use ucore_memory::memory_set::*; use ucore_memory::memory_set::*;
use ucore_memory::PAGE_SIZE; use ucore_memory::PAGE_SIZE;
use ucore_memory::paging::*; use ucore_memory::paging::*;
@ -10,6 +7,10 @@ use aarch64::{PhysAddr, VirtAddr};
use aarch64::paging::{Mapper, PageTable as Aarch64PageTable, PageTableEntry, PageTableFlags as EF, RecursivePageTable}; use aarch64::paging::{Mapper, PageTable as Aarch64PageTable, PageTableEntry, PageTableFlags as EF, RecursivePageTable};
use aarch64::paging::{FrameAllocator, FrameDeallocator, Page, PhysFrame as Frame, Size4KiB, Size2MiB, Size1GiB}; use aarch64::paging::{FrameAllocator, FrameDeallocator, Page, PhysFrame as Frame, Size4KiB, Size2MiB, Size1GiB};
use aarch64::paging::memory_attribute::*; use aarch64::paging::memory_attribute::*;
use log::*;
// Depends on kernel
use crate::consts::{KERNEL_PML4, RECURSIVE_INDEX};
use crate::memory::{active_table, alloc_frame, dealloc_frame};
// need 3 page // need 3 page
pub fn setup_temp_page_table(frame_lvl4: Frame, frame_lvl3: Frame, frame_lvl2: Frame) { pub fn setup_temp_page_table(frame_lvl4: Frame, frame_lvl3: Frame, frame_lvl2: Frame) {
@ -25,7 +26,7 @@ pub fn setup_temp_page_table(frame_lvl4: Frame, frame_lvl3: Frame, frame_lvl2: F
for page in Page::<Size2MiB>::range_of(start_addr, end_addr) { for page in Page::<Size2MiB>::range_of(start_addr, end_addr) {
let paddr = PhysAddr::new(page.start_address().as_u64()); let paddr = PhysAddr::new(page.start_address().as_u64());
use arch::board::IO_REMAP_BASE; use super::board::IO_REMAP_BASE;
if paddr.as_u64() >= IO_REMAP_BASE as u64 { if paddr.as_u64() >= IO_REMAP_BASE as u64 {
p2[page.p2_index()].set_block::<Size2MiB>(paddr, block_flags | EF::PXN, MairDevice::attr_value()); p2[page.p2_index()].set_block::<Size2MiB>(paddr, block_flags | EF::PXN, MairDevice::attr_value());
} else { } else {
@ -55,7 +56,7 @@ impl PageTable for ActivePageTable {
let attr = MairNormal::attr_value(); let attr = MairNormal::attr_value();
self.0.map_to(Page::of_addr(addr), Frame::of_addr(target), flags, attr, &mut FrameAllocatorForAarch64) self.0.map_to(Page::of_addr(addr), Frame::of_addr(target), flags, attr, &mut FrameAllocatorForAarch64)
.unwrap().flush(); .unwrap().flush();
self.get_entry(addr) self.get_entry(addr).expect("fail to get entry")
} }
fn unmap(&mut self, addr: usize) { fn unmap(&mut self, addr: usize) {
@ -241,13 +242,14 @@ impl InactivePageTable for InactivePageTable0 {
ttbr_el1_write(1, new_frame); ttbr_el1_write(1, new_frame);
tlb_invalidate_all(); tlb_invalidate_all();
} }
f(); let ret = f();
debug!("switch TTBR1 {:?} -> {:?}", new_frame, old_frame); debug!("switch TTBR1 {:?} -> {:?}", new_frame, old_frame);
if old_frame != new_frame { if old_frame != new_frame {
ttbr_el1_write(1, old_frame); ttbr_el1_write(1, old_frame);
tlb_invalidate_all(); tlb_invalidate_all();
flush_icache_all(); flush_icache_all();
} }
ret
} }
fn token(&self) -> usize { fn token(&self) -> usize {

@ -161,10 +161,6 @@ impl ActivePageTable {
// Unmap the page // Unmap the page
self.unmap(0xcafebabe); self.unmap(0xcafebabe);
} }
pub fn token() -> usize {
satp::read().frame().number() | (1 << 31)
}
} }
/// implementation for the Entry trait in /crate/memory/src/paging/mod.rs /// implementation for the Entry trait in /crate/memory/src/paging/mod.rs
impl Entry for PageEntry { impl Entry for PageEntry {

@ -96,9 +96,6 @@ impl ActivePageTable {
// Unmap the page // Unmap the page
self.unmap(0xcafebabe); self.unmap(0xcafebabe);
} }
pub fn token() -> usize {
Cr3::read().0.start_address().as_u64() as usize
}
} }
impl Entry for PageEntry { impl Entry for PageEntry {

@ -34,7 +34,7 @@ _user_img_end:
lazy_static! { lazy_static! {
pub static ref ROOT_INODE: Arc<INode> = { pub static ref ROOT_INODE: Arc<INode> = {
#[cfg(target_arch = "riscv32")] #[cfg(any(target_arch = "riscv32", target_arch = "aarch64"))]
let device = { let device = {
extern { extern {
fn _user_img_start(); fn _user_img_start();
@ -44,8 +44,6 @@ lazy_static! {
}; };
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
let device = Box::new(ide::IDE::new(1)); let device = Box::new(ide::IDE::new(1));
#[cfg(target_arch = "aarch64")]
let device = unimplemented!();
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS"); let sfs = SimpleFileSystem::open(device).expect("failed to open SFS");
sfs.root_inode() sfs.root_inode()

@ -110,7 +110,6 @@ pub fn page_fault_handler(addr: usize) -> bool {
info!("start handling swap in/out page fault"); info!("start handling swap in/out page fault");
//unsafe { ACTIVE_TABLE_SWAP.force_unlock(); } //unsafe { ACTIVE_TABLE_SWAP.force_unlock(); }
info!("active page table token in pg fault is {:x?}", ActivePageTable::token());
/*LAB3 EXERCISE 1: YOUR STUDENT NUMBER /*LAB3 EXERCISE 1: YOUR STUDENT NUMBER
* handle the frame deallocated * handle the frame deallocated
*/ */

Loading…
Cancel
Save