Add test architecture
This commit is contained in:
parent
1c9b6361c9
commit
29b6544d8f
10
Cargo.toml
10
Cargo.toml
|
@ -3,15 +3,19 @@ name = "kernel"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
name = "kernel"
|
||||||
path = "kernel/lib.rs"
|
path = "kernel/lib.rs"
|
||||||
crate-type = ["staticlib"]
|
crate-type = ["staticlib"]
|
||||||
|
|
||||||
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
|
||||||
arch = { path = "arch/x86_64" }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "*"
|
bitflags = "*"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
arch_test = { path = "arch/test" }
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
||||||
|
arch_x86_64 = { path = "arch/x86_64" }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ qemu: build/harddrive.bin
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
||||||
build/libkernel.a: FORCE
|
build/libkernel.a: FORCE
|
||||||
cargo rustc -- -C lto -o $@
|
cargo rustc -- --crate-type staticlib -o $@
|
||||||
#--target $(ARCH)-unknown-none.json
|
#--target $(ARCH)-unknown-none.json
|
||||||
|
|
||||||
build/kernel.bin: build/libkernel.a
|
build/kernel.bin: build/libkernel.a
|
||||||
|
|
3
arch/test/Cargo.toml
Normal file
3
arch/test/Cargo.toml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[package]
|
||||||
|
name = "arch_test"
|
||||||
|
version = "0.1.0"
|
24
arch/test/src/interrupt.rs
Normal file
24
arch/test/src/interrupt.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//! Interrupt instructions
|
||||||
|
|
||||||
|
static mut INTERRUPTS_ENABLED: bool = false;
|
||||||
|
|
||||||
|
/// Clear interrupts
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn clear_interrupts() {
|
||||||
|
println!("CLEAR INTERRUPTS");
|
||||||
|
INTERRUPTS_ENABLED = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set interrupts
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn set_interrupts() {
|
||||||
|
println!("SET INTERRUPTS");
|
||||||
|
INTERRUPTS_ENABLED = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Halt instruction
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn halt() {
|
||||||
|
assert!(INTERRUPTS_ENABLED);
|
||||||
|
::std::thread::yield_now();
|
||||||
|
}
|
40
arch/test/src/lib.rs
Normal file
40
arch/test/src/lib.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//! Architecture support for testing
|
||||||
|
|
||||||
|
pub use std::io;
|
||||||
|
|
||||||
|
/// Print to console
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! print {
|
||||||
|
($($arg:tt)*) => ({
|
||||||
|
use $crate::io::Write;
|
||||||
|
let _ = write!($crate::io::stdout(), $($arg)*);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Print with new line to console
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! println {
|
||||||
|
($fmt:expr) => (print!(concat!($fmt, "\n")));
|
||||||
|
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create an interrupt function that can safely run rust code
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! interrupt {
|
||||||
|
($name:ident, $func:block) => {
|
||||||
|
pub unsafe extern fn $name () {
|
||||||
|
unsafe fn inner() {
|
||||||
|
$func
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call inner rust function
|
||||||
|
inner();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Interrupt instructions
|
||||||
|
pub mod interrupt;
|
||||||
|
|
||||||
|
/// Initialization and main function
|
||||||
|
pub mod main;
|
11
arch/test/src/main.rs
Normal file
11
arch/test/src/main.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/// This function is where the kernel sets up IRQ handlers
|
||||||
|
/// It is increcibly unsafe, and should be minimal in nature
|
||||||
|
|
||||||
|
extern {
|
||||||
|
fn kmain() -> !;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern fn kstart() -> ! {
|
||||||
|
kmain();
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "arch"
|
name = "arch_x86_64"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -72,13 +72,23 @@ extern crate bitflags;
|
||||||
|
|
||||||
use arch::interrupt::{set_interrupts, halt};
|
use arch::interrupt::{set_interrupts, halt};
|
||||||
|
|
||||||
/// Architecture specific items
|
/// Architecture specific items (test)
|
||||||
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate arch;
|
extern crate arch_test as arch;
|
||||||
|
|
||||||
|
/// Architecture specific items (x86_64)
|
||||||
|
#[cfg(all(not(test), target_arch = "x86_64"))]
|
||||||
|
#[macro_use]
|
||||||
|
extern crate arch_x86_64 as arch;
|
||||||
|
|
||||||
/// Intrinsics for panic handling
|
/// Intrinsics for panic handling
|
||||||
pub mod panic;
|
pub mod panic;
|
||||||
|
|
||||||
|
/// Tests
|
||||||
|
#[cfg(test)]
|
||||||
|
pub mod tests;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn kmain() {
|
pub extern fn kmain() {
|
||||||
println!("TEST");
|
println!("TEST");
|
||||||
|
|
9
kernel/tests/mod.rs
Normal file
9
kernel/tests/mod.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
use arch::interrupt::{set_interrupts, halt};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn halt_with_interrupts() {
|
||||||
|
unsafe {
|
||||||
|
set_interrupts();
|
||||||
|
halt();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue