Newer
Older
ubix-32 / src / sys / init / main.c
@reddawg reddawg on 6 Nov 2004 3 KB Fixens
/*****************************************************************************************
 Copyright (c) 2002-2004 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 <sys/gdt.h>
#include <sys/tss.h>
#include <lib/kprintf.h>
#include <ubixos/init.h>
#include <mpi/mpi.h>
#include <isa/fdc.h>

/*****************************************************************************************
 Desc: The Kernels Descriptor table:
       0x00 - Dummy Entry
       0x08 - Ring 0 CS
       0x10 - Ring 0 DS 
       0x18 - Ring 3 CS
       0x20 - Ring 3 DS
       0x28 - Dummy LDT
       0x30 - GPF TSS
       0x38 - Stack Fault TSS
       0x40 - Task TSS

 Notes: 
 
   The lower 1mb memory:
     Conventional Memory - memory from 0x00000 to 0x9FFFF hex (0 to 640 K byte)
     Reserved Memory     - memory from 0xA0000 to 0xFFFFF hex (640 K byte to 1 MB)
     
     0x00000 - 0x00FFF - Reserved
     0x01000 - 0x03FFF - Reserved
     0x04000 - 0x05FFF - GPF TSS
     0x06000 - 0x07FFF - Stack Fault TSS
     0x08000 - 0x09FFF - Task TSS
     0x10000 - 0x2FFFF - Reserved
     0x30000 - 0x9FFFF - Kernel
     
   

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

int main() {
  int i = 0x0;

  /* Modify src/sys/include/ubixos/init.h to add a startup routine */
  for (i=0x0;i<init_tasksTotal;i++) {
    if (init_tasks[i]() != 0x0) {
      kprintf("Error: Initializing System.\n");
      }
    }


  while (1) asm("hlt");
  
  return(0x0);
  }

/***
 END
 ***/