Newer
Older
ubixos / src / sys / init / main.c
@reddawg reddawg on 4 May 2004 7 KB Ok Mark Cleaned Up Boot This
/*****************************************************************************************
 Copyright (c) 2002 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.

 $Log$
 Revision 1.16  2004/05/02 14:34:21  reddawg
 SMP Support Thanks To Some Help From Slowcoder now to make it interface
 well with the rest of the kernel

 Revision 1.15  2004/04/30 17:04:23  reddawg
 Ok GUI is back on

 Revision 1.14  2004/04/30 16:58:37  reddawg
 Turned On PCI Detections

 Revision 1.13  2004/04/30 16:29:34  reddawg
 Turned Off Gui

 Revision 1.12  2004/04/30 13:40:34  reddawg
 Just doing spring cleaning for the new members

 Revision 1.7  2004/04/26 22:27:36  reddawg
 Now mounts our harddrive I need to either impliment fstab or do something similar

 Revision 1.6  2004/04/25 04:35:50  reddawg
 Minor bug fixes to set default partition information

 Revision 1.107  2004/04/13 16:36:33  reddawg
 Changed our copyright, it is all now under a BSD-Style license


 $Id$

*****************************************************************************************/

#include <sys/gdt.h>
#include <sys/video.h>
#include <sys/idt.h>
#include <sys/tss.h>
#include <vmm/vmm.h>
#include <ubixos/vitals.h>
#include <ubixos/exec.h>
#include <ubixos/kpanic.h>
#include <ubixos/sched.h>
#include <ubixos/idletask.h>
#include <ubixos/time.h>
#include <vfs/mount.h>
#include <lib/kprintf.h>
#include <lib/kmalloc.h>
#include <lib/bioscall.h>
#include <isa/8259.h>
#include <isa/pit.h>
#include <isa/fdc.h>
#include <isa/atkbd.h>
#include <isa/ne2k.h>
#include <vfs/vfs.h>
#include <ubixfs/ubixfs.h>
#include <pci/pci.h>
#include <pci/hd.h>
#include <sde/sde.h>
#include <devfs/devfs.h>
#include <net/net.h>
#include <ubixos/smp.h>

char kernelStack[8192]; // Stack Space For Our Kernel

ubixDescriptorTable(ubixGDT,8) {
  {dummy:0},
  ubixStandardDescriptor(0x0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)),
  ubixStandardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)),
  ubixStandardDescriptor(0x0, 0xFFFFF, (dLdt)),
  ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)),
  ubixStandardDescriptor(0x0, 0xFFFFF, (dCode + dWrite + dBig + dBiglim + dDpl3)),
  ubixStandardDescriptor(0x0, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)),
  ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)),
  };
struct {
  unsigned short limit __attribute__ ((packed));
  union descriptorTableunion *gdt __attribute__ ((packed));
  } loadGDT = { (8 * sizeof(union descriptorTableUnion) - 1), ubixGDT };


int main() {

  // Clear the screen so we have a nice pretty starting place for the os to spew its info
  clearScreen();
  //smpInit();
  // Initialize the kernels vital systems
  // This initialization is for the systems memory and memory map for the os to allocate with
  if (vmmInit() != 0x0) {
    kpanic("Error: Initializing VMM Subsystem.\n");
    }
  // This initialization is for the systems vital information
  if (initVitals() != 0x0) {
    kpanic("Error: Initializing vitals\n");
    }
  // This initialization is for the VFS(Virtual file system) layer
  if (vfsInit() != 0x0) {
    kpanic("Error: Initializing VFS\n");
    }
  if (devFSEnable() != 0x0) {
    kpanic("Error: Enabling devFS\n");
    }
  // This initialization is for the systems PICs for our IRQ handling
  if (init8259() != 0x0) {
    kpanic("Error: Initializing 8259\n");
    }
  // This initialization is for the systems IDT
  if (idtInit() != 0x0) {
    kpanic("Error: Initializing IDT\n");
    }
  // This initialization is for the operating systems scheduler
  if (schedInit() != 0x0) {
    kpanic("Error: Initializing: Scheduler\n");
    }
  // This initialization is for the systems timer
  if (pitInit(1000) != 0x0) {
    kpanic("Error: Initializing PIT\n");
    }
  // This initialization is for the keyboard
  if (keyboardInit() != 0x0) {
    kpanic("Error: Initializing Keyboard\n");
    }
  /*
  if (pciInit() != 0x0) {
    kpanic("Error: Initializing PCI\n");
    }
  */
  if (timeInit() != 0x0) {
    kpanic("Error: Initializing TIME\n");
    }
  if (ne2kInit(0x240) != 0x0) {
    kpanic("Error: Initializing NE2000\n");
    }
  enableUbixFS();
  fdcInit();
  initHardDisk();
  if (mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) {
    kprintf("Problem Mounting sys Mount Point\n");
    }
  if (mount(0x0,0x0,0x1,0x0,"tmp","rw") != 0x0) {
    kprintf("Problem Mounting tmp Mount Point\n");
    }
  /*
  if (mount(0x1,0x1,0x0,0x0,"sys","rw") != 0x0) {
    kprintf("Problem Mounting HD Mount Point\n");
    }
  */
  kprintf("Free Pages: [%i]\n",freePages); 
  kprintf("MemoryMap:  [0x%X]\n",vmmMemoryMap);
  kprintf("Starting Os\n");
  netInit();
  execThread(idleTask,(uInt32)(kmalloc(0x2000,sysID)+0x2000),0x0,"Idle Thread");
  //execFile("init@sys",0x0,0x0,0x0);
  execFile("shell@sys",0x0,0x0,0x0);
  irqEnable(0x0);
  sched();
  return(0x0);
  }

/************************************************************************

Function: _start();
Description: This Is The Kernels Main Entry Point From Here We Must
             Re-Setup Our GDT And Set All Registers To Their Default
             Values So We Are Sure Of No Error When The OS Boots Up Also
             We Have To Quickly Set Up Our Interrupt Table Because We Do
             Not Have Any Fault Protection Yet

Notes:

02/17/03 - I'm Unhappy With The Infinite Loop I Decided To Do If The Call
           To Main Returns I Think I Shall Change It To A Kernel Panic
           At A Later Date Then Reboot The Machine

************************************************************************/
void _start(void) {
  asm ("pushl $2; popf");
  asm volatile(
    "lgdtl (loadGDT)        \n"
    "movw $0x10,%%ax        \n" // Select Ring 0 Data Segment
    "movw %%ax,%%ds         \n" // Set Default Segment
    "movw %%ax,%%es         \n" //   ""           ""
    "movw %%ax,%%fs         \n" //   ""           ""
    "movw %%ax,%%gs         \n" //   ""           ""
    "movw %%ax,%%ss         \n" //   ""           ""
    "movl $0x2000,%%esp     \n" // Set Default Stack Pointer Its The End Of First Page
    "movl $0x2000,%%ebp     \n"
    "mov $0x18,%%ax         \n" // Set Up Dummy LDT
    "lldt %%ax              \n" // Load The Dummy LDT
    "mov $0x20,%%ax         \n" // Set Up Dummy TSS
    "ltr %%ax               \n" // Load The Dummy TSS
    "ljmp $0x08,$next       \n"
    "nop\n"
    "nop\n"
    "next:\n"
    :
    : "r" (ubixGDT), "p" (kernelStack+8192)
    : "%eax"
    );
  main();
  kpanic("We Should Not Get This Far\n");
  }

/***
 END
 ***/