UbixOS V2  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/io.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  }
74  kprintf("Rebooting NOW!!!\n");
75  while (inportByte(0x64) & 0x02)
76  ;
77  outportByte(0x64, 0xFE);
78  break;
79  case 31337:
80  kprintf("system: backdoor opened\n");
81  break;
82  case 0x80:
83  if (!strcmp(myMsg.data, "sdeStart")) {
84  kprintf("Starting SDE\n");
85  execThread(sdeThread,0x2000,0x0);
86  }
87  else if (!strcmp(myMsg.data, "freePage")) {
88  kprintf("kkk Free Pages");
89  }
90  else if (!strcmp(myMsg.data, "sdeStop")) {
91  printOff = 0x0;
92  biosCall(0x10, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
93  for (i = 0x0; i < 100; i++)
94  asm("hlt");
95  }
96  break;
97  default:
98  kprintf("system: Received message %i:%s\n", myMsg.header, myMsg.data);
99  break;
100  }
101  }
102 
103  /*
104  Here we get the next task from the delete task queue
105  we first check to see if it has an fd attached for the binary and after that
106  we free the pages for the process and then free the task
107  */
108  tmpTask = sched_getDelTask();
109 
110  if (tmpTask != 0x0) {
111  if (tmpTask->files[0] != 0x0)
112  fclose(tmpTask->files[0]);
113  vmm_freeProcessPages(tmpTask->id);
114  kfree(tmpTask);
115 
116  }
117 
118  if (ogprintOff == 1) {
119  videoBuffer[0] = systemVitals->sysTicks;
120  videoBuffer[1] = 'c';
121  }
122  /*
123  else
124  ogPrintf(buf);
125  */
126 
127  sched_yield();
128  }
129 
130  return;
131 }
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
outportByte
void outportByte(unsigned int, unsigned char)
outputut one byte to specified port
Definition: io.c:72
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
sdeThread
void sdeThread()
Definition: main.cc:51
inportByte
unsigned char inportByte(unsigned int)
input one byte from specified port
Definition: io.c:38
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:526
kprintf.h
mpi.h
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
io.h
sde.h
mpi_message::data
char data[248]
Definition: mpi.h:38
vitalsStruct::sysUptime
uint32_t sysUptime
Definition: vitals.h:38
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