UbixOS  2.0
systemtask.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <ubixos/systemtask.h>
30 #include <ubixos/kpanic.h>
31 #include <ubixos/exec.h>
32 #include <ubixos/tty.h>
33 #include <ubixos/sched.h>
34 #include <ubixos/vitals.h>
35 #include <lib/kmalloc.h>
36 #include <lib/kprintf.h>
37 #include <lib/bioscall.h>
38 #include <sde/sde.h>
39 #include <sys/shutdown.h>
40 #include <vmm/vmm.h>
41 #include <mpi/mpi.h>
42 #include <string.h>
43 
44 static unsigned char *videoBuffer = (unsigned char*) 0xB8000;
45 
46 void systemTask() {
47 
48  mpi_message_t myMsg;
49  uint32_t counter = 0x0;
50  int i = 0x0;
51  int *x = 0x0;
52  kTask_t *tmpTask = 0x0;
53 
54  char buf[16] = { "a\n" };
55 
56  if (mpi_createMbox("system") != 0x0) {
57  kpanic("Error: Error creating mailbox: system\n");
58  }
59 
60  while (1) {
61  if (mpi_fetchMessage("system", &myMsg) == 0x0) {
62  switch (myMsg.header) {
63  case 0x69:
64  x = (int*) &myMsg.data;
65  kprintf("Switching to term: [%i][%i]\n", *x, myMsg.pid);
66  schedFindTask(myMsg.pid)->term = tty_find(*x);
67  break;
68  case 1000:
69  kprintf("Restarting the system in 5 seconds\n");
70  counter = systemVitals->sysUptime + 5;
71  while (systemVitals->sysUptime < counter) {
72  sched_yield();
73  }
75  break;
76  case 31337:
77  kprintf("system: backdoor opened\n");
78  break;
79  case 0x80:
80  if (!strcmp(myMsg.data, "sdeStart")) {
81  kprintf("Starting SDE\n");
82  execThread(sdeThread, 0x2000, 0x0);
83  }
84  else if (!strcmp(myMsg.data, "freePage")) {
85  kprintf("kkk Free Pages");
86  }
87  else if (!strcmp(myMsg.data, "sdeStop")) {
88  printOff = 0x0;
89  biosCall(0x10, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
90  for (i = 0x0; i < 100; i++)
91  asm("hlt");
92  }
93  break;
94  default:
95  kprintf("system: Received message %i:%s\n", myMsg.header, myMsg.data);
96  break;
97  }
98  }
99 
100  /*
101  Here we get the next task from the delete task queue
102  we first check to see if it has an fd attached for the binary and after that
103  we free the pages for the process and then free the task
104  */
105  tmpTask = sched_getDelTask();
106 
107  if (tmpTask != 0x0) {
108  if (tmpTask->files[0] != 0x0)
109  fclose(tmpTask->files[0]);
110  vmm_freeProcessPages(tmpTask->id);
111  kfree(tmpTask);
112 
113  }
114 
115  if (ogprintOff == 1) {
116  videoBuffer[0] = systemVitals->sysTicks;
117  videoBuffer[1] = 'c';
118  }
119  /*
120  else
121  ogPrintf(buf);
122  */
123 
124  sched_yield();
125  }
126 
127  return;
128 }
mpi_fetchMessage
int mpi_fetchMessage(char *, mpi_message_t *)
Definition: system.c:187
systemtask.h
taskStruct
Definition: sched.h:62
ogprintOff
int ogprintOff
Definition: kprintf.c:257
string.h
mpi_message::header
uInt32 header
Definition: mpi.h:39
kfree
void kfree(void *baseAddr)
Definition: kmalloc.c:342
vmm_freeProcessPages
void vmm_freeProcessPages(pidType pid)
Definition: vmm_memory.c:342
strcmp
int strcmp(const char *str1, const char *str2)
vmm.h
exec.h
sched.h
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition: kpanic.c:41
biosCall
void biosCall(int biosInt, int eax, int ebx, int ecx, int edx, int esi, int edi, int es, int ds)
Definition: bioscall.c:49
shutdown.h
sdeThread
void sdeThread()
Definition: main.cc:51
tty_find
tty_term * tty_find(uInt16)
Definition: tty.c:167
kpanic.h
taskStruct::id
pidType id
Definition: sched.h:63
schedFindTask
kTask_t * schedFindTask(uInt32 id)
Definition: sched.c:207
systemVitals
vitalsNode * systemVitals
Definition: vitals.c:35
fclose
int fclose(fileDescriptor_t *fd)
Definition: file.c:533
kprintf.h
mpi.h
REBOOT
Definition: shutdown.h:34
taskStruct::term
tty_term * term
Definition: sched.h:77
buf
Definition: buf.h:35
vitals.h
vitalsStruct::sysTicks
uint32_t sysTicks
Definition: vitals.h:37
taskStruct::files
fileDescriptor_t * files[MAX_OFILES]
Definition: sched.h:71
uint32_t
__uint32_t uint32_t
Definition: types.h:46
tty.h
execThread
uInt32 execThread(void(*tproc)(void), uInt32 stack, char *arg)
Definition: exec.c:66
mpi_message::pid
pidType pid
Definition: mpi.h:40
sde.h
mpi_message::data
char data[248]
Definition: mpi.h:38
vitalsStruct::sysUptime
uint32_t sysUptime
Definition: vitals.h:38
sys_shutdown
int sys_shutdown(shutdownCMD_t)
Definition: shutdown.c:34
printOff
int printOff
Definition: kprintf.c:256
bioscall.h
systemTask
void systemTask()
Definition: systemtask.c:47
mpi_message
Definition: mpi.h:37
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
kmalloc.h
sched_getDelTask
kTask_t * sched_getDelTask()
Definition: sched.c:195
mpi_createMbox
int mpi_createMbox(char *)
Definition: system.c:68
sched_yield
void sched_yield()
Definition: sched.c:244