-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
120 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"kernel", | ||
"userlib", | ||
"boot", | ||
"dep/gmanager", | ||
"dep/basemachine", | ||
"apps/slint-helper", | ||
"apps/cat", | ||
"apps/sleep", | ||
"apps/todo", | ||
"apps/printdemo", | ||
"apps/egui", | ||
"apps/sysinfo", | ||
"apps/init", | ||
"apps/ls", | ||
"apps/mkdir", | ||
"apps/pwd", | ||
"apps/shell", | ||
"apps/touch", | ||
"apps/run_test", | ||
"apps/slint", | ||
"apps/socket_test", | ||
"apps/tests", | ||
"apps/memory-game", | ||
"apps/print", | ||
"apps/final_test", | ||
] | ||
|
||
|
||
[profile.release] | ||
#lto = true | ||
#codegen-units = 1 | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"kernel", | ||
"userlib", | ||
"boot", | ||
"dep/gmanager", | ||
"dep/basemachine", | ||
"apps/slint-helper", | ||
"apps/cat", | ||
"apps/sleep", | ||
"apps/todo", | ||
"apps/printdemo", | ||
"apps/egui", | ||
"apps/sysinfo", | ||
"apps/init", | ||
"apps/ls", | ||
"apps/mkdir", | ||
"apps/pwd", | ||
"apps/shell", | ||
"apps/touch", | ||
"apps/run_test", | ||
"apps/slint", | ||
"apps/socket_test", | ||
"apps/tests", | ||
"apps/memory-game", | ||
"apps/print", | ||
"apps/final_test", | ||
] | ||
|
||
|
||
[profile.release] | ||
#lto = true | ||
#codegen-units = 1 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 编译 riscv64gc-unknown-linux-musl rust程序 | ||
|
||
## 提示找不到运行时库的问题 | ||
https://stackoverflow.com/questions/74424444/how-to-build-a-rust-program-for-riscv64gc-unknown-linux-musl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
use kernel_sync::TicketMutexGuard; | ||
use kernel_sync::{LockAction, ticket::TicketMutexGuard}; | ||
use core::cell::{RefCell, RefMut}; | ||
use crate::arch::{hart_id, interrupt_disable, interrupt_enable, is_interrupt_enable}; | ||
use crate::config::CPU_NUM; | ||
|
||
pub type SpinMutex<T> = kernel_sync::SpinMutex<T>; | ||
pub type TicketMutex<T> = kernel_sync::TicketMutex<T>; | ||
|
||
pub type SpinMutex<T> = kernel_sync::spin::SpinMutex<T,KernelLockAction>; | ||
pub type TicketMutex<T> = kernel_sync::ticket::TicketMutex<T,KernelLockAction>; | ||
pub type RwLock<T> = kernel_sync::RwLock<T>; | ||
pub type Mutex<T> = TicketMutex<T>; | ||
pub type MutexGuard<'a, T> = TicketMutexGuard<'a, T>; | ||
pub type MutexGuard<'a, T> = TicketMutexGuard<'a, T, KernelLockAction>; | ||
|
||
#[derive(Debug, Default, Clone, Copy)] | ||
#[repr(align(64))] | ||
pub struct Cpu { | ||
pub noff: i32, // Depth of push_off() nesting. | ||
pub interrupt_enable: bool, // Were interrupts enabled before push_off()? | ||
} | ||
|
||
impl Cpu { | ||
const fn new() -> Self { | ||
Self { | ||
noff: 0, | ||
interrupt_enable: false, | ||
} | ||
} | ||
} | ||
|
||
pub struct SafeRefCell<T>(RefCell<T>); | ||
|
||
/// # Safety: Only the corresponding cpu will access it. | ||
unsafe impl<Cpu> Sync for SafeRefCell<Cpu> {} | ||
|
||
impl<T> SafeRefCell<T> { | ||
const fn new(t: T) -> Self { | ||
Self(RefCell::new(t)) | ||
} | ||
} | ||
|
||
#[allow(clippy::declare_interior_mutable_const)] | ||
const DEFAULT_CPU: SafeRefCell<Cpu> = SafeRefCell::new(Cpu::new()); | ||
|
||
static CPUS: [SafeRefCell<Cpu>; CPU_NUM] = [DEFAULT_CPU; CPU_NUM]; | ||
|
||
pub fn mycpu() -> RefMut<'static, Cpu> { | ||
CPUS[hart_id()].0.borrow_mut() | ||
} | ||
|
||
// push_off/pop_off are like intr_off()/intr_on() except that they are matched: | ||
// it takes two pop_off()s to undo two push_off()s. Also, if interrupts | ||
// are initially off, then push_off, pop_off leaves them off. | ||
pub(crate) fn push_off() { | ||
let old = is_interrupt_enable(); | ||
interrupt_disable(); | ||
let mut cpu = mycpu(); | ||
if cpu.noff == 0 { | ||
cpu.interrupt_enable = old; | ||
} | ||
cpu.noff += 1; | ||
} | ||
|
||
pub(crate) fn pop_off() { | ||
let mut cpu = mycpu(); | ||
if is_interrupt_enable() || cpu.noff < 1 { | ||
panic!("pop_off"); | ||
} | ||
cpu.noff -= 1; | ||
let should_enable = cpu.noff == 0 && cpu.interrupt_enable; | ||
drop(cpu); | ||
// NOTICE: intr_on() may lead to an immediate inerrupt, so we *MUST* drop(cpu) in advance. | ||
if should_enable { | ||
interrupt_enable(); | ||
} | ||
} | ||
|
||
pub struct KernelLockAction; | ||
impl LockAction for KernelLockAction { | ||
fn before_lock() { | ||
push_off(); | ||
} | ||
fn after_lock() { | ||
pop_off(); | ||
} | ||
} |