login 61de2cdc3f
新增rust版本的lockref (#135)
* new:Rust封装cpu_relax(),通过pause指令,让cpu休息一会儿。降低空转功耗

* new: Rust版本的lockref

* Rust的RawSpinlock新增is_locked()和set_value()方法。

* lockref文档
2023-01-03 23:09:25 +08:00

90 lines
1.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#![no_std] // <1>
#![no_main] // <1>
#![feature(core_intrinsics)] // <2>
#![feature(alloc_error_handler)]
#![feature(panic_info_message)]
#![feature(drain_filter)] // 允许Vec的drain_filter特性
#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
use core::panic::PanicInfo;
/// 导出x86_64架构相关的代码命名为arch模块
#[cfg(target_arch = "x86_64")]
#[path = "arch/x86_64/mod.rs"]
#[macro_use]
mod arch;
mod driver;
mod filesystem;
#[macro_use]
mod include;
mod ipc;
#[macro_use]
mod libs;
mod mm;
mod process;
mod sched;
mod smp;
mod time;
extern crate alloc;
use mm::allocator::KernelAllocator;
// <3>
use crate::{
arch::asm::current::current_pcb,
include::bindings::bindings::{process_do_exit, BLACK, GREEN},
libs::lockref::LockRef,
};
// 声明全局的slab分配器
#[cfg_attr(not(test), global_allocator)]
pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator {};
/// 全局的panic处理函数
#[panic_handler]
#[no_mangle]
pub fn panic(info: &PanicInfo) -> ! {
kerror!("Kernel Panic Occurred.");
match info.location() {
Some(loc) => {
println!(
"Location:\n\tFile: {}\n\tLine: {}, Column: {}",
loc.file(),
loc.line(),
loc.column()
);
}
None => {
println!("No location info");
}
}
match info.message() {
Some(msg) => {
println!("Message:\n\t{}", msg);
}
None => {
println!("No panic message.");
}
}
println!("Current PCB:\n\t{:?}", current_pcb());
unsafe {
process_do_exit(u64::MAX);
};
loop {}
}
/// 该函数用作测试在process.c的initial_kernel_thread()中调用了此函数
#[no_mangle]
pub extern "C" fn __rust_demo_func() -> i32 {
printk_color!(GREEN, BLACK, "__rust_demo_func()\n");
return 0;
}