Commit f5a74cbd authored by gh's avatar gh
Browse files

feat[gh]: 尝试实现shutdown

No related merge requests found
Showing with 51 additions and 21 deletions
+51 -21
......@@ -30,7 +30,26 @@ pub fn console_getchar() -> usize {
}
}
// pub const ACPI_BASE: usize = 0x800000001FE27000;
// pub struct ACPI {
// pub base: usize,
// }
// pub static mut ACPI_REG: ACPI = ACPI { base: ACPI_BASE };
// impl ACPI {
// #[allow(unused)]
// pub fn new(base: usize) -> Self {
// // already init in RustSBI
// Self { base }
// }
// }
use core::ptr::write_volatile;
pub fn shutdown() -> ! {
print!("[panic(\"shutdown\")] {:?}", super::register::CrMd::read());
// print!("[panic(\"shutdown\")] {:?}", super::register::CrMd::read());
// loop {}
unsafe{
((0x1FE27000 + 0x14) as *mut u32).write_volatile(0b1111<<10);
}
println!("shutdown failed");
loop {}
}
......@@ -205,6 +205,7 @@ pub fn syscall(syscall_id: usize, args: [usize; 6]) -> isize {
args[2] as *const [TimeSpec; 2],
args[3] as u32,
),
SYSCALL_SHUTDOWN => sys_shutdown(),
SYSCALL_EXIT => sys_exit(args[0] as u32),
SYSCALL_EXIT_GROUP => sys_exit_group(args[0] as u32),
SYSCALL_CLOCK_GETTIME => sys_clock_gettime(args[0], args[1] as *mut TimeSpec),
......
......@@ -23,7 +23,10 @@ use alloc::vec::Vec;
use core::mem::size_of;
use log::{debug, error, info, trace, warn};
use num_enum::FromPrimitive;
use crate::arch::shutdown;
pub fn sys_shutdown() -> isize {
shutdown()
}
pub fn sys_exit(exit_code: u32) -> ! {
exit_current_and_run_next((exit_code & 0xff) << 8);
}
......
#![no_std]
#![no_main]
use user_lib::{exit, exec, fork, wait, yield_};
use user_lib::{exit, exec, fork, wait, yield_, shutdown};
#[no_mangle]
#[link_section = ".text.entry"]
......@@ -28,23 +28,24 @@ fn main() -> i32 {
"LD_LIBRARY_PATH=/\0".as_ptr(),
core::ptr::null(),
];
if fork() == 0 {
exec(path, &[path.as_ptr() as *const u8, core::ptr::null()], &environ);
} else {
loop {
let mut exit_code: i32 = 0;
let pid = wait(&mut exit_code);
// ECHLD is -10
if pid == -10 {
yield_();
continue;
}
user_lib::println!(
"[initproc] Released a zombie process, pid={}, exit_code={}",
pid,
exit_code,
);
}
}
// if fork() == 0 {
// exec(path, &[path.as_ptr() as *const u8, core::ptr::null()], &environ);
// } else {
// loop {
// let mut exit_code: i32 = 0;
// let pid = wait(&mut exit_code);
// // ECHLD is -10
// if pid == -10 {
// yield_();
// continue;
// }
// user_lib::println!(
// "[initproc] Released a zombie process, pid={}, exit_code={}",
// pid,
// exit_code,
// );
// }
// }
shutdown();
0
}
......@@ -168,3 +168,6 @@ pub fn sys_exec(path: &str, args: &[*const u8], envp: &[*const u8]) -> isize {
pub fn sys_waitpid(pid: isize, exit_code: *mut i32) -> isize {
syscall(SYSCALL_WAIT4, [pid as usize, exit_code as usize, 0])
}
pub fn sys_shutdown() -> isize {
syscall(SYSCALL_SHUTDOWN, [0, 0, 0])
}
\ No newline at end of file
......@@ -53,3 +53,6 @@ pub fn sleep(period_ms: usize) {
sys_yield();
}
}
pub fn shutdown() -> isize{
sys_shutdown()
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment