summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-17 02:28:02 +0200
committerMiguel <m.i@gmx.at>2018-08-17 02:28:02 +0200
commitc742be9c738c91703a7be787639cad167de3a6b1 (patch)
treedb0e170dab1b7f34630489d0cb1d396c92f15c79 /kernel
parent559eea53ecdd1e3e45f24d15e8739419b0cd647a (diff)
started reviving my fool os
Diffstat (limited to 'kernel')
-rw-r--r--kernel/config.h4
-rw-r--r--kernel/fifo.h2
-rw-r--r--kernel/kernel.c23
-rw-r--r--kernel/kernel.h3
-rw-r--r--kernel/ringbuffer.c2
-rw-r--r--kernel/smp.c1
-rw-r--r--kernel/syscalls.c26
-rw-r--r--kernel/syscalls.h2
-rw-r--r--kernel/task.c10
-rw-r--r--kernel/usermode.c8
10 files changed, 22 insertions, 59 deletions
diff --git a/kernel/config.h b/kernel/config.h
index cf81361..4923a0e 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -13,8 +13,8 @@
#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_FINE // minimal severity level to log
+#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
diff --git a/kernel/fifo.h b/kernel/fifo.h
index e0a81e5..a574a25 100644
--- a/kernel/fifo.h
+++ b/kernel/fifo.h
@@ -1,6 +1,5 @@
// SIMPLE FIFO DRIVER
-
#ifndef FIFO_H
#define FIFO_H
@@ -21,5 +20,4 @@ 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 cea1056..2760e8b 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -20,7 +20,6 @@
#include "multiboot.h"
#include "ringbuffer.h"
-
#include <stddef.h>
// for built-in shell
@@ -30,7 +29,6 @@
#include "terminal/terminal.h"
#include "driver/screen.h"
-
//
// The Foolish structure of Fool OS!
//
@@ -43,8 +41,6 @@ fool_os *get_fool()
//
//
-
-
// stdio init : TODO: move away!
static terminal_tty tty1;
static term_out screen;
@@ -52,7 +48,6 @@ static term_in input;
static ringbuffer stdin_buf;
-
static void put_kb(uint8_t c)
{
terminal_kb(&tty1,c);
@@ -75,8 +70,11 @@ static void init_stdio()
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;
@@ -89,12 +87,11 @@ static void init_stdio()
keyboard_init(put_kb);
}
-
-
-
void kernel_main(uint32_t eax,uint32_t ebx)
{
-
+ //
+ // STDIN and STDOUT
+ //
init_stdio();
//
@@ -117,13 +114,11 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
int_init(0x08);
-
//
// Process Multiboot Header
//
multiboot_information *info=get_multiboot(eax, ebx);
-
//
// Gather Info about other processors. (APs = application processors)
// ACPI or MP
@@ -171,20 +166,14 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//empty stdin!
while(fifo_has(&get_fool()->std_in))
fifo_get(&get_fool()->std_in);
-
//
// Initialize Multitasking
//
task_init(dir);
-
//
// Abvoe should never returon
//
panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!");
-
}
-
-
-
diff --git a/kernel/kernel.h b/kernel/kernel.h
index 757c3bf..749125e 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -1,7 +1,7 @@
#ifndef FOOLOS_KERNEL_H
#define FOOLOS_KERNEL_H
-#define KERNEL_VERSION "FoolOs 0.2.1"
+#define KERNEL_VERSION "FoolOS 0.3.1"
#include "fifo.h"
#include "terminal/terminal.h"
@@ -17,5 +17,4 @@ typedef struct fool_os_struct
fool_os *get_fool();
-
#endif
diff --git a/kernel/ringbuffer.c b/kernel/ringbuffer.c
index cba7eb4..181679a 100644
--- a/kernel/ringbuffer.c
+++ b/kernel/ringbuffer.c
@@ -3,8 +3,6 @@
#include "ringbuffer.h"
-
-
// 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!!!!
diff --git a/kernel/smp.c b/kernel/smp.c
index f3bc73b..2bf0755 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -123,7 +123,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/syscalls.c b/kernel/syscalls.c
index 38cac63..31579e1 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -6,8 +6,8 @@
#include "kernel/kernel.h"
#include "kernel/config.h"
#include <sys/stat.h>
-#include <stdbool.h>
-#include <stddef.h>
+#include <stdbool.h>
+#include <stddef.h>
int syscall_unhandled(int nr)
{
@@ -29,7 +29,6 @@ int syscall_lseek(int file,int ptr,int dir)
panic(FOOLOS_MODULE_NAME,"unhandled syscall: lseek");
return 0;
-
}
// TODO: /dev/console or /dev/tty1 - /dev/ttyN
@@ -77,14 +76,11 @@ int syscall_read(int file, char *buf, int len)
if(l==len)return l;
if(c=='\n')return l;
}
-
-
}
//TODO: replace with dirent!
int syscall_readdir(const char *name,fs_dirent *dirs,int max)
{
-
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"readdir(name=0x%08X, dirs=0x%08X, %d)", name,dirs,max);
#endif
@@ -95,7 +91,6 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max)
// for non blocking io?
int syscall_has_data_waiting(int file)
{
-
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"has data waiting?");
#endif
@@ -105,13 +100,10 @@ int syscall_has_data_waiting(int file)
int syscall_tune(int v1,int v2, int v3)
{
-
-
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"tuning request");
#endif
-
if(v1==0) // regular tty mode
{
get_fool()->tty->set_buff=true;
@@ -127,10 +119,6 @@ int syscall_tune(int v1,int v2, int v3)
return 0;
}
-
-
-
-
int copy_args(char **in, char **out)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy_args(0x%08x, 0x%08X)",in,out);
@@ -160,10 +148,8 @@ int copy_args(char **in, char **out)
return count;
}
-
int syscall_execve(char *name, char **argv, char **env)
{
-
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv,env);
#endif
@@ -177,9 +163,9 @@ int syscall_execve(char *name, char **argv, char **env)
copy_args(argv,argv1);
copy_args(env,env1);
-
uint32_t alloc;
uint32_t entry_global=load_elf(name,&alloc);
+
task_set_brk(alloc);
if(!entry_global)
@@ -191,7 +177,9 @@ int syscall_execve(char *name, char **argv, char **env)
}
/* try to move this to asm */
- //asm volatile("jmp .");
+ // asm volatile("jmp ."); // loop forever
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"returning to jump addy (0x%08X)", entry_global);
+
asm volatile("mov $0x8fff000,%esp"); // set stack at high end of process image
asm volatile ("push %0" :: "r" (argv1));
@@ -201,7 +189,7 @@ int syscall_execve(char *name, char **argv, char **env)
// push addr and return to it
asm volatile ("pushl %0"::"r"(entry_global));
-
+
asm volatile ("sti");
asm volatile ("ret");
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index 5c7a772..ff7760e 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -59,8 +59,6 @@ int syscall_unlink(char *name);
int syscall_wait(int *status);
//
int syscall_unhandled(int nr);
-
-
*/
diff --git a/kernel/task.c b/kernel/task.c
index 5373133..be9ddd9 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -1,6 +1,8 @@
// http://hosted.cjmovie.net/TutMultitask.htm
//
//
+#define FOOLOS_MODULE_NAME "task"
+
#include "kernel.h"
#include "lib/logger/log.h" // logger facilities
#include "mem.h"
@@ -11,8 +13,6 @@
#include "syscalls.h"
#include "fs/fs.h"
#include "fs/ext2.h"
-#define FOOLOS_MODULE_NAME "task"
-
#define MAX_TASKS 10
@@ -92,7 +92,6 @@ volatile uint32_t task_switch_next(uint32_t oldesp)
}
-
//TODO: free vmem too!
//TODO: notify waiting parent when child finished;
volatile uint32_t task_exit(uint32_t oldesp)
@@ -145,7 +144,6 @@ volatile uint32_t task_fork(uint32_t oldesp)
return pid;
}
-
// init task (root of all other tasks / processes) //
volatile void task_init(pdirectory *dir)
{
@@ -161,7 +159,6 @@ volatile void task_init(pdirectory *dir)
switch_to_user_mode();
}
-
volatile int task_get_current_pid()
{
return current_task;
@@ -171,9 +168,8 @@ volatile uint32_t task_get_brk()
{
return task_list[current_task].brk;
}
+
volatile void task_set_brk(uint32_t brk)
{
task_list[current_task].brk=brk;
}
-
-
diff --git a/kernel/usermode.c b/kernel/usermode.c
index e6568a4..f0618d7 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -2,12 +2,10 @@
#define FOOLOS_MODULE_NAME "usermode"
#include "lib/logger/log.h"
#include "syscalls.h"
-
-
+#include <stddef.h>
tss_struct sys_tss; //Define the TSS as a global structure
-
// generic syscall interface!
int syscall(int call, int p1, int p2, int p3)
{
@@ -33,10 +31,12 @@ int syscall(int call, int p1, int p2, int p3)
return ebx;
}
+
int write(int file, char *ptr, int len)
{
return syscall(SYSCALL_WRITE,file,ptr,len);
}
+
int execve(char *name, char **argv, char **env)
{
return syscall(SYSCALL_EXECVE,name,argv,env);
@@ -57,8 +57,6 @@ void install_tss(int cpu_no){
void switch_to_user_mode()
{
asm_usermode();
- // userfunc();
-
}
char *argv_init[]={"/bin/init",NULL};