Skip to content

Commit 592197d

Browse files
sys_shutdown: initial implementation
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 830f54f commit 592197d

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

src/aero_kernel/src/drivers/lai.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl lai::Host for LaiHost {
3636
fn sleep(&self, ms: u64) {
3737
scheduler::get_scheduler()
3838
.inner
39-
.sleep(Some(ms as usize * 1_000_000))
39+
.sleep(Some(ms as usize / 1000))
4040
.expect("lai: unexpected signal during sleep")
4141
}
4242

@@ -88,6 +88,14 @@ impl lai::Host for LaiHost {
8888
let header = PciHeader::new(bus, slot, fun);
8989
unsafe { header.read::<u32>(offset as u32) }
9090
}
91+
92+
// Memory functions:
93+
#[inline]
94+
fn map(&self, address: usize, _count: usize) -> *mut u8 {
95+
PhysAddr::new(address as u64)
96+
.as_hhdm_virt()
97+
.as_mut_ptr::<u8>()
98+
}
9199
}
92100

93101
pub fn init_lai() {
@@ -98,7 +106,6 @@ pub fn init_lai() {
98106
lai::create_namespace();
99107

100108
lai::enable_acpi(1);
101-
lai::enter_sleep(5);
102109
}
103110

104111
crate::module_init!(init_lai);

src/aero_kernel/src/syscall/process.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::fs::Path;
2828
use crate::mem::paging::VirtAddr;
2929
use crate::userland::scheduler;
3030
use crate::userland::signals::SignalEntry;
31+
use crate::utils::sync::IrqGuard;
3132

3233
static HOSTNAME: Once<Mutex<String>> = Once::new();
3334

@@ -309,6 +310,8 @@ pub fn shutdown() -> ! {
309310
fs::cache::clear_inode_cache();
310311
fs::cache::clear_dir_cache();
311312

312-
// TODO
313-
loop {}
313+
let _guard = IrqGuard::new();
314+
lai::enter_sleep(5);
315+
316+
unreachable!("aml: failed to shutdown (enter state S5)")
314317
}

src/aero_kernel/src/utils/io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ pub unsafe fn inb(port: u16) -> u8 {
8585
#[inline]
8686
pub unsafe fn outw(port: u16, value: u16) {
8787
asm!(
88-
"out dx, eax",
88+
"out dx, ax",
8989
in("dx") port,
90-
in("eax") value,
90+
in("ax") value,
9191
options(preserves_flags, nomem, nostack)
9292
);
9393
}
@@ -114,7 +114,7 @@ pub unsafe fn inl(port: u16) -> u32 {
114114
"in eax, dx",
115115
in("dx") port,
116116
out("eax") ret,
117-
options(preserves_flags, nomem, nostack)
117+
options(nomem, nostack, preserves_flags)
118118
);
119119

120120
ret
@@ -127,10 +127,10 @@ pub unsafe fn inw(port: u16) -> u16 {
127127
let ret: u16;
128128

129129
asm!(
130-
"in eax, dx",
131-
out("eax") ret,
130+
"in ax, dx",
131+
out("ax") ret,
132132
in("dx") port,
133-
options(preserves_flags, nomem, nostack)
133+
options(nomem, nostack, preserves_flags)
134134
);
135135

136136
ret

userland/apps/aero_shell/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ fn repl(history: &mut Vec<String>) -> Result<(), AeroSyscallError> {
157157
sys_sleep(&timespec)?;
158158
}
159159

160+
"shutdown" => sys_shutdown(),
161+
160162
"doom" => {
161163
let child = sys_fork()?;
162164

0 commit comments

Comments
 (0)