summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/fifo.c2
-rw-r--r--kernel/fifo.h6
-rw-r--r--kernel/kernel.c29
-rw-r--r--kernel/ringbuffer.c85
-rw-r--r--kernel/ringbuffer.h27
-rw-r--r--kernel/syscalls.c9
7 files changed, 139 insertions, 21 deletions
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/kernel/ringbuffer.c b/kernel/ringbuffer.c
new file mode 100644
index 0000000..a749b16
--- /dev/null
+++ b/kernel/ringbuffer.c
@@ -0,0 +1,85 @@
+#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;
+
+ringbuffer ringbuffer_init(uint32_t size)
+{
+ ringbuffer f;
+ f.data=kballoc(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;
+}
+
+volatile bool ringbuffer_put(ringbuffer* f,uint8_t c)
+{
+ x86_int_disable();
+ lock_spin(sl);
+
+ if((f->back-1+f->size)%f->size==f->front)
+ {
+ lock_release(sl);
+ x86_int_enable();
+ return false;
+ }
+
+ f->data[f->back]=c;
+ f->back--;
+ f->back+=f->size;
+ f->back%=f->size;
+
+ lock_release(sl);
+ x86_int_enable();
+
+ return true;
+}
+
+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();
+ lock_spin(sl);
+
+ if(f->front==f->back)
+ {
+ lock_release(sl);
+ x86_int_enable();
+ return ' ';
+ }
+
+ c=f->data[f->front];
+
+ f->front--;
+ f->front+=f->size;
+ f->front%=f->size;
+
+ lock_release(sl);
+ x86_int_enable();
+
+ return c;
+}
diff --git a/kernel/ringbuffer.h b/kernel/ringbuffer.h
new file mode 100644
index 0000000..c79fdcf
--- /dev/null
+++ b/kernel/ringbuffer.h
@@ -0,0 +1,27 @@
+#ifndef RINGBUFFER_H
+#define RINGBUFFER_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+// Simple FIRST IN FIRST OUT
+// requires kballoc - block allocation
+typedef volatile struct ringbuffer_struct
+{
+ uint32_t size;
+ uint32_t front;
+ uint32_t back;
+
+ uint8_t *data;
+
+}ringbuffer;
+
+// create new fifo of given size (in blocks)
+ringbuffer ringbuffer_init(uint32_t blocks);
+
+// true on success
+bool ringbuffer_put(ringbuffer*,uint8_t);
+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)
{