Newer
Older
ubixos / src / sys / init / main.c
@reddawg reddawg on 30 Aug 2002 7 KB working on new bootloader
/**************************************************************************************
 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.

 $Id$

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

#include <ubixos/gdt.h>
#include <ubixos/schedule.h>
#include <ubixos/idt.h>
#include <ubixos/exec.h>
#include <ubixos/idlethread.h>
#include <ubixos/vitals.h>
#include <drivers/video.h>
#include <drivers/8259.h>
#include <drivers/keyboard.h>
#include <drivers/fdc.h>
#include <version/version.h>
#include <vmm/memory.h>
#include <vmm/paging.h>
#include <ubixfs/ubixfs.h>
#include <ubixfs/file.h>


descriptorTable(GDT,5) {
  {dummy:0},
  standardDescriptor(0, 0xFFFFF, (dCode + dRead + dBig + dBiglim)),
  standardDescriptor(0, 0xFFFFF, (dData + dWrite + dBig + dBiglim)),
  standardDescriptor(0, 0xFFFFF, (dLdt)),
  standardDescriptor(100000, (sizeof(struct tssStruct)-1), (dTss)),
  };

struct {
  unsigned short limit __attribute__ ((packed));
  union descriptorTableunion *gdt __attribute__ ((packed));
  } loadGdt = { (5 * sizeof(union descriptorTableunion) - 1), GDT };

typedef signed char        Int8;
typedef signed short int   Int16;
typedef signed long int    Int32;

typedef unsigned char      UInt8;
typedef unsigned short int UInt16;
typedef unsigned long int  UInt32;

typedef struct {
          UInt16 ModeAttributes;
          UInt8  WindowAFlags;
          UInt8  WindowBFlags;
          UInt16 Granularity;
          UInt16 WindowSize;
          UInt16 WindowASeg;
          UInt16 WindowBSeg;
          void*  BankSwitch;
          UInt16 BytesPerLine;
          UInt16 xRes, yRes;
          UInt8  CharWidth;
          UInt8  CharHeight;
          UInt8  NumBitPlanes;
          UInt8  BitsPerPixel;
          UInt8  NumberOfBanks;
          UInt8  MemoryModel;
          UInt8  BankSize;
          UInt8  NumOfImagePages;
          UInt8  Reserved;
          // Direct colour fields (required for Direct/6 and YUV/7 memory models
          UInt8  RedMaskSize;
          UInt8  RedFieldPosition;
          UInt8  GreenMaskSize;
          UInt8  GreenFieldPosition;
          UInt8  BlueMaskSize;
          UInt8  BlueFieldPosition;
          UInt8  RsvdMaskSize;
          UInt8  RsvdFieldPosition;
          UInt8  DirectColourMode;
          // VESA 2.0 specific fields
          UInt32 PhysBasePtr;
          void*  OffScreenMemOffset;
          UInt16 OffScreenMemSize;
          UInt8  paddington[461];
        } TMode_Rec;

typedef struct {
          char    VBESignature[4];
          UInt8   minVersion;
          UInt8   majVersion;
          char *  OEMStringPtr;
          UInt32  Capabilities;
          UInt16* VideoModePtr;
          UInt16  TotalMemory;
          // VESA 2.0 specific fields
          UInt16  OEMSoftwareRev;
          char *  OEMVendorNamePtr;
          char *  OEMProductNamePtr;
          char *  OEMProductRevPtr;
          UInt8   paddington[474];
        } TVESA_Rec;
                
int main();

void _start(void) {
  asm("cli");
  asm(
    "lgdtl (loadGdt)   \n"
    "movw $0x10,%ax    \n"
    "movw %ax,%ds      \n"
    "movw %ax,%es      \n"
    "movw %ax,%fs      \n"
    "movw %ax,%gs      \n"
    "movw %ax,%ss      \n"
    "movl $0xFFFF,%esp \n"
    "mov $0x18,%ax     \n" //Set up dummy LDT
    "lldt %ax          \n"
    "mov $0x20,%ax     \n" // Set up dummy TSS
    "ltr %ax           \n" // Loads dummy TSS
    );
  main(); //Start Of Kernel Functionality
  while(1);
  }

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

Function: int main();
Description: This Is The Main Kernel Function Does All The Initialization
             Then Starts The INIT Program Which Will Take Over
Notes:

07/30/02 - I'm Considering Making The Kernel Fork Then Execute INIT
           However It Seems To Be Pretty Stable As Is

************************************************************************/  
int main() {
  /*
  long i = 0x0;
  long xx = 0x0,yy = 0x0,zz = 0x0;
  uLong *testBuffer = 0x40000000;
  TMode_Rec *testVesa = 0x1000;
  */  
  initMmap();         //Initialize Memory Map
  clearScreen();      //Clear The Screen
  outputVersion();    //Display Version Info
  initPagingSystem(); //Initialize Paging System
  initVitals();       //Initialize Vitals Tracking
  init8259();         //Initialize PIC
  initIdt();          //Initialize IDT
  initKeyboard();     //Initialize Keyboard
  initScheduler();    //Initialize Scheduler
  initFloppy();       //Initialize Floppy Controller
  initUbixFS();       //Initialize File System
  /*
  kprintf("PhysBasePtr:   [%i]\n",testVesa->PhysBasePtr);
  kprintf("BytesPerLine:  [%i]\n",testVesa->BytesPerLine);
  kprintf("xRes:          [%i]\n",testVesa->xRes);
  kprintf("yRes:          [%i]\n",testVesa->yRes);
  kprintf("BitsPerPixel:  [%i]\n",testVesa->BitsPerPixel);
  kprintf("NumberOfBanks: [%i]\n",testVesa->NumberOfBanks);
  while(1);
  */

  /*
  for (i=0;i<=(((testVesa->xRes*testVesa->yRes)*(testVesa->BitsPerPixel/1))+(0x1000-1));i+=0x1000) {
    remapPage((testVesa->PhysBasePtr + i),(0x40000000 + i));
    }
  while (1) {
    for (zz=0; zz<64; zz++)
      for (yy=-128; yy<=128; yy++)
        for (xx=-128; xx<=128; xx++)
          testBuffer[(yy+128)*(800*2)+((xx+128)*2)]=xx*yy*zz;
    for (zz=0; zz<64; zz++)
      for (yy=128; yy>=-128;yy --)
        for (xx=128; xx>=-128; xx--)
          testBuffer[(yy+128)*(800*2)+((xx+128)*2)]=xx*yy*zz;
    }
  */
  /*
  for (yy = 0;yy < 256;yy++) {
    for (xx = 0;xx < 256;xx++) {
      testBuffer[yy*800+xx] = (char)xx;
      }
    }
  */
  /*   
  for (i=0;i<((testVesa->xRes*testVesa->yRes)*4);i++) {
    for (zz=0;zz<=0x10;zz++) {
      for (xx=0;xx<=0x10;xx++);
      }
    testBuffer[i] = i;
    }

  for (i=0;i<((testVesa->xRes*testVesa->yRes)*4);i++) {
    for (zz=0;zz<=0x10;zz++) {
      for (xx=0;xx<=0x10;xx++);
      }
    testBuffer[i] = (i/2);
    }
  */        
  execThread(idleThread,0xAFFF,"Idle Thread");
  execFile("init");
  kprintf("Free Pages: [%i]\n",freePages);
  enableIrq(0);
  while (1);
  }