add CI autotest, update README
This commit is contained in:
parent
d7815c6297
commit
31cbc6d290
10 changed files with 267 additions and 52 deletions
|
@ -2,7 +2,7 @@
|
|||
name = "os"
|
||||
version = "0.1.0"
|
||||
authors = ["Yifan Wu <shinbokuow@163.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
|
|
|
@ -1 +1,20 @@
|
|||
pub const CLOCK_FREQ: usize = 403000000 / 62;
|
||||
|
||||
pub const MMIO: &[(usize, usize)] = &[
|
||||
// we don't need clint in S priv when running
|
||||
// we only need claim/complete for target0 after initializing
|
||||
(0x0C00_0000, 0x3000), /* PLIC */
|
||||
(0x0C20_0000, 0x1000), /* PLIC */
|
||||
(0x3800_0000, 0x1000), /* UARTHS */
|
||||
(0x3800_1000, 0x1000), /* GPIOHS */
|
||||
(0x5020_0000, 0x1000), /* GPIO */
|
||||
(0x5024_0000, 0x1000), /* SPI_SLAVE */
|
||||
(0x502B_0000, 0x1000), /* FPIOA */
|
||||
(0x502D_0000, 0x1000), /* TIMER0 */
|
||||
(0x502E_0000, 0x1000), /* TIMER1 */
|
||||
(0x502F_0000, 0x1000), /* TIMER2 */
|
||||
(0x5044_0000, 0x1000), /* SYSCTL */
|
||||
(0x5200_0000, 0x1000), /* SPI0 */
|
||||
(0x5300_0000, 0x1000), /* SPI1 */
|
||||
(0x5400_0000, 0x1000), /* SPI2 */
|
||||
];
|
|
@ -1 +1,87 @@
|
|||
//! Constants used in rCore for qemu
|
||||
|
||||
pub const CLOCK_FREQ: usize = 12500000;
|
||||
|
||||
pub const MMIO: &[(usize, usize)] = &[
|
||||
(0x0010_0000, 0x00_2000), // VIRT_TEST/RTC in virt machine
|
||||
];
|
||||
|
||||
//ref:: https://github.com/andre-richter/qemu-exit
|
||||
use core::arch::asm;
|
||||
|
||||
const EXIT_SUCCESS: u32 = 0x5555; // Equals `exit(0)`. qemu successful exit
|
||||
|
||||
const EXIT_FAILURE_FLAG: u32 = 0x3333;
|
||||
const EXIT_FAILURE: u32 = exit_code_encode(1); // Equals `exit(1)`. qemu failed exit
|
||||
const EXIT_RESET: u32 = 0x7777; // qemu reset
|
||||
|
||||
pub trait QEMUExit {
|
||||
/// Exit with specified return code.
|
||||
///
|
||||
/// Note: For `X86`, code is binary-OR'ed with `0x1` inside QEMU.
|
||||
fn exit(&self, code: u32) -> !;
|
||||
|
||||
/// Exit QEMU using `EXIT_SUCCESS`, aka `0`, if possible.
|
||||
///
|
||||
/// Note: Not possible for `X86`.
|
||||
fn exit_success(&self) -> !;
|
||||
|
||||
/// Exit QEMU using `EXIT_FAILURE`, aka `1`.
|
||||
fn exit_failure(&self) -> !;
|
||||
}
|
||||
|
||||
/// RISCV64 configuration
|
||||
pub struct RISCV64 {
|
||||
/// Address of the sifive_test mapped device.
|
||||
addr: u64,
|
||||
}
|
||||
|
||||
/// Encode the exit code using EXIT_FAILURE_FLAG.
|
||||
const fn exit_code_encode(code: u32) -> u32 {
|
||||
(code << 16) | EXIT_FAILURE_FLAG
|
||||
}
|
||||
|
||||
impl RISCV64 {
|
||||
/// Create an instance.
|
||||
pub const fn new(addr: u64) -> Self {
|
||||
RISCV64 { addr }
|
||||
}
|
||||
}
|
||||
|
||||
impl QEMUExit for RISCV64 {
|
||||
/// Exit qemu with specified exit code.
|
||||
fn exit(&self, code: u32) -> ! {
|
||||
// If code is not a special value, we need to encode it with EXIT_FAILURE_FLAG.
|
||||
let code_new = match code {
|
||||
EXIT_SUCCESS | EXIT_FAILURE | EXIT_RESET => code,
|
||||
_ => exit_code_encode(code),
|
||||
};
|
||||
|
||||
unsafe {
|
||||
asm!(
|
||||
"sw {0}, 0({1})",
|
||||
in(reg)code_new, in(reg)self.addr
|
||||
);
|
||||
|
||||
// For the case that the QEMU exit attempt did not work, transition into an infinite
|
||||
// loop. Calling `panic!()` here is unfeasible, since there is a good chance
|
||||
// this function here is the last expression in the `panic!()` handler
|
||||
// itself. This prevents a possible infinite loop.
|
||||
loop {
|
||||
asm!("wfi", options(nomem, nostack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn exit_success(&self) -> ! {
|
||||
self.exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
fn exit_failure(&self) -> ! {
|
||||
self.exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
const VIRT_TEST: u64 = 0x100000;
|
||||
|
||||
pub const QEMU_EXIT_HANDLE: RISCV64 = RISCV64::new(VIRT_TEST);
|
||||
|
|
|
@ -16,4 +16,4 @@ pub fn kernel_stack_position(app_id: usize) -> (usize, usize) {
|
|||
(bottom, top)
|
||||
}
|
||||
|
||||
pub use crate::board::CLOCK_FREQ;
|
||||
pub use crate::board::{CLOCK_FREQ, MMIO};
|
||||
|
|
|
@ -4,7 +4,7 @@ use super::{frame_alloc, FrameTracker};
|
|||
use super::{PTEFlags, PageTable, PageTableEntry};
|
||||
use super::{PhysAddr, PhysPageNum, VirtAddr, VirtPageNum};
|
||||
use super::{StepByOne, VPNRange};
|
||||
use crate::config::{MEMORY_END, PAGE_SIZE, TRAMPOLINE, TRAP_CONTEXT, USER_STACK_SIZE};
|
||||
use crate::config::{MEMORY_END, MMIO, PAGE_SIZE, TRAMPOLINE, TRAP_CONTEXT, USER_STACK_SIZE};
|
||||
use crate::sync::UPSafeCell;
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::sync::Arc;
|
||||
|
@ -138,6 +138,18 @@ impl MemorySet {
|
|||
),
|
||||
None,
|
||||
);
|
||||
println!("mapping memory-mapped registers");
|
||||
for pair in MMIO {
|
||||
memory_set.push(
|
||||
MapArea::new(
|
||||
(*pair).0.into(),
|
||||
((*pair).0 + (*pair).1).into(),
|
||||
MapType::Identical,
|
||||
MapPermission::R | MapPermission::W,
|
||||
),
|
||||
None,
|
||||
);
|
||||
}
|
||||
memory_set
|
||||
}
|
||||
/// Include sections in elf and trampoline and TrapContext and user stack,
|
||||
|
|
|
@ -4,13 +4,15 @@ use core::arch::asm;
|
|||
|
||||
const SBI_SET_TIMER: usize = 0;
|
||||
const SBI_CONSOLE_PUTCHAR: usize = 1;
|
||||
|
||||
#[cfg(feature = "board_k210")]
|
||||
const SBI_SHUTDOWN: usize = 8;
|
||||
// const SBI_CONSOLE_GETCHAR: usize = 2;
|
||||
// const SBI_CLEAR_IPI: usize = 3;
|
||||
// const SBI_SEND_IPI: usize = 4;
|
||||
// const SBI_REMOTE_FENCE_I: usize = 5;
|
||||
// const SBI_REMOTE_SFENCE_VMA: usize = 6;
|
||||
// const SBI_REMOTE_SFENCE_VMA_ASID: usize = 7;
|
||||
const SBI_SHUTDOWN: usize = 8;
|
||||
|
||||
#[inline(always)]
|
||||
/// general sbi call
|
||||
|
@ -44,8 +46,16 @@ pub fn console_putchar(c: usize) {
|
|||
// sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
|
||||
// }
|
||||
|
||||
#[cfg(feature = "board_qemu")]
|
||||
use crate::board::QEMUExit;
|
||||
/// use sbi call to shutdown the kernel
|
||||
pub fn shutdown() -> ! {
|
||||
#[cfg(feature = "board_k210")]
|
||||
sbi_call(SBI_SHUTDOWN, 0, 0, 0);
|
||||
|
||||
#[cfg(feature = "board_qemu")]
|
||||
crate::board::QEMU_EXIT_HANDLE.exit_failure();
|
||||
|
||||
#[cfg(feature = "board_k210")]
|
||||
panic!("It should shutdown!");
|
||||
}
|
||||
|
|
|
@ -143,6 +143,14 @@ impl TaskManager {
|
|||
}
|
||||
// go back to user mode
|
||||
} else {
|
||||
println!("All applications completed!");
|
||||
|
||||
#[cfg(feature = "board_qemu")]
|
||||
use crate::board::QEMUExit;
|
||||
#[cfg(feature = "board_qemu")]
|
||||
crate::board::QEMU_EXIT_HANDLE.exit_success();
|
||||
|
||||
#[cfg(feature = "board_k210")]
|
||||
panic!("All applications completed!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue