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/io.h>
40 #include <vmm/vmm.h>
41 #include <mpi/mpi.h>
42 #include <string.h>
43 
44 static unsigned char *videoBuffer = (char *)0xB8000;
45 
46 
47 void systemTask() {
48  mpi_message_t myMsg;
49  uInt32 counter = 0x0;
50  int i = 0x0;
51  int *x = 0x0;
52  kTask_t *tmpTask = 0x0;
53 
54  if (mpi_createMbox("system") != 0x0) {
55  kpanic("Error: Error creating mailbox: system\n");
56  }
57 
58  while(1) {
59  if (mpi_fetchMessage("system",&myMsg) == 0x0) {
60  kprintf("A");
61  switch(myMsg.header) {
62  case 0x69:
63  x = (int *)&myMsg.data;
64  kprintf("Switching to term: [%i][%i]\n",*x,myMsg.pid);
65  schedFindTask(myMsg.pid)->term = tty_find(*x);
66  break;
67  case 1000:
68  kprintf("Restarting the system in 5 seconds\n");
69  counter = systemVitals->sysUptime + 5;
70  while (systemVitals->sysUptime < counter) {
71  sched_yield();
72  }
73  kprintf("Rebooting NOW!!!\n");
74  while(inportByte(0x64) & 0x02);
75  outportByte(0x64, 0xFE);
76  break;
77  case 31337:
78  kprintf("system: backdoor opened\n");
79  break;
80  case 0x80:
81  if (!strcmp(myMsg.data,"sdeStart")) {
82  kprintf("Starting SDE\n");
83  //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0);
84  }
85  else if (!strcmp(myMsg.data,"freePage")) {
86  kprintf("kkk Free Pages");
87  }
88  else if (!strcmp(myMsg.data,"sdeStop")) {
89  printOff = 0x0;
90  biosCall(0x10,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0);
91  for (i=0x0;i<100;i++) 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  if (tmpTask != 0x0) {
107  if (tmpTask->files[0] != 0x0)
108  fclose(tmpTask->files[0]);
109  vmmFreeProcessPages(tmpTask->id);
110  kfree(tmpTask);
111  }
112  videoBuffer[0] = systemVitals->sysTicks;
113  sched_yield();
114  }
115 
116  return;
117  }
118 
119 /***
120  END
121  ***/
122 
mpi_fetchMessage
int mpi_fetchMessage(char *, mpi_message_t *)
Definition: system.c:187
systemtask.h
taskStruct
Definition: sched.h:62
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
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
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
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:533
kprintf.h
mpi.h
taskStruct::term
tty_term * term
Definition: sched.h:77
vitals.h
vitalsStruct::sysTicks
uint32_t sysTicks
Definition: vitals.h:37
taskStruct::files
fileDescriptor_t * files[MAX_OFILES]
Definition: sched.h:71
tty.h
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