# systemtask.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002-2004 The UbixOS Project
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are
    00006  permitted provided that the following conditions are met:
    00007
    00008  Redistributions of source code must retain the above copyright notice, this list of
    00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010  form must reproduce the above copyright notice, this list of conditions, the following
    00011  disclaimer and the list of authors in the documentation and/or other materials provided
    00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013  contributors may be used to endorse or promote products derived from this software
    00014  without specific prior written permission.
    00015
    00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: systemtask_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <ubixos/systemtask.h>
    00031 #include <ubixos/kpanic.h>
    00032 #include <ubixos/exec.h>
    00033 #include <ubixos/tty.h>
    00034 #include <ubixos/sched.h>
    00035 #include <ubixos/vitals.h>
    00036 #include <lib/kmalloc.h>
    00037 #include <lib/kprintf.h>
    00038 #include <lib/bioscall.h>
    00039 #include <sde/sde.h>
    00040 #include <sys/io.h>
    00041 #include <vmm/vmm.h>
    00042 #include <mpi/mpi.h>
    00043 #include <string.h>
    00044
    00045 static unsigned char  *videoBuffer = (char *)0xB8000;
    00046
    00047
    00048 void systemTask() {
    00049   mpi_message_t myMsg;
    00050   uInt32       counter  = 0x0;
    00051   int          i        = 0x0;
    00052   int          *x       = 0x0;
    00053   kTask_t      *tmpTask = 0x0;
    00054
    00055   if (mpi_createMbox("system") != 0x0) {
    00056     kpanic("Error: Error creating mailbox: system\n");
    00057     }
    00058
    00059   while(1) {
    00060     if (mpi_fetchMessage("system",&myMsg) == 0x0) {
    00061       kprintf("A");
    00062       switch(myMsg.header) {
    00063         case 0x69:
    00064           x = (int *)&myMsg.data;
    00065           kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid);
    00066           schedFindTask(myMsg.pid)->term = tty_find(*x);
    00067           break;
    00068         case 1000:
    00069           kprintf("Restarting the system in 5 seconds\n");
    00070           counter = systemVitals->sysUptime + 5;
    00071           while (systemVitals->sysUptime < counter) {
    00072             sched_yield();
    00073             }
    00074           kprintf("Rebooting NOW!!!\n");
    00075           while(inportByte(0x64) & 0x02);
    00076           outportByte(0x64, 0xFE);
    00077           break;
    00078         case 31337:
    00079            kprintf("system: backdoor opened\n");
    00080            break;
    00081         case 0x80:
    00082            if (!strcmp(myMsg.data,"sdeStart")) {
    00083              kprintf("Starting SDE\n");
    00084              //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0);
    00085              }
    00086            else if (!strcmp(myMsg.data,"freePage")) {
    00087             kprintf("kkk Free Pages");
    00088              }
    00089            else if (!strcmp(myMsg.data,"sdeStop")) {
    00090              printOff = 0x0;
    00091              biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0);
    00092              for (i=0x0;i<100;i++) asm("hlt");
    00093              }
    00094            break;
    00095         default:
    00096           kprintf("system: Received message %i:%s\n",myMsg.header,myMsg.data);
    00097           break;
    00098         }
    00099       }
    00100
    00101     /*
    00102      Here we get the next task from the delete task queue
    00103      we first check to see if it has an fd attached for the binary and after that
    00104      we free the pages for the process and then free the task
    00105     */
    00106     tmpTask = sched_getDelTask();
    00107     if (tmpTask != 0x0) {
    00108       if (tmpTask->imageFd != 0x0)
    00109         fclose(tmpTask->imageFd);
    00110       vmmFreeProcessPages(tmpTask->id);
    00111       kfree(tmpTask);
    00112       }
    00113     videoBuffer[0] = systemVitals->sysTicks;
    00114     sched_yield();
    00115     }
    00116
    00117   return;
    00118   }
    00119
    00120 /***
    00121  END
    00122  ***/
    00123