Trivial Solutions
                    The LoseThos 64-bit PC Operating System
File:/LT/OSMain/OSMain.CPZ
This, and all LoseThos files, are public domain.  Do whatever you like.
God is watching; God is just; God is never out-done in generosity.  He talks!

LoseThos code compiles with the 64-bit LoseThos compiler/assembler I wrote.
Boot the LoseThos CD and you can compile it.  Not in Kansas anymore!

Click here for preliminary compiler information you need.

Project: OSMain

U0 SysGlbls2Init()
{
//Simple initializations go in SysGlblsInit.
  I64 i,j;
  U8 *m;

  InDbg(ON);

  reverse_bits_table=CAlloc(256);
  for (i=0;i<256;i++)
    for (j=0;j<8;j++)
      if (Bt(&i,7-j))
        LBts(reverse_bits_table+i,j);
  set_bits_table=CAlloc(256);
  for (i=0;i<256;i++)
    for (j=0;j<8;j++)
      if (Bt(&i,j))
        set_bits_table[i]++;

  ext=CAlloc(EXT_TABLE_SIZE*sizeof(U0 *));
  fp_ctrl_alt_let_cbs=CAlloc(26*sizeof(U0 *));
  ctrl_alt_let_descs=CAlloc(26*sizeof(U8 *));;
  ctrl_alt_let_in_irq_flags=0;

  StrCpy(sys_temp_filename,"HOME/Temp.TXZ");
  MemSet(&sys_put_key_root,0,sizeof(KeyDevStruct));
  sys_put_key_root.next=sys_put_key_root.last=&sys_put_key_root;
  KeyDevAdd(&AKDInputFilterPutKey,&AKDInputFilterPutS,0x40000000,FALSE);
  KeyDevAdd(&AKDTaskPutKey,&AKDTaskPutS,0x50000000,TRUE);
  KeyDevAdd(&AKDRawDisplayPutKey,&AKDRawDisplayPutS,0x60000000,FALSE);
  #exe {
    StreamPrintF("sys_startup_acct=\"%s\";",osmain_cfg->startup_acct);
    StreamPrintF("LTDCInit(%d);",osmain_cfg->dsk_cache_size);
  };
  pow10_I64=CAlloc(sizeof(F64)*(308+308+1));
  for (i=-308;i<309;i++)
    pow10_I64[i+309]=Pow10(i);

//Independent Heap Ctrl Example
  i=1; //Request 1 blk, we might get more.
  m=AllocUncachedMemBlks(&i,sys_code_bp);
  sys_uncached_heap=IndependentHeapCtrlInit(m,i*0x200000/0x200);

  for (i=0;i<NUM_PROGRESS_BARS;i++)
    progress_descs[i]=AMAlloc(PROGRESS_DESC_LEN+1);
  ProgressBarsReset;
}

U0 SndInit()
{
  snd_dev=SD_PC_SPEAKER;
  snd_vol=0.1;
  snd_reverb_intensity=0.2;
  snd_reverb_delay=0.3;
  snd_record=FALSE;
}

U0 GrInit()
{
//See SYS_GR_MODE
//See ::/LT/Adam/Gr/GrConfig.APZ

  sys_dc_col=0;
  sys_dc_flags=0;
  gr_font=sys_font_8x8;
  if (gr_mode==0x12) {
    text_mode=FALSE;
    gr_width =640;
    gr_height=480;
    text_cols=gr_width/FONT_WIDTH;
    text_rows=gr_height/FONT_HEIGHT;
    OutU8(VGA_SC_INDEX,VGA_MAP_MASK);
    OutU8(VGA_SC_DATA,0x0F);
    MemSet(VGA_GRAPHIC_MEM_BASE,0,gr_width*gr_height>>3);
    sys_dc_screen_image=CAlloc(gr_width*gr_height/8);
  } else {
    text_mode=TRUE;
    gr_width =640;
    gr_height=480;
    text_cols=80;
    text_rows=25;
    MemSet(VGA_TEXT_MEM_BASE,0,text_rows*text_cols<<1);
  }
}


U0 TimersInit()
{
  U64 i,*qq;
  U32 *dd;

  OutU8(0x43,0x34);
  OutU8(0x40,SYS_TIMER0_PERIOD);
  OutU8(0x40,SYS_TIMER0_PERIOD>>8);

// High Precision Event Timer

  if (PCIReadU16(0,31,0,0)==0x8086) { //Intel?
    //D31 F0, config 0xF0=RCBA of PCI-LPC Bridge
    dd=PCIReadU32(0,31,0,0xF0)><(U8 *)&~0x3FFF+0x3404; //HPET config
  //7   enable
  //1:0 HPET is at 0xFED00000,0xFED01000, 0xFED02000 or 0xFED03000.
    *dd=*dd&3|0x80;
  }

  qq=HPET_GCAP_ID;
  i=*qq; //i.u32[1]= period in femtoS (10e-15)
  if (100000<i.u32[1]<1000000000) {
    HPET_freq    =1000000000000000/i.u32[1];
    HPET_kHz_freq=1000000000000/i.u32[1];
    qq=HPET_GEN_CONF;
    *qq|=1; //Enable counting
  } else {
    HPET_freq=0;
    HPET_kHz_freq=0;
  }
}

