mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-22 08:06:17 +04:00
Cleanup code
This commit is contained in:
parent
0290937833
commit
7479293a11
@ -12,7 +12,7 @@
|
||||
|
||||
路径:`src/arch/ISA`。其余的代码尽量不要出现平台相关的代码。
|
||||
|
||||
### consts.rs
|
||||
### consts
|
||||
|
||||
- KERNEL_OFFSET: 线性映射的偏移
|
||||
- ARCH:ISA 的名称
|
||||
@ -38,6 +38,10 @@
|
||||
- Syscall:系统调用的 trap
|
||||
- Timer:时钟中断的 trap
|
||||
|
||||
### interrupt/handler
|
||||
|
||||
- fn trap_handler(tf: &mut TrapFrame):处理来自内核的异常
|
||||
|
||||
### syscall
|
||||
|
||||
含有所有 syscall 的编号的定义
|
||||
|
@ -6,6 +6,8 @@ pub fn is_page_fault(trap: usize) -> bool {
|
||||
if trap != 0x2 {
|
||||
return false;
|
||||
}
|
||||
|
||||
// determine by esr
|
||||
let esr = ESR_EL1.get() as u32;
|
||||
let syndrome = Syndrome::from(esr);
|
||||
match syndrome {
|
||||
|
@ -77,21 +77,23 @@ pub extern "C" fn trap_handler(tf: &mut TrapFrame) {
|
||||
trace!("ESR: {:#x?}, Syndrome: {:?}", esr, syndrome);
|
||||
// syndrome is only valid with sync
|
||||
match syndrome {
|
||||
Syndrome::Brk(brk) => handle_break(brk, tf),
|
||||
Syndrome::Svc(svc) => handle_syscall(svc, tf),
|
||||
Syndrome::DataAbort { kind, level: _ }
|
||||
| Syndrome::InstructionAbort { kind, level: _ } => match kind {
|
||||
Fault::Translation | Fault::AccessFlag | Fault::Permission => {
|
||||
handle_page_fault(tf)
|
||||
let addr = FAR_EL1.get() as usize;
|
||||
if !crate::memory::handle_page_fault(addr) {
|
||||
panic!("\nEXCEPTION: Page Fault @ {:#x}", addr);
|
||||
}
|
||||
}
|
||||
_ => panic!(), // crate::trap::error(tf),
|
||||
_ => panic!(),
|
||||
},
|
||||
_ => panic!(), //crate::trap::error(tf),
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
Kind::Irq => {
|
||||
if timer::is_pending() {
|
||||
handle_timer()
|
||||
crate::arch::board::timer::set_next();
|
||||
crate::trap::timer();
|
||||
} else {
|
||||
IRQ_MANAGER.read().try_handle_interrupt(Some(tf.trap_num));
|
||||
}
|
||||
@ -100,48 +102,3 @@ pub extern "C" fn trap_handler(tf: &mut TrapFrame) {
|
||||
}
|
||||
trace!("Exception end");
|
||||
}
|
||||
|
||||
fn handle_break(_num: u16, tf: &mut TrapFrame) {
|
||||
// Skip the current brk instruction (ref: J1.1.2, page 6147)
|
||||
tf.elr += 4;
|
||||
}
|
||||
|
||||
fn handle_syscall(num: u16, tf: &mut TrapFrame) {
|
||||
if num != 0 {
|
||||
panic!()
|
||||
//crate::trap::error(tf);
|
||||
}
|
||||
|
||||
syscall(tf)
|
||||
}
|
||||
|
||||
pub fn syscall(tf: &mut TrapFrame) {
|
||||
// svc instruction has been skipped in syscall (ref: J1.1.2, page 6152)
|
||||
/*
|
||||
let ret = crate::syscall::syscall(
|
||||
tf.x1to29[7] as usize,
|
||||
[
|
||||
tf.x0,
|
||||
tf.x1to29[0],
|
||||
tf.x1to29[1],
|
||||
tf.x1to29[2],
|
||||
tf.x1to29[3],
|
||||
tf.x1to29[4],
|
||||
],
|
||||
tf,
|
||||
);
|
||||
tf.x0 = ret as usize;
|
||||
*/
|
||||
}
|
||||
|
||||
fn handle_timer() {
|
||||
crate::arch::board::timer::set_next();
|
||||
crate::trap::timer();
|
||||
}
|
||||
|
||||
fn handle_page_fault(tf: &mut TrapFrame) {
|
||||
let addr = FAR_EL1.get() as usize;
|
||||
if !crate::memory::handle_page_fault(addr) {
|
||||
panic!("\nEXCEPTION: Page Fault @ {:#x}", addr);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::drivers::*;
|
||||
use crate::memory::phys_to_virt;
|
||||
use riscv::register::sie;
|
||||
|
||||
@ -5,3 +6,10 @@ use riscv::register::sie;
|
||||
pub unsafe fn init_external_interrupt() {
|
||||
sie::set_sext();
|
||||
}
|
||||
|
||||
pub fn init(dtb: usize) {
|
||||
serial::uart16550::driver_init();
|
||||
bus::virtio_mmio::driver_init();
|
||||
irq::plic::driver_init();
|
||||
device_tree::init(dtb);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! {
|
||||
timer::init();
|
||||
// FIXME: init driver on u540
|
||||
#[cfg(not(any(feature = "board_u540")))]
|
||||
crate::drivers::init(device_tree_vaddr);
|
||||
board::init(device_tree_vaddr);
|
||||
unsafe {
|
||||
board::init_external_interrupt();
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
use crate::drivers::gpu::fb::{self, ColorDepth, ColorFormat, FramebufferInfo};
|
||||
use crate::drivers::*;
|
||||
use crate::memory::phys_to_virt;
|
||||
use rboot::BootInfo;
|
||||
|
||||
pub fn init_driver(boot_info: &BootInfo) {
|
||||
pub fn early_init() {
|
||||
serial::com::init();
|
||||
}
|
||||
|
||||
pub fn init(boot_info: &BootInfo) {
|
||||
let info = &boot_info.graphic_info;
|
||||
let width = info.mode.resolution().0 as u32;
|
||||
let height = info.mode.resolution().1 as u32;
|
||||
@ -21,4 +26,9 @@ pub fn init_driver(boot_info: &BootInfo) {
|
||||
screen_size: info.fb_size as usize,
|
||||
};
|
||||
fb::init(fb_info);
|
||||
|
||||
bus::pci::init();
|
||||
rtc::rtc_cmos::init();
|
||||
serial::keyboard::init();
|
||||
console::init();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
|
||||
crate::memory::init_heap();
|
||||
|
||||
// serial
|
||||
crate::drivers::early_init();
|
||||
board::early_init();
|
||||
|
||||
println!("Hello world! from CPU {}!", cpu_id);
|
||||
|
||||
@ -62,9 +62,7 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
|
||||
// now we can start LKM.
|
||||
crate::lkm::manager::ModuleManager::init();
|
||||
// init board
|
||||
board::init_driver(boot_info);
|
||||
// init pci/bus-based devices ,e.g. Intel 10Gb NIC, ...
|
||||
crate::drivers::init();
|
||||
board::init(boot_info);
|
||||
// init cpu scheduler and process manager, and add user shell app in process manager
|
||||
crate::process::init();
|
||||
// load acpi
|
||||
|
@ -113,27 +113,6 @@ lazy_static! {
|
||||
pub static ref SOCKET_ACTIVITY: Condvar = Condvar::new();
|
||||
}
|
||||
|
||||
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64", target_arch = "mips"))]
|
||||
pub fn init(dtb: usize) {
|
||||
serial::uart16550::driver_init();
|
||||
bus::virtio_mmio::driver_init();
|
||||
irq::plic::driver_init();
|
||||
device_tree::init(dtb);
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn init() {
|
||||
bus::pci::init();
|
||||
rtc::rtc_cmos::init();
|
||||
serial::keyboard::init();
|
||||
console::init();
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn early_init() {
|
||||
serial::com::init();
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
// Write only once at boot
|
||||
pub static ref CMDLINE: RwLock<String> = RwLock::new(String::new());
|
||||
|
Loading…
Reference in New Issue
Block a user