summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-17 21:41:21 +0200
committerMiguel <m.i@gmx.at>2018-08-17 21:41:21 +0200
commitc15925a24efe14f437d8a2699500241a58fdc8f9 (patch)
treec0db3a7d2a4f857324735df35e9cc1f0539c5f24
parent6fd78c2ff950310d8372ec0353553cc4a5a43e72 (diff)
cleanup and working on fifo pipes
-rw-r--r--Makefile4
-rw-r--r--asm/syscall.h11
-rw-r--r--asm/syscall.s5
-rw-r--r--asm/usermode.h7
-rw-r--r--asm/usermode.s15
-rw-r--r--kernel/config.h14
-rw-r--r--kernel/fd.c32
-rw-r--r--kernel/fd.h30
-rw-r--r--kernel/fifo.c25
-rw-r--r--kernel/fifo.h11
-rw-r--r--kernel/kernel.c22
-rw-r--r--kernel/kernel.h2
-rw-r--r--kernel/kmalloc.c12
-rw-r--r--kernel/kmalloc.h6
-rw-r--r--kernel/ringbuffer.c21
-rw-r--r--kernel/ringbuffer.h3
-rw-r--r--kernel/smp.c4
-rw-r--r--kernel/spinlock.c20
-rw-r--r--kernel/spinlock.h2
-rw-r--r--kernel/syscalls.c21
-rw-r--r--kernel/usermode.c20
-rw-r--r--kernel/x86.c33
-rw-r--r--kernel/x86.h23
-rw-r--r--lib/logger/log.c3
-rw-r--r--lib/printf/printf.c1
-rw-r--r--lib/string/string.h1
-rw-r--r--syscalls.c118
27 files changed, 237 insertions, 229 deletions
diff --git a/Makefile b/Makefile
index 52f9acb..4878633 100644
--- a/Makefile
+++ b/Makefile
@@ -32,9 +32,9 @@ CFLAGS+=-gstabs
#CFLAGS+= -w # disable all warnings
#CFLAGS+= -Wimplicit-function-declaration
#CFLAGS+= -Wextra
-#CFLAGS+= -Wall
+CFLAGS+= -Wall
#CFLAGS+= -Werror
-CFLAGS+= -Werror=implicit-function-declaration
+#CFLAGS+= -Werror=implicit-function-declaration
######## linker flags ####################
LDFLAGS=
diff --git a/asm/syscall.h b/asm/syscall.h
new file mode 100644
index 0000000..2cadce4
--- /dev/null
+++ b/asm/syscall.h
@@ -0,0 +1,11 @@
+/*
+ * Issue a System Call from Ring 3 / User Space
+ *
+ * Accepts up to 3 parameters.
+ * Check syscalls.h for details.
+ */
+
+uint32_t syscall(uint32_t code,
+ uint32_t param_1,
+ uint32_t param_2,
+ uint32_t param_3);
diff --git a/asm/syscall.s b/asm/syscall.s
index 8860d89..388b6fa 100644
--- a/asm/syscall.s
+++ b/asm/syscall.s
@@ -1,10 +1,5 @@
.global syscall
-// call from c with 4 x 32bit params
-// syscall number, p1,p2,p3,p4
-
-// TODO: push stack frame?
-
syscall:
push %ebx // preserve (sysV abi convnetion)
diff --git a/asm/usermode.h b/asm/usermode.h
new file mode 100644
index 0000000..9b76db3
--- /dev/null
+++ b/asm/usermode.h
@@ -0,0 +1,7 @@
+/*
+ * Switch to User Mode and returin to function given by pointer
+ * provide the address of a void func() that will be called without
+ * any params.
+ */
+
+void usermode(uint32_t func);
diff --git a/asm/usermode.s b/asm/usermode.s
index acf4b04..67eca04 100644
--- a/asm/usermode.s
+++ b/asm/usermode.s
@@ -1,8 +1,9 @@
-.global asm_usermode
-.extern userfunc
+.global usermode
-# pass address to func to exec (TODO)
-asm_usermode:
+usermode:
+
+ mov 0x4(%esp),%edx //get adress of passed : void func()
+ //to be called in ring 3
// 0x23 is user data segment (|2 low bits)
// 0x1b is user code segment (|2 low bits)
@@ -13,6 +14,7 @@ asm_usermode:
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
+
// ss is handled by iret
mov %esp, %eax
@@ -25,10 +27,11 @@ asm_usermode:
//mov $0x200, %eax
//push %eax // eflags image
pushl $0x1B // return code segment selector
- push $userfunc // return instruction pointer
+ push %edx // return instruction pointer
+
iret
- jmp . // will never be reached?
+ jmp . // never to be reached
diff --git a/kernel/config.h b/kernel/config.h
index 6c9e3d5..2d64db1 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -1,13 +1,16 @@
/********************************************
- * Fool OS Central Configuration File *
+ * F00l 0S Central Configuration File *
********************************************/
-#include "lib/logger/log.h"
-
#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 FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
#define FOOLOS_LOG_OFF // do not log anything
@@ -20,5 +23,10 @@
#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
new file mode 100644
index 0000000..5eb2678
--- /dev/null
+++ b/kernel/fd.c
@@ -0,0 +1,32 @@
+#include "fd.h"
+
+bool fd_write(fd* f,uint8_t c)
+{
+ return f->write(f->data,c);
+}
+
+uint8_t fd_read(fd* f)
+{
+ return f->read(f->data);
+}
+
+bool fd_has(fd* f)
+{
+ return f->has(f->data);
+}
+
+bool fd_close(fd* f)
+{
+ return f->close(f->data);
+}
+
+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;
+ return f;
+}
diff --git a/kernel/fd.h b/kernel/fd.h
new file mode 100644
index 0000000..fe048f4
--- /dev/null
+++ b/kernel/fd.h
@@ -0,0 +1,30 @@
+// SIMPLE FILE DESCRIPTOR //
+
+#ifndef FD_H
+#define FD_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "fifo.h"
+
+typedef struct fd_struct
+{
+ bool (*write)(struct fd_struct*,uint8_t);
+ uint8_t (*read)(struct fd_struct*);
+ bool (*has)(struct fd_struct*);
+ bool (*close)(struct fd_struct*);
+
+ void *data; // opaque data
+
+}fd;
+
+uint8_t fd_read(fd*);
+bool fd_has(fd*);
+bool fd_write(fd*,uint8_t);
+bool fd_close(fd*);
+
+fd fd_from_fifo(fifo* f);
+//fd fd_from_path(char *path);
+
+#endif
diff --git a/kernel/fifo.c b/kernel/fifo.c
index 314e9ff..eb477be 100644
--- a/kernel/fifo.c
+++ b/kernel/fifo.c
@@ -1,11 +1,21 @@
+#define FOOLOS_MODULE_NAME "fifo"
#include "fifo.h"
+#include "ringbuffer.h"
+#include "config.h"
+#include "lib/logger/log.h"
+
+#include <stddef.h>
+
+static ringbuffer fifo_ringbuffers[FIFO_MAX_RINGBUFFERS];
+static ringbuffer_c=0;
+
bool fifo_put(fifo* f,uint8_t c)
{
return f->put(f->data,c);
}
-volatile uint8_t fifo_get(fifo* f)
+uint8_t fifo_get(fifo* f)
{
return f->get(f->data);
}
@@ -14,3 +24,16 @@ bool fifo_has(fifo* f)
{
return f->has(f->data);
}
+
+fifo fifo_create_buffered(uint8_t size)
+{
+ if (ringbuffer_c>=FIFO_MAX_RINGBUFFERS) panic(FOOLOS_MODULE_NAME,"ran out of ringbuffers for fifos");
+
+ fifo f;
+ fifo_ringbuffers[ringbuffer_c]=ringbuffer_init(size);
+ f.data=&fifo_ringbuffers[ringbuffer_c];
+ f.put=ringbuffer_put;
+ f.get=ringbuffer_get;
+ f.has=ringbuffer_has;
+ return f;
+}
diff --git a/kernel/fifo.h b/kernel/fifo.h
index a574a25..b5c11a4 100644
--- a/kernel/fifo.h
+++ b/kernel/fifo.h
@@ -1,4 +1,4 @@
-// SIMPLE FIFO DRIVER
+// SIMPLE FIFO DRIVER //
#ifndef FIFO_H
#define FIFO_H
@@ -12,12 +12,13 @@ typedef struct fifo_struct
uint8_t (*get)(struct fifo_struct*);
bool (*has)(struct fifo_struct*);
- void *data; // opaque! can be a vt52 or a ringbuffer..
+ void *data; // opaque data
}fifo;
-volatile bool fifo_put(fifo*,uint8_t);
-volatile uint8_t fifo_get(fifo*);
-volatile bool fifo_has(fifo*);
+bool fifo_put(fifo*,uint8_t);
+uint8_t fifo_get(fifo*);
+bool fifo_has(fifo*);
+fifo fifo_create_buffered(uint8_t size);
#endif
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 2760e8b..fca6fe6 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -1,16 +1,12 @@
#define FOOLOS_MODULE_NAME "kernel"
-
-#ifdef __linux__
-#error "Watchout! this is not Linux but FoolOS. Use a cross-compiler"
-#endif
-
#include "kernel.h"
#include <stdint.h>
+#include <stddef.h>
+
#include "config.h"
#include "types.h"
#include "lib/logger/log.h"
-
#include "fifo.h"
#include "timer.h"
#include "mem.h"
@@ -19,27 +15,19 @@
#include "interrupts.h"
#include "multiboot.h"
#include "ringbuffer.h"
-
-#include <stddef.h>
-
-// for built-in shell
#include "task.h"
#include "multiboot.h"
-
#include "terminal/terminal.h"
#include "driver/screen.h"
-//
-// The Foolish structure of Fool OS!
-//
+// 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;
@@ -87,6 +75,8 @@ static void init_stdio()
keyboard_init(put_kb);
}
+
+/* F00L 0S Entry point (called directly from asm/multiboot.asm */
void kernel_main(uint32_t eax,uint32_t ebx)
{
//
diff --git a/kernel/kernel.h b/kernel/kernel.h
index 749125e..cb9810c 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -1,8 +1,6 @@
#ifndef FOOLOS_KERNEL_H
#define FOOLOS_KERNEL_H
-#define KERNEL_VERSION "FoolOS 0.3.1"
-
#include "fifo.h"
#include "terminal/terminal.h"
diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c
index e3b0863..6db07a1 100644
--- a/kernel/kmalloc.c
+++ b/kernel/kmalloc.c
@@ -1,12 +1,10 @@
#define FOOLOS_MODULE_NAME "kmalloc"
#include "kmalloc.h"
+#include "kernel/config.h"
#include "lib/logger/log.h"
-// 8MB for in kernel-memory
-#define MEM_SIZE 1024*1024*8
-
-static uint8_t data[MEM_SIZE]; // bytes
+static uint8_t data[KMALLOC_MEM_SIZE]; // bytes
static uint32_t next;
static uint32_t first;
@@ -41,12 +39,12 @@ uint32_t kballoc(uint32_t size)
uint32_t old=next;
next+=size;
- if(next>=first+MEM_SIZE)
+ if(next>=first+KMALLOC_MEM_SIZE)
{
- panic(FOOLOS_MODULE_NAME,"kballoc ran out of memory! maybe increase MEM_SIZE in kmalloc.c?");
+ panic(FOOLOS_MODULE_NAME,"kballoc ran out of memory! maybe increase KMALLOC_MEM_SIZE in kmalloc.c?");
}
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"(%d) : 0x%08X (~%dKB left)",size,old,(MEM_SIZE-next+first)/1024);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"(%d) : 0x%08X (~%dKB left)",size,old,(KMALLOC_MEM_SIZE-next+first)/1024);
return old;
}
diff --git a/kernel/kmalloc.h b/kernel/kmalloc.h
index 2faecb8..6e7157a 100644
--- a/kernel/kmalloc.h
+++ b/kernel/kmalloc.h
@@ -1,14 +1,12 @@
-#include <stdint.h>
-
/*
* Kernel Block Memory Allocation
*
* The kernel reserves some memory for internal operation, since malloc
* is not available.
- *
- * Last Revision: 17 AUG 2018
*/
+#include <stdint.h>
+
// Allocate size*4096 bytes and returns a 32-bit pointer
uint32_t kballoc (uint32_t size);
diff --git a/kernel/ringbuffer.c b/kernel/ringbuffer.c
index 181679a..31185dc 100644
--- a/kernel/ringbuffer.c
+++ b/kernel/ringbuffer.c
@@ -6,8 +6,7 @@
// TODO: this is disabled because a kb interrupt can occur anytime
// and the kernel will need to access the ringbuffer while we are accessing!
// DO WE need a spinlock in general? do not use a global one anyway!!!!
-
-static int sl=9;
+//static int sl=9;
ringbuffer ringbuffer_init(uint32_t size)
{
@@ -16,19 +15,15 @@ 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;
}
-volatile bool ringbuffer_put(ringbuffer* f,uint8_t c)
+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;
}
@@ -38,36 +33,29 @@ volatile bool ringbuffer_put(ringbuffer* f,uint8_t c)
f->back+=f->size;
f->back%=f->size;
- lock_release(sl);
x86_int_enable();
return true;
}
-volatile bool ringbuffer_has(ringbuffer* f)
+bool ringbuffer_has(ringbuffer* f)
{
x86_int_disable();
bool res=true;
- 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
+uint8_t ringbuffer_get(ringbuffer* f) // non blocking . please check first
{
x86_int_disable();
char c;
- lock_spin(sl);
-
if(f->front==f->back)
{
- lock_release(sl);
x86_int_enable();
return ' ';
}
@@ -78,7 +66,6 @@ volatile uint8_t ringbuffer_get(ringbuffer* f) // non blocking . please check fi
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
index c79fdcf..bb2b875 100644
--- a/kernel/ringbuffer.h
+++ b/kernel/ringbuffer.h
@@ -6,6 +6,7 @@
// Simple FIRST IN FIRST OUT
// requires kballoc - block allocation
+
typedef volatile struct ringbuffer_struct
{
uint32_t size;
@@ -16,7 +17,7 @@ typedef volatile struct ringbuffer_struct
}ringbuffer;
-// create new fifo of given size (in blocks)
+// create new fifo/ringbuffer of given size (in blocks)
ringbuffer ringbuffer_init(uint32_t blocks);
// true on success
diff --git a/kernel/smp.c b/kernel/smp.c
index 2bf0755..08af652 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -69,8 +69,10 @@ void kernel_ap()
lock_spin(0);
if(cpu_counter[p]%1000000==0)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"cpu[%d] %d",p,cpu_counter[p]);
lock_release(0);
+
}
}
+
void smp_log_procdata(smp_processors *procdata)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"---- smp -----");
@@ -81,7 +83,6 @@ void smp_log_procdata(smp_processors *procdata)
}
-
// this will start all our application processors!
void smp_start_aps(smp_processors *pros,char *path)
{
@@ -124,7 +125,6 @@ void smp_start_aps(smp_processors *pros,char *path)
// start proc 0x7 = 0x7000; etc..
*reg=(6<<8)|(1<<14)|0x7; // 110 SIPI
}
-
}
diff --git a/kernel/spinlock.c b/kernel/spinlock.c
index a8bcc85..68e64a9 100644
--- a/kernel/spinlock.c
+++ b/kernel/spinlock.c
@@ -1,13 +1,14 @@
#define FOOLOS_MODULE_NAME "spinlock"
+#include "spinlock.h"
+
+#include "config.h"
#include "lib/logger/log.h"
-#include "spinlock.h"
#include "x86.h"
// https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
-#define NUMBER_SPINLOCKS 16
-static spinlock spinlocks[NUMBER_SPINLOCKS];
+static volatile uint32_t spinlocks[NUMBER_SPINLOCKS];
void check_spinlocks()
{
@@ -16,18 +17,17 @@ void check_spinlocks()
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d",spinlocks[i]);
}
-void lock_spin(spinlock i)
+void lock_spin(uint32_t i)
{
- spinlock *addr=spinlocks+i;
-// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"locking %d (0x%08X)",i,addr);
-
+ uint32_t *addr=spinlocks+i;
+// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"locking %d (0x%08X)",i,addr);
while(x86_xchg(addr,1));
}
-void lock_release(spinlock i)
+void lock_release(uint32_t i)
{
-// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"unlocking %d",i);
- spinlock *addr=spinlocks+i;
+// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"unlocking %d",i);
+ uint32_t *addr=spinlocks+i;
asm("movb $0,%0"::"m"(*addr));
}
diff --git a/kernel/spinlock.h b/kernel/spinlock.h
index 40d9194..df35e3b 100644
--- a/kernel/spinlock.h
+++ b/kernel/spinlock.h
@@ -3,8 +3,6 @@
#include <stdint.h>
-typedef volatile uint8_t spinlock;
-
void lock_spin(spinlock);
void lock_release(spinlock);
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index c507a4e..9f10d20 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -175,10 +175,22 @@ int syscall_execve(char *name, char **argv, char **env)
while(argv[arg_count]!=NULL)arg_count++;
char **argv1=kballoc(1);
- char **env1=kballoc(1);
+ if(argv!=NULL)
+ {
+ copy_args(argv,argv1);
+ }
+ else{
+ argv1=NULL;
+ }
- copy_args(argv,argv1);
- copy_args(env,env1);
+ char **env1=kballoc(1);
+ if(env!=NULL)
+ {
+ copy_args(env,env1);
+ }
+ else{
+ env1=NULL;
+ }
uint32_t alloc;
uint32_t entry_global=load_elf(name,&alloc);
@@ -214,12 +226,13 @@ int syscall_execve(char *name, char **argv, char **env)
}
+// TODO: support other files too (not only fifo 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
- panic(FOOLOS_MODULE_NAME,"unhandled syscall: open");
+ //panic(FOOLOS_MODULE_NAME,"unhandled syscall: open");
}
diff --git a/kernel/usermode.c b/kernel/usermode.c
index db4ac9f..2455ba6 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -4,6 +4,10 @@
#include "syscalls.h"
#include "kmalloc.h"
+#include "asm/syscall.h"
+#include "asm/usermode.h"
+#include "kernel/config.h"
+
#include "lib/logger/log.h"
#include <stddef.h>
@@ -22,17 +26,15 @@ void install_tss(int cpu_no){
// sys_tss.iomap = ( unsigned short ) sizeof( tss_struct );
}
-void switch_to_user_mode()
+// THIS IS THE FUNCTION TO BE RUN IN RING 3 // USER MODE
+static void userfunc()
{
- asm_usermode();
+ syscall(SYSCALL_EXECVE,BIN_INIT,NULL,NULL);
+ while(1); // we should never get here.
}
-char *argv_init[]={"/bin/init",NULL};
-char *env_init[]={"var1=dupa","var2=mundl",NULL};
-
-// THIS WILL BE RUN IN RING 3!
-void userfunc()
+void switch_to_user_mode()
{
- syscall(SYSCALL_EXECVE,"/bin/init",argv_init,env_init);
- while(1); // we should never get here.
+ usermode(&userfunc);
}
+
diff --git a/kernel/x86.c b/kernel/x86.c
index fdfb638..d664657 100644
--- a/kernel/x86.c
+++ b/kernel/x86.c
@@ -8,16 +8,6 @@
// suffix (b, w, l, q for byte, word, dword, and qword).
//
-
-/*
-volatile void sleep(int i)
-{
- uint64_t clock=timer_get_ticks();
- while(clock+i>timer_get_ticks());
-}
-*/
-
-
// disable interrupts
void x86_int_disable()
{
@@ -49,10 +39,6 @@ uint32_t x86_get_cr1()
return cr;
}
-void x86_mov(uint8_t val)
-{
-}
-
uint32_t x86_get_cr2()
{
uint32_t cr;
@@ -73,36 +59,36 @@ uint32_t x86_get_cr4()
asm volatile("mov %%cr4, %0": "=b"(cr));
return cr;
}
-void x86_outb(int port, uint8_t data)
+void x86_outb(uint32_t port, uint8_t data)
{
asm volatile("outb %0,%w1" : : "a" (data), "d" (port));
}
-uint8_t x86_inb(int port)
+uint8_t x86_inb(uint32_t port)
{
uint8_t data;
asm volatile("inb %w1,%0" : "=a" (data) : "d" (port));
return data;
}
-void x86_outw(int port, uint16_t data)
+void x86_outw(uint32_t port, uint16_t data)
{
asm volatile("outw %0,%w1" : : "a" (data), "d" (port));
}
-uint16_t x86_inw(int port)
+uint16_t x86_inw(uint32_t port)
{
uint16_t data;
asm volatile("inw %w1,%0" : "=a" (data) : "d" (port));
return data;
}
-void x86_outl(int port, uint32_t data)
+void x86_outl(uint32_t port, uint32_t data)
{
asm volatile("outl %0,%w1" : : "a" (data), "d" (port));
}
-uint32_t x86_inl(int port)
+uint32_t x86_inl(uint32_t port)
{
uint32_t data;
asm volatile("inl %w1,%0" : "=a" (data) : "d" (port));
@@ -124,7 +110,6 @@ void x86_paging_enable()
asm volatile("mov %0, %%cr0":: "b"(cr0));
}
-
// disable PT bit in CR0
void x86_paging_disable()
{
@@ -150,10 +135,6 @@ uint8_t x86_xchg(uint8_t *addr, uint8_t val)
"1" (val) :
"cc");
- //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"xchg val:%d with addr:0x%08X : result: %d",val,addr,result);
-
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"xchg val:%d with addr:0x%08X : result: %d",val,addr,result);
return result;
}
-
-
-
diff --git a/kernel/x86.h b/kernel/x86.h
index 2cd9e8e..b634722 100644
--- a/kernel/x86.h
+++ b/kernel/x86.h
@@ -5,25 +5,30 @@
// http://wiki.osdev.org/Interrupt_Service_Routines
-//void sleep(int i); // TODO : Real sleep!
-
-void x86_outb(int port, uint8_t data);
-uint8_t x86_inb(int port);
-void x86_outw(int port, uint16_t data);
-uint16_t x86_inw(int port);
-void x86_outl(int port, uint32_t data);
-uint32_t x86_inl(int port);
+// TODO : Real sleep()!
+
+void x86_outb(uint32_t port, uint8_t data);
+uint8_t x86_inb(uint32_t port);
+
+void x86_outw(uint32_t port, uint16_t data);
+uint16_t x86_inw(uint32_t port);
+
+void x86_outl(uint32_t port, uint32_t data);
+uint32_t x86_inl(uint32_t port);
+
void x86_set_pdbr(uint32_t addr);
void x86_paging_enable();
void x86_flush_tlb(uint32_t addr);
+
void x86_int_enable();
void x86_int_disable();
+
uint32_t x86_get_cr0();
uint32_t x86_get_cr1();
uint32_t x86_get_cr2();
uint32_t x86_get_cr3();
uint32_t x86_get_cr4();
+
uint8_t x86_xchg(uint8_t *addr, uint8_t val);
-void sleep(int i);
#endif
diff --git a/lib/logger/log.c b/lib/logger/log.c
index fbc0614..d591b36 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -1,10 +1,9 @@
#define FOOLOS_MODULE_NAME "log"
+#include "log.h"
#include <stdarg.h>
#include <stdbool.h>
-#include "log.h"
-
#include "kernel/kernel.h"
#include "kernel/config.h"
#include "kernel/timer.h"
diff --git a/lib/printf/printf.c b/lib/printf/printf.c
index 23d3d46..0a947d3 100644
--- a/lib/printf/printf.c
+++ b/lib/printf/printf.c
@@ -35,7 +35,6 @@ typedef void (*putcf) (void*,char);
static putcf stdout_putf;
static void* stdout_putp;
-
#ifdef PRINTF_LONG_SUPPORT
static void uli2a(unsigned long int num, unsigned int base, int uc,char * bf)
diff --git a/lib/string/string.h b/lib/string/string.h
index bd43b34..dd756a7 100644
--- a/lib/string/string.h
+++ b/lib/string/string.h
@@ -1,7 +1,6 @@
#ifndef STRING_H
#define STRING_H
-
void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size);
int strcmp(char *str1, char *str2);
int strcmp_l(char *str1, char *str2, int length);
diff --git a/syscalls.c b/syscalls.c
index c4bd549..f2978cc 100644
--- a/syscalls.c
+++ b/syscalls.c
@@ -12,117 +12,49 @@ typedef struct fs_dirent_struct
char name[256];
}fs_dirent;
-//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_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_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_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
extern char **environ;
//struct _reent *_impure_ptr;
-// generic syscall interface!
-/*int volatile __attribute__ ((noinline)) syscall(int call, int p1, int p2, int p3)
-{
- int ebx; // persist over func call( a,c,d are scratch)
- int ret; // will hold return val
-
- asm("mov %%ebx, %0": "=b" (ebx));
-
-// asm("pusha");
-
- // select syscall
- asm("mov %0, %%eax"::"m"(call));
-
- // pass params
- asm("mov %0,%%edx"::"m"(p1));
- asm("mov %0,%%ecx"::"m"(p2));
- asm("mov %0,%%ebx"::"m"(p3));
-
- // interrrupt
- asm("int $0x80");
-
- // get return value
- asm("mov %%ebx, %0": "=b" (ret));
-
- // restore
- asm("mov %0,%%ebx"::"m"(ebx));
-
-// asm("popa");
-
- return ret;
-}
-*/
-
// 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()
{
-
return syscall(SYSCALL_HAS_DATA,0,0,0);
}
int fool_tune(int v1, int v2, int v3)
{
-
return syscall(SYSCALL_TUNE,v1,v2,v3);
}
+//
void _exit(int ret)
{
@@ -134,7 +66,6 @@ void _exit2(int ret,char **environ)
return syscall(SYSCALL_EXIT,ret,environ,0);
}
-//required by newlibc
int _close(int file)
{
return syscall(SYSCALL_CLOSE,file,0,0);
@@ -152,7 +83,6 @@ int _lseek(int file, int ptr, int dir)
int _read(int file, char *ptr, int len)
{
-
return syscall(SYSCALL_READ,file,ptr,len);
}