diff --git a/src/bin/init/main.c b/src/bin/init/main.c index 3a173a1..7aaadf4 100755 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -34,7 +34,7 @@ exit(1); } printf("Initializing System.\n"); - if (!fork()) { + if (!fork()) { exec("login"); printf("Error Starting System\n"); } diff --git a/src/bin/login/main.c b/src/bin/login/main.c index 62ff855..73cbe19 100755 --- a/src/bin/login/main.c +++ b/src/bin/login/main.c @@ -46,7 +46,7 @@ printf("Error Opening File"); } fread(data,4096,0,fd); - fclose(fd); + fclose(fd); printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)\n\n"); login: printf("Login: "); diff --git a/src/sys/boot/Makefile.inc b/src/sys/boot/Makefile.inc new file mode 100755 index 0000000..e3011be --- /dev/null +++ b/src/sys/boot/Makefile.inc @@ -0,0 +1,6 @@ +# Common defines for all of /sys/boot/i386/ +# +# $FreeBSD: src/sys/boot/i386/Makefile.inc,v 1.1.2.2 2000/12/28 12:04:04 ps Exp $ + +LOADER_ADDRESS?= 0x200000 +CFLAGS+= -mpreferred-stack-boundary=2 diff --git a/src/sys/include/ubixfs/ubixfs.h b/src/sys/include/ubixfs/ubixfs.h index 8883d5a..b640649 100755 --- a/src/sys/include/ubixfs/ubixfs.h +++ b/src/sys/include/ubixfs/ubixfs.h @@ -27,7 +27,26 @@ #include #include - //Partition Information +#define UBIXDISKMAGIC ((u_int32_t)0x45) /* The disk magic number */ +#define MAXUBIXPARTITIONS 16 + +//Partition Information +struct ubixDiskLabel { + uLong magicNum; + uLong magicNum2; + uShort driveType; + uShort numPartitions; + struct ubixPartitions { /* the partition table */ + uLong p_size; /* number of sectors in partition */ + uLong p_offset; /* starting sector */ + uLong p_fsize; /* filesystem basic fragment size */ + uLong p_bsize; /* BAT size */ + uChar p_fstype; /* filesystem type, see below */ + uChar p_frag; /* filesystem fragments per block */ + } partitions[MAXUBIXPARTITIONS]; + }; + + struct partitionInformation { uLong size; //Size In Sectors uLong startSector; //Base Sector Of Partition @@ -76,9 +95,7 @@ int readFile(char *file); int getFileByte(fileDescriptor *fd,long offset); -extern int startSector; -extern int partitionSize; -extern int rootDirectory; extern struct blockAllocationTableEntry *blockAllocationTable; +extern struct ubixDiskLabel *diskLabel; #endif diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 6167979..c09c029 100755 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -117,6 +117,11 @@ void _start(void) { asm("cli"); asm( + "mov %cr0,%eax \n" + "and $0xFFFFFFFE,%eax \n" + "mov %eax,%cr0 \n" + "or $0x1,%eax \n" + "mov %eax,%cr0 \n" "lgdtl (loadGdt) \n" "movw $0x10,%ax \n" "movw %ax,%ds \n" diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 3bee998..2608544 100755 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -183,3 +183,78 @@ //Return return; } + +/************************************************************************ + +Function: void sysExec(); +Description: This Is The System Call To Execute A New Task +Notes: + +************************************************************************/ +void sysExec() { + int i = 0,x = 0; + int *status; + uLong eStart = 0; + char *binarySpace = (char *)0x7C0000; + char *newLoc; + char *file; + fileDescriptor *tmpFd = 0x0; + elfHeader *binaryHeader = (elfHeader *)0x7C0000; + elfProgramheader *programHeader; + asm("":"=b"(file),"=c"(status)); + asm("sti"); + tmpFd = fopen(file,"r"); + //If We Dont Find the File Return + if (tmpFd == 0x0) { + *status = 0; + return; + } + //Now We Must Allocate Memory To Load The Binary Into + for (i=0;i<((tmpFd->size+4095)/4096);i++) { + remapPage(findFreePage(_current->id),(0x7C0000 + (0x1000 * i))); + } + //Load The Binary Into Memory Byte For Byte I Should Find A Faster Way + for (i=0;feof(tmpFd) == 0;i++) { + binarySpace[i] = fgetc(tmpFd); + } + //Close The File + fclose(tmpFd); + //Set programHeader To Point To Loaded Binary So We Can Gather Info + programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); + //Loop Through The Header And Load Sections Which Need To Be Loaded + for (i=0;iePhnum;i++) { + if (programHeader[i].phType == 1) { + newLoc = (char *)programHeader[i].phVaddr; + /* + Allocate Memory Im Going To Have To Make This Load Memory With Corrent + Settings so it helps us in the future + */ + for (x=0;x<=((programHeader[i].phMemsz & 0xFFFFF000)+4095);x+=4096) { + remapPage(findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + (0x1000 * x))); + _current->vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + (0x1000 * x) + 0x1000); + } + //Now Copy The Binary To Its Correct Location + for (x=0;xeEntry; + //Now That We Relocated The Binary We Can Unmap And Free Old Pages + for (i=0;i<((tmpFd->size+4095)/4096);i++) { + unmapPage((0x7C0000 + (0x1000 * i)),0); + } + //Set Up Args + + //Jump To Start Of New Binary + asm( + "pushl %0\n" + "jmp *%1\n" + : + : "g" (file), "g" (eStart) + ); + } \ No newline at end of file diff --git a/src/sys/kernel/idt.c b/src/sys/kernel/idt.c index 33722c4..f40b8ce 100755 --- a/src/sys/kernel/idt.c +++ b/src/sys/kernel/idt.c @@ -38,10 +38,12 @@ /* Sets Up Initial IDT Table */ void initIdt() { int i=0; + uLong tmp; for (i=15;i<256;i++) { - setVector(intNull, i, dPresent + dInt + dDpl3); + setVector(intNull, i, dPresent + dInt + dDpl1); } asm ( + "cli\n" "lidt (%0) \n" /* Load the IDT */ "pushfl \n" /* Clear the NT flag */ "andl $0xffffbfff,(%%esp) \n" @@ -50,14 +52,14 @@ : : "r" ((char *) &loadidt) ); - setVector(_int0,0,dPresent + dInt + dDpl3); - setVector(_int1,1,dPresent + dInt + dDpl3); - setVector(_int2,2,dPresent + dInt + dDpl3); - setVector(_int3,3,dPresent + dInt + dDpl3); - setVector(_int4,4,dPresent + dInt + dDpl3); - setVector(_int5,5,dPresent + dInt + dDpl3); - setVector(_int6,6,dPresent + dInt + dDpl3); - setVector(_sysCall,128,dPresent + dInt + dDpl3); + setVector(_int0,0,dPresent + dInt + dDpl1); + setVector(_int1,1,dPresent + dInt + dDpl1); + setVector(_int2,2,dPresent + dInt + dDpl1); + setVector(_int3,3,dPresent + dInt + dDpl1); + setVector(_int4,4,dPresent + dInt + dDpl1); + setVector(_int5,5,dPresent + dInt + dDpl1); + setVector(_int6,6,dPresent + dInt + dDpl1); + setVector(_sysCall,128,dPresent + dInt + dDpl1); } /* Sets Up IDT Vector */ @@ -74,20 +76,16 @@ /* Null Intterupt Descriptor */ void intNull() { kprintf("Woot Invalid Interrupt\n"); - /* freeProcessPages(_current->id); _current->status = EMPTY; schedule(); - */ while(1); } void _int0() { kprint("int0: Divide-by-Zero\n"); - /* freeProcessPages(_current->id); _current->status = EMPTY; schedule(); - */ while(1); } void _int1() { @@ -99,38 +97,30 @@ } void _int2() { kprint("int2: unknown error\n"); - /* freeProcessPages(_current->id); _current->status = EMPTY; schedule(); - */ while(1); } void _int3() { kprint("int3: Breakpoint\n"); - /* freeProcessPages(_current->id); _current->status = EMPTY; schedule(); - */ while(1); } void _int4() { kprint("int4: Overflow\n"); - /* freeProcessPages(_current->id); _current->status = EMPTY; schedule(); - */ while(1); } void _int5() { kprint("int5: Bounds check\n"); - /* freeProcessPages(_current->id); _current->status = EMPTY; schedule(); - */ while(1); } void _int6() { diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 3afd2cc..78ec4a4 100755 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -81,75 +81,6 @@ schedule(); } - -void sysExec() { - int i = 0,x = 0; - int *status; - uLong eStart = 0; - char *binarySpace = (char *)0x7C0000; - char *newLoc; - char *file; - fileDescriptor *tmpFd = 0x0; - elfHeader *binaryHeader = (elfHeader *)0x7C0000; - elfProgramheader *programHeader; - asm("":"=b"(file),"=c"(status)); - asm("sti"); - tmpFd = fopen(file,"r"); - //If We Dont Find the File Return - if (tmpFd == 0x0) { - *status = 0; - return; - } - //Now We Must Allocate Memory To Load The Binary Into - for (i=0;i<((tmpFd->size+4095)/4096);i++) { - remapPage(findFreePage(_current->id),(0x7C0000 + (0x1000 * i))); - } - //Load The Binary Into Memory Byte For Byte I Should Find A Faster Way - for (i=0;feof(tmpFd) == 0;i++) { - binarySpace[i] = fgetc(tmpFd); - } - //Close The File - fclose(tmpFd); - //Set programHeader To Point To Loaded Binary So We Can Gather Info - programHeader = (elfProgramheader *)(0x7C0000 + binaryHeader->ePhoff); - //Loop Through The Header And Load Sections Which Need To Be Loaded - for (i=0;iePhnum;i++) { - if (programHeader[i].phType == 1) { - newLoc = (char *)programHeader[i].phVaddr; - /* - Allocate Memory Im Going To Have To Make This Load Memory With Corrent - Settings so it helps us in the future - */ - for (x=0;x<=((programHeader[i].phMemsz & 0xFFFFF000)+4095);x+=4096) { - remapPage(findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + (0x1000 * x))); - _current->vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + (0x1000 * x) + 0x1000); - } - //Now Copy The Binary To Its Correct Location - for (x=0;xeEntry; - //Now That We Relocated The Binary We Can Unmap And Free Old Pages - for (i=0;i<((tmpFd->size+4095)/4096);i++) { - unmapPage((0x7C0000 + (0x1000 * i)),0); - } - //Set Up Args - - //Jump To Start Of New Binary - asm( - "pushl %0\n" - "jmp *%1\n" - : - : "g" (file), "g" (eStart) - ); - } - void sysCheckPid() { int *ptr; asm("": "=b" (ptr)); diff --git a/src/sys/ubixfs/ubixfs.c b/src/sys/ubixfs/ubixfs.c index 5d7f443..8fb7fa0 100755 --- a/src/sys/ubixfs/ubixfs.c +++ b/src/sys/ubixfs/ubixfs.c @@ -29,34 +29,25 @@ #include #include -int startSector = 0; -int partitionSize = 0; -int rootDirectory = 0; struct blockAllocationTableEntry *blockAllocationTable = 0x0; +struct ubixDiskLabel *diskLabel = 0x0; void initUbixFS() { - struct bootSect *bs = 0x0; - struct partitionInformation *pInfo = 0x0; - bs = (struct bootSect *)kmalloc(512); - pInfo = (struct partitionInformation *)kmalloc(512); - readBlock(0,(char *)bs,(long)1); - if ((bs[0].id[0] == 'U') && (bs[0].id[1] == 'b') && (bs[0].id[2] == 'i') && (bs[0].id[3] == 'x') && (bs[0].id[4] == 'F') && (bs[0].id[5] == 'S')) { - readBlock(bs->fsStart,(char *)pInfo,(long)1); - startSector = pInfo[0].blockAllocationTable; - partitionSize = pInfo[0].size; - rootDirectory = pInfo[0].rootDirectory; - blockAllocationTable = (struct blockAllocationTableEntry *)kmalloc(((rootDirectory-startSector)*512)); - readBlock(startSector,(char *)blockAllocationTable,(rootDirectory-startSector)); + diskLabel = (struct ubixDiskLabel *)kmalloc(512); + readBlock(1,(char *)diskLabel,(long)1); + if ((diskLabel->magicNum == UBIXDISKMAGIC) && (diskLabel->magicNum2 == UBIXDISKMAGIC)) { + blockAllocationTable = (struct blockAllocationTableEntry *)kmalloc(diskLabel->partitions[0].p_bsize * 512); + readBlock(diskLabel->partitions[0].p_offset,(char *)blockAllocationTable,diskLabel->partitions[0].p_bsize); kprintf("UbixFS Initialized\n"); } else { - kfree(bs); - kfree(pInfo); + //kfree(bs); + //kfree(pInfo); kprintf("Insert System Disk\n"); initUbixFS(); } - kfree(bs); - kfree(pInfo); + //kfree(bs); + //kfree(pInfo); //Return return; } @@ -106,7 +97,7 @@ if (offset < fd->size) { //If FD Status Is Not fdRead Then Load A Sector From Disk if (fd->status != fdRead) { - readBlock(blockAllocationTable[batIndex].realSector+bSect,fd->buffer,1); + readBlock(diskLabel->partitions[0].p_offset+blockAllocationTable[batIndex].realSector+bSect,fd->buffer,1); fd->status = fdRead; } //This Sets The Char To Return @@ -125,7 +116,7 @@ int x=0; bool ret = TRUE; struct directoryEntry *dirEntry = (struct directoryEntry *)kmalloc(4096); - ret = (bool)readBlock(rootDirectory,(char *)dirEntry,8); + ret = (bool)readBlock((diskLabel->partitions[0].p_offset+blockAllocationTable[0].realSector),(char *)dirEntry,8); for (x=0;x<(4096/sizeof(struct directoryEntry));x++) { if ((int)!kstrcmp(dirEntry[x].fileName,file)) { fd->start = dirEntry[x].startCluster; diff --git a/ubixos.kdevprj b/ubixos.kdevprj index bac4546..0ec1fd9 100755 --- a/ubixos.kdevprj +++ b/ubixos.kdevprj @@ -566,7 +566,7 @@ type=DATA [src/sys/boot/Makefile.am] -files=src/sys/boot/Makefile,src/sys/boot/bootsec.asm,src/sys/boot/boot.asm +files=src/sys/boot/Makefile,src/sys/boot/boot.asm sub_dirs= type=normal @@ -576,12 +576,6 @@ install_location= type=SOURCE -[src/sys/boot/bootsec.asm] -dist=true -install=false -install_location= -type=DATA - [src/sys/compile/Makefile] dist=true install=false