diff --git a/sys/arch/i386/systemtask.c b/sys/arch/i386/systemtask.c index b598744..7be480f 100644 --- a/sys/arch/i386/systemtask.c +++ b/sys/arch/i386/systemtask.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -71,12 +71,7 @@ while (systemVitals->sysUptime < counter) { sched_yield(); } - // XXX Temp Hack To Cleanup File system we need a shutdown procedure somewhere. - fl_shutdown(); - kprintf("Rebooting NOW!!!\n"); - while (inportByte(0x64) & 0x02) - ; - outportByte(0x64, 0xFE); + sys_shutdown(REBOOT); break; case 31337: kprintf("system: backdoor opened\n"); diff --git a/sys/include/sys/shutdown.h b/sys/include/sys/shutdown.h new file mode 100644 index 0000000..2a1d127 --- /dev/null +++ b/sys/include/sys/shutdown.h @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2020 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SHUTDOWN_H +#define _SYS_SHUTDOWN_H + +typedef enum { + HALT, + REBOOT +} shutdownCMD_t; + +int sys_shutdown(shutdownCMD_t); + +#endif /* _SYS_SHUTDOWN_H */ diff --git a/sys/isa/atkbd.c b/sys/isa/atkbd.c index 3d4b1f9..ec94c61 100644 --- a/sys/isa/atkbd.c +++ b/sys/isa/atkbd.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -296,13 +297,7 @@ sched_setStatus(tty_foreground->owner, DEAD); break; case 0x9: - kprintf("REBOOTING"); - - // XXX Hack add shutdown procedure - fl_shutdown(); - while (inportByte(0x64) & 0x02) - ; - outportByte(0x64, 0xFE); + sys_shutdown(REBOOT); break; case 0x18: if (tty_foreground->owner == _current->id) diff --git a/sys/kernel/Makefile b/sys/kernel/Makefile index 6d6e4e6..230a7f5 100644 --- a/sys/kernel/Makefile +++ b/sys/kernel/Makefile @@ -6,7 +6,7 @@ include ../Makefile.incl # Objects -OBJS = sem.o vfs_calls.o tty.o kern_sig.o pipe.o descrip.o kern_sysctl.o gen_calls.o endtask.o ld.o time.o elf.o ubthread.o vitals.o access.o syscall.o syscall_posix.o syscalls.o syscalls_posix.o execve.o kern_pipe.o +OBJS = sem.o vfs_calls.o tty.o kern_sig.o pipe.o descrip.o kern_sysctl.o gen_calls.o endtask.o ld.o time.o elf.o ubthread.o vitals.o access.o syscall.o syscall_posix.o syscalls.o syscalls_posix.o execve.o kern_pipe.o shutdown.o #OBJS += ../${_ARCH}/schedyield.o ../${_ARCH}/kpanic.o ../${_ARCH}/timer.o ../${_ARCH}/spinlock.o ../${_ARCH}/exec.o ../${_ARCH}/sys_call_new.o ../${_ARCH}/sys_call.o ../${_ARCH}/bioscall.o ../${_ARCH}/fork.o ../${_ARCH}/syscall.o ../${_ARCH}/systemtask.o ../${_ARCH}/sched.o ../${_ARCH}/cpu.o # ap-boot.o smp.o vitals.o(obsolete) diff --git a/sys/kernel/shutdown.c b/sys/kernel/shutdown.c new file mode 100644 index 0000000..d2a5f87 --- /dev/null +++ b/sys/kernel/shutdown.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2020 The UbixOS Project. + * All rights reserved. + * + * This was developed by Christopher W. Olsen for the UbixOS Project. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted + * provided that the following conditions are met: + * + * 1) Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. + * 2) Redistributions in binary form must reproduce the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors in the documentation and/or + * other materials provided with the distribution. + * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + + +int sys_shutdown(shutdownCMD_t cmd) { + kprintf("System Shutting Down: %i", cmd); + switch (cmd) { + case REBOOT: + kprintf("REBOOTING"); + fl_shutdown(); + while (inportByte(0x64) & 0x02) + ; + outportByte(0x64, 0xFE); + break; + case HALT: + kprintf("HALTING -> right now same as reboot."); + + fl_shutdown(); + while (inportByte(0x64) & 0x02) + ; + outportByte(0x64, 0xFE); + break; + default: + kprintf("Invalid Command: %i", cmd); + } + return (-1); +}