UbixOS  2.0
main.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/init.h>
30 #include <sys/gdt.h>
31 #include <sys/video.h>
32 #include <sys/tss.h>
33 #include <sys/bootinfo.h>
34 #include <ubixos/exec.h>
35 #include <ubixos/kpanic.h>
36 #include <ubixos/systemtask.h>
37 #include <vfs/mount.h>
38 #include <lib/kprintf.h>
39 #include <lib/kmalloc.h>
40 #include <sde/sde.h>
41 
42 #define B_ADAPTORSHIFT 24
43 #define B_ADAPTORMASK 0x0f
44 #define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK)
45 #define B_CONTROLLERSHIFT 20
46 #define B_CONTROLLERMASK 0xf
47 #define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK)
48 /*
49  * Constants for converting boot-style device number to type,
50  * adaptor (uba, mba, etc), unit number and partition number.
51  * Type (== major device number) is in the low byte
52  * for backward compatibility. Except for that of the "magic
53  * number", each mask applies to the shifted value.
54  * Format:
55  * (4) (8) (4) (8) (8)
56  * --------------------------------
57  * |MA | SLICE | UN| PART | TYPE |
58  * --------------------------------
59  */
60 #define B_SLICESHIFT 20
61 #define B_SLICEMASK 0xff
62 #define B_SLICE(val) (((val)>>B_SLICESHIFT) & B_SLICEMASK)
63 #define B_UNITSHIFT 16
64 #define B_UNITMASK 0xf
65 #define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK)
66 #define B_PARTITIONSHIFT 8
67 #define B_PARTITIONMASK 0xff
68 #define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK)
69 #define B_TYPESHIFT 0
70 #define B_TYPEMASK 0xff
71 #define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK)
72 
73 
74 /*****************************************************************************************
75  Desc: The Kernels Descriptor table:
76  0 - 0x00 - Dummy Entry
77  1 - 0x08 - Ring 0 CS
78  2 - 0x10 - Ring 0 DS
79  3 - 0x18 - LDT
80  4 - 0x20 - Scheduler TSS
81  5 - 0x28 - Ring 3 CS
82  6 - 0x30 - Ring 3 DS
83  7 - 0x38 - GPF TSS
84  8 - 0x40 - Stack Fault TSS
85  9 - 0x48 - SMP Private Data
86  10 - 0x50 - USER %GS (Stack!)
87 
88  Notes:
89 
90  MrOlsen: test
91 
92  *****************************************************************************************/
94 { .dummy = 0},
95 ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dRead + dBig + dBiglim)),
96 ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim)),
98 ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss + dDpl3)),
99 ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dRead + dBig + dBiglim + dDpl3)),
100 ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)),
101 ubixStandardDescriptor(0x5200, (sizeof(struct tssStruct)), (dTss + dDpl3)),
102 ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)),
103 ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl0)),
104 ubixStandardDescriptor(0xBFC00000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)),
105 };
106 
107 struct {
108  unsigned short limit __attribute__ ((packed));
109  union descriptorTableUnion *gdt __attribute__ ((packed));
110 } loadGDT = { (11 * sizeof(union descriptorTableUnion) - 1), ubixGDT };
111 
112 static char *argv_init[2] = {
113  "init",
114  0x0, }; /* ARGV For Initial Process */
115 
116 static char *envp_init[6] = {
117  "HOME=/",
118  "PWD=/",
119  "PATH=/bin:/sbin:/usr/bin:/usr/sbin",
120  "USER=root",
121  "GROUP=admin",
122  0x0, }; /* ENVP For Initial Process */
123 
125 char _kernelname[512];
128 
134 int kmain(uint32_t rootdev) {
135  /* Set up counter for startup routine */
136  int i = 0x0;
137 
138  /* Do A Clear Screen Just To Make The TEXT Buffer Nice And Empty */
139  clearScreen();
140 
141  /* Modify src/sys/include/ubixos/init.h to add a startup routine */
142  for (i = 0x0; i < init_tasksTotal; i++) {
143  if (init_tasks[i]() != 0x0)
144  kpanic("Error: Initializing System Task[%i].\n", i);
145  }
146 
147  /* New Root Mount Point */
148  /* Old 2 new 10 */
149  kprintf("[0x%X][0x%X:0x%X:0x%X:0x%X:0x%X:0x%X]\n", B_ADAPTOR(rootdev), B_CONTROLLER(rootdev), B_SLICE(rootdev), B_UNIT(rootdev), B_PARTITION(rootdev), B_TYPE(rootdev));
150  /* if ( vfs_mount( B_UNIT(_bootdev), B_PARTITION(_bootdev), 0x0, 0xAA, "sys", "rw" ) != 0x0 ) { */
151 
152  if (vfs_mount(0x1, 0x2, 0x0, 0xAA, "sys2", "rw") != 0x0) { //UFS FS
153  kprintf("Problem Mounting sys2 Mount Point\n");
154  }
155  else
156  kprintf("Mounted sys2\n");
157 
158 
159  if (vfs_mount(0x2, 0x1, 0x1, 0xFA, "sys", "rw") != 0x0) { //FAT FS
160  kprintf("Problem Mounting sys Mount Point\n");
161  }
162  else
163  kprintf("Mounted sys\n");
164 
165  /* Do our mounting */
166  /*
167  if (vfs_mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) {
168  kprintf("Problem Mounting sys Mount Point\n");
169  }
170  if (vfs_mount(0x0,0x0,0x1,0x0,"tmp","rw") != 0x0) {
171  kprintf("Problem Mounting tmp Mount Point\n");
172  }
173  */
174 
175  /* Initialize the system */
176  kprintf("Free Pages: [%i]\n", systemVitals->freePages);
177  kprintf("MemoryMap: [0x%X]\n", vmmMemoryMap);
178  kprintf("Starting OS\n");
179 
180 
181  /* kprintf("SDE Thread Start! [0x%X]\n", &sdeThread); */
182  /* execThread(&sdeThread, 0x2000,0x0); */
183 
184  kprintf("Kernel Name: [%s], Boot How To [0x%X], Boot Dev: [0x%X]\n", _kernelname, _boothowto, _bootdev);
185  kprintf("B_TYPE(0x%X), B_SLICE(0x%X), B_UNIT(0x%X), B_PARTITION(0x%X)\n", B_TYPE(_bootdev), B_SLICE(_bootdev), B_UNIT(_bootdev), B_PARTITION(_bootdev));
186  kprintf("_bootinfo.bi_version: 0x%X\n", _bootinfo.bi_version);
187  kprintf("_bootinfo.bi_size: 0x%X\n", _bootinfo.bi_size);
188  kprintf("_bootinfo.bi_bios_dev: 0x%X\n", _bootinfo.bi_bios_dev);
189 
190  execThread(systemTask, 0x2000, 0x0);
191 
192  execFile("sys:/bin/init", argv_init, envp_init, 0x0); /* OS Initializer */
193 
194  //execFile("fat:/bin/init", argv_init, envp_init, 0x0);
195 
196  irqEnable(0x0);
197 
198  while (0x1)
199  asm("hlt");
200 
201  /* Keep haulting until the scheduler reacts */
202 
203  /* Return to start however we should never get this far */
204  return (0x0);
205 }
systemtask.h
u_long
unsigned long u_long
Definition: types.h:73
bootinfo
Definition: bootinfo.h:5
bootinfo::bi_size
u_int32_t bi_size
Definition: bootinfo.h:13
vfs_mount
int vfs_mount(int major, int minor, int partition, int vfsType, char *mountPoint, char *perms)
Definition: mount.c:45
init_tasksTotal
int init_tasksTotal
Definition: init.h:64
__attribute__
union descriptorTableUnion __attribute__
gdt.h
vmmMemoryMap
mMap * vmmMemoryMap
Definition: vmm_memory.c:47
ubixGDT
union descriptorTableUnion ubixGDT[11]
dCode
#define dCode
Definition: gdt.h:41
loadGDT
struct @24 loadGDT
video.h
VMM_USER_LDT
#define VMM_USER_LDT
Definition: vmm.h:56
init_tasks
intFunctionPTR init_tasks[]
Definition: init.h:58
_kernelname
char _kernelname[512]
Definition: main.c:124
dRead
#define dRead
Definition: gdt.h:58
dTss
#define dTss
Definition: gdt.h:47
exec.h
dLdt
#define dLdt
Definition: gdt.h:44
kmain
int kmain(uint32_t rootdev)
This is the entry point into the os where all of the kernels sub systems are started up.
Definition: main.c:133
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition: kpanic.c:41
kpanic.h
_bootinfo
struct bootinfo _bootinfo
Definition: main.c:123
systemVitals
vitalsNode * systemVitals
Definition: vitals.c:35
kprintf.h
dData
#define dData
Definition: gdt.h:42
bootinfo::bi_bios_dev
u_int8_t bi_bios_dev
Definition: bootinfo.h:15
B_SLICE
#define B_SLICE(val)
Definition: main.c:62
descriptorTableUnion
Definition: gdt.h:83
uint32_t
__uint32_t uint32_t
Definition: types.h:46
ubixDescriptorTable
ubixDescriptorTable(ubixGDT, 11)
Definition: main.c:92
tssStruct
Definition: tss.h:34
execThread
uInt32 execThread(void(*tproc)(void), uInt32 stack, char *arg)
Definition: exec.c:66
B_TYPE
#define B_TYPE(val)
Definition: main.c:71
ubixStandardDescriptor
#define ubixStandardDescriptor(base, limit, control)
Definition: gdt.h:90
B_ADAPTOR
#define B_ADAPTOR(val)
Definition: main.c:44
bootinfo.h
bootinfo::bi_version
u_int32_t bi_version
Definition: bootinfo.h:6
vitalsStruct::freePages
uint32_t freePages
Definition: vitals.h:43
init.h
_bootdev
u_long _bootdev
Definition: main.c:125
execFile
void execFile(char *file, int argc, char **argv, int console)
Definition: exec.c:153
sde.h
clearScreen
void clearScreen()
Definition: video.c:109
irqEnable
void irqEnable(uInt16 irqNo)
dBiglim
#define dBiglim
Definition: gdt.h:63
dBig
#define dBig
Definition: gdt.h:62
mount.h
systemTask
void systemTask()
Definition: systemtask.c:47
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
B_UNIT
#define B_UNIT(val)
Definition: main.c:65
B_PARTITION
#define B_PARTITION(val)
Definition: main.c:68
dDpl0
#define dDpl0
Definition: gdt.h:53
kmalloc.h
tss.h
_boothowto
u_long _boothowto
Definition: main.c:126
B_CONTROLLER
#define B_CONTROLLER(val)
Definition: main.c:47
dDpl3
#define dDpl3
Definition: gdt.h:50
dWrite
#define dWrite
Definition: gdt.h:57