diff options
| author | Miguel <m.i@gmx.at> | 2018-08-18 13:23:53 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-08-18 13:23:53 +0200 |
| commit | 7b0d88b2dff9b635d9ff69f6d51b6832c1ca4c40 (patch) | |
| tree | 22c452e9c7ad586136721e776e0b67b23fb33119 | |
| parent | 17fd357bad5f6c3362cfdab1d807aa463c69a4e9 (diff) | |
cleaning up syscalls and playing with new pipes
| -rw-r--r-- | asm/int_syscall_handler.asm | 34 | ||||
| -rw-r--r-- | driver/keyboard.c | 15 | ||||
| -rw-r--r-- | driver/screen.c | 3 | ||||
| -rw-r--r-- | kernel/config.h | 34 | ||||
| -rw-r--r-- | kernel/fd.c | 9 | ||||
| -rw-r--r-- | kernel/fd.h | 1 | ||||
| -rw-r--r-- | kernel/fifo.c | 2 | ||||
| -rw-r--r-- | kernel/fifo.h | 1 | ||||
| -rw-r--r-- | kernel/kernel.c | 77 | ||||
| -rw-r--r-- | kernel/kernel.h | 38 | ||||
| -rw-r--r-- | kernel/kmalloc.c | 2 | ||||
| -rw-r--r-- | kernel/mem.c | 2 | ||||
| -rw-r--r-- | kernel/spinlock.c | 2 | ||||
| -rw-r--r-- | kernel/syscalls.c | 96 | ||||
| -rw-r--r-- | kernel/syscalls.h | 82 | ||||
| -rw-r--r-- | kernel/usermode.c | 2 | ||||
| -rw-r--r-- | lib/logger/log.c | 11 | ||||
| -rw-r--r-- | syscalls/syscalls.c (renamed from syscalls.c) | 56 | ||||
| -rw-r--r-- | terminal/terminal.c | 17 | ||||
| -rw-r--r-- | terminal/terminal.h | 1 | ||||
| -rw-r--r-- | userspace/cat.c | 14 | ||||
| -rw-r--r-- | userspace/err.c | 9 | ||||
| -rw-r--r-- | userspace/foolshell.c | 21 |
23 files changed, 198 insertions, 331 deletions
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm index d928519..952faae 100644 --- a/asm/int_syscall_handler.asm +++ b/asm/int_syscall_handler.asm @@ -11,15 +11,12 @@ global int_syscall_handler [extern syscall_execve] [extern syscall_open] [extern syscall_close] -[extern syscall_fstat] [extern syscall_isatty] [extern syscall_lseek] [extern syscall_sbrk] [extern syscall_stat] -[extern syscall_lstat] [extern syscall_fork] -[extern syscall_has_data_waiting] -[extern syscall_tune] +[extern syscall_poll] [extern syscall_gettimeofday] [extern syscall_unhandled] @@ -62,9 +59,6 @@ je call_wait cmp eax, 66 je call_close - cmp eax, 67 - je call_fstat - cmp eax, 68 je call_isatty @@ -80,14 +74,14 @@ je call_wait cmp eax, 74 je call_stat + cmp eax, 67 + je call_stat + cmp eax, 79 - je call_lstat + je call_stat cmp eax, 80 - je call_has_data - - cmp eax, 81 - je call_tune + je call_poll push eax jmp call_unhandled @@ -186,10 +180,6 @@ call_stat: call syscall_stat jmp done -call_lstat: - call syscall_lstat - jmp done - call_write: call syscall_write jmp done @@ -206,10 +196,6 @@ call_close: call syscall_close jmp done -call_fstat: - call syscall_fstat - jmp done - call_isatty: call syscall_isatty jmp done @@ -222,12 +208,8 @@ call_sbrk: call syscall_sbrk jmp done -call_has_data: - call syscall_has_data_waiting - jmp done - -call_tune: - call syscall_tune +call_poll: + call syscall_poll jmp done call_unhandled: diff --git a/driver/keyboard.c b/driver/keyboard.c index f2a44ec..8d7c8aa 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -1,5 +1,5 @@ /// idiots keyboard driver //// -// http://www.computer-engineering.org/ps2keyboard/scancodes1.html +// http://www.computer-engineering.org/ps2keyboard/scancodes1.html #define FOOLOS_MODULE_NAME "keyboard" #include <stdbool.h> @@ -10,11 +10,16 @@ static bool shift_l=false; static bool shift_r=false; static bool capslock=false; -static void (*put)(uint8_t c); +static uint32_t kb_stream; -void keyboard_init(void (*func)(uint8_t c)) +static void put(uint8_t c) { - put=func; + syscall_write(kb_stream,&c,1); +} + +void keyboard_init(uint32_t s) +{ + kb_stream=s; } void keyboard_handle(uint8_t in) @@ -122,10 +127,10 @@ void keyboard_handle(uint8_t in) if(break_caps_lock==in)capslock=!capslock; - char ascii; bool match=false; + // optimize this! if(ctrl_l) { diff --git a/driver/screen.c b/driver/screen.c index 6b47312..f095a15 100644 --- a/driver/screen.c +++ b/driver/screen.c @@ -1,5 +1,5 @@ #include "screen.h" -#include "kernel/config.h" +#include "kernel/kernel.h" //#define FOOLOS_CONSOLE @@ -15,6 +15,7 @@ void update_cursor(uint32_t col,uint32_t row) // cursor LOW port to vga INDEX register x86_outb(0x3D4, 0x0F); x86_outb(0x3D5, (unsigned char)(position&0xFF)); + // cursor HIGH port to vga INDEX register x86_outb(0x3D4, 0x0E); x86_outb(0x3D5, (unsigned char )((position>>8)&0xFF)); diff --git a/kernel/config.h b/kernel/config.h deleted file mode 100644 index 9297a99..0000000 --- a/kernel/config.h +++ /dev/null @@ -1,34 +0,0 @@ - -/******************************************** - * F00l 0S Central Configuration File * - ********************************************/ - -#ifndef FOOLOS_CONFIG_H -#define FOOLOS_CONFIG_H - -#include "lib/logger/log.h" - -#define KERNEL_VERSION "FoolOS 0.3.2" -#define FIFO_MAX_RINGBUFFERS 20 -#define MAX_FIFOS 20 -#define MAX_FD 20 - -#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line - -#define FOOLOS_LOG_OFF // do not log anything -#define FOOLOS_LOG_WHITELIST "" //,"elf","ext2","" // make exceptions for these modules. wmpty string marks the end -#define FOOLOS_LOG_LEVEL FOOLOS_LOG_DEBUG // minimal severity level to log - -#define FOOLOS_CONSOLE // otherwise VESA will be used! -#define FOOLSOS_SHOW_VESAMODES -#define MEM_PRINT_MEMORYMAP -#define LOG_BUF_SIZE 4069 -#define LOG_SYSCALLS - -#define BIN_INIT "/bin/init" - -#define KMALLOC_MEM_SIZE 1024*1024*8 // 8MB for in kernel-memory -#define NUMBER_SPINLOCKS 16 - -#endif - diff --git a/kernel/fd.c b/kernel/fd.c index 5eb2678..524737e 100644 --- a/kernel/fd.c +++ b/kernel/fd.c @@ -1,4 +1,5 @@ #include "fd.h" +#include "fifo.h" bool fd_write(fd* f,uint8_t c) { @@ -24,9 +25,9 @@ fd fd_from_fifo(fifo* fif) { fd f; f.data=fif; - f.read=fd_read; - f.write=fd_write; - f.close=fd_close; - f.has=fd_has; + f.read=fifo_get; + f.write=fifo_put; +// f.close=fd_close; + f.has=fifo_has; return f; } diff --git a/kernel/fd.h b/kernel/fd.h index fe048f4..8c7ea45 100644 --- a/kernel/fd.h +++ b/kernel/fd.h @@ -16,7 +16,6 @@ typedef struct fd_struct bool (*close)(struct fd_struct*); void *data; // opaque data - }fd; uint8_t fd_read(fd*); diff --git a/kernel/fifo.c b/kernel/fifo.c index 8eb2273..8062c82 100644 --- a/kernel/fifo.c +++ b/kernel/fifo.c @@ -2,7 +2,7 @@ #include "fifo.h" #include "ringbuffer.h" -#include "config.h" +#include "kernel.h" #include "lib/logger/log.h" #include <stddef.h> diff --git a/kernel/fifo.h b/kernel/fifo.h index b5c11a4..fd9146c 100644 --- a/kernel/fifo.h +++ b/kernel/fifo.h @@ -11,7 +11,6 @@ typedef struct fifo_struct bool (*put)(struct fifo_stuct*,uint8_t); uint8_t (*get)(struct fifo_struct*); bool (*has)(struct fifo_struct*); - void *data; // opaque data }fifo; diff --git a/kernel/kernel.c b/kernel/kernel.c index fca6fe6..79acf18 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,10 +1,10 @@ #define FOOLOS_MODULE_NAME "kernel" -#include "kernel.h" #include <stdint.h> #include <stddef.h> -#include "config.h" +#include "syscalls.h" +#include "kernel.h" #include "types.h" #include "lib/logger/log.h" #include "fifo.h" @@ -20,75 +20,28 @@ #include "terminal/terminal.h" #include "driver/screen.h" -// The Foolish structure of Fool OS! // -static fool_os foolos; - -fool_os *get_fool() -{ - return &foolos; -} -// - -// stdio init : TODO: move away! -static terminal_tty tty1; -static term_out screen; -static term_in input; - -static ringbuffer stdin_buf; - -static void put_kb(uint8_t c) -{ - terminal_kb(&tty1,c); -} - -static void stdin_put_char(uint8_t c) -{ - ringbuffer_put(&stdin_buf,c); -} - -static void init_stdio() -{ - // - // Setup terminal output / input - // - - screen.put_char=console_put_char; - screen.update_cursor=update_cursor; - - input.put_char=stdin_put_char; - - tty1=terminal_init(&screen,&input); - - get_fool()->tty=&tty1; - - // - - get_fool()->std_out.data=&tty1; - get_fool()->std_out.put=terminal_put; - - stdin_buf=ringbuffer_init(1); - get_fool()->std_in.data=&stdin_buf; - get_fool()->std_in.put=ringbuffer_put; - get_fool()->std_in.get=ringbuffer_get; - get_fool()->std_in.has=ringbuffer_has; - - keyboard_init(put_kb); -} - /* F00L 0S Entry point (called directly from asm/multiboot.asm */ void kernel_main(uint32_t eax,uint32_t ebx) { + + // + // STDIN & STDOUT // - // STDIN and STDOUT - // - init_stdio(); + uint32_t sstdin = syscall_open("stdin",0,0); // stdin 0 + uint32_t sstdout = syscall_open("term",0,0); // stdout 1 + uint32_t sstderr = syscall_open("stderr",0,0); // stderr 2 // // PR // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - compiled on %s at %s",KERNEL_VERSION,__DATE__,__TIME__); + // + // Setup Keyboard Driver + // + keyboard_init(sstdin); + // // Configuring the PIT timer. // @@ -152,10 +105,6 @@ void kernel_main(uint32_t eax,uint32_t ebx) // //pci_init(); // - - //empty stdin! - while(fifo_has(&get_fool()->std_in)) - fifo_get(&get_fool()->std_in); // // Initialize Multitasking diff --git a/kernel/kernel.h b/kernel/kernel.h index cb9810c..44b9b2d 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -1,18 +1,34 @@ -#ifndef FOOLOS_KERNEL_H -#define FOOLOS_KERNEL_H -#include "fifo.h" -#include "terminal/terminal.h" +/******************************************** + * F00l 0S Central Configuration File * + ********************************************/ -typedef struct fool_os_struct -{ +#ifndef FOOLOS_CONFIG_H +#define FOOLOS_CONFIG_H - fifo std_in; - fifo std_out; - terminal_tty* tty; +#include "lib/logger/log.h" -}fool_os; +#define KERNEL_VERSION "FoolOS 0.3.2" +#define FIFO_MAX_RINGBUFFERS 20 +#define MAX_FIFOS 20 +#define MAX_FD 20 -fool_os *get_fool(); +#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line + +//#define FOOLOS_LOG_OFF // do not log anything +#define FOOLOS_LOG_WHITELIST "" //,"elf","ext2","" // make exceptions for these modules. wmpty string marks the end +#define FOOLOS_LOG_LEVEL FOOLOS_LOG_DEBUG // minimal severity level to log + +#define FOOLOS_CONSOLE // otherwise VESA will be used! +#define FOOLSOS_SHOW_VESAMODES +#define MEM_PRINT_MEMORYMAP +#define LOG_BUF_SIZE 4069 +//#define LOG_SYSCALLS + +#define BIN_INIT "/bin/init" + +#define KMALLOC_MEM_SIZE 1024*1024*8 // 8MB for in kernel-memory +#define NUMBER_SPINLOCKS 16 #endif + diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c index 6db07a1..492d471 100644 --- a/kernel/kmalloc.c +++ b/kernel/kmalloc.c @@ -1,7 +1,7 @@ #define FOOLOS_MODULE_NAME "kmalloc" #include "kmalloc.h" -#include "kernel/config.h" +#include "kernel.h" #include "lib/logger/log.h" static uint8_t data[KMALLOC_MEM_SIZE]; // bytes diff --git a/kernel/mem.c b/kernel/mem.c index 74b3a98..029ea10 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -2,7 +2,7 @@ #include <stdint.h> -#include "config.h" +#include "kernel.h" #include "multiboot.h" #include "lib/logger/log.h" diff --git a/kernel/spinlock.c b/kernel/spinlock.c index 68e64a9..f97b7db 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c @@ -1,7 +1,7 @@ #define FOOLOS_MODULE_NAME "spinlock" #include "spinlock.h" -#include "config.h" +#include "kernel.h" #include "lib/logger/log.h" #include "x86.h" diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 621880a..0be0602 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -1,12 +1,14 @@ #define FOOLOS_MODULE_NAME "syscalls" #include "lib/logger/log.h" +#include "lib/string/string.h" #include "fs/fs.h" #include "fs/ext2.h" -#include "kernel/kernel.h" -#include "kernel/config.h" +#include "kernel.h" #include "fifo.h" #include "fd.h" +#include "terminal/terminal.h" +#include "driver/screen.h" #include <sys/stat.h> #include <sys/time.h> #include <stdbool.h> @@ -21,10 +23,15 @@ static uint32_t next_fd=0; static fifo fifos[MAX_FIFOS]; static uint32_t next_fifo=0; +// screen / terminal +term_out screen; +terminal_tty tty1; + int syscall_unhandled(int nr) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr); - panic(FOOLOS_MODULE_NAME,"unhandled syscall (generic handler)"); + char msg[256]; + tfp_sprintf(msg, "unhandled syscall : %d",nr); + panic(FOOLOS_MODULE_NAME,msg); } int syscall_gettimeofday(struct timeval *tv, struct timezone *tz) @@ -59,23 +66,15 @@ int syscall_lseek(int file,int ptr,int dir) // TODO: /dev/console or /dev/tty1 - /dev/ttyN int syscall_write(int file, char *buf, int len) { - lock_spin(2); - - //x86_int_disable(); #ifdef LOG_SYSCALLS 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: write (only stdout and stderr)"); - - //stderr and stdout go to console for(int i=0;i<len;i++) { - fifo_put(&get_fool()->std_out,buf[i]); + fd_write(&fds[file],buf[i]); } - lock_release(2); - //x86_int_enable(); return len; } @@ -84,22 +83,20 @@ int syscall_read(int file, char *buf, int len) #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"read(file=%d, buf=0x%08X, len=%d)", file,buf,len); #endif + //file 0 = stdin , file 1 = stdout , file 2 = stderr - // file 1 = stdin , file 2 = stdout - - // stdin TODO: other descroptiors! - if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall: read (only stdin)"); - char c; int l=0; while(1) { - while(!fifo_has(&get_fool()->std_in)); - c=fifo_get(&get_fool()->std_in); + while(!fd_has(&fds[file])); + c=fd_read(&fds[file]); + *buf=c; buf++; l++; + if(l==len)return l; if(c=='\n')return l; } @@ -116,21 +113,25 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max) } // for non blocking io? -int syscall_has_data_waiting(int file) +int syscall_poll(int file) { + file=2; //workaround #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"has data waiting?"); #endif - return fifo_has(&get_fool()->std_in); + return fd_has(&fds[file]); } +// TODO: DELETE THIS SHIT! int syscall_tune(int v1,int v2, int v3) { #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"tuning request"); #endif + // osbolete + /* if(v1==0) // regular tty mode { get_fool()->tty->set_buff=true; @@ -141,7 +142,7 @@ int syscall_tune(int v1,int v2, int v3) get_fool()->tty->set_buff=false; get_fool()->tty->set_echo=false; } - + */ return 0; } @@ -235,17 +236,39 @@ int syscall_execve(char *name, char **argv, char **env) // this is never reached! } +// minihack +int get_max_fd() +{ + return next_fd-1; +} + // TODO: support other files too (not only fifo pipes) +// TODO: allow opening existing files/named pipes 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 - + if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)panic(FOOLOS_MODULE_NAME,"we ran out of fd's or fifo's"); + + if(0!=strcmp(name,"term")) + { + fifos[next_fifo]=fifo_create_buffered(1); + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } + else + { + screen.put_char=console_put_char; + screen.update_cursor=update_cursor; + tty1=terminal_init(&screen,NULL); + + fifos[next_fifo].data=&tty1; + fifos[next_fifo].put=terminal_put; + + fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); + } - fifos[next_fifo]=fifo_create_buffered(1); - fds[next_fd]=fd_from_fifo(&fifos[next_fifo]); next_fifo++; next_fd++; @@ -304,24 +327,3 @@ int syscall_stat(const char *path, struct stat *st,int none) st->st_mode = S_IFCHR; return 0; } - -int syscall_fstat(int file, struct stat *st,int none) -{ - #ifdef LOG_SYSCALLS - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fstat (file=%d,stat=0x%08X)", file,st); - #endif - - st->st_mode = S_IFCHR; - return 0; -} - - -int syscall_lstat(const char *path, struct stat *st,int none) -{ - #ifdef LOG_SYSCALLS - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lstat (path=0x%08X,stat=0x%08X)", path,st); - #endif - - st->st_mode = S_IFCHR; - return 0; -} diff --git a/kernel/syscalls.h b/kernel/syscalls.h index 9a08cba..c8bc807 100644 --- a/kernel/syscalls.h +++ b/kernel/syscalls.h @@ -1,62 +1,22 @@ -#include <sys/time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <stdint.h> -#include "fs/fs.h" - -//fool-os syscalls -#define SYSCALL_READDIR 63 -#define SYSCALL_HAS_DATA 80 -#define SYSCALL_TUNE 81 - -//syscalls required by newlib -#define SYSCALL_EXIT 60 -#define SYSCALL_WRITE 61 -#define SYSCALL_READ 62 -#define SYSCALL_EXECVE 64 -#define SYSCALL_OPEN 65 -#define SYSCALL_CLOSE 66 -#define SYSCALL_FSTAT 67 -#define SYSCALL_ISATTY 68 -#define SYSCALL_LSEEK 69 -#define SYSCALL_SBRK 70 -#define SYSCALL_STAT 74 -#define SYSCALL_LSTAT 79 - -// stubs only so far! +#define SYSCALL_EXIT 60 +#define SYSCALL_CLOSE 66 +#define SYSCALL_EXECVE 64 +#define SYSCALL_FORK 72 +#define SYSCALL_GETPID 78 +#define SYSCALL_ISATTY 68 +#define SYSCALL_LINK 82 +#define SYSCALL_LSEEK 69 +#define SYSCALL_OPEN 65 +#define SYSCALL_READ 62 +#define SYSCALL_SBRK 70 +#define SYSCALL_STAT 74 +#define SYSCALL_FSTAT 67 +#define SYSCALL_LSTAT 79 +#define SYSCALL_TIMES 75 +#define SYSCALL_UNLINK 76 +#define SYSCALL_WAIT 77 +#define SYSCALL_WRITE 61 #define SYSCALL_GETTIMEOFDAY 71 -#define SYSCALL_FORK 72 -#define SYSCALL_KILL 73 -#define SYSCALL_LINK 73 -#define SYSCALL_TIMES 75 -#define SYSCALL_UNLINK 76 -#define SYSCALL_WAIT 77 -#define SYSCALL_GETPID 78 - -/* -int syscall_execve(char *name, char **argv, char **env); -int syscall_write(int file, char *buf, int len); - -int syscall_readdir(const char *name,struct fs_dirent *dirs,int max); - -int syscall_exit(int ret, int none1, int none2); -int syscall_open(char *name, int flags, int len); -int syscall_read(int file, char *buf, int len); -int syscall_close(int file,int none1,int none2); -int syscall_fstat(int file, struct stat *st,int none); -int syscall_isatty(int file,int none1,int none2); -int syscall_lseek(int file,int ptr,int dir); -int syscall_stat(char *file, struct stat *st); -int syscall_sbrk(int incr, int none1, int none2); -// -int syscall_gettimeofday(struct timeval *tv, struct timezone *tz); -int syscall_fork(void); -int syscall_getpid(void); -int syscall_kill(int pid, int sig); -int syscall_link(char *old, char *ne); -int syscall_times(struct tms *buf); -int syscall_unlink(char *name); -int syscall_wait(int *status); -// -int syscall_unhandled(int nr); -*/ +#define SYSCALL_READDIR 63 +#define SYSCALL_KILL 73 +#define SYSCALL_POLL 80 diff --git a/kernel/usermode.c b/kernel/usermode.c index 2455ba6..76558d8 100644 --- a/kernel/usermode.c +++ b/kernel/usermode.c @@ -6,7 +6,7 @@ #include "asm/syscall.h" #include "asm/usermode.h" -#include "kernel/config.h" +#include "kernel.h" #include "lib/logger/log.h" diff --git a/lib/logger/log.c b/lib/logger/log.c index d591b36..5350eda 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -5,7 +5,6 @@ #include <stdbool.h> #include "kernel/kernel.h" -#include "kernel/config.h" #include "kernel/timer.h" #include "kernel/fifo.h" @@ -13,10 +12,8 @@ static void log_string(char *str) { - while(*str!=0) - { - fifo_put(&get_fool()->std_out,*(str++)); - } + if(get_max_fd()<2)return; +// syscall_write(2,str,strlen(str)); } void log(char *module_name, int log_level, char *format_string, ...) @@ -52,7 +49,9 @@ void panic(char *module_name, char *message) { char buf_log[256]; tfp_sprintf(buf_log,"\033[41;37m\n !! KERNEL PANIC !! %s: %s\n\n",module_name,message); - log_string(buf_log); +// log_string(buf_log); + //PANIC DIRECTLY TO STDOUT// + syscall_write(1,buf_log,strlen(buf_log)); while(1) { diff --git a/syscalls.c b/syscalls/syscalls.c index f2978cc..3cd1f95 100644 --- a/syscalls.c +++ b/syscalls/syscalls.c @@ -1,68 +1,26 @@ +#include <stdint.h> + #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> -#include <stdint.h> -typedef struct fs_dirent_struct -{ - uint32_t inode; - uint32_t offset; - uint16_t length; - uint8_t type; - char name[256]; -}fs_dirent; - -#define SYSCALL_EXIT 60 -#define SYSCALL_WRITE 61 -#define SYSCALL_READ 62 -#define SYSCALL_READDIR 63 // fool-os-special -#define SYSCALL_EXECVE 64 -#define SYSCALL_OPEN 65 -#define SYSCALL_CLOSE 66 -#define SYSCALL_FSTAT 67 -#define SYSCALL_ISATTY 68 -#define SYSCALL_LSEEK 69 -#define SYSCALL_SBRK 70 -#define SYSCALL_GETTIMEOFDAY 71 -#define SYSCALL_FORK 72 -#define SYSCALL_KILL 73 -#define SYSCALL_STAT 74 -#define SYSCALL_TIMES 75 -#define SYSCALL_UNLINK 76 -#define SYSCALL_WAIT 77 -#define SYSCALL_GETPID 78 -#define SYSCALL_LSTAT 79 -#define SYSCALL_HAS_DATA 80 // fool-os-special -#define SYSCALL_TUNE 81 // fool-os-special -#define SYSCALL_LINK 82 +#include "fs.h" +#include "syscalls.h" extern char **environ; -//struct _reent *_impure_ptr; -// fool os custom -int readdir(const char *name,fs_dirent *dirs,int max) +int _readdir(const char *name,fs_dirent *dirs,int max) { return syscall(SYSCALL_READDIR,name,dirs,max); } -int has_data_waiting() +int _poll(int file) { - return syscall(SYSCALL_HAS_DATA,0,0,0); + return syscall(SYSCALL_POLL,file,0,0); } -int fool_tune(int v1, int v2, int v3) -{ - return syscall(SYSCALL_TUNE,v1,v2,v3); -} -// - void _exit(int ret) { - _exit2(ret,environ); -} - -void _exit2(int ret,char **environ) -{ return syscall(SYSCALL_EXIT,ret,environ,0); } diff --git a/terminal/terminal.c b/terminal/terminal.c index 872a7fb..2f10ab8 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -12,6 +12,8 @@ #include "lib/logger/log.h" +#include <stddef.h> + typedef enum { ecma48_reset, @@ -251,6 +253,7 @@ terminal_tty terminal_init(term_out *screen,term_in *input) return tty; } +/* void terminal_kb(terminal_tty *tty, uint8_t c) { if(tty->set_echo)terminal_put(tty,c); @@ -280,6 +283,7 @@ void terminal_kb(terminal_tty *tty, uint8_t c) } } +*/ // send one ASCII character to the terminal bool terminal_put(terminal_tty *tty, uint8_t c) @@ -431,11 +435,14 @@ bool terminal_put(terminal_tty *tty, uint8_t c) if(c=='Z'){// IDENTIFY: claim we are vt102 - tty->input->put_char(0x1B); //ESC - tty->input->put_char('['); - tty->input->put_char('?'); - tty->input->put_char('6'); - tty->input->put_char('c'); + if(tty->input!=NULL) + { + tty->input->put_char(0x1B); //ESC + tty->input->put_char('['); + tty->input->put_char('?'); + tty->input->put_char('6'); + tty->input->put_char('c'); + } return;} diff --git a/terminal/terminal.h b/terminal/terminal.h index 0106f29..be711f5 100644 --- a/terminal/terminal.h +++ b/terminal/terminal.h @@ -70,6 +70,7 @@ typedef struct terminal_tty_struct }terminal_tty; terminal_tty terminal_init(term_out *screen,term_in *input); + bool terminal_put(terminal_tty *tty, uint8_t c); void terminal_kb(terminal_tty *tty, uint8_t c); diff --git a/userspace/cat.c b/userspace/cat.c index a371397..8980546 100644 --- a/userspace/cat.c +++ b/userspace/cat.c @@ -2,16 +2,14 @@ int main() { - FILE *f = fopen("README", "r"); - if (f == NULL) - { - perror("unable to open file"); - return 1; - } - puts("open success"); - fclose(f); + char buf[256]; + + while(has_data_waiting(2)){ + fread(buf,1,5,stderr); // read stderr; + printf("[%s]\n",buf); + } return 0; } diff --git a/userspace/err.c b/userspace/err.c new file mode 100644 index 0000000..b8dc8ed --- /dev/null +++ b/userspace/err.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main() +{ + char buf[]="errrrrrro\n"; + printf("writing some err\n"); + fwrite(buf,1,10,stderr); // write stderr; + return 0; +} diff --git a/userspace/foolshell.c b/userspace/foolshell.c index a502f47..7247871 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -71,11 +71,27 @@ int main(int argc, char **argv) //char *buf=malloc(256); char *buf=calloc(sizeof(char),256); + printf("setvbuf returned %i\n",setvbuf(stdin,NULL,_IONBF,0)); + while(1) { prompt(); - fgets(buf,255,stdin); - buf[strlen(buf)-1]=0; // remove \n + int bl=0; + + while(1) + { + char c=fgetc(stdin); + putc(c,stdout); + if(c=='\n')break; + + + buf[bl]=c; + buf[bl+1]='\0'; + bl++; + } + + //fgets(buf,255,stdin); + //buf[strlen(buf)-1]=0; // remove \n process(buf); } @@ -125,7 +141,6 @@ char **tokenize(char *buf) int process(char *buf) { - char **token=tokenize(buf); char *command=token[0]; // puts(command); |
