diff options
| -rw-r--r-- | asm/asm_int.s | 72 | ||||
| -rw-r--r-- | fs/elf.c | 1 | ||||
| -rw-r--r-- | fs/elf.h | 8 | ||||
| -rw-r--r-- | fs/ext2.c | 4 | ||||
| -rw-r--r-- | fs/ext2.h | 2 | ||||
| -rw-r--r-- | fs/fs.c | 21 | ||||
| -rw-r--r-- | fs/fs.h | 24 | ||||
| -rw-r--r-- | fs/mount.h | 2 | ||||
| -rw-r--r-- | interface/crt0.s | 1 | ||||
| -rw-r--r-- | interface/fs.h | 25 | ||||
| -rw-r--r-- | kernel/exceptions.c | 64 | ||||
| -rw-r--r-- | kernel/kernel.c | 1 | ||||
| -rw-r--r-- | kernel/kernel.h | 6 | ||||
| -rw-r--r-- | kernel/scheduler.c | 1 | ||||
| -rw-r--r-- | kernel/syscalls.c | 18 | ||||
| -rw-r--r-- | userspace/cat.c | 16 | ||||
| -rw-r--r-- | userspace/clear.c | 3 | ||||
| -rw-r--r-- | userspace/crt0.s | 1 | ||||
| -rw-r--r-- | userspace/foolshell.c | 2 | ||||
| -rw-r--r-- | userspace/init.c | 8 | ||||
| -rw-r--r-- | userspace/ls.c | 22 | ||||
| -rw-r--r-- | userspace/snake2.h | 2 |
22 files changed, 168 insertions, 136 deletions
diff --git a/asm/asm_int.s b/asm/asm_int.s index ec81885..8d5ac9a 100644 --- a/asm/asm_int.s +++ b/asm/asm_int.s @@ -67,6 +67,13 @@ pop %eax // load original .endm +.macro err0 +.endm + +.macro err1 + add $4,%esp +.endm + .macro intx ack num func /* @@ -131,35 +138,58 @@ .endm -.macro excx num func +.macro excx num err func + cli // exception does not prevent from rescheduling? mov %esp,%eax // remember THIS stack position and $-16,%esp // padding to align stack on 16byte boundary before CALL sub $8,%esp // ... push \num // pass in this interrupt number push %eax // pass in original %esp (saved just few lines before) call \func // call aligned - jmp . + mov %eax,%esp // use the %esp we got from c function + + pop %gs // pop everything back... + pop %fs // ... + pop %es + pop %ds + popa + + cmp $0x0,(%esp) + je skipEx\num + pop %ebx + pop %ebx + jmp retEx\num + skipEx\num: + add $8,%esp // potentially set return value to eax to return to the caller + retEx\num: + sti + + iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack +// pop %esp + // \err + //iret + .endm -exc0: excx $0 exception_handle -exc1: excx $1 exception_handle -exc2: excx $2 exception_handle -exc3: excx $3 exception_handle -exc4: excx $4 exception_handle -exc5: excx $5 exception_handle -exc6: excx $6 exception_handle -exc7: excx $7 exception_handle -exc8: excx $8 exception_handle -exc9: excx $9 exception_handle -exc10: excx $10 exception_handle -exc11: excx $11 exception_handle -exc12: excx $12 exception_handle -exc13: excx $13 exception_handle -exc14: excx $14 exception_handle -exc15: excx $15 exception_handle -exc16: excx $16 exception_handle -exc17: excx $17 exception_handle -exc18: excx $18 exception_handle +exc0: excx $0 err0 exception_handle +exc1: excx $1 err0 exception_handle +exc2: excx $2 err0 exception_handle +exc3: excx $3 err0 exception_handle +exc4: excx $4 err0 exception_handle +exc5: excx $5 err0 exception_handle +exc6: excx $6 err0 exception_handle +exc7: excx $7 err0 exception_handle +exc8: excx $8 err1 exception_handle +exc9: excx $9 err0 exception_handle +exc10: excx $10 err1 exception_handle +exc11: excx $11 err1 exception_handle +exc12: excx $12 err1 exception_handle +exc13: excx $13 err1 exception_handle +exc14: excx $14 err1 exception_handle +exc15: excx $15 err0 exception_handle +exc16: excx $16 err0 exception_handle +exc17: excx $17 err1 exception_handle +exc18: excx $18 err0 exception_handle int0: intx ack0 $0 interrupt_handler int1: intx ack0 $1 interrupt_handler @@ -2,6 +2,7 @@ #include "log.h" #include <stdint.h> #include "ext2.h" +#include "elf.h" #include "lib/string/string.h" #define EI_NIDENT 16 @@ -1,3 +1,9 @@ -//https://docs.oracle.com/cd/E19455-01/806-3773/elf-2/index.html +/** @file + * == elf == + * https://docs.oracle.com/cd/E19455-01/806-3773/elf-2/index.html + */ + +#include "multiboot.h" + uint32_t load_elf(char *name, uint32_t *alloc); void elf_multiboot_read(multiboot_information *info); @@ -8,7 +8,7 @@ #include "lib/string/string.h" -#include "fs.h" +#include "interface/fs.h" // THE SUPERBLOCK typedef struct ext2_superblock_struct @@ -226,7 +226,7 @@ static uint32_t ext2_filename_to_inode_traverse(uint32_t ext2_start_addr, char * uint32_t ret=ext2_read_dir(VMEM_EXT2_RAMIMAGE,inode_start, &dirs,&pos); if(!ret)break; - if(!strcmp_l(first,dirs.name,len)) + if(strlen(dirs.name)==len && !strcmp_l(first,dirs.name,len)) { klog("found inode %d %s%s (in inode %d)",dirs.inode,dirs.name,dirs.type==FS_FILE_TYPE_DIR?"/ ":" ",inode_start); if(final)return dirs.inode; @@ -14,7 +14,7 @@ */ #include <stdint.h> -#include "fs.h" +#include "interface/fs.h" /** klog some basic info about the ext2 fs */ void ext2_dump_info(uint32_t ext2_start_addr); diff --git a/fs/fs.c b/fs/fs.c deleted file mode 100644 index a9cf5f6..0000000 --- a/fs/fs.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "kernel/kernel.h" -// abstraction layer for filesystems - -#include "fs.h" -#include "ext2.h" - -// returns number of entries in the directory specified by name. -// fills 0-max into *dirs - -int fs_readdir(const char *name,fs_dirent *dirs,int max) -{ - int inode_nr=ext2_filename_to_inode(VMEM_EXT2_RAMIMAGE,name); - if(inode_nr<1)return -1; - return ext2_read_dir(VMEM_EXT2_RAMIMAGE, inode_nr,dirs,0); // TODO: hardcoded, fix this -} - -void fs_content(char *path, uint32_t dest, uint32_t max_bytes) -{ - int inode= ext2_filename_to_inode(VMEM_EXT2_RAMIMAGE, path); -// ext2_inode_content(VMEM_EXT2_RAMIMAGE,inode,dest,max_bytes); -} diff --git a/fs/fs.h b/fs/fs.h deleted file mode 100644 index f5c9a6e..0000000 --- a/fs/fs.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef FOOLOS_FS -#define FOOLOS_FS - -#include <stdint.h> -#include "kernel/multiboot.h" - -enum FS_FILE_TYPE{ - FS_FILE_TYPE_DIR = 1, - FS_FILE_TYPE_FILE = 2 -}; - -typedef struct fs_dirent_struct -{ - uint32_t inode; - uint8_t type; - char name[255]; - -}fs_dirent; - -int fs_readdir(const char *name,fs_dirent *dirs,int max); -void fs_content(char *path, uint32_t dest, uint32_t max_bytes); -void fs_mount(multiboot_information *info); // mounts ext2 ramimage from module as root - -#endif @@ -5,7 +5,7 @@ #include <stdint.h> #include "file.h" -#include "fs.h" +#include "interface/fs.h" typedef struct mount_struct { diff --git a/interface/crt0.s b/interface/crt0.s index ad9884f..9ef2a67 100644 --- a/interface/crt0.s +++ b/interface/crt0.s @@ -26,7 +26,6 @@ movl $0xf5000000, _impure_ptr pop %eax mov %eax, environ - # call main (argc and argv are on the stack) call main diff --git a/interface/fs.h b/interface/fs.h new file mode 100644 index 0000000..0a8b59e --- /dev/null +++ b/interface/fs.h @@ -0,0 +1,25 @@ +/** + * @file + * abstraction layer for filesystems + */ + +#ifndef FOOLOS_FS +#define FOOLOS_FS + +#include <stdint.h> + +enum FS_FILE_TYPE{ + FS_FILE_TYPE_DIR = 1, + FS_FILE_TYPE_FILE = 2 +}; + +typedef struct fs_dirent_struct +{ + uint32_t mount; //mount identifier + uint32_t inode; //inode number or similar + uint8_t type; //FILE OR DIR + char name[255]; + +}fs_dirent; + +#endif diff --git a/kernel/exceptions.c b/kernel/exceptions.c index bcb5c40..4ad87e8 100644 --- a/kernel/exceptions.c +++ b/kernel/exceptions.c @@ -1,6 +1,7 @@ #include "kernel.h" #include "exceptions.h" #include "scheduler.h" +#include "syscalls.h" #include "log.h" #include "asm_x86.h" @@ -35,7 +36,7 @@ static void show_page_fault_error(uint32_t error_code) klog("at addr: 0x%08X",x86_get_cr(2)); } -void exception_handle(uint32_t esp, uint32_t irq) +uint32_t exception_handle(uint32_t esp, uint32_t irq) { uint32_t error_code=0; @@ -60,48 +61,71 @@ void exception_handle(uint32_t esp, uint32_t irq) switch(irq){ case 0: - kpanic("Divide by 0"); + klog("Divide by 0"); + break; case 1: - kpanic("Single step (debugger)"); + klog("Single step (debugger)"); + break; case 2: - kpanic("Non Maskable Interrupt"); + klog("Non Maskable Interrupt"); + break; case 3: - kpanic("Breakpoint (debugger)"); + klog("Breakpoint (debugger)"); + break; case 4: - kpanic("Overflow"); + klog("Overflow"); + break; case 5: - kpanic("Bounds check"); + klog("Bounds check"); + break; case 6: - kpanic("Undefined OP Code"); + klog("Undefined OP Code"); + break; case 7: - kpanic("No coprocessor"); + klog("No coprocessor"); + break; case 8: - kpanic("Double Fault"); + klog("Double Fault"); + break; case 9: - kpanic("Coprocessor Segment Overrun"); + klog("Coprocessor Segment Overrun"); + break; case 10: show_selector_error(error_code); - kpanic("Invalid TSS"); + klog("Invalid TSS"); + break; case 11: show_selector_error(error_code); - kpanic("Segment Not Present"); + klog("Segment Not Present"); + break; case 12: show_selector_error(error_code); - kpanic("Stack Segment Overrun"); + klog("Stack Segment Overrun"); + break; case 13: show_selector_error(error_code); - kpanic("Exception: Fault: General Protection Fault"); + klog("Exception: Fault: General Protection Fault"); + break; case 14: show_page_fault_error(error_code); - kpanic("Exception: Fault: Page Fault"); + klog("Exception: Fault: Page Fault"); + break; case 15: - kpanic("RESERVED"); + klog("RESERVED"); + break; case 16: - kpanic("Coprocessor error"); + klog("Coprocessor error"); + break; case 17: - kpanic("Alignment Check"); + klog("Alignment Check"); + break; case 18: - kpanic("Machine Check"); + klog("Machine Check"); + break; } + klog("killing task in question!"); + + task_syscall(SYSCALL_EXIT,task_get_current_pid(),0,0); + return scheduler_run(esp,0); } diff --git a/kernel/kernel.c b/kernel/kernel.c index 6f04454..9088d00 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -28,7 +28,6 @@ #include "driver/screen.h" #include "smp.h" -#include "fs/fs.h" #include "fs/elf.h" #include "kmalloc.h" #include "driver/vesa.h" diff --git a/kernel/kernel.h b/kernel/kernel.h index 27798cf..06f96e1 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -51,9 +51,9 @@ REFERENCES // minimal space between user and kernel pages 1024 pages! #define VMEM_KERNEL 0x00000000 // 8192 pages (32megs) / identity mapped -#define VMEM_KERNEL_END 0x02000000 +// VMEM_KERNEL END 0x02000000 -#define VMEM_USER_ENV 0x07000000 // ? pages / per user process +#define VMEM_USER_ENV 0x07000000 // 1 page / per user process #define VMEM_USER_PROG_PAGES 256 #define VMEM_USER_PROG 0x08048000 // ? pages / per user process (usual entry: 0x8048080) @@ -70,7 +70,7 @@ REFERENCES #define VMEM_COPY_PAGE 0xF4000000 // 1 page / temporery map-in tables for copying -//TODO: do not hardcode in crt0.s! +//TODO: do not hardcode in crt0.s!!!! #define VMEM_USER_NEWLIB 0xF5000000 // 1 page / newlib reentrancy struct. 1 per thread #define VMEM_FRAMEBUFFER 0xF6000000 // 8192 pages (32megs) / identity mapped diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 3b50259..ad6b370 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -14,7 +14,6 @@ #include "vmem.h" #include "spinlock.h" #include "syscalls.h" -#include "fs/fs.h" #include "fs/ext2.h" #define NO_TASK 0xffffffff diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 3fb813e..4d1c29d 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -1,6 +1,5 @@ #include "lib/string/string.h" #include "lib/printf/printf.h" -#include "fs/fs.h" #include "fs/ext2.h" #include "kernel.h" #include "driver/vesa.h" @@ -149,10 +148,11 @@ int syscall_read(int file, char *buf, int len) } //TODO: replace with dirent! -int syscall_readdir(const char *name,fs_dirent *dirs,int max) +int syscall_readdir(const char *name,fs_dirent *dirs,int *pos) { - - return fs_readdir(name,dirs,max); + uint32_t inode = ext2_filename_to_inode(VMEM_EXT2_RAMIMAGE,name); + if(inode==0)return 0; + return ext2_read_dir(VMEM_EXT2_RAMIMAGE, inode, dirs, pos); } // for non blocking io? @@ -215,7 +215,7 @@ int copy_args(char **in, char **out) int syscall_execve(char *name, char **argv, char **env,int pid) { - //TODO copy environment to target pages somehow// + fixme("not overwrite yourself?"); int arg_count=0; while(argv[arg_count]!=NULL)arg_count++; @@ -245,10 +245,10 @@ int syscall_execve(char *name, char **argv, char **env,int pid) return -1; // errror loading } - uint32_t *stack=VMEM_USER_STACK_TOP-3*32; - *++stack=argv1; - *++stack=arg_count; - *++stack=env1; + uint32_t *stack=VMEM_USER_STACK_TOP-4*32; + *--stack=argv1; + *--stack=arg_count; + *--stack=env1; task_reset(pid,entry_global,stack,alloc); return 0; diff --git a/userspace/cat.c b/userspace/cat.c index 800a14b..39d994f 100644 --- a/userspace/cat.c +++ b/userspace/cat.c @@ -1,18 +1,24 @@ #include <stdio.h> -int main() +int main(int argc, char **argv) { + FILE *f; + if(argc>1)f=fopen(argv[1],"r"); + else f=stdin; + + setvbuf(stdin,NULL,_IONBF,0); + setvbuf(stdout,NULL,_IONBF,0); char c; - printf("-- read from stderr byte by byte --\n"); + printf("-- read from file byte by byte --\n"); - while(_poll(2)){ - fread(&c,1,1,stderr); + while(fread(&c,1,1,f)) + { printf("%c",c); } - printf("\n-- no more data on stderr --\n"); + printf("\n-- no more data on this file --\n"); return 0; } diff --git a/userspace/clear.c b/userspace/clear.c index 38efeb6..9557760 100644 --- a/userspace/clear.c +++ b/userspace/clear.c @@ -1,6 +1,7 @@ +#include <stdio.h> int main() { printf("\033c"); - fflush(0); // force printing to console + fflush(stdout); // force printing to console return 0; } diff --git a/userspace/crt0.s b/userspace/crt0.s index ad9884f..9ef2a67 100644 --- a/userspace/crt0.s +++ b/userspace/crt0.s @@ -26,7 +26,6 @@ movl $0xf5000000, _impure_ptr pop %eax mov %eax, environ - # call main (argc and argv are on the stack) call main diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 3c1fb50..6877adb 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -257,7 +257,7 @@ int process(char *buf) exit(0); } - if(token[1]!=NULL&&strcmp(token[1],"branch"))_wait(pid); + if(token[1]==NULL||strcmp(token[1],"branch"))_wait(pid); } return 0; diff --git a/userspace/init.c b/userspace/init.c index a367fd9..3384edb 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,13 +1,10 @@ #include <stdio.h> #include <time.h> - int main(int argc, char **argv) { - char *argv1[]={"/bin/foolshell",0}; char *env1[]={"PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; - printf("fool-init\n"); time_t ltime; time(<ime); @@ -18,8 +15,6 @@ int main(int argc, char **argv) { int pid=_fork(); - printf("fool-init: forked pid=%d\n", pid); - if(pid==0) { _execve("/bin/foolshell",argv1,env1); // replace process with our foolshell :) @@ -31,8 +26,7 @@ int main(int argc, char **argv) _wait(pid); printf("fool-init: catched exit of process %d.\n",pid); - printf("fool-init: respawning a Fools Shell\n"); - + printf("fool-init: respawning a new fool-shell\n"); } return 0; diff --git a/userspace/ls.c b/userspace/ls.c index 413755b..416e139 100644 --- a/userspace/ls.c +++ b/userspace/ls.c @@ -1,4 +1,4 @@ -#include "fs/fs.h" +#include "interface/fs.h" void usage() { @@ -7,10 +7,7 @@ void usage() int main(int argc, char **argv) { - - fs_dirent *dirs=malloc(sizeof(fs_dirent)*25); char *dir=getenv("PWD"); -// printf("PWD = %s\n",dir); if(argc==2) { @@ -26,19 +23,16 @@ int main(int argc, char **argv) } } - int ls=_readdir(dir,dirs,25); - if(ls==-1) + fs_dirent dirs; + uint32_t pos=0; + int cnt=0; + while(1) { - printf("%s: file or directory '%s' not found.\n",argv[0],dir); - return 0; + cnt =_readdir(dir,&dirs,&pos); + if(cnt<1) break; + printf("% 12i %s%c\n",dirs.inode, dirs.name, ((dirs.type==FS_FILE_TYPE_DIR)?'/':' ')); } - int i; - for(i=0;i<ls;i++) - { - printf("%i %s%c\n",dirs[i].inode, dirs[i].name, ((dirs[i].type==FS_FILE_TYPE_DIR)?'/':' ')); - } - return 0; } diff --git a/userspace/snake2.h b/userspace/snake2.h index 06ca797..d4c47a8 100644 --- a/userspace/snake2.h +++ b/userspace/snake2.h @@ -1,6 +1,6 @@ ////////////////////////////////////////////////// -// this syscall will be move to newlib later! +// this syscall will be moved to newlib later! #define SYSCALL_CLONE 83 int _clone(void) |
