diff options
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | README.md | 38 | ||||
| -rw-r--r-- | fs/elf.c | 3 | ||||
| -rw-r--r-- | fs/fs.h | 2 | ||||
| -rw-r--r-- | kernel/config.h | 2 | ||||
| -rw-r--r-- | kernel/console.c | 2 | ||||
| -rw-r--r-- | kernel/kernel.c | 3 | ||||
| -rw-r--r-- | kernel/mem.c | 4 | ||||
| -rw-r--r-- | kernel/syscalls.c | 49 | ||||
| -rw-r--r-- | kernel/task.c | 2 | ||||
| -rw-r--r-- | userspace/Makefile | 10 | ||||
| -rw-r--r-- | userspace/cat.c | 17 | ||||
| -rw-r--r-- | userspace/foolshell.c | 9 | ||||
| -rw-r--r-- | userspace/init.c | 2 | ||||
| -rw-r--r-- | userspace/sys/Makefile | 41 | ||||
| -rw-r--r-- | userspace/sys/crt0.o | bin | 0 -> 660 bytes | |||
| -rw-r--r-- | userspace/sys/libfool.a | bin | 0 -> 7420 bytes | |||
| -rw-r--r-- | userspace/sys/sys.c | 2 | ||||
| -rw-r--r-- | userspace/sys/sys.o | bin | 0 -> 3744 bytes | |||
| -rw-r--r-- | userspace/sys/syscalls.o | bin | 0 -> 2948 bytes | |||
| -rw-r--r-- | userspace/sys/termios.h | 2 |
21 files changed, 123 insertions, 74 deletions
@@ -19,13 +19,13 @@ FOOLOS=FoolOS.img FOOLOS_VDI=FoolOS.vdi #submodules -SUBDIRS=boot1 boot2 font userspace +SUBDIRS=font userspace #take care to set this properly! USB_STICK=/dev/sdf #use our cross compiler -CC=i686-elf-gcc +CC=i686-foolos-gcc ############ compiler flags ############ CFLAGS= @@ -85,7 +85,7 @@ ASM_MULTIBOOT_OBJ=$(patsubst %.s, %.o, $(ASM_MULTIBOOT)) ############ Final Targets ############ -all: $(FOOLOS) $(FOOLOS_VDI) +all: $(FOOLOS) tags # $(FOOLOS_VDI) new: clean all run: run-qemu-debug newrun: clean run @@ -134,8 +134,9 @@ $(KERNEL_IMG): $(ASM_MULTIBOOT_OBJ) $(ASM_OBJECTS) $(OBJECTS) ############ assembling of final image ############ # master boot record, kernel binary and fool-font -$(FOOLOS): $(KERNEL_IMG) # $(SUBDIRS) +$(FOOLOS): $(KERNEL_IMG) $(SUBDIRS) sudo cp $(KERNEL_IMG) /mnt/vdi/boot + sudo cp $(IMG_USERSPACE) /mnt/vdi/boot sync # dd if=$(BIN_MBR) of=$@ bs=512 seek=0 conv=notrunc @@ -24,6 +24,35 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Building +-------- + +Adapt $SYSROOT in userspace/sys/Makefile + +Requirements: + +* OS Specific Toolchain [1] + + binutils-2.25 + gcc-5.1.0 + +* Newlib 2.2.0 [2] + + adapt config.sub + + $ ./configure --target=i686-foolos --prefix=/home/miguel/opt/gcc-5.1.0-foolos/ + $ make + $ make install + + /* + adapt libgloss/libnosys + uncomment environ.c and add stubwarnings for sbrk and exit + */ + +* GRUB2 + + + Usage ----- @@ -34,12 +63,6 @@ following way: $ cat FoolOS.img > /dev/sdX -You will require some dependencies (as newlib) in order to build. - -adapt libgloss/libnosys - -uncomment environ.c and add stubwarnings for sbrk and exit -Build newlib with: --target=i686-elf to use the crosscompiler Supported Platforms @@ -145,6 +168,9 @@ REFERENCES * http://wiki.xomb.org/index.php?title=ACPI_Tables * and many many more... +[1] http://wiki.osdev.org/Hosted_GCC_Cross-Compiler +[2] https://sourceware.org/newlib/ + NOTES ===== in freestanding mode we can just use this c lib headers: @@ -76,7 +76,8 @@ uint32_t load_elf(char *name, uint32_t *alloc) //TODO: load ELF binary and move this to own compilation unit //load binary - uint32_t vaddr=0x08048000; +// uint32_t vaddr=0x08048000; + uint32_t vaddr=0x08000000; log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"loading %s",name); ext2_check(EXT2_RAM_ADDRESS); @@ -4,7 +4,7 @@ #include <stdint.h> -#define EXT2_RAM_ADDRESS 0x120000 // here the bootloader puts our image +#define EXT2_RAM_ADDRESS 0x124000 // here the bootloader puts our image enum FS_FILE_TYPE{ diff --git a/kernel/config.h b/kernel/config.h index 216641c..2e2a169 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -8,7 +8,7 @@ #define FOOLOS_CONFIG_H #define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line -//#define FOOLOS_LOG_OFF // do not log anything +#define FOOLOS_LOG_OFF // do not log anything #define FOOLOS_CONSOLE // otherwise VESA will be used! #define FOOLSOS_SHOW_VESAMODES #define MEM_PRINT_MEMORYMAP diff --git a/kernel/console.c b/kernel/console.c index 0a208bb..9db1c0b 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -16,7 +16,7 @@ uint32_t console_init(){ scr_clear(); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init console"); - // int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,"/binfont.bin"); +//int inode_nr=ext2_filename_to_inode(EXT2_RAM_ADDRESS,"/binfont.bin"); // if(inode_nr!=-1)ext2_inode_content(EXT2_RAM_ADDRESS,inode_nr,0x8000000,0xffff); // load font; return 0; } diff --git a/kernel/kernel.c b/kernel/kernel.c index 76ae8d7..97847e6 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -118,7 +118,6 @@ void kernel_main(uint32_t eax,uint32_t ebx) int_init(0x08); - //while(1); // // Scan the PCI Bus @@ -151,7 +150,7 @@ void kernel_main(uint32_t eax,uint32_t ebx) // // Initialize Multitasking // - //task_init(dir); //; this will never return! + task_init(dir); //; this will never return! // while(1); //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"."); diff --git a/kernel/mem.c b/kernel/mem.c index 72b92af..f29c34f 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -102,10 +102,11 @@ int mmap_first_free_s (uint32_t x) void pmmngr_init_region (uint32_t base, uint32_t size) { - if(base<0x100000)return; uint32_t align = base / PMMNGR_BLOCK_SIZE +1; // TODO: calc properly uint32_t blocks = size / PMMNGR_BLOCK_SIZE -1; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init blocks: 0x%08X 0x%08X",base,size); + for (; blocks>0; blocks--) { mmap_unset (align++); @@ -253,6 +254,7 @@ void mem_init(uint32_t memmap,uint32_t length) // deinitialize kernel + memory (TODO: modules) pmmngr_deinit_region(kernel_start,((uint32_t)kernel_end-(uint32_t)kernel_start)); pmmngr_deinit_region(_mmngr_memory_map,mem_array_size*4+PMMNGR_BLOCK_SIZE); + pmmngr_deinit_region(0,0x700000); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Usable Mem: %d (0x%X) bytes. (~%d MB)",total_mem,total_mem,total_mem/1024/1024); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Currently Free 4K blocks: %d blocks.",mem_free_blocks); diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 6d46f1a..38f7161 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -14,7 +14,7 @@ int syscall_unhandled(int nr) { log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr); - panic(FOOLOS_MODULE_NAME,"unhandled syscall"); + panic(FOOLOS_MODULE_NAME,"unhandled syscall (generic handler)"); } int syscall_lseek(int file,int ptr,int dir) @@ -23,7 +23,7 @@ int syscall_lseek(int file,int ptr,int dir) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir); #endif - panic(FOOLOS_MODULE_NAME,"unhandled syscall"); + panic(FOOLOS_MODULE_NAME,"unhandled syscall: lseek"); return 0; @@ -39,7 +39,7 @@ int syscall_write(int file, char *buf, int len) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] write(file=%d, buf=0x%08X, len=%d)", task_get_current_pid(),file,buf,len); #endif - if(file!=1&&file!=2) panic(FOOLOS_MODULE_NAME,"unhandled syscall"); + if(file!=1&&file!=2) panic(FOOLOS_MODULE_NAME,"unhandled syscall: write (only stdout and stderr)"); //stderr and stdout go to console for(int i=0;i<len;i++) @@ -59,8 +59,9 @@ int syscall_read(int file, char *buf, int len) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len); #endif + // stdin TODO: other descroptiors! - if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall"); + if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall: read (only stdin)"); { if(eof) { @@ -149,28 +150,18 @@ int copy_args(char **in, char **out) return count; } - -int *entry_global=1; -char **argv_global=10; -char **env_global=300; -char **argv=0x8000000; -char **env=0x8000000+300; - - int syscall_execve(char *name, char **argv1, char **env1) { #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv1,env1); #endif - copy_args(argv1,argv_global); - copy_args(env1,env_global); - uint32_t alloc; - *entry_global=load_elf(name,&alloc); + uint32_t entry_global=load_elf(name,&alloc); + task_set_brk(alloc); - if(!*entry_global) + if(!entry_global) { #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve: bailing out!"); @@ -181,18 +172,14 @@ int syscall_execve(char *name, char **argv1, char **env1) /* try to move this to asm */ //asm volatile("jmp ."); asm volatile("mov $0x8fff000,%esp"); // set stack at high end of process image + int arg_count=0; - int arg_count=copy_args(argv_global,argv); - copy_args(env_global,env); - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"argc: %d" ,arg_count); - - asm volatile ("push %0" :: "r" (argv)); + asm volatile ("push %0" :: "r" (argv1)); asm volatile ("push %0" :: "r" (arg_count)); - asm volatile ("push %0" :: "r" (env)); + asm volatile ("push %0" :: "r" (env1)); // push addr and return to it - asm volatile ("push %0"::"r"(*entry_global)); + asm volatile ("pushl %0"::"r"(entry_global)); asm volatile ("sti"); asm volatile ("ret"); @@ -206,7 +193,7 @@ int syscall_open(char *name, int flags, int mode) #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"open (name=0x%08X(\"%s\"), flags=%d, mode=%d)",name, name,flags,mode); #endif - panic(FOOLOS_MODULE_NAME,"unhandled syscall"); + panic(FOOLOS_MODULE_NAME,"unhandled syscall: open"); } @@ -220,7 +207,7 @@ int syscall_close(int file,int none1,int none2) #endif if(file!=0&&file!=1&&file!=2) - panic(FOOLOS_MODULE_NAME,"unhandled syscall"); + panic(FOOLOS_MODULE_NAME,"unhandled syscall: close"); return -1; } @@ -234,18 +221,22 @@ int syscall_isatty(int file,int none1,int none2) return 1; } +uint32_t fuckalloc=0x8500000; // TODO: per process basis! uint32_t syscall_sbrk(int incr, int none1, int none2) { uint32_t alloc=task_get_brk(); - uint32_t oldalloc=alloc; - alloc+=incr; + + uint32_t oldalloc=fuckalloc; + fuckalloc+=incr; + task_set_brk(alloc); #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sbrk (incr=%d) = 0x%08X", incr,oldalloc); #endif + return oldalloc; } diff --git a/kernel/task.c b/kernel/task.c index a2a2ab8..1474a64 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -85,6 +85,7 @@ volatile uint32_t task_switch_next(uint32_t oldesp) timer_tick(); + // check if multitasking has been started if(current_task<0)return oldesp; @@ -160,6 +161,7 @@ volatile void task_init(pdirectory *dir) current_task=0; syscall_execve("/bin/init",argv_init,env_init); + //syscall_execve("/bin/foolshell",argv_init,env_init); // syscall_execve("/bin/tput",argv,env); } diff --git a/userspace/Makefile b/userspace/Makefile index f112e67..8e97ac8 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -7,13 +7,16 @@ CFLAGS+=-w CFLAGS+=-std=gnu11 CFLAGS+=-O3 CFLAGS+=-g +LDFLAGS= +LDFLAGS=-lfool +#CFLAGS+=$(SYSROOT)/usr/lib/crt0.o -PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init +PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat ext2.img: $(PROGS) dd if=/dev/zero of=ext2.img bs=512 count=10000 - sudo mkfs.ext2 -O none ext2.img -F + sudo mkfs.ext2 -O none ext2.img -F mkdir mnt sudo mount ext2.img mnt sudo chown miguel mnt @@ -35,11 +38,12 @@ brainfuck: brainfuck.o foolshell: foolshell.o simple: simple.o add: add.o - $(CC) -o $@ $< -lm + $(CC) -o $@ $< -lm -lfool checker: checker.o task1: task1.o task2: task2.o init: init.o +cat: cat.o clean: -rm *.o $(PROGS) ext2.img diff --git a/userspace/cat.c b/userspace/cat.c new file mode 100644 index 0000000..a371397 --- /dev/null +++ b/userspace/cat.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +int main() +{ + FILE *f = fopen("README", "r"); + + if (f == NULL) + { + perror("unable to open file"); + return 1; + } + + puts("open success"); + fclose(f); + + return 0; +} diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 3a87158..da05e96 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -45,6 +45,7 @@ int main(int argc, char **argv) if(!silent)hello(); char *buf=malloc(256); + // printf("malloc returned: 0x%08X\n",buf); while(1) { @@ -87,8 +88,6 @@ char **tokenize(char *buf) i++; } token[c][t]=0; - - // printf("token %i : <%s>\n",c, token[c]); c++; @@ -216,15 +215,17 @@ int process(char *buf) int pid=fork(); if(pid!=0) { - //printf("new task pid: %i \n",pid); + printf("new task pid: %i \n",pid); } if(pid==0) { char buf[256]; sprintf(buf,"%s",token[0]); execve(buf,token,environ); - sprintf(buf,"%s/%s",getenv("PATH"),token[0]); + //sprintf(buf,"%s/%s",getenv("PATH"),token[0]); + sprintf(buf,"%s/%s","/bin",token[0]); execve(buf,token,environ); + puts("foolshell: command not found"); exit(1); } diff --git a/userspace/init.c b/userspace/init.c index f588875..5d3658c 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,7 +1,7 @@ int main(int argc, char **argv) { - //printf("fool-init: spawning a Fool's Shell\n"); + printf("fool-init: spawning a Fool's Shell\n"); // loop forever and spawn shells if the top-shell exits while(1) diff --git a/userspace/sys/Makefile b/userspace/sys/Makefile index 5e217fa..cdcd3b7 100644 --- a/userspace/sys/Makefile +++ b/userspace/sys/Makefile @@ -1,29 +1,32 @@ +SYSROOT=/home/miguel/opt/foolos CC=i686-foolos-gcc CFLAGS= -CFLAGS+=-I../.. CFLAGS+=-w - +CFLAGS+=-I../.. +CFLAGS+=-gstabs OBJECTS=sys.o syscalls.o crt0.o -full: clean library_install crt_install + +full: clean library_install crt_install header_install + all: $(OBJECTS) -library_install: all - mkdir temp - mv *.o temp - cp /home/miguel/temp/sysroot/usr/lib/libc.a . - ar x libc.a - rm libc.a -# rm lib_a-environ.o - cp temp/sys*.o . - ar rs libc.a *.o - mv libc.a /home/miguel/temp/sysroot/usr/lib/libc.a - cp temp/*.o . - rm temp -rf - -crt_install: all - cp crt0.o /home/miguel/temp/sysroot/usr/lib/ +crt0.o: crt0.S + +crt_install: crt0.o + cp crt0.o $(SYSROOT)/usr/lib/ + + +header_install: + cp termios.h $(SYSROOT)/usr/include/sys/ + +libfool.a: sys.o syscalls.o + ar rcs libfool.a sys.o syscalls.o + +library_install: libfool.a + cp libfool.a $(SYSROOT)/usr/lib/ + clean: - -rm *.o + -rm *.o *.a diff --git a/userspace/sys/crt0.o b/userspace/sys/crt0.o Binary files differnew file mode 100644 index 0000000..db292b0 --- /dev/null +++ b/userspace/sys/crt0.o diff --git a/userspace/sys/libfool.a b/userspace/sys/libfool.a Binary files differnew file mode 100644 index 0000000..31fee46 --- /dev/null +++ b/userspace/sys/libfool.a diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c index 25dff7b..adf6ff9 100644 --- a/userspace/sys/sys.c +++ b/userspace/sys/sys.c @@ -1,7 +1,7 @@ #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> -#include <sys/termios.h> +#include <termios.h> // CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate diff --git a/userspace/sys/sys.o b/userspace/sys/sys.o Binary files differnew file mode 100644 index 0000000..14413b2 --- /dev/null +++ b/userspace/sys/sys.o diff --git a/userspace/sys/syscalls.o b/userspace/sys/syscalls.o Binary files differnew file mode 100644 index 0000000..371b8af --- /dev/null +++ b/userspace/sys/syscalls.o diff --git a/userspace/sys/termios.h b/userspace/sys/termios.h new file mode 100644 index 0000000..ff1e838 --- /dev/null +++ b/userspace/sys/termios.h @@ -0,0 +1,2 @@ +typedef uint32_t speed_t; +typedef uint32_t DIR; |
