diff options
-rw-r--r-- | .github/workflows/build.yml | 2 | ||||
-rw-r--r-- | apps/test.c | 6 | ||||
-rw-r--r-- | kernel/features/syscall.c | 25 | ||||
-rw-r--r-- | libc/crt/crt0.asm | 2 | ||||
-rw-r--r-- | libc/inc/sys.h | 10 |
5 files changed, 35 insertions, 10 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d909e45..9e9c29f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: - name: Checkout uses: actions/checkout@v2 - name: Install - run: sudo apt-get update && sudo apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo libcloog-isl-dev libisl-0.18-dev ccache curl nasm grub-common qemu qemu-kvm mtools ctags + run: sudo apt-get update && sudo apt-get install -y build-essential bison flex libgmp3-dev libmpc-dev libmpfr-dev texinfo ccache curl nasm grub-common qemu qemu-kvm mtools ctags - name: Get cross compiler id: cache-cross uses: actions/cache@v1 diff --git a/apps/test.c b/apps/test.c index 80f24ad..d64e224 100644 --- a/apps/test.c +++ b/apps/test.c @@ -82,11 +82,7 @@ int main(void) else log("All tests passed\n"); - // Try emulator shutdown - outw(0xB004, 0x2000); - outw(0x604, 0x2000); - outw(0x4004, 0x3400); + boot(SYS_BOOT_SHUTDOWN); - loop(); return 0; } diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 486da6c..31cdf5f 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -86,9 +86,32 @@ static void syscall_handler(struct regs *r) break; } case SYS_EXIT: { + print("EXIT!\n"); proc_exit(proc_current(), (int)r->ebx); break; } + case SYS_BOOT: { // TODO: Move + if (r->ebx != SYS_BOOT_MAGIC || !proc_super()) { + r->eax = -1; + break; + } + switch (r->ecx) { + case SYS_BOOT_REBOOT: + print("Rebooting...\n"); + __asm__ volatile("ud2"); + break; + case SYS_BOOT_SHUTDOWN: + print("Shutting down...\n"); + outw(0xB004, 0x2000); + outw(0x604, 0x2000); + outw(0x4004, 0x3400); + __asm__ volatile("ud2"); + break; + default: + r->eax = -1; + } + break; + } case SYS_YIELD: { proc_yield(r); break; @@ -130,7 +153,7 @@ static void syscall_handler(struct regs *r) break; } default: { - print("Unknown syscall!\n"); + printf("Unknown syscall %d!\n", num); break; } } diff --git a/libc/crt/crt0.asm b/libc/crt/crt0.asm index a0621ff..0f8024d 100644 --- a/libc/crt/crt0.asm +++ b/libc/crt/crt0.asm @@ -10,6 +10,6 @@ _start: call main push eax - push 8 + push 9 call sys1 jmp $ diff --git a/libc/inc/sys.h b/libc/inc/sys.h index c100e6a..3125cb0 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -9,6 +9,10 @@ #define KEYBOARD_MAGIC 0x555555 #define MOUSE_MAGIC 0xaaaaaa +#define SYS_BOOT_MAGIC 0x18122002 +#define SYS_BOOT_REBOOT 0xeeb007 +#define SYS_BOOT_SHUTDOWN 0xdead + enum sys { SYS_LOOP, // To infinity and beyond (debug)! SYS_ALLOC, // Allocate memory @@ -19,7 +23,8 @@ enum sys { SYS_IOCTL, // Interact with a file/device SYS_POLL, // Wait for multiple files SYS_EXEC, // Execute path - SYS_EXIT, // Exit current process // TODO: Free all memory of process + SYS_EXIT, // Exit current process + SYS_BOOT, // Boot functions (e.g. reboot/shutdown) SYS_YIELD, // Switch to next process SYS_TIME, // Get kernel time SYS_NET_OPEN, // Open network socket @@ -82,7 +87,8 @@ int sysv(enum sys num, ...); yield(); \ } \ } -#define yield(void) (int)sys0(SYS_YIELD) +#define boot(cmd) (s32) sys2(SYS_BOOT, SYS_BOOT_MAGIC, cmd) +#define yield(void) (s32) sys0(SYS_YIELD) #define time(void) (u32) sys0(SYS_TIME) static inline u32 getpid(void) |