summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/config.h34
-rw-r--r--kernel/fd.c9
-rw-r--r--kernel/fd.h1
-rw-r--r--kernel/fifo.c2
-rw-r--r--kernel/fifo.h1
-rw-r--r--kernel/kernel.c77
-rw-r--r--kernel/kernel.h38
-rw-r--r--kernel/kmalloc.c2
-rw-r--r--kernel/mem.c2
-rw-r--r--kernel/spinlock.c2
-rw-r--r--kernel/syscalls.c96
-rw-r--r--kernel/syscalls.h82
-rw-r--r--kernel/usermode.c2
13 files changed, 120 insertions, 228 deletions
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"