U0 IntsInit()
{
//Init 8259
  OutU8(0x20,0x11); //IW1
  OutU8(0xA0,0x11); //IW1
  PortNop;
  OutU8(0x21,0x20); //IW2
  OutU8(0xA1,0x28); //IW2
  PortNop;
  OutU8(0x21,0x04); //IW3
  OutU8(0xA1,0x02); //IW3
  PortNop;
  OutU8(0x21,0x0D); //IW4
  OutU8(0xA1,0x09); //IW4
  PortNop;
  OutU8(0x21,0xFA); //Mask all but IRQ0 (timer) and IRQ2 Cascade
  OutU8(0xA1,0xFF);
  PortNop;
}

U0 Reboot()
{
  U16 *d=0x472;
  Cli;
  if (mp_cnt>1)
    MPHalt;
  MemMarkPresent(d,TRUE);
  *d=0;
  OutU8(0x70,0x8F);
  OutU8(0x71,0x00);
  OutU8(0x70,0x00);
  OutU8(0x92,InU8(0x92)|1);
  SysHlt;
}

U0 OSMain()
{ //Continued from OSMain
  adam_task=Fs;
  HeapsInit;
  LBts(&sys_run_level,RLf_FULL_HEAP);
  Fs->hash_table=HashTableNew(ADAM_HASH_SIZE,Fs);

  SysGlblsInit;
  SysGlbls2Init;
  Mem32BitDevInit;
  MemMarkPagesNotPresent;
  LoadOSMainHeader;
  GrInit;
  SndInit;
  StrCpy(Fs->task_name,"Adam Task CPU#0");
  StrCpy(Fs->task_title,Fs->task_name);
  Fs->text_attr=WHITE<<4+PURPLE;
  Fs->border_attr=WHITE<<4+LTPURPLE;
  Fs->win_right=text_cols-2;
  Fs->win_top++;
  TaskDerivedValsUpdate;

  LoadSysStrs;
  MPInit;
  IDTInit;

//Before this point use Snd() and BusyWait()
//to debug.  After this point, use DbgNum()
  LBts(&sys_run_level,RLf_RAW);

  if (BIOSTotalMem<500*0x100000)
    Dbg("Requires 512 Meg of RAM Memory");

  TimersInit;
  IntsInit;

  coutln "Enable IRQ's";
  SetFlags(SYS_NORMAL_RFLAGS);
  LBts(&sys_run_level,RLf_INTERRUPTS);

  TimeStampFreqCal;

  Preempt(ON);

#exe {
  if (!osmain_cfg->opts[CFG_NO_MP])
    StreamPutS("coutln \"MultiCore Start\";"
               "MPStart;");
};
  LBts(&sys_run_level,RLf_MP);

//  USBInitAll;

  KbdMouseVarsInit;
  IPVarsInit;
  KbdInit;

  //Just call directly if debugging
  //MouseDriverInstall;
  if (mp_cnt>1)
    MPSpawn(&MouseDriverInstall);
  else
    Spawn(&MouseDriverInstall);

  coutln "BlkDevsInitAll";
  BlkDevsInitAll;
  coutln "BlkDevsInitAll Done";
#exe {
  if (osmain_cfg->cdrom_ports_pmt)
    StreamPutS("if (boot_drv_pmt) PutDefine(\"ST_CDROM_PORTS_PMT\");");
};
  DrvDftSelect;
  HomeDirReset;
  LBts(&sys_run_level,RLf_DSK);

  coutln "Loading Compiler";
  Cd("/LT/Compiler");
  Load("Compiler",LDF_SILENT);
  time_stamp_freq_initial=TimeStampFreqCal;
  InDbg(OFF);
  LBts(&sys_run_level,RLf_COMPILER);

  coutln "Loading OSMain2";
  Cd("/LT/OSMain2");
  //This runs the start-up scripts.
  //See OSMain2().
  Load("OSMain2",LDF_SILENT);

  LBts(&sys_run_level,RLf_ADAM_SERVER);
  ServantTaskCont; //Never to return
}

asm {   ALIGN   16,OC_NOP
SYS_OSMAIN_END::}
Historical capture: 2010-11-23. Home | Power on LoseThos | Sources and changes