diff --git a/crate/bcm2837/Cargo.toml b/crate/bcm2837/Cargo.toml index 3fb3e2e..456ee0e 100644 --- a/crate/bcm2837/Cargo.toml +++ b/crate/bcm2837/Cargo.toml @@ -2,10 +2,11 @@ name = "bcm2837" version = "0.1.0" authors = ["equation314 "] +edition = "2018" [features] -use_generic_timer = [] +use_generic_timer = ["aarch64"] [dependencies] volatile = "0.2.4" -cortex-a = "2.2.2" +aarch64= { git = "https://github.com/equation314/aarch64", optional = true } diff --git a/crate/bcm2837/src/gpio.rs b/crate/bcm2837/src/gpio.rs index 1fb7fec..ef258d6 100644 --- a/crate/bcm2837/src/gpio.rs +++ b/crate/bcm2837/src/gpio.rs @@ -1,5 +1,5 @@ -use IO_BASE; -use timer::delay; +use crate::IO_BASE; +use crate::timer::delay; use core::marker::PhantomData; use volatile::{ReadOnly, Volatile, WriteOnly}; diff --git a/crate/bcm2837/src/interrupt.rs b/crate/bcm2837/src/interrupt.rs index 9d6befe..03657c9 100644 --- a/crate/bcm2837/src/interrupt.rs +++ b/crate/bcm2837/src/interrupt.rs @@ -1,4 +1,4 @@ -use IO_BASE; +use crate::IO_BASE; use volatile::{ReadOnly, Volatile}; const INT_BASE: usize = IO_BASE + 0xB000 + 0x200; diff --git a/crate/bcm2837/src/mini_uart.rs b/crate/bcm2837/src/mini_uart.rs index d21c249..c1d0101 100644 --- a/crate/bcm2837/src/mini_uart.rs +++ b/crate/bcm2837/src/mini_uart.rs @@ -1,5 +1,5 @@ -use IO_BASE; -use gpio::{Function, Gpio}; +use crate::IO_BASE; +use crate::gpio::{Function, Gpio}; use volatile::{ReadOnly, Volatile}; /// The base address for the `MU` registers. diff --git a/crate/bcm2837/src/timer/generic_timer.rs b/crate/bcm2837/src/timer/generic_timer.rs index 14aabe6..8333cb9 100644 --- a/crate/bcm2837/src/timer/generic_timer.rs +++ b/crate/bcm2837/src/timer/generic_timer.rs @@ -1,6 +1,6 @@ -extern crate cortex_a; +extern crate aarch64; -use self::cortex_a::regs::*; +use aarch64::regs::*; use volatile::*; /// The base address for the ARM generic timer, IRQs, mailboxes diff --git a/crate/bcm2837/src/timer/system_timer.rs b/crate/bcm2837/src/timer/system_timer.rs index cad2af4..4d5dc12 100644 --- a/crate/bcm2837/src/timer/system_timer.rs +++ b/crate/bcm2837/src/timer/system_timer.rs @@ -1,6 +1,6 @@ -use ::IO_BASE; +use crate::IO_BASE; +use crate::interrupt::{Controller, Interrupt}; use volatile::{ReadOnly, Volatile}; -use interrupt::{Controller, Interrupt}; /// The base address for the ARM system timer registers. const TIMER_REG_BASE: usize = IO_BASE + 0x3000; diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index f760ced..064af4a 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -48,7 +48,7 @@ version = "0.1.0" name = "bcm2837" version = "0.1.0" dependencies = [ - "cortex-a 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "aarch64 2.2.2 (git+https://github.com/equation314/aarch64)", "volatile 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -96,14 +96,6 @@ name = "cfg-if" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "cortex-a" -version = "2.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "register 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "fixedvec" version = "0.2.3" @@ -453,7 +445,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bootloader 0.3.4 (git+https://github.com/wangrunji0408/bootloader)" = "" "checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" -"checksum cortex-a 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2b187d0d728b4a99ba1d79f9671b976bcdd71a8a2c719585218fd2dc14a4d08c" "checksum fixedvec 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7c6c16d316ccdac21a4dd648e314e76facbbaf316e83ca137d0857a9c07419d0" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index aa429ce..6718500 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -12,7 +12,8 @@ no_mmu = [] # Kernel in M-mode (for riscv32) m_mode = ["no_mmu"] # (for aarch64 RaspberryPi3) -board_raspi3 = [] +board_raspi3 = ["bcm2837"] +raspi3_use_generic_timer = ["bcm2837/use_generic_timer"] [profile.dev] # MUST >= 1 : Enable RVO to avoid stack overflow @@ -53,7 +54,7 @@ bbl = { path = "../crate/bbl" } [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64 = { git = "https://github.com/equation314/aarch64" } atags = { path = "../crate/atags" } -bcm2837 = { path = "../crate/bcm2837", features = ["use_generic_timer"] } +bcm2837 = { path = "../crate/bcm2837", optional = true } [package.metadata.bootimage] default-target = "x86_64-blog_os.json" diff --git a/kernel/Makefile b/kernel/Makefile index 87668a4..7173184 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -78,6 +78,15 @@ features += no_bbl endif endif +ifeq ($(board), raspi3) +# qemu only has generic timer +# TODO: configure system/generic timer automatically +raspi3_timer ?= generic +ifeq ($(raspi3_timer), generic) +features += raspi3_use_generic_timer +endif +endif + ifdef m_mode features += no_mmu m_mode bbl_m_mode := --enable-boot-machine diff --git a/kernel/src/arch/aarch64/board/raspi3/irq.rs b/kernel/src/arch/aarch64/board/raspi3/irq.rs index a982947..d8730dc 100644 --- a/kernel/src/arch/aarch64/board/raspi3/irq.rs +++ b/kernel/src/arch/aarch64/board/raspi3/irq.rs @@ -6,7 +6,7 @@ pub use bcm2837::interrupt::Interrupt; static IRQ_HANDLERS: &'static [Option; 64] = &[None; 64]; -pub fn handle_irq(tf: &mut TrapFrame) { +pub fn handle_irq(_tf: &mut TrapFrame) { let controller = bcm2837::timer::Timer::new(); if controller.is_pending() { super::timer::set_next(); @@ -16,9 +16,6 @@ pub fn handle_irq(tf: &mut TrapFrame) { for int in Controller::new().pending_interrupts() { if let Some(handler) = IRQ_HANDLERS[int] { handler(); - } else { - error!("Unregistered IRQ {}", int); - crate::trap::error(tf); } } } diff --git a/kernel/src/arch/aarch64/interrupt/context.rs b/kernel/src/arch/aarch64/interrupt/context.rs index 8b231e7..0d6502c 100644 --- a/kernel/src/arch/aarch64/interrupt/context.rs +++ b/kernel/src/arch/aarch64/interrupt/context.rs @@ -99,7 +99,7 @@ impl Context { /// Pop all callee-saved registers, then return to the target. #[naked] #[inline(never)] - unsafe extern fn __switch(self_stack: &mut usize, target_stack: &mut usize) { + unsafe extern fn __switch(_self_stack: &mut usize, _target_stack: &mut usize) { asm!( " mov x10, #-(12 * 8) @@ -149,7 +149,7 @@ impl Context { tf: TrapFrame::new_kernel_thread(entry, arg, kstack_top), }.push_at(kstack_top, ttbr) } - pub unsafe fn new_user_thread(entry_addr: usize, ustack_top: usize, kstack_top: usize, is32: bool, ttbr: usize) -> Self { + pub unsafe fn new_user_thread(entry_addr: usize, ustack_top: usize, kstack_top: usize, _is32: bool, ttbr: usize) -> Self { InitStack { context: ContextData::new(), tf: TrapFrame::new_user_thread(entry_addr, ustack_top), diff --git a/kernel/src/arch/aarch64/memory.rs b/kernel/src/arch/aarch64/memory.rs index cf86c76..6a5996f 100644 --- a/kernel/src/arch/aarch64/memory.rs +++ b/kernel/src/arch/aarch64/memory.rs @@ -99,7 +99,7 @@ fn init_frame_allocator() { /// remap kernel page table after all initialization. fn remap_the_kernel() { - let mut ms = unsafe { MemorySet::new_bare() }; + let mut ms = MemorySet::new_bare(); ms.push(MemoryArea::new_identity(0, bootstacktop as usize, MemoryAttr::default(), "kstack")); 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")); diff --git a/kernel/src/arch/aarch64/paging.rs b/kernel/src/arch/aarch64/paging.rs index 14426d7..fa0e074 100644 --- a/kernel/src/arch/aarch64/paging.rs +++ b/kernel/src/arch/aarch64/paging.rs @@ -9,7 +9,7 @@ use aarch64::paging::{FrameAllocator, FrameDeallocator, Page, PhysFrame as Frame use aarch64::paging::memory_attribute::*; use log::*; // Depends on kernel -use crate::consts::{KERNEL_PML4, RECURSIVE_INDEX}; +use crate::consts::RECURSIVE_INDEX; use crate::memory::{active_table, alloc_frame, dealloc_frame}; // need 3 page @@ -60,7 +60,7 @@ impl PageTable for ActivePageTable { } fn unmap(&mut self, addr: usize) { - let (frame, flush) = self.0.unmap(Page::of_addr(addr)).unwrap(); + let (_frame, flush) = self.0.unmap(Page::of_addr(addr)).unwrap(); flush.flush(); } @@ -271,15 +271,6 @@ impl InactivePageTable for InactivePageTable0 { } impl InactivePageTable0 { - fn map_kernel(&mut self) { - let table = unsafe { &mut *ROOT_PAGE_TABLE }; - let e0 = table[KERNEL_PML4].clone(); - assert!(!e0.is_unused()); - - self.edit(|_| { - table[KERNEL_PML4].set_frame(Frame::containing_address(e0.addr()), EF::default(), MairNormal::attr_value()); - }); - } /// Activate as kernel page table (TTBR0). /// Used in `arch::memory::remap_the_kernel()`. pub unsafe fn activate_as_kernel(&self) { diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index 7fdaa13..e985e69 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -1,5 +1,5 @@ pub use crate::arch::paging::*; -use bit_allocator::{BitAlloc, BitAlloc4K, BitAlloc64K, BitAlloc1M}; +use bit_allocator::BitAlloc; use crate::consts::MEMORY_OFFSET; use super::HEAP_ALLOCATOR; use ucore_memory::{*, paging::PageTable}; @@ -21,15 +21,15 @@ pub type MemorySet = ucore_memory::no_mmu::MemorySet; // x86_64 support up to 256M memory #[cfg(target_arch = "x86_64")] -pub type FrameAlloc = BitAlloc64K; +pub type FrameAlloc = bit_allocator::BitAlloc64K; // RISCV only have 8M memory #[cfg(target_arch = "riscv32")] -pub type FrameAlloc = BitAlloc4K; +pub type FrameAlloc = bit_allocator::BitAlloc4K; // Raspberry Pi 3 has 1G memory #[cfg(target_arch = "aarch64")] -pub type FrameAlloc = BitAlloc1M; +pub type FrameAlloc = bit_allocator::BitAlloc1M; lazy_static! { pub static ref FRAME_ALLOCATOR: SpinNoIrqLock = SpinNoIrqLock::new(FrameAlloc::default());