Trivial Solutions The LoseThos 64-bit PC Operating System File:/LT/Adam/Boot/InsBoot.APZ 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. #help_index "Install" //See Install Documentation or Upgrading Documentation. //OSMain binary #define BOOT_BIC "Boot.BIC" #define BOOT_DIR "/0000Boot" //OSMain binary #define BOOT1_BIC "/0000Boot/Boot.BIC" //Patched part 2 of hard drive mbr boot loader BootMHD2 #define BOOT_LOADER_BIC "/0000Boot/BootLoader.BIC" #define OLD_BOOT_BIC "/0000Boot/OldMBR.BIC" //patched version of BootCD.BIZ #define CD_BOOT "/0000Boot/CDBoot.BIZ" if (IsDrvWritable) { PutS("BootCD ");Cmp("BootCD"); PutS("BootHD ");Cmp("BootHD"); PutS("BootMHD ");Cmp("BootMHD"); PutS("BootMHD2");Cmp("BootMHD2"); MkDir("/Temp"); //Good to have a Temp } Load("BootCD",LDF_NO_ABSS); Load("BootHD",LDF_NO_ABSS); Load("BootMHD",LDF_NO_ABSS); Load("BootMHD2",LDF_NO_ABSS); #help_index "Install;File/Install Related;File/CD DVD" public BoolI64 CDBootFileCreate() { U8 *br; U64 d,size; U16 *ww; LTFile *f=FOpen(BOOT1_BIC,"r"); size=FSize(f); FClose(f); br=CAlloc(CD_BOOT_LOADER_SIZE); ww=BCD_BLK_CNT; *ww=(size+CD_BLK_SIZE-1)/CD_BLK_SIZE; //After preboot + CDBoot.BIZ comes Boot.BIC //CDBOOT //No emulation d=1+(CD_FILE_OFFSET+CD_BOOT_LOADER_SIZE/BLK_SIZE)/(CD_BLK_SIZE>>BLK_SIZE_BITS); ww=BCD_BLK_LO; *ww=d.u16[0]; ww=BCD_BLK_HI; *ww=d.u16[1]; MemCpy(br,BCD_START,BCD_END-BCD_START); FileWrite(CD_BOOT,br,CD_BOOT_LOADER_SIZE); Free(br); return TRUE; } if (IsDrvWritable) CDBootFileCreate; #help_index "Boot" public U0 Boot(U8 *filename) //Soft Reboot (no hardware rst) //Specify the OSMain binary file you //wish to boot. { U64 size; OSMainStruct *hi_image,*lo_image=sys_boot_base-sizeof(BinFileHeaderStruct), reg *shutdown,*hi_image2; if (!(hi_image2=FileRead(filename,&size))) return; switch (snd_dev) { case SD_PC_SPEAKER: break; case SD_HD_AUDIO: CallExtStr("HDAudioEnd",TRUE); break; } shutdown=MAlloc(SYS_RESTART_OSMAIN_END-SYS_RESTART_OSMAIN,Fs->code_heap); hi_image=MAlloc(size,Fs->code_heap); MemCpy(hi_image,hi_image2,size); Free(hi_image2); hi_image->boot_base=lo_image><(U8 *)+sizeof(BinFileHeaderStruct); hi_image->boot_patch_table_base=lo_image><(U8 *)+hi_image->h.loader_patch_table_offset; MemCpy(&hi_image->sys_mem_E801,&lo_image->sys_mem_E801,2*2); MemCpy(&hi_image->sys_mem_E820,&lo_image->sys_mem_E820,NUM_MEM_E820_ENTRIES*MEM_E820_ENTRY_SIZE); hi_image->sys_gr_mode=lo_image->sys_gr_mode; hi_image->sys_pci_busses=lo_image->sys_pci_busses; hi_image->boot_code=BOOT_CODE_RAM; Cli; if (mp_cnt>1) MPHalt; MemCpy(shutdown,SYS_RESTART_OSMAIN,SYS_RESTART_OSMAIN_END-SYS_RESTART_OSMAIN); MemCpy(&hi_image->sys_gdttab,&lo_image->sys_gdttab,sizeof(GdtTabStruct)*MAXGDT); MemCpy(lo_image,hi_image,size); HiCall(shutdown); } #help_index "Install" U0 InstallLTDir(U8 src,U8 dst) { U8 buf_s[64],buf_d[64]; if (src==dst) return; SPrintF(buf_s,"%c:/LT",src); SPrintF(buf_d,"%c:/LT",dst); DelTree(buf_d); CopyTree(buf_s,buf_d); } U8 ChkWritable(U8 drv_let=0) { BoolI8 cont=TRUE; U8 writable_drv=drv_let; LTPrt *p; LTBlkDev *bdev; if (!IsDrvWritable(drv_let)) { PutChar(drv_let); PutS(": Drive is read-only.\r\n"); while (cont) { PutS("Enter RAM drive (usually 'B') for temporary files:"); writable_drv=ToUpper(GetChar); CrLf; p=Drv2Prt(writable_drv); bdev=p->bdev; if (bdev->type!=LTBDT_RAM || !IsDrvWritable(writable_drv)) PutS("Not A RAM Drive\r\n"); else cont=FALSE; } Fmt(writable_drv,FALSE,FALSE); InstallLTDir(drv_let,writable_drv); } return writable_drv; } #help_index "Install" U0 BootImageCreate(U8 src_drv,U8 dst_drv,U64 *out_size,U8 *filename) { LTPrt *p; U8 *buf; Drv(src_drv); Cd("/LT/Compiler"); if (Cmp("Compiler","Compiler",NULL,':')) throw; Cd("/LT/OSMain2"); if (Cmp("OSMain2","OSMain2",NULL,':')) throw; Cd("/LT/OSMain"); if (Cmp("OS","OS",NULL,':')) throw; buf=FileRead("OS.BIZ",out_size); filename[StrLen(filename)-1]='C'; PrintF("Creating %s from OS.BIZ\r\n",filename); Drv(dst_drv); Cd("/"); p=Fs->cur_prt; PrintF("Size:%X\r\n",*out_size); FileWrite(filename,buf,*out_size,0,LT_ATTR_FIXED|LT_ATTR_CONTIGUOUS,FALSE); Free(buf); Drv(src_drv); Del("/LT/OSMain/OS.BIZ"); } public BoolI64 InstallBoot(U8 src_drv,U8 dst_drv=0,BoolI8 cfg_mgr=TRUE) { //Normally, you just supply a src_drv. It will compile //the code on that drive and update the boot sect. //If you are making a bootable CD-ROM you supply a dst_drv. //See Bootable CD-ROMs //See Install Documentation //Study my account examples my technique Cfg Strs Update Funs BoolI8 result=FALSE; LTBlkDev *bdev; LTPrt *p; FAT32BootStruct br; LTDirEntry de; U64 *dd,i,size; U8 *bb; U16 *ww; if (cfg_mgr) CfgStart(CFG_LT_MAIN); try { if (!src_drv) src_drv=Fs->cur_prt->drv_let; if (!dst_drv) dst_drv=src_drv; //This passes a cfg arg for //compilation of OSMain which is accessed //within a #exe {} statement. //See InsBootDstDrv NamedFramePtrAdd("InsBootDstDrv",dst_drv); bdev=Drv2BlkDev(dst_drv); switch (bdev->type) { case LTBDT_ATAPI: BootImageCreate(src_drv,src_drv,&size,BOOT1_BIC); Drv(src_drv); CDBootFileCreate; result=TRUE; goto ib_done; case LTBDT_RAM: case LTBDT_ATA: case LTBDT_NON_LT_FILE: break; default: result=FALSE; goto ib_done; } Drv(dst_drv); p=Fs->cur_prt; if (p->type!=PT_LT && p->type!=PT_FAT32) PutDefineErr("ST_NOT_LT"); else { src_drv=ChkWritable(src_drv); BootImageCreate(src_drv,dst_drv,&size,BOOT_BIC); Drv(dst_drv); RBlks(p,&br,p->offset,1); if (!FileFind(BOOT_BIC,&de,FALSE,TRUE)) PutS("No image\r\n"); else { PutS("Modifying partition boot record.\r\n"); br.jump_and_nop[0]=0xEB; br.jump_and_nop[1]=0x58; br.jump_and_nop[2]=0x90; switch (bdev->type) { case LTBDT_ATA: case LTBDT_NON_LT_FILE: ww=BHD_BLK_CNT; *ww=(size+BLK_SIZE-1)>>BLK_SIZE_BITS; dd=BHD_DAP_BLK; *dd=p->data+de.cluster*p->spc; bb=BHD_CODE; for (i=0;i<BHD_END-BHD_CODE;i++) br.code[i]=bb[i]; break; } for (;i<420;i++) br.code[i]=0; WBlks(p,&br,p->offset,1); result=TRUE; } } ib_done: if (cfg_mgr) CfgEnd; } catch if (cfg_mgr) CfgEnd; NamedFramePtrDel("InsBootDstDrv"); return result; } public U0 OldMasterBootRead(U8 src_drv,U8 dst_drv) { LTBlkDev *bdev; LTPrt *p,*p2; MasterBootStruct mbr; bdev=Drv2BlkDev(src_drv); try { while (bdev->non_lt_drv) { p2=Drv2Prt(bdev->non_lt_drv); bdev=Drv2BlkDev(Prt2Drv(p2)); } } catch Fs->catch_except=TRUE; Drv(dst_drv); p=Fs->cur_prt; if (p->type!=PT_LT && p->type!=PT_FAT32) PutDefineErr("ST_NOT_LT"); else { //Bypass partition bounds-checking BlkDevLock(bdev); ATAReadBlks(bdev,&mbr,0,1); BlkDevUnlock(bdev); Drv(dst_drv); MkDir(BOOT_DIR); FileWrite(OLD_BOOT_BIC,&mbr,BLK_SIZE); } } public U0 OldMasterBootWrite(U8 src_drv,U8 dst_drv) { LTBlkDev *bdev; MasterBootStruct *mbr; LTPrt *p2; bdev=Drv2BlkDev(dst_drv); try { while (bdev->non_lt_drv) { p2=Drv2Prt(bdev->non_lt_drv); bdev=Drv2BlkDev(Prt2Drv(p2)); } } catch Fs->catch_except=TRUE; Drv(src_drv); mbr=FileRead(OLD_BOOT_BIC); if (mbr) { //Bypass partition bounds-checking BlkDevLock(bdev); ATAWriteBlks(bdev,mbr,0,1); BlkDevUnlock(bdev); } Free(mbr); } public U0 MasterBootZero(U8 dst_drv) { //This is dangerous!! //The LoseThos parter doesn't play well //with other operating systems at this time and you need //to do this on a drive partitioned by LoseThos //if you wish to partition with another operating system. LTBlkDev *bdev; MasterBootStruct mbr; LTPrt *p2; bdev=Drv2BlkDev(dst_drv); try { while (bdev->non_lt_drv) { p2=Drv2Prt(bdev->non_lt_drv); bdev=Drv2BlkDev(Prt2Drv(p2)); } } catch Fs->catch_except=TRUE; MemSet(&mbr,0,BLK_SIZE); //Bypass partition bounds-checking BlkDevLock(bdev); ATAWriteBlks(bdev,&mbr,0,1); BlkDevUnlock(bdev); } public BoolI64 InstallMasterBoot(U8 drv_let,U8 *drv_list=NULL) { BoolI8 result=FALSE; LTBlkDev *bdev,*bd1; LTPrt *p,*p1,*p2; MasterBootStruct mbr; LTDirEntry de; U64 i,j,size,*dd; U8 *bb; U16 *ww; U8 *menu_ptr,*ptr,ch,buf[128],buf2[128]; try { if (drv_list) StrCpy(buf2,drv_list); else { j=0; for (i='A';i<='Z';i++) buf2[j++]=i; buf2[j++]=0; } Drv(drv_let); p=Fs->cur_prt; if (p->type!=PT_LT && p->type!=PT_FAT32) PutDefineErr("ST_NOT_LT"); else { bdev=Drv2BlkDev(drv_let); try { while (bdev->non_lt_drv) { p2=Drv2Prt(bdev->non_lt_drv); bdev=Drv2BlkDev(Prt2Drv(p2)); } } catch Fs->catch_except=TRUE; if (!FileFind(OLD_BOOT_BIC,&de,FALSE,TRUE)) OldMasterBootRead(drv_let,drv_let); dd=BMHD2_BLK_ARRAY; MemSet(dd,0,sizeof(U64)*8); menu_ptr=BMHD2_BOOT_MSG; SPrintF(menu_ptr,"\r\n\r\nLoseThos Boot Loader\r\n\r\n"); j=0; if (FileFind(OLD_BOOT_BIC,&de,FALSE,TRUE)) { *dd++=p->data+de.cluster*p->spc; StrCat(menu_ptr,"0. Old Boot Record\r\n"); j++; } ptr=buf2; while (ch=*ptr++) { try p1=Drv2Prt(ch); catch { Fs->catch_except=TRUE; p1=NULL; } if (p1) { bd1=p1->bdev; try { while (bd1->non_lt_drv) { p2=Drv2Prt(bd1->non_lt_drv); bd1=Drv2BlkDev(Prt2Drv(p2)); } } catch Fs->catch_except=TRUE; if (bd1==bdev) { *dd=p1->offset; PrintF("Drive %c:%16X\r\n",Prt2Drv(p1),*dd); SPrintF(buf,"%d. Drive %c\r\n",j++,Prt2Drv(p1)); StrCat(menu_ptr,buf); dd++; } } } StrCat(menu_ptr,"\r\nSelection:"); size=BMHD2_END-BMHD2_START; FileWrite(BOOT_LOADER_BIC,BMHD2_START,size); if (!FileFind(BOOT_LOADER_BIC,&de,FALSE,TRUE)) PutS("No Boot Loader Image\r\n"); else { ww=BMHD_BLK_CNT; *ww=(size+BLK_SIZE-1)>>BLK_SIZE_BITS; dd=BMHD_DAP_BLK; *dd=p->data+de.cluster*p->spc; bb=BMHD_CODE; //Bypass partition bounds-checking BlkDevLock(bdev); ATAReadBlks(bdev,&mbr,0,1); for (i=0;i<BMHD_END-BMHD_CODE;i++) mbr.boot_code[i]=bb[i]; for (;i<440;i++) mbr.boot_code[i]=0; if (!mbr.media_id) mbr.media_id=RandU32; mbr.zero=0; mbr.signature=0xAA55; ATAWriteBlks(bdev,&mbr,0,1); BlkDevUnlock(bdev); result=TRUE; } } } catch CatchAll; return result; } #help_index "Boot" /* These routines are intended for use when booted to the production CD. They allow compiling and booting the RAM Drive 'B'. These are good when you are trying to get a new system working and you don't want to burn a CD-ROM for each attempt. If you alter the kernel, the RAM drive might shift to a new location and data will not be recognized. */ public U0 CmpProdCDROM(U8 src_drv,U8 dst_drv=0) { Auto(PROD_CDROM_CFG); InstallBoot(src_drv,dst_drv,FALSE); } public U0 Install2RAMDrv(U8 src_drv='T',U8 dst_drv='B') { U8 buf_s[64],buf_d[64]; Fmt(dst_drv,TRUE,FALSE); SPrintF(buf_s,"%C:/",src_drv); SPrintF(buf_d,"%C:/",dst_drv); CopyTree(buf_s,buf_d); CmpProdCDROM(dst_drv); } public U0 Boot2RAMDrv(U8 drv_let='B') { U8 buf[64]; CmpProdCDROM(drv_let); SPrintF(buf,"%C:/Boot.BIC",drv_let); Boot(buf); } #help_index ""