main.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2004, 2005 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$
00027 
00028 *****************************************************************************************/
00029 
00030 #include <ubixos/init.h>
00031 #include <sys/gdt.h>
00032 #include <sys/video.h>
00033 #include <sys/tss.h>
00034 #include <ubixos/exec.h>
00035 #include <ubixos/kpanic.h>
00036 #include <ubixos/systemtask.h>
00037 #include <vfs/mount.h>
00038 #include <lib/kprintf.h>
00039 #include <lib/kmalloc.h>
00040 
00041 #define B_ADAPTORSHIFT          24
00042 #define B_ADAPTORMASK           0x0f
00043 #define B_ADAPTOR(val)          (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK)
00044 #define B_CONTROLLERSHIFT       20
00045 #define B_CONTROLLERMASK        0xf
00046 #define B_CONTROLLER(val)       (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK)
00047 #define B_SLICESHIFT            20
00048 #define B_SLICEMASK             0xff
00049 #define B_SLICE(val)            (((val)>>B_SLICESHIFT) & B_SLICEMASK)
00050 #define B_UNITSHIFT             16
00051 #define B_UNITMASK              0xf
00052 #define B_UNIT(val)             (((val) >> B_UNITSHIFT) & B_UNITMASK)
00053 #define B_PARTITIONSHIFT        8
00054 #define B_PARTITIONMASK         0xff
00055 #define B_PARTITION(val)        (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK)
00056 #define B_TYPESHIFT             0
00057 #define B_TYPEMASK              0xff
00058 #define B_TYPE(val)             (((val) >> B_TYPESHIFT) & B_TYPEMASK)
00059 
00060 
00061 /*****************************************************************************************
00062  Desc: The Kernels Descriptor table:
00063        0x00 - Dummy Entry
00064        0x08 - Ring 0 CS
00065        0x10 - Ring 0 DS 
00066        0x18 - Dummy LDT
00067        0x20 - Scheduler TSS
00068        0x28 - Ring 3 CS
00069        0x30 - Ring 3 DS
00070        0x38 - GPF TSS
00071        0x40 - Stack Fault TSS
00072 
00073  Notes: 
00074 
00075 *****************************************************************************************/
00076 ubixDescriptorTable(ubixGDT,9) {
00077   {dummy:0},
00078   ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dRead + dBig + dBiglim)),
00079   ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim)),
00080   ubixStandardDescriptor(0x0000, 0xFFFFF, (dLdt)),
00081   ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss + dDpl3)),
00082   ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dWrite + dBig + dBiglim + dDpl3)),
00083   ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)),
00084   ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)),
00085   ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)),
00086   };
00087 struct {
00088   unsigned short limit __attribute__ ((packed));
00089   union descriptorTableUnion *gdt __attribute__ ((packed));
00090   } loadGDT = { (9 * sizeof(union descriptorTableUnion) - 1), ubixGDT };
00091 
00092 /*****************************************************************************************
00093  Functoin: int main()
00094  
00095  Desc: This is the entry point into the os where all of the kernels sub systems are 
00096        started up. 
00097 
00098  Notes: 
00099 
00100 *****************************************************************************************/
00101 int kmain(uInt32 rootdev) {
00102   /* Set up counter for startup routine */
00103   int i = 0x0;
00104   uInt32 *sysTask = 0x0;
00105 
00106   /* Do A Clear Screen Just To Make The TEXT Buffer Nice And Empty */
00107   clearScreen();
00108   kprint("AAA");
00109   kprint("BBB");
00110 kprintf("TEST");
00111   /* Modify src/sys/include/ubixos/init.h to add a startup routine */
00112   for (i=0x0;i<init_tasksTotal;i++) {
00113     if (init_tasks[i]() != 0x0) {
00114       kpanic("Error: Initializing System.\n");
00115       }
00116     }
00117 
00118   /* New Root Mount Point */
00119   //Old 2 new 10
00120   kprintf("[0xX][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));
00121   if (vfs_mount(0x1,B_PARTITION(rootdev)+2,0x0,0xAA,"sys","rw") != 0x0) {
00122     kprintf("Problem Mounting sys Mount Point\n");
00123     }
00124 
00125   /* Do our mounting */
00126  /* 
00127   if (vfs_mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) {
00128     kprintf("Problem Mounting sys Mount Point\n");
00129     }
00130   if (vfs_mount(0x0,0x0,0x1,0x0,"tmp","rw") != 0x0) {
00131     kprintf("Problem Mounting tmp Mount Point\n");
00132     }
00133   */
00134   
00135   /* Initialize the system */
00136   kprintf("Free Pages: [%i]\n",systemVitals->freePages); 
00137 
00138   kprintf("MemoryMap:  [0x%X]\n",vmmMemoryMap);
00139   kprintf("Starting OS\n");
00140   
00141         sysTask = kmalloc(0x2000);
00142         if(sysTask == NULL)
00143                 kprintf("OS: Unable to allocate memory\n");
00144 
00145         execThread(systemTask, (uInt32)sysTask+0x2000,0x0);
00146 
00147         execFile("sys:/bin/init",0x0,0x0,0x0); /* OS Initializer    */
00148   
00149         irqEnable(0x0);
00150   
00151         while (0x1)
00152                 asm("hlt"); /* Keep haulting until the scheduler reacts */
00153   
00154         /* Return to start however we should never get this far */
00155         return(0x0);
00156 }
00157 
00158 /***
00159  END
00160  ***/
00161 

Generated on Tue Dec 5 09:28:04 2006 for UbixOS V2 by  doxygen 1.4.7