diff --git a/src/Makefile.inc b/src/Makefile.inc new file mode 100644 index 0000000..3bd5131 --- /dev/null +++ b/src/Makefile.inc @@ -0,0 +1,11 @@ +# $Id$ +# Global 'Source' Options + +# allow you to change your default compiler without affecting your other work +CC = gcc +CXX = g++ +LD = ld +AR = ar +REMOVE = rm -rf + +FD_DEVICE = /dev/md0 diff --git a/src/sys/Makefile b/src/sys/Makefile new file mode 100644 index 0000000..36050f2 --- /dev/null +++ b/src/sys/Makefile @@ -0,0 +1,23 @@ +# Kernel Makefile (C) 2002-2004 The UbixOS Project +# +# $Id$ + +all: init-code kernel-img + +init-code: init + (cd init;make) + +kernel-img: compile + (/bin/echo "/* " > ./compile/null.c) + (date >> ./compile/null.c) + (echo $user >> ./compile/null.c) + (/bin/echo " */" >> ./compile/null.c) + (cd compile;make) + +install: + (cd ../tools/;make format-dsk) + +clean: + (cd init;make clean) + (cd compile;make clean) + (cd ../tools/;make clean) diff --git a/src/sys/Makefile.inc b/src/sys/Makefile.inc new file mode 100644 index 0000000..450682a --- /dev/null +++ b/src/sys/Makefile.inc @@ -0,0 +1,6 @@ +# $Id$ +# global 'sys' options + +INCLUDES = -I../include +CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O +KERNEL = ubix.elf diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile new file mode 100644 index 0000000..8761f3b --- /dev/null +++ b/src/sys/compile/Makefile @@ -0,0 +1,39 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +#Objects +OBJS = null.o + +#Kernel Parts +KPARTS = ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../isa/*.o ../vfs/*.o ../ubixfs/*.o ../pci/*.o ../sde/*.o ../devfs/*.o ../net/core/*.o ../net/net/*.o ../net/api/*.o ../net/netif/*.o ../mpi/*.o ../ufs/*.o +#../graphics/*.o ../ld/*.o -Ttext 0x30000 -Tdata 0x34000 + +# Link the kernel statically with fixed text+data address @1M +$(KERNEL) : $(OBJS) + #$(LD) -nostdlib -nostdinc --warn-section-align -o $@ $(OBJS) $(KPARTS) -Ttext 0x30000 -Tdata 0x20000 + $(LD) -T ./ldscript.i386 -o $@ $(OBJS) $(KPARTS) + #/usr/bin/strip $@ + +# Compile the source files +.cc.o: + $(CXX) -${CFLAGS} $(INCLUDES) -c -o $@ $< + +.cc.s: + $(CXX) ${CFLAGS} $(INCLUDES) -S -o $@ $< + +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< + +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(KERNEL) null.c diff --git a/src/sys/compile/ldscript.i386 b/src/sys/compile/ldscript.i386 new file mode 100644 index 0000000..731e787 --- /dev/null +++ b/src/sys/compile/ldscript.i386 @@ -0,0 +1,77 @@ +OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") +OUTPUT_ARCH(i386) + +ENTRY(_start) +SEARCH_DIR("libgcc"); +SECTIONS +{ + . = 0x30000 + SIZEOF_HEADERS; + + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } + .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } + .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } + .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } + .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } + .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : { *(.init) } =0x9090 + .plt : { *(.plt) } + + /* text/read-only data */ + .text : { *(.text .gnu.linkonce.t.*) } =0x9090 + + .rodata : { *(.rodata) .rodata.* .gnu.linkonce.r.* } + + /* writable data */ + . = ALIGN(0x1000); + __data_start = .; + .data : { *(.data .gnu.linkonce.d.*) } + + __ctor_list = .; + .ctors : + { + LONG((__ctor_end - __ctor_list) / 4 - 2) + *(.ctors) + LONG(0) + } + __ctor_end = .; + + __dtor_list = .; + .dtors : + { + LONG((__dtor_end - __dtor_list) / 4 - 2) + *(.dtors) + LONG(0) + } + __dtor_end = .; + + .got : { *(.got.plt) *(.got) } + .dynamic : { *(.dynamic) } + + /* unintialized data (in same segment as writable data) */ + __bss_start = .; + .bss : { *(.bss) } + + . = ALIGN(0x1000); + _end = . ; + + /* Strip unnecessary stuff */ + /DISCARD/ : { *(.comment .note .eh_frame) } +} diff --git a/src/tools/Makefile b/src/tools/Makefile new file mode 100644 index 0000000..574ae02 --- /dev/null +++ b/src/tools/Makefile @@ -0,0 +1,75 @@ +# $Id$ +# Kernel Makefile (C) 2002 The UbixOS Project + +# Include Global 'Source' Options +include ../Makefile.inc + +CC=gcc + +#Kernel File Name +BINARY = format + +#Objects +OBJS = format.o + +# Link the kernel statically with fixed text+data address @1M +$(BINARY) : $(OBJS) + $(CC) -o $@ $(OBJS) + +# Compile the source files +.cc.o: + $(CXX) -Wall -fomit-frame-pointer -O -I../sys/include -c -o $@ $< + +.cc.s: + $(CXX) -Wall -fomit-frame-pointer -O -I../sys/include -S -o $@ $< + +.c.o: + $(CC) -Wall -O -c -o $@ $< + +.c.s: + $(CC) -Wall -fomit-frame-pointer -O -I../sys/include -S -o $@ $< + +.S.o: + $(CC) -Wall -fomit-frame-pointer -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) $(BINARY) *.core + +format-dsk: + (cp ../sys/compile/ubix.elf ./) + (cp ../bin/init/init ./) + (cp ../bin/login/login ./) + (cp ../bin/shell/shell ./) + (cp ../bin/ls/ls ./) + (cp ../bin/clock/clock ./) + (cp ../lib/libc_old/libc_old.so ./) + (cp ../bin/fdisk/fdisk ./) + (cp ../bin/cp/cp ./) + #(cp ../bin/format/format ./) + (cp ../bin/ubistry/ubistry ./) + (cp ../sys/boot/mbr/mbr ./) + (cp ../bin/ld/ld.so ./) + #(cp /lib/libc.so.5 ./) + (cp ../bin/ttyd/ttyd ./) + (./format 50 2000 ${FD_DEVICE} ubix.elf 0 login 3754 ROM8X14.DPF 3754 init 3754 ubistry 3754 shell 3754 userdb 3754 ls 3754 motd 3754 fdisk 3754 cp 3754 clock 3754 libc_old.so 3754 ld.so 3754 ttyd 3754 mbr 3754) +# (./format 50 2000 ${FD_DEVICE} ubix.elf 0 login 3754 init 3754 ubistry 3754 shell 3754 userdb 3754 motd 3754 libc_old.so 3754 ld.so 3754 test 3754 libc.so.5 3754) + + #(./format 263 204361 /dev/md1 ubix.elf 0 format 3754 fdisk 3754 ROM8X14.DPF 3754 init 3754 login 3754 shell 3754 userdb 3754 ls 3754 motd 3754 cp 3754) + (./format 1064 2000 ${FD_DEVICE} shell 3754 clock 3754) + #(./format 200 2000 /dev/md1 ubix.elf 0 shell 3754 motd 3754 libc_old.so 3754) + (rm -fr ubix.elf) + (rm -fr login) + (rm -fr init) + (rm -fr shell) + (rm -fr ls) + (rm -fr clock) + (rm -fr libc_old.so) + (rm -fr cp) + (rm -fr fdisk) + #(rm -fr format) + (rm -fr mbr) + (rm -fr ubistry) + (rm -fr ld.so) + (rm -fr libc.so.5) + (rm -fr ttyd) diff --git a/src/tools/format.c b/src/tools/format.c new file mode 100644 index 0000000..8de1291 --- /dev/null +++ b/src/tools/format.c @@ -0,0 +1,156 @@ +#include +#include +#include +#include "./ubixfs.h" + +#define typeFile 1 +#define typeContainer 2 +#define typeDirectory 4 + + +//Michelle My Bell + +struct blockAllocationTableEntry *BAT = 0x0; + +int findFreeBlock(int cBlock,int size) { + int i = 0x0; + for (i=1;isize = (size/512); + partInfo->startSector = (startSector+1); + partInfo->blockAllocationTable = (startSector+1); + partInfo->rootDirectory = ((startSector+1) + (batSize/512)); + partInfo->rootDirectorySize = 0x4000/512; + fseek(driveFd,(startSector * 512),0); + fwrite(partInfo,512,1,driveFd); + startSector++; + dirEntry[0].attributes = typeDirectory; + dirEntry[0].permissions = 0xEAA; + dirEntry[0].gid = 0x0; + dirEntry[0].uid = 0x0; + dirEntry[0].startCluster = 0x0; + dirEntry[0].size = 0x4000; + sprintf(dirEntry[0].fileName,"/"); + dirEntry[1].attributes = typeDirectory; + dirEntry[1].permissions = 0xEAA; + dirEntry[1].gid = 0x0; + dirEntry[1].uid = 0x0; + dirEntry[1].startCluster = 0x0; + dirEntry[1].size = 0x4000; + sprintf(dirEntry[1].fileName,".."); + BAT[0].nextBlock = 0x1; + BAT[0].attributes = 1; + BAT[0].realSector = (batSize/512); + BAT[1].nextBlock = 0x2; + BAT[1].attributes = 1; + BAT[1].realSector = ((batSize/512) + 1 * 8); + BAT[2].nextBlock = 0x3; + BAT[2].attributes = 1; + BAT[2].realSector = ((batSize/512) + 2 * 8); + BAT[3].nextBlock = -1; + BAT[3].attributes = 1; + BAT[3].realSector = ((batSize/512) + 3 * 8); + + for (i=4;i<(size/4096);i++) { + BAT[i].nextBlock = -1; + BAT[i].attributes = 0x0; + BAT[i].realSector = ((batSize/512) + (i*8)); + BAT[i].reserved = 0x0; + } + file = 0x2; + while (x < argc) { + counter = 0x0; + blockCount = 0x0; + fileFd = fopen(argv[x],"rb"); + block = findFreeBlock(-1,(size/4096)); + dirEntry[file].startCluster = block; + dirEntry[file].attributes = typeFile; + dirEntry[file].permissions = atoi(argv[x+1]); + rewind(driveFd); + /* fseek(driveFd,((BAT[startSector].realSector * 512) + ((batSize/512)+(BAT[block].realSector*4096))),0); */ + fseek(driveFd,((startSector + BAT[block].realSector) * 512),0); + while (!feof(fileFd)) { + if (4096 == (counter - (blockCount * 4096))) { + block = findFreeBlock(block,(size/4096)); + printf("Block: [%i][%s]\n",block,argv[x]); + rewind(driveFd); + /* fseek(driveFd,((startSector * 512) + ((batSize/512)+(BAT[block].realSector*4096))),0); */ + fseek(driveFd,((startSector + BAT[block].realSector) * 512),0); + blockCount++; + } + fputc(fgetc(fileFd),driveFd); + counter++; + } + i = 0; + while((counter + i)%512) { + fputc(0x0,driveFd); + i++; + } + fclose(fileFd); + dirEntry[file].size = (counter - 1); + dirEntry[file].uid = 0x0; + dirEntry[file].gid = 0x0; + sprintf(dirEntry[file].fileName,"%s",argv[x]); + x += 2; + file++; + } + dirEntry[1].attributes = typeDirectory; + dirEntry[1].permissions = 0xEAA; + dirEntry[1].gid = 0x0; + dirEntry[1].uid = 0x0; + dirEntry[1].startCluster = 0x0; + dirEntry[1].size = 0x4000; + sprintf(dirEntry[1].fileName,"fakeDir"); + rewind(driveFd); + fseek(driveFd,(long)(((startSector) * 512) + batSize),0); + fwrite(dirEntry,0x4000,1,driveFd); + rewind(driveFd); + fseek(driveFd,((startSector) * 512),0); + if (fwrite(BAT,batSize,1,driveFd) >= 1) { +/* + * printf("size [%i]\n",partInfo->size); + * printf("startSector: [%i]\n",partInfo->startSector); + * printf("bat: [%i]\n",partInfo->blockAllocationTable); + * printf("rootDir: [%i]\n",partInfo->rootDirectory); + * printf("sizeof: [%i]\n",sizeof(struct blockAllocationTableEntry)); + * printf("size: [%i]\n",(size/4096)); + */ + printf("Formatted!\n"); + } + else { + printf("Error Formatting!!\n"); + } + fclose(driveFd); + return(0); + } diff --git a/src/tools/makeuser.c b/src/tools/makeuser.c new file mode 100644 index 0000000..29d6ce5 --- /dev/null +++ b/src/tools/makeuser.c @@ -0,0 +1,52 @@ +#include + +struct passwd { + char username[32]; + char passwd[32]; + int uid; + int gid; + char shell[128]; + char realname[256]; + char path[256]; + }; + +int main(int argc,char **argv) { + int i = 0x0; + struct passwd *password = 0x0; + FILE *out; + password = (struct passwd *)malloc(4096); + out = fopen("./userdb","wbb"); + sprintf(password[0].username,"root"); + sprintf(password[0].passwd,"user"); + sprintf(password[0].shell,"shell@sys"); + sprintf(password[0].realname,"Root User"); + sprintf(password[0].path,"root"); + password[0].uid = 0; + password[0].gid = 0; + sprintf(password[1].username,"guest"); + sprintf(password[1].passwd,"user"); + sprintf(password[1].shell,"shell@sys"); + sprintf(password[1].realname,"Guest User"); + sprintf(password[1].path,"guest"); + password[1].uid = 1; + password[1].gid = 1; + sprintf(password[2].username,"reddawg"); + sprintf(password[2].passwd,"temp123"); + sprintf(password[2].shell,"shell@sys"); + sprintf(password[2].realname,"Christopher"); + sprintf(password[2].path,"reddawg"); + password[2].uid = 1000; + password[2].gid = 1000; + fwrite(password,4096,1,out); + fclose(out); + for (i=0;i<3;i++) { + printf("User: [%s]\n",password[i].username); + printf("Pass: [%s]\n",password[i].passwd); + printf("UID: [%i]\n",password[i].uid); + printf("GID: [%i]\n",password[i].gid); + printf("Shell: [%s]\n",password[i].shell); + printf("Name: [%s]\n",password[i].realname); + printf("Path: [%s]\n",password[i].path); + } + return(0); + } diff --git a/src/tools/motd b/src/tools/motd new file mode 100644 index 0000000..e09c887 --- /dev/null +++ b/src/tools/motd @@ -0,0 +1,9 @@ +Welcome to UbixOS + +This is an experimental kernel so it has the potential +to crash if it does please send us some info so we can +fix it or if you have access to the source fix it and +commit the changes. + +All reports can be sent to colsen@ubixos.com + diff --git a/src/tools/ubixfs.h b/src/tools/ubixfs.h new file mode 100644 index 0000000..ba8f525 --- /dev/null +++ b/src/tools/ubixfs.h @@ -0,0 +1,78 @@ +/************************************************************************************** + 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$ + +**************************************************************************************/ + +#ifndef _UBIXFS_H +#define _UBIXFS_H + +typedef unsigned long uLong; +typedef unsigned short uShort; +typedef unsigned char uChar; +typedef unsigned int uInt; + +//Partition Information +struct partitionInformation { + uLong size; //Size In Sectors + uLong startSector; //Base Sector Of Partition + uLong blockAllocationTable; //Base Sector Of BAT + uLong rootDirectory; //Base Sector Of Root Directory + uLong rootDirectorySize; /* Size In Sectors Of Root Directory */ + }; + +//Block Allocation Table Entry +struct blockAllocationTableEntry { + long attributes; //Block Attributes + long realSector; //Real Sector + long nextBlock; //Sector Of Next Block + long reserved; //Reserved + }; + +//UbixFS Directory Entry +struct directoryEntry { + uLong startCluster; //Starting Cluster Of File + uLong size; //Size Of File + uLong creationDate; //Date Created + uLong lastModified; //Date Last Modified + uLong uid; //UID Of Owner + uLong gid; //GID Of Owner + uShort attributes; //Files Attributes + uShort permissions; //Files Permissions + char fileName[256]; //File Name + }; + + +struct bootSect { + uChar jmp[4]; + uChar id[6]; + uShort version; + uShort tmp; + uShort fsStart; + uShort tmp2; + uLong krnl_start; + uInt BytesPerSector; + uInt SectersPerTrack; + uInt TotalHeads; + uLong TotalSectors; + uChar code[479]; + }; + +#endif diff --git a/src/tools/user.c b/src/tools/user.c new file mode 100644 index 0000000..4e89daf --- /dev/null +++ b/src/tools/user.c @@ -0,0 +1,31 @@ +#include + +struct passwd { + char username[32]; + char passwd[32]; + int uid; + int gid; + char shell[128]; + char realname[256]; + char path[256]; + }; + +int main(int argc,char **argv) { + int i = 0x0; + struct passwd *password = 0x0; + FILE *in; + password = (struct passwd *)malloc(4096); + in = fopen("./userdb","rb"); + fread(password,4096,1,in); + fclose(in); + for (i=0;i<3;i++) { + printf("User: [%s]\n",password[i].username); + printf("Pass: [%s]\n",password[i].passwd); + printf("UID: [%i]\n",password[i].uid); + printf("GID: [%i]\n",password[i].gid); + printf("Shell: [%s]\n",password[i].shell); + printf("Name: [%s]\n",password[i].realname); + printf("Path: [%s]\n",password[i].path); + } + return(0); + } diff --git a/src/tools/userdb b/src/tools/userdb new file mode 100644 index 0000000..af82415 --- /dev/null +++ b/src/tools/userdb Binary files differ