mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-25 17:33:28 +04:00
aarch64: basic framework
This commit is contained in:
parent
1140d32aaa
commit
174e0da3b6
5
kernel/src/arch/aarch64/board/raspi3/mod.rs
Normal file
5
kernel/src/arch/aarch64/board/raspi3/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//! Raspberry PI 3 Model B/B+
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
// TODO
|
||||||
|
}
|
62
kernel/src/arch/aarch64/context.rs
Normal file
62
kernel/src/arch/aarch64/context.rs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
//! Trapframe and context definitions for aarch64.
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct TrapFrame {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
///TODO
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Context {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Context {
|
||||||
|
/// TODO
|
||||||
|
#[inline(never)]
|
||||||
|
pub unsafe extern fn switch(&mut self, target: &mut Self) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub unsafe fn null() -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub unsafe fn new_kernel_thread(entry: extern fn(usize) -> !, arg: usize, kstack_top: usize, cr3: usize) -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub unsafe fn new_user_thread(entry_addr: usize, ustack_top: usize, kstack_top: usize, is32: bool, cr3: usize) -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub unsafe fn new_fork(tf: &TrapFrame, kstack_top: usize, cr3: usize) -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn enable() {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn disable() {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn disable_and_store() -> usize {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn restore(flags: usize) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
42
kernel/src/arch/aarch64/interrupt.rs
Normal file
42
kernel/src/arch/aarch64/interrupt.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
//! Interrupt handler implementation on raspi3.
|
||||||
|
|
||||||
|
pub use self::context::*;
|
||||||
|
|
||||||
|
#[path = "context.rs"]
|
||||||
|
mod context;
|
||||||
|
|
||||||
|
/// Initialize the trap to enable the interrupt.
|
||||||
|
pub fn init() {
|
||||||
|
// TODO
|
||||||
|
// info!("interrupt: init end");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable the interrupt.
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn enable() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disable the interrupt.
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn disable() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disable the interrupt and store the status.
|
||||||
|
///
|
||||||
|
/// return: status(usize)
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn disable_and_store() -> usize {
|
||||||
|
// TODO
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Use the original status to restore the process
|
||||||
|
///
|
||||||
|
/// Arguments:
|
||||||
|
/// * flags: original status(usize)
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn restore(flags: usize) {
|
||||||
|
// TODO
|
||||||
|
}
|
13
kernel/src/arch/aarch64/io.rs
Normal file
13
kernel/src/arch/aarch64/io.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
//! Serial driver for aarch64.
|
||||||
|
|
||||||
|
use core::fmt::{Arguments};
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub fn getchar() -> char {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub fn putfmt(fmt: Arguments<'_>) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
8
kernel/src/arch/aarch64/memory.rs
Normal file
8
kernel/src/arch/aarch64/memory.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
//! Memory initialization for aarch64.
|
||||||
|
|
||||||
|
use ucore_memory::PAGE_SIZE;
|
||||||
|
|
||||||
|
/// Memory initialization.
|
||||||
|
pub fn init() {
|
||||||
|
// TODO
|
||||||
|
}
|
34
kernel/src/arch/aarch64/mod.rs
Normal file
34
kernel/src/arch/aarch64/mod.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
//! Entrance and initialization for aarch64.
|
||||||
|
|
||||||
|
pub mod io;
|
||||||
|
pub mod paging;
|
||||||
|
pub mod memory;
|
||||||
|
pub mod interrupt;
|
||||||
|
|
||||||
|
#[cfg(feature = "board_raspi3")]
|
||||||
|
#[path = "board/raspi3/mod.rs"]
|
||||||
|
pub mod board;
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
/// The entry point of kernel
|
||||||
|
#[no_mangle] // don't mangle the name of this function
|
||||||
|
pub extern fn rust_main() -> ! {
|
||||||
|
println!("Hello ARM64!");
|
||||||
|
|
||||||
|
// First init log mod, so that we can print log info.
|
||||||
|
// ::logging::init();
|
||||||
|
// Init trap handling.
|
||||||
|
// interrupt::init();
|
||||||
|
// Init physical memory management and heap.
|
||||||
|
// memory::init();
|
||||||
|
// Now heap is available
|
||||||
|
// timer::init();
|
||||||
|
|
||||||
|
// Init board.
|
||||||
|
board::init();
|
||||||
|
::kmain();
|
||||||
|
}
|
||||||
|
|
||||||
|
// global_asm!(include_str!("boot/boot.asm"));
|
||||||
|
// global_asm!(include_str!("boot/entry.asm"));
|
||||||
|
// global_asm!(include_str!("boot/trap.asm"));
|
199
kernel/src/arch/aarch64/paging.rs
Normal file
199
kernel/src/arch/aarch64/paging.rs
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
//! Page table implementations for aarch64.
|
||||||
|
|
||||||
|
use ucore_memory::memory_set::*;
|
||||||
|
use ucore_memory::paging::*;
|
||||||
|
|
||||||
|
type VirtAddr = usize;
|
||||||
|
type PhysAddr = usize;
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub struct ActivePageTable {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActivePageTable {
|
||||||
|
/// TODO
|
||||||
|
pub unsafe fn new() -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PageTable for ActivePageTable {
|
||||||
|
type Entry = PageEntry;
|
||||||
|
|
||||||
|
fn map(&mut self, addr: VirtAddr, target: PhysAddr) -> &mut Self::Entry {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
fn unmap(&mut self, addr: VirtAddr) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_entry(&mut self, addr: VirtAddr) -> &mut Self::Entry {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
// For testing with mock
|
||||||
|
fn get_page_slice_mut<'a,'b>(&'a mut self, addr: VirtAddr) -> &'b mut [u8] {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read(&mut self, addr: VirtAddr) -> u8 {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(&mut self, addr: VirtAddr, data: u8) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub struct PageEntry {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entry for PageEntry {
|
||||||
|
/// IMPORTANT!
|
||||||
|
/// This must be called after any change to ensure it become effective.
|
||||||
|
/// Usually this will make a flush to TLB/MMU.
|
||||||
|
fn update(&mut self) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will be set when accessed
|
||||||
|
fn accessed(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will be set when written
|
||||||
|
fn dirty(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will PageFault when try to write page where writable=0
|
||||||
|
fn writable(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Will PageFault when try to access page where present=0
|
||||||
|
fn present(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn clear_accessed(&mut self) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_dirty(&mut self) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_writable(&mut self, value: bool) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_present(&mut self, value: bool) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn target(&self) -> PhysAddr {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_target(&mut self, target: PhysAddr) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For Copy-on-write extension
|
||||||
|
fn writable_shared(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn readonly_shared(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_shared(&mut self, writable: bool) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_shared(&mut self) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// For Swap extension
|
||||||
|
fn swapped(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_swapped(&mut self, value: bool) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn user(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_user(&mut self, value: bool) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute(&self) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_execute(&mut self, value: bool) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
pub struct InactivePageTable0 {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TODO
|
||||||
|
impl InactivePageTable for InactivePageTable0 {
|
||||||
|
type Active = ActivePageTable;
|
||||||
|
|
||||||
|
fn new() -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_bare() -> Self {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn edit(&mut self, f: impl FnOnce(&mut Self::Active)) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn activate(&self) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn with(&self, f: impl FnOnce()) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn token(&self) -> usize {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn alloc_frame() -> Option<PhysAddr> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dealloc_frame(target: PhysAddr) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn alloc_stack() -> Stack {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@
|
|||||||
pub use self::riscv::*;
|
pub use self::riscv::*;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
pub use self::x86_64::*;
|
pub use self::x86_64::*;
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
pub use self::aarch64::*;
|
||||||
|
|
||||||
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;
|
||||||
@ -126,3 +128,18 @@ mod x86_64 {
|
|||||||
pub const USER_TMP_MISC_OFFSET: usize = USER_TMP_TLS_OFFSET + PML4_SIZE;
|
pub const USER_TMP_MISC_OFFSET: usize = USER_TMP_TLS_OFFSET + PML4_SIZE;
|
||||||
pub const USER_TMP_MISC_PML4: usize = (USER_TMP_MISC_OFFSET & PML4_MASK) / PML4_SIZE;
|
pub const USER_TMP_MISC_PML4: usize = (USER_TMP_MISC_OFFSET & PML4_MASK) / PML4_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
mod aarch64 {
|
||||||
|
//! TODO: replace unmiplemented consts with real value
|
||||||
|
const UNIMPLEMENTED: usize = 0;
|
||||||
|
pub const KERNEL_OFFSET: usize = UNIMPLEMENTED;
|
||||||
|
pub const KERNEL_PML4: usize = UNIMPLEMENTED;
|
||||||
|
pub const KERNEL_HEAP_OFFSET: usize = UNIMPLEMENTED;
|
||||||
|
pub const KERNEL_HEAP_SIZE: usize = 8 * 1024 * 1024;
|
||||||
|
pub const MEMORY_OFFSET: usize = UNIMPLEMENTED;
|
||||||
|
pub const MEMORY_END: usize = UNIMPLEMENTED;
|
||||||
|
pub const USER_STACK_OFFSET: usize = UNIMPLEMENTED;
|
||||||
|
pub const USER_STACK_SIZE: usize = UNIMPLEMENTED;
|
||||||
|
pub const USER32_STACK_OFFSET: usize = UNIMPLEMENTED;
|
||||||
|
}
|
||||||
|
@ -23,8 +23,14 @@ pub fn shell() {
|
|||||||
}
|
}
|
||||||
Box::new(unsafe { MemBuf::new(_binary_user_riscv_img_start, _binary_user_riscv_img_end) })
|
Box::new(unsafe { MemBuf::new(_binary_user_riscv_img_start, _binary_user_riscv_img_end) })
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
let device = Box::new(&ide::DISK1);
|
let device = Box::new(&ide::DISK1);
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
// TODO
|
||||||
|
let device: Box<dyn Device> = unimplemented!();
|
||||||
|
|
||||||
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS");
|
let sfs = SimpleFileSystem::open(device).expect("failed to open SFS");
|
||||||
let root = sfs.root_inode();
|
let root = sfs.root_inode();
|
||||||
let files = root.borrow().list().unwrap();
|
let files = root.borrow().list().unwrap();
|
||||||
|
@ -60,6 +60,10 @@ pub mod arch;
|
|||||||
#[path = "arch/riscv32/mod.rs"]
|
#[path = "arch/riscv32/mod.rs"]
|
||||||
pub mod arch;
|
pub mod arch;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
#[path = "arch/aarch64/mod.rs"]
|
||||||
|
pub mod arch;
|
||||||
|
|
||||||
pub fn kmain() -> ! {
|
pub fn kmain() -> ! {
|
||||||
process::init();
|
process::init();
|
||||||
unsafe { arch::interrupt::enable(); }
|
unsafe { arch::interrupt::enable(); }
|
||||||
|
@ -17,6 +17,10 @@ pub type FrameAlloc = BitAlloc64K;
|
|||||||
#[cfg(target_arch = "riscv32")]
|
#[cfg(target_arch = "riscv32")]
|
||||||
pub type FrameAlloc = BitAlloc4K;
|
pub type FrameAlloc = BitAlloc4K;
|
||||||
|
|
||||||
|
// Raspberry Pi 3 has 1G memory
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
pub type FrameAlloc = BitAlloc64K;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref FRAME_ALLOCATOR: Mutex<FrameAlloc> = Mutex::new(FrameAlloc::default());
|
pub static ref FRAME_ALLOCATOR: Mutex<FrameAlloc> = Mutex::new(FrameAlloc::default());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user