diff options
| author | Michal Idziorek <m.i@gmx.at> | 2015-05-18 09:20:01 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2015-05-18 09:20:01 +0200 |
| commit | a6184be79e3918764d5e683796afbd8e8ccba018 (patch) | |
| tree | 870a5506efad410c89524bbeb740fb44974bf1da | |
| parent | fe79552d9fcfd60d8c2bb828c6b93cf471ef7b75 (diff) | |
fifo through ringbuffer(stdin) and vt52(stdout) finally working!
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | kernel/config.h | 2 | ||||
| -rw-r--r-- | kernel/fifo.c | 2 | ||||
| -rw-r--r-- | kernel/fifo.h | 6 | ||||
| -rw-r--r-- | kernel/kernel.c | 29 | ||||
| -rw-r--r-- | kernel/ringbuffer.c (renamed from fs/ringbuffer.c) | 32 | ||||
| -rw-r--r-- | kernel/ringbuffer.h (renamed from fs/ringbuffer.h) | 4 | ||||
| -rw-r--r-- | kernel/syscalls.c | 9 | ||||
| -rw-r--r-- | terminal/vt52.c | 13 | ||||
| -rw-r--r-- | userspace/foolshell.c | 8 |
10 files changed, 60 insertions, 47 deletions
@@ -34,7 +34,7 @@ CFLAGS+=-ffreestanding #CFLATS+=-Wall #CFLAGS+=-Wextra #CFLAGS+=-O3 -#CFLAGS+=-O0 +CFLAGS+=-O0 #CFLAGS+=-nostdlib CFLAGS+=-std=gnu11 CFLAGS+=-I. diff --git a/kernel/config.h b/kernel/config.h index c4f9af1..0a6fd3c 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/fifo.c b/kernel/fifo.c index abd6c46..314e9ff 100644 --- a/kernel/fifo.c +++ b/kernel/fifo.c @@ -5,7 +5,7 @@ bool fifo_put(fifo* f,uint8_t c) return f->put(f->data,c); } -uint8_t fifo_get(fifo* f) +volatile uint8_t fifo_get(fifo* f) { return f->get(f->data); } diff --git a/kernel/fifo.h b/kernel/fifo.h index bae7d57..e0a81e5 100644 --- a/kernel/fifo.h +++ b/kernel/fifo.h @@ -17,9 +17,9 @@ typedef struct fifo_struct }fifo; -bool fifo_put(fifo*,uint8_t); -uint8_t fifo_get(fifo*); -bool fifo_has(fifo*); +volatile bool fifo_put(fifo*,uint8_t); +volatile uint8_t fifo_get(fifo*); +volatile bool fifo_has(fifo*); #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index dd3f502..5350109 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -18,6 +18,7 @@ #include "mp.h" #include "interrupts.h" #include "multiboot.h" +#include "ringbuffer.h" #include <stddef.h> @@ -41,12 +42,16 @@ fool_os *get_fool() } // // -// // stdio init : TODO: move away! static vt52_tty tty1; +static term_out screen; +static term_in input; + +static ringbuffer stdin_buf; + static void put_kb(uint8_t c) { @@ -55,30 +60,32 @@ static void put_kb(uint8_t c) static void stdin_put_char(uint8_t c) { - vt52_kb(&tty1,c); + ringbuffer_put(&stdin_buf,c); } - static void init_stdio() { -// get_fool().std_in - // // Setup terminal output / input // - term_out screen; + screen.put_char=console_put_char; screen.update_cursor=update_cursor; - term_in input; input.put_char=stdin_put_char; tty1=vt52_init(&screen,&input); + get_fool()->std_out.data=&tty1; get_fool()->std_out.put=vt52_put; - keyboard_init(put_kb); + 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); } @@ -147,8 +154,6 @@ void kernel_main(uint32_t eax,uint32_t ebx) smp_log_procdata(&procdata); smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr - - // // Activate Virtual Memory (paging) // @@ -161,8 +166,10 @@ void kernel_main(uint32_t eax,uint32_t ebx) // Its driver will be hopefully implemented one day ;) TODO // //pci_init(); - + //empty stdin! + while(fifo_has(&get_fool()->std_in)) + fifo_get(&get_fool()->std_in); // // Initialize Multitasking diff --git a/fs/ringbuffer.c b/kernel/ringbuffer.c index 449ad88..a749b16 100644 --- a/fs/ringbuffer.c +++ b/kernel/ringbuffer.c @@ -1,6 +1,8 @@ #define FOOLOS_MODULE_NAME "ringbuffer" #include "lib/logger/log.h" +// TODO: why do we disable interrupts? (Eg. kb input) + #include "ringbuffer.h" static int sl=9; @@ -12,10 +14,12 @@ ringbuffer ringbuffer_init(uint32_t size) f.size=size*4096; f.front=f.size-1; f.back=f.size-1; + f.front=f.size-1; + f.back=f.size-1; return f; } -bool ringbuffer_put(ringbuffer* f,uint8_t c) +volatile bool ringbuffer_put(ringbuffer* f,uint8_t c) { x86_int_disable(); lock_spin(sl); @@ -23,13 +27,11 @@ bool ringbuffer_put(ringbuffer* f,uint8_t c) if((f->back-1+f->size)%f->size==f->front) { lock_release(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put"); x86_int_enable(); return false; } f->data[f->back]=c; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put %d %d (%c)", f->back, f->front,c); f->back--; f->back+=f->size; f->back%=f->size; @@ -40,9 +42,24 @@ bool ringbuffer_put(ringbuffer* f,uint8_t c) return true; } -uint8_t ringbuffer_get(ringbuffer* f) // blocking +volatile bool ringbuffer_has(ringbuffer* f) { + bool res=true; + + x86_int_disable(); + lock_spin(sl); + + if(f->front==f->back) + res=false; + lock_release(sl); + x86_int_enable(); + + return res; +} + +volatile uint8_t ringbuffer_get(ringbuffer* f) // non blocking . please check first +{ char c; x86_int_disable(); @@ -51,14 +68,11 @@ uint8_t ringbuffer_get(ringbuffer* f) // blocking if(f->front==f->back) { lock_release(sl); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by get"); x86_int_enable(); - c='_'; - return false; + return ' '; } c=f->data[f->front]; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get %d %d (%c)", f->back, f->front,c); f->front--; f->front+=f->size; @@ -67,5 +81,5 @@ uint8_t ringbuffer_get(ringbuffer* f) // blocking lock_release(sl); x86_int_enable(); - return true; + return c; } diff --git a/fs/ringbuffer.h b/kernel/ringbuffer.h index 31d00cf..c79fdcf 100644 --- a/fs/ringbuffer.h +++ b/kernel/ringbuffer.h @@ -6,7 +6,7 @@ // Simple FIRST IN FIRST OUT // requires kballoc - block allocation -typedef struct ringbuffer_struct +typedef volatile struct ringbuffer_struct { uint32_t size; uint32_t front; @@ -21,7 +21,7 @@ ringbuffer ringbuffer_init(uint32_t blocks); // true on success bool ringbuffer_put(ringbuffer*,uint8_t); -uint8_t ringbuffer_get(ringbuffer*); // blocking +uint8_t ringbuffer_get(ringbuffer*); // non-blocking please check first bool ringbuffer_has(ringbuffer*); // check if somehting waiting? #endif diff --git a/kernel/syscalls.c b/kernel/syscalls.c index cd54d7b..7ad977e 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -43,14 +43,13 @@ int syscall_write(int file, char *buf, int len) //stderr and stdout go to console for(int i=0;i<len;i++) { -// fifo_put(&get_fool()->fifo_stdout,buf[i]); + fifo_put(&get_fool()->std_out,buf[i]); } lock_release(2); //x86_int_enable(); return len; } -// TODO: /dev/kb int syscall_read(int file, char *buf, int len) { static bool eof=false; @@ -59,7 +58,6 @@ 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: read (only stdin)"); { @@ -74,8 +72,9 @@ int syscall_read(int file, char *buf, int len) while(1) { -// bool ret=ringbuffer_get(&c); - bool ret=false; + while(!fifo_has(&get_fool()->std_in)); + c=fifo_get(&get_fool()->std_in); + bool ret=true; if(ret) { diff --git a/terminal/vt52.c b/terminal/vt52.c index 66fd5f1..9197347 100644 --- a/terminal/vt52.c +++ b/terminal/vt52.c @@ -6,8 +6,8 @@ #include "vt52.h" #include "kernel/kmalloc.h" -#define VT52_WIDTH 80 -#define VT52_HEIGHT 25 +#define VT52_WIDTH 75 +#define VT52_HEIGHT 24 #define VT52_ESC_1 0x1b //ESC @@ -130,7 +130,7 @@ bool vt52_put(vt52_tty *tty, uint8_t c) case VT52_ERASE_SCR: for(uint32_t y=tty->y+1;y<tty->height;y++) { - for(uint32_t x=0;x<tty->width-1;x++) + for(uint32_t x=0;x<tty->width;x++) { uint32_t c=tty->data[index(tty,x,y+1)]; tty->data[index(tty,x,y)] = c; @@ -139,7 +139,7 @@ bool vt52_put(vt52_tty *tty, uint8_t c) } case VT52_ERASE_LINE: - for(uint32_t x=tty->x;x<tty->width-1;x++) + for(uint32_t x=tty->x;x<tty->width;x++) { uint32_t c=tty->data[index(tty,x,tty->y)]; tty->data[index(tty,x,tty->y)] = c; @@ -165,7 +165,7 @@ bool vt52_put(vt52_tty *tty, uint8_t c) else { tty->y++; - tty->x=0; + tty->x=-1; } tty->x++; @@ -182,9 +182,10 @@ bool vt52_put(vt52_tty *tty, uint8_t c) tty->y--; for(uint32_t y=0;y<tty->height;y++) { - for(uint32_t x=0;x<tty->width-1;x++) + for(uint32_t x=0;x<tty->width;x++) { uint32_t c=tty->data[index(tty,x,y+1)]; + if(y==tty->height-1)c=' '; tty->data[index(tty,x,y)] = c; tty->screen->put_char(c,0xf,x,y); } diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 84d24b0..8496b05 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -45,14 +45,6 @@ int main(int argc, char **argv) if(!silent)hello(); char *buf=malloc(256); - // printf("malloc returned: 0x%08X\n",buf); - // - while(1) - { - fgets(buf,2,stdin); - buf[1]=0; - puts(buf); - } while(1) |
