From 146e7f65ca5e0076fac2560c02062bfb805a3144 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 11 Jan 2025 14:50:17 +0100 Subject: [PATCH] Halt syscall and userspace util. Mapped qemu power. --- kernel/memlayout.h | 2 ++ kernel/sysproc.c | 3 ++- kernel/vm.c | 3 +++ user/halt.c | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/memlayout.h b/kernel/memlayout.h index 57c3839..ff6d045 100644 --- a/kernel/memlayout.h +++ b/kernel/memlayout.h @@ -23,6 +23,8 @@ #define UART0 0x10000000L #define UART0_IRQ 10 +#define QEMU_POWER 0x100000 + // virtio mmio interface #define VIRTIO0 0x10001000 #define VIRTIO0_IRQ 1 diff --git a/kernel/sysproc.c b/kernel/sysproc.c index ba0aeb9..8c1f1d5 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -100,5 +100,6 @@ sys_trace(void) void sys_halt(void) { - /* TODO: Implement sys_halt */ + (*(volatile u32 *)QEMU_POWER) = 0x5555; + panic("sys_poweroff"); } diff --git a/kernel/vm.c b/kernel/vm.c index c4541bd..af3ff45 100644 --- a/kernel/vm.c +++ b/kernel/vm.c @@ -21,6 +21,9 @@ kvmmake(void) kpgtbl = (pagetable_t)kalloc(); memset(kpgtbl, 0, PGSIZE); + // Map qemu + kvmmap(kpgtbl, QEMU_POWER, QEMU_POWER, PGSIZE, PTE_R | PTE_W); + // uart registers kvmmap(kpgtbl, UART0, UART0, PGSIZE, PTE_R | PTE_W); diff --git a/user/halt.c b/user/halt.c index ab73dd3..9f26b81 100644 --- a/user/halt.c +++ b/user/halt.c @@ -4,6 +4,7 @@ int main(int argc, char *argv[]) { + printf("System powering down...\n"); halt(); return 0; }