/***************************************************************************************** Copyright (c) 2002-2004, 2005, 2007, 2008 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Id$ *****************************************************************************************/ #include <ubixos/init.h> #include <sys/gdt.h> #include <sys/video.h> #include <sys/tss.h> #include <ubixos/exec.h> #include <ubixos/kpanic.h> #include <ubixos/systemtask.h> #include <vfs/mount.h> #include <lib/kprintf.h> #include <lib/kmalloc.h> /***************************************************************************************** Desc: The Kernels Descriptor table: 0x00 - Dummy Entry 0x08 - Ring 0 CS 0x10 - Ring 0 DS 0x18 - Dummy LDT 0x20 - Scheduler TSS 0x28 - Ring 3 CS 0x30 - Ring 3 DS 0x38 - GPF TSS 0x40 - Stack Fault TSS Notes: *****************************************************************************************/ ubixDescriptorTable(ubixGDT,9) { {dummy:0}, ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dRead + dBig + dBiglim)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dLdt)), ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss + dDpl3)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dWrite + dBig + dBiglim + dDpl3)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)), }; struct { unsigned short limit __attribute__ ((packed)); union descriptorTableUnion *gdt __attribute__ ((packed)); } loadGDT = { (9 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; /** * \brief This is the entry point into the OS where all of the kernels sub systems are started up. * * \param rootdev address of root device structure */ struct bootinfo { u_int32_t version; u_int32_t kernel; u_int32_t nfs; #define bi_endcommon bios_used u_int32_t bios_used; u_int32_t bios_geom[8]; u_int32_t bi_size; u_int8_t mem_sizes; u_int8_t bios_dev; u_int8_t bi_pad[2]; u_int32_t bi_basemem; u_int32_t bi_extmem; }; #define B_SLICESHIFT 20 #define B_SLICEMASK 0xff #define B_SLICE(val) (((val)>>B_SLICESHIFT) & B_SLICEMASK) #define B_UNITSHIFT 16 #define B_UNITMASK 0xf #define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK) #define B_PARTITIONSHIFT 8 #define B_PARTITIONMASK 0xff #define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK) #define B_TYPESHIFT 0 #define B_TYPEMASK 0xff #define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK) int kmain(struct bootinfo *binfo) { /* Set up counter for startup routine */ int i = 0x0; u_int32_t *sysTask = 0x0; int bDev = -1; /* We preform a clearScreen to make the TEXT buffer nice and empty */ screenClear(); bDev = binfo->bios_dev; kprintf("Slice: [%i]\n",B_SLICE(bDev)); kprintf("Unit: [%i]\n",B_UNIT(bDev)); kprintf("Partition: [%i]\n",B_PARTITION(bDev)); kprintf("Type: [%i]\n",B_TYPE(bDev)); kprintf("Version: [0x%X]\n",binfo->version); kprintf("Kernel: [%s]\n",(char *)binfo->kernel); kprintf("BIOS Used: [0x%X]\n",binfo->bios_used); kprintf("BI Size: [0x%X]\n",binfo->bi_size); kprintf("BIOS Dev: [0x%X]\n",binfo->bios_dev); kprintf("Base Mem: [0x%X]\n",binfo->bi_basemem); kprintf("Ext Mem: [0x%X]\n",binfo->bi_extmem); kprintf("GEOM[0]: [0x%X]\n",binfo->bios_geom[0]); kprintf("GEOM[1]: [0x%X]\n",binfo->bios_geom[1]); kprintf("GEOM[2]: [0x%X]\n",binfo->bios_geom[2]); kprintf("GEOM[3]: [0x%X]\n",binfo->bios_geom[3]); kprintf("GEOM[4]: [0x%X]\n",binfo->bios_geom[4]); kprintf("GEOM[5]: [0x%X]\n",binfo->bios_geom[5]); kprintf("GEOM[6]: [0x%X]\n",binfo->bios_geom[6]); kprintf("GEOM[7]: [0x%X]\n",binfo->bios_geom[7]); kprintf("End Com: [0x%X]\n",binfo->bi_endcommon); /* Modify src/sys/include/ubixos/init.h to add a startup routine */ for (i = 0x0;i < init_tasksTotal;i++) { if (init_tasks[i]() != 0x0) { kpanic("Error: Initializing System.\n"); } } /* New Root Mount Point */ //Old 2 new 10 //#ifdef DEBUG //kprintf("[0x%X][0x%X:0x%X:0x%X:0x%X:0x%X:0x%X]\n",rootdev,B_ADAPTOR(rootdev),B_CONTROLLER(rootdev),B_SLICE(rootdev),B_UNIT(rootdev),B_PARTITION(rootdev),B_TYPE(rootdev)); //#endif //if (vfs_mount(0x1,B_PARTITION(rootdev)+2,0x0,0xAA,"sys","rw") != 0x0) { if (vfs_mount(0x1,0x1,0x0,0xAA,"sys","rw") != 0x0) { kprintf("Problem Mounting sys Mount Point\n"); } /* Do our mounting */ /* if (vfs_mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) { kprintf("Problem Mounting sys Mount Point\n"); } if (vfs_mount(0x0,0x0,0x1,0x0,"tmp","rw") != 0x0) { kprintf("Problem Mounting tmp Mount Point\n"); } */ /* Initialize the system */ kprintf("Free Pages: [%i]\n",systemVitals->freePages); kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); kprintf("Starting UbixOS\n"); sysTask = kmalloc(0x2000); if(sysTask == NULL) kprintf("OS: Unable to allocate memory\n"); execThread(systemTask, (uInt32)sysTask+0x2000,0x0); execFile("sys:/bin/init",0x0,0x0,0x0); /* OS Initializer */ //execFile("sys:/bin/login",0x0,0x0,0x1); //execFile("sys:/bin/login",0x0,0x0,0x2); irqEnable(0x0); while (0x1) asm("hlt"); /* Keep haulting until the scheduler reacts */ /* Return to start however we should never get this far */ return(0x0); } /*** END ***/