summaryrefslogtreecommitdiff
path: root/kernel/syscalls.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/syscalls.c')
-rw-r--r--kernel/syscalls.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 6d46f1a..38f7161 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -14,7 +14,7 @@
int syscall_unhandled(int nr)
{
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr);
- panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall (generic handler)");
}
int syscall_lseek(int file,int ptr,int dir)
@@ -23,7 +23,7 @@ int syscall_lseek(int file,int ptr,int dir)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
#endif
- panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall: lseek");
return 0;
@@ -39,7 +39,7 @@ int syscall_write(int file, char *buf, int len)
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");
+ 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++)
@@ -59,8 +59,9 @@ 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");
+ if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall: read (only stdin)");
{
if(eof)
{
@@ -149,28 +150,18 @@ int copy_args(char **in, char **out)
return count;
}
-
-int *entry_global=1;
-char **argv_global=10;
-char **env_global=300;
-char **argv=0x8000000;
-char **env=0x8000000+300;
-
-
int syscall_execve(char *name, char **argv1, char **env1)
{
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv1,env1);
#endif
- copy_args(argv1,argv_global);
- copy_args(env1,env_global);
-
uint32_t alloc;
- *entry_global=load_elf(name,&alloc);
+ uint32_t entry_global=load_elf(name,&alloc);
+
task_set_brk(alloc);
- if(!*entry_global)
+ if(!entry_global)
{
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve: bailing out!");
@@ -181,18 +172,14 @@ int syscall_execve(char *name, char **argv1, char **env1)
/* try to move this to asm */
//asm volatile("jmp .");
asm volatile("mov $0x8fff000,%esp"); // set stack at high end of process image
+ int arg_count=0;
- int arg_count=copy_args(argv_global,argv);
- copy_args(env_global,env);
-
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"argc: %d" ,arg_count);
-
- asm volatile ("push %0" :: "r" (argv));
+ asm volatile ("push %0" :: "r" (argv1));
asm volatile ("push %0" :: "r" (arg_count));
- asm volatile ("push %0" :: "r" (env));
+ asm volatile ("push %0" :: "r" (env1));
// push addr and return to it
- asm volatile ("push %0"::"r"(*entry_global));
+ asm volatile ("pushl %0"::"r"(entry_global));
asm volatile ("sti");
asm volatile ("ret");
@@ -206,7 +193,7 @@ 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");
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall: open");
}
@@ -220,7 +207,7 @@ int syscall_close(int file,int none1,int none2)
#endif
if(file!=0&&file!=1&&file!=2)
- panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall: close");
return -1;
}
@@ -234,18 +221,22 @@ int syscall_isatty(int file,int none1,int none2)
return 1;
}
+uint32_t fuckalloc=0x8500000;
// TODO: per process basis!
uint32_t syscall_sbrk(int incr, int none1, int none2)
{
uint32_t alloc=task_get_brk();
- uint32_t oldalloc=alloc;
- alloc+=incr;
+
+ uint32_t oldalloc=fuckalloc;
+ fuckalloc+=incr;
+
task_set_brk(alloc);
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sbrk (incr=%d) = 0x%08X", incr,oldalloc);
#endif
+
return oldalloc;
}