summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/config.h4
-rw-r--r--kernel/kernel.c1
-rw-r--r--kernel/syscalls.c43
-rw-r--r--kernel/task.c40
-rw-r--r--kernel/vmem.c21
-rw-r--r--userspace/sys/sys.c23
6 files changed, 87 insertions, 45 deletions
diff --git a/kernel/config.h b/kernel/config.h
index 17b5f27..a741c4a 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -8,11 +8,11 @@
#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 MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
-//#define LOG_SYSCALLS
+#define LOG_SYSCALLS
#endif
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 64c87c0..82136c0 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -44,7 +44,6 @@ void kernel_main(uint32_t initial_stack, int mp)
//
// Activate Virtual Memory (paging)
- // 0x8048000 is where user programms start!
pdirectory *dir=vmem_init();
//
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index d57fe80..6925b87 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -124,6 +124,8 @@ int syscall_execve(char *name, char **argv1, char **env1)
{
int temp=0x1;
+ uint32_t *entry=temp;
+ temp+=4;
char *force_argv[]={"",NULL};
char *force_env[]={"PS1=$","PWD=/home/miguel","PATH=/bin",NULL};
@@ -168,8 +170,6 @@ int syscall_execve(char *name, char **argv1, char **env1)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv1,env1);
#endif
- uint32_t alloc;
- uint32_t entry=load_elf(name,&alloc);
if(!entry)
{
@@ -179,21 +179,27 @@ int syscall_execve(char *name, char **argv1, char **env1)
return -1; // errror loading
}
+ /* try to move this to asm */
+ //asm volatile("jmp .");
+ asm volatile("mov $0x8fff000,%esp"); // set stack at high end of process image
+ uint32_t alloc;
+ *entry=load_elf(name,&alloc);
+
// TODO: avoid code duplication for argv and env!!
char **env_new=alloc;
alloc+=sizeof(char **)*(env_count+1);
i=0;
do{
- #ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"envr %d : 0x%08X : %s" ,i,env[i],env[i]);
- #endif
int l=strlen(env[i]);
char *env_var=alloc;
alloc+=sizeof(char)*l+1;
memcpy(env_var,env[i],l+1);
env_new[i]=env_var;
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"envr %d : 0x%08X : %s" ,i,env_new[i],env_new[i]);
+ #endif
i++;
}while(env[i]!=NULL);
env_new[i]=NULL;
@@ -207,31 +213,34 @@ int syscall_execve(char *name, char **argv1, char **env1)
alloc+=sizeof(char)*l+1;
memcpy(arg_var,argv[i],l+1);
argv_new[i]=arg_var;
-// #ifdef LOG_SYSCALLS
-// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"arg %d : 0x%08X : %s" ,i,argv_new[i],argv_new[i]);
- // #endif
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"arg %d : 0x%08X : %s" ,i,argv_new[i],argv_new[i]);
+ #endif
i++;
}while(argv[i]!=NULL);
+
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"argc: %d" ,arg_count);
+ #endif
+
task_set_brk(alloc);
- // TODO: why can i not put it ~0x48000 bytes higher!?
- asm("mov $0x8800000,%esp"); // set stack at high end of process image
- asm("push %0" :: "r" (argv_new));
- asm("push %0" :: "r" (arg_count));
- asm("push %0" :: "r" (env_new));
+ asm volatile ("push %0" :: "r" (argv_new));
+ asm volatile ("push %0" :: "r" (arg_count));
+ asm volatile ("push %0" :: "r" (env_new));
// push addr and return to it
- asm("push %0"::"r"(entry));
+ asm volatile ("push %0"::"r"(*entry));
- asm("sti");
- asm("ret");
+ asm volatile ("sti");
+ asm volatile ("ret");
+
// this is never reached!
}
-
int syscall_open(char *name, int flags, int mode)
{
#ifdef LOG_SYSCALLS
diff --git a/kernel/task.c b/kernel/task.c
index 2d52017..b01975d 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -18,21 +18,21 @@
#define MAX_TASKS 10
-static volatile int current_task=-1;
+static volatile int volatile current_task=-1;
static volatile struct task_list_struct
{
- int parent;
- bool active;
- uint32_t esp; // stack pointer of the task;
- pdirectory *vmem; // number of virtual memory table to switch to
- bool waiting;
- bool skipwait;
- uint32_t brk;
+ volatile int parent;
+ volatile bool active;
+ volatile uint32_t esp; // stack pointer of the task;
+ volatile pdirectory *vmem; // number of virtual memory table to switch to
+ volatile bool waiting;
+ volatile bool skipwait;
+ volatile uint32_t brk;
}volatile task_list[MAX_TASKS];
-int add_task(uint32_t esp, uint32_t vmem)
+volatile int add_task(uint32_t esp, uint32_t vmem)
{
for(int i=0;i<MAX_TASKS;i++)
@@ -55,7 +55,7 @@ int add_task(uint32_t esp, uint32_t vmem)
panic(FOOLOS_MODULE_NAME,"out of task slots!");
}
-uint32_t my_scheduler(uint32_t oldesp)
+volatile uint32_t my_scheduler(uint32_t oldesp)
{
task_list[current_task].esp=oldesp;
@@ -65,8 +65,8 @@ uint32_t my_scheduler(uint32_t oldesp)
if(task_list[pid].active && !task_list[pid].waiting)
{
- // if(current_task!=pid)
- // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"switch from %d to %d", current_task, pid);
+// if(current_task!=pid)
+// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"switch from %d to %d", current_task, pid);
current_task=pid;
@@ -80,7 +80,7 @@ uint32_t my_scheduler(uint32_t oldesp)
}
// this gets called by our clock interrupt regularly!
-uint32_t task_switch_next(uint32_t oldesp)
+volatile uint32_t task_switch_next(uint32_t oldesp)
{
timer_tick();
@@ -94,7 +94,7 @@ uint32_t task_switch_next(uint32_t oldesp)
//TODO: free vmem too!
//TODO: notify waiting parent when child finished;
-uint32_t task_exit(uint32_t oldesp)
+volatile uint32_t task_exit(uint32_t oldesp)
{
task_list[current_task].active=false;
int parent_pid=task_list[current_task].parent;
@@ -123,7 +123,7 @@ uint32_t task_exit(uint32_t oldesp)
}
-uint32_t task_wait(uint32_t oldesp)
+volatile uint32_t task_wait(uint32_t oldesp)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] wait", current_task);
if(task_list[current_task].skipwait)
@@ -137,7 +137,7 @@ uint32_t task_wait(uint32_t oldesp)
return my_scheduler(oldesp);
}
-uint32_t task_fork(uint32_t oldesp)
+volatile uint32_t task_fork(uint32_t oldesp)
{
int pid=add_task(oldesp,vmem_new_space_dir(task_list[current_task].vmem));
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] forked -> [%d] (free blocks remaining: %d )", current_task, pid,mem_get_free_blocks_count());
@@ -145,7 +145,7 @@ uint32_t task_fork(uint32_t oldesp)
}
// init task (root of all other tasks / processes) //
-void task_init(pdirectory *dir)
+volatile void task_init(pdirectory *dir)
{
// this is our main task on slot 0
task_list[0].parent=0;
@@ -158,16 +158,16 @@ void task_init(pdirectory *dir)
}
-int task_get_current_pid()
+volatile int task_get_current_pid()
{
return current_task;
}
-uint32_t task_get_brk()
+volatile uint32_t task_get_brk()
{
return task_list[current_task].brk;
}
-void task_set_brk(uint32_t brk)
+volatile void task_set_brk(uint32_t brk)
{
task_list[current_task].brk=brk;
}
diff --git a/kernel/vmem.c b/kernel/vmem.c
index 5dccc13..a909b1a 100644
--- a/kernel/vmem.c
+++ b/kernel/vmem.c
@@ -299,8 +299,14 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
{
ptable* table = (ptable*) pmmngr_alloc_block ();
- pd_entry *oldentry= &(copy_dir->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]);
- ptable* oldtable=pd_entry_get_frame(oldentry);
+ pd_entry *oldentry=NULL;
+ ptable* oldtable=NULL;
+
+ if(copy_dir!=NULL)
+ {
+ oldentry=&(copy_dir->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]);
+ oldtable=pd_entry_get_frame(oldentry);
+ }
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"oldtable at: 0x%08X",oldtable);
if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table");
@@ -308,6 +314,7 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
for (int i=0, virt=virt_addr; i<1024; i++, virt+=4096)
{
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"i = %d",i);
phys_addr=pmmngr_alloc_block(); // get free space from the memory manager
if (!phys_addr)panic(FOOLOS_MODULE_NAME,"unable to alloc spce for frame");
@@ -350,8 +357,14 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir)
{
ptable* table = (ptable*) pmmngr_alloc_block ();
- pd_entry *oldentry= &(copy_dir->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]);
- ptable* oldtable=pd_entry_get_frame(oldentry);
+ pd_entry *oldentry=NULL;
+ ptable* oldtable=NULL;
+
+ if(copy_dir!=NULL)
+ {
+ oldentry=&(copy_dir->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]);
+ oldtable=pd_entry_get_frame(oldentry);
+ }
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"oldtable at: 0x%08X",oldtable);
if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table");
diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c
index a9d54ce..fa96ba4 100644
--- a/userspace/sys/sys.c
+++ b/userspace/sys/sys.c
@@ -32,31 +32,36 @@ void __stack_chk_fail(void)
long sysconf(int name)
{
- printf("SYSCONF CALLED WITH : %s",name);
+ printf("UNIMPL: sysconf\n");
+ printf("SYSCONF CALLED WITH : %s\n",name);
return 0;
}
// set file mode creation mask
mode_t umask(mode_t mask)
{
+ printf("UNIMPL: umask\n");
return mask;
}
// chmod
int chmod(const char * path, mode_t mode)
{
+ printf("UNIMPL: chmod\n");
return -1;
}
// manipulating file descriptor
int fcntl(int fd, int cmd, ...)
{
+ printf("UNIMPL: fcntl\n");
return -1;
}
// working directory
char *getwd(char *buf)
{
+ printf("UNIMPL: getwd\n");
static char wd[]="/";
buf=wd;
return buf;
@@ -65,6 +70,7 @@ char *getwd(char *buf)
// check if access allowed
int access(const char *pathname, int mode)
{
+ printf("UNIMPL: access\n");
//TODO: at leas check if this file exists!
return 0;
}
@@ -72,76 +78,91 @@ int access(const char *pathname, int mode)
// update time
int utime(const char *filename, const int *x)
{
+ printf("UNIMPL: utime\n");
return -1;
}
// rmdir
int rmdir (const char *pathname)
{
+ printf("UNIMPL: rmdir\n");
return -1;
}
// chonw
int chown(const char *path, uid_t owner, gid_t group)
{
+ printf("UNIMPL: chown\n");
return -1;
}
// termios / ncurses
int tcgetattr(int fd, struct termios *termios_p)
{
+ printf("UNIMPL: tcgetattr\n");
return 0;
}
int tcsetattr(int fd, int optional_actions, const struct termios *termios_p){
+ printf("UNIMPL: tsetattr\n");
return 0;
}
int mkdir(const char *pathname, mode_t mode)
{
+ printf("UNIMPL: mkdir\n");
return -1;
}
int chdir (const char *pathname)
{
+ printf("UNIMPL: chdir\n");
return -1;
}
speed_t cfgetospeed(const struct termios *termios_p)
{
+ printf("UNIMPL: cfgetospeed\n");
return 1;
}
char *ttyname(int fd)
{
+ printf("UNIMPL: ttyname\n");
return "foolterm";
}
DIR *opendir(const char *name)
{
+ printf("UNIMPL: opendir\n");
return 0;
}
int closedir(DIR *dirp)
{
+ printf("UNIMPL: closedir\n");
return 0;
}
int tcflush(int fd, int queue_selector)
{
+ printf("UNIMPL: tcflush\n");
return -1;
}
long fpathconf(int fd, int name)
{
+ printf("UNIMPL: fpathconf\n");
return -1;
}
unsigned int sleep(unsigned int seconds)
{
+ printf("UNIMPL: sleep\n");
return 0;
}
char *getlogin(void)
{
+ printf("UNIMPL: getlogin\n");
return NULL;
}