Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
NPUcore-重生之我是菜狗
OSKernel2024-NPUcore-重生之我是菜狗
Commits
f5a74cbd
Commit
f5a74cbd
authored
1 year ago
by
gh
Browse files
Options
Download
Patches
Plain Diff
feat[gh]: 尝试实现shutdown
parent
418446bf
testLA
gh-qemu2k1000-init
gh-sdcard
hyt-pre-test
lwy-test
main
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
os/src/arch/la64/sbi.rs
+20
-1
os/src/arch/la64/sbi.rs
os/src/syscall/mod.rs
+1
-0
os/src/syscall/mod.rs
os/src/syscall/process.rs
+4
-1
os/src/syscall/process.rs
user/src/bin/initproc.rs
+20
-19
user/src/bin/initproc.rs
user/src/syscall.rs
+3
-0
user/src/syscall.rs
user/src/usr_call.rs
+3
-0
user/src/usr_call.rs
with
51 additions
and
21 deletions
+51
-21
os/src/arch/la64/sbi.rs
+
20
−
1
View file @
f5a74cbd
...
...
@@ -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
{}
}
This diff is collapsed.
Click to expand it.
os/src/syscall/mod.rs
+
1
−
0
View file @
f5a74cbd
...
...
@@ -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
),
...
...
This diff is collapsed.
Click to expand it.
os/src/syscall/process.rs
+
4
−
1
View file @
f5a74cbd
...
...
@@ -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
);
}
...
...
This diff is collapsed.
Click to expand it.
user/src/bin/initproc.rs
+
20
−
19
View file @
f5a74cbd
#![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
}
This diff is collapsed.
Click to expand it.
user/src/syscall.rs
+
3
−
0
View file @
f5a74cbd
...
...
@@ -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
This diff is collapsed.
Click to expand it.
user/src/usr_call.rs
+
3
−
0
View file @
f5a74cbd
...
...
@@ -53,3 +53,6 @@ pub fn sleep(period_ms: usize) {
sys_yield
();
}
}
pub
fn
shutdown
()
->
isize
{
sys_shutdown
()
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets