summaryrefslogtreecommitdiff
path: root/kernel/syscalls.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-02 00:08:42 +0200
committerMiguel <m.i@gmx.at>2018-09-02 00:08:42 +0200
commit8e3411139b27a3421e9ac75c13f14f99f6dd3137 (patch)
treecf8b53ab02863117c310bde11ee4683e134cf1b2 /kernel/syscalls.c
parent0fff2e6dc6fae82da1c7978918a490c25cc36f04 (diff)
syscalls
Diffstat (limited to 'kernel/syscalls.c')
-rw-r--r--kernel/syscalls.c80
1 files changed, 28 insertions, 52 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 56c4ae8..7a0dc50 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -22,6 +22,8 @@ static uint32_t next_fd=0;
static fifo fifos[MAX_FIFOS];
static uint32_t next_fifo=0;
+extern uint32_t fb_addr;
+
// screen / terminal
term_out screen;
terminal_tty tty1;
@@ -54,9 +56,6 @@ int syscall_gettimeofday(struct timeval *tv, struct timezone *tz)
int syscall_lseek(int file,int ptr,int dir)
{
- #ifdef LOG_SYSCALLS
- klog("lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
- #endif
kpanic("unhandled syscall: lseek");
@@ -66,9 +65,6 @@ 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)
{
- #ifdef LOG_SYSCALLS
- klog("[%d] write(file=%d, buf=0x%08X, len=%d)", task_get_current_pid(),file,buf,len);
- #endif
for(int i=0;i<len;i++)
{
@@ -80,9 +76,6 @@ int syscall_write(int file, char *buf, int len)
int syscall_read(int file, char *buf, int len)
{
- #ifdef LOG_SYSCALLS
- klog("read(file=%d, buf=0x%08X, len=%d)", file,buf,len);
- #endif
//file 0 = stdin , file 1 = stdout , file 2 = stderr
char c;
@@ -105,9 +98,6 @@ int syscall_read(int file, char *buf, int len)
//TODO: replace with dirent!
int syscall_readdir(const char *name,fs_dirent *dirs,int max)
{
- #ifdef LOG_SYSCALLS
- klog("readdir(name=0x%08X, dirs=0x%08X, %d)", name,dirs,max);
- #endif
return fs_readdir(name,dirs,max);
}
@@ -116,9 +106,6 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max)
int syscall_poll(int file)
{
file=2; //workaround
- #ifdef LOG_SYSCALLS
- klog("has data waiting?");
- #endif
return fd_has(&fds[file]);
}
@@ -126,9 +113,6 @@ int syscall_poll(int file)
// TODO: DELETE THIS SHIT!
int syscall_tune(int v1,int v2, int v3)
{
- #ifdef LOG_SYSCALLS
- klog("tuning request");
- #endif
// osbolete
/*
@@ -176,29 +160,28 @@ int copy_args(char **in, char **out)
return count;
}
-int syscall_execve(char *name, char **argv, char **env)
+int syscall_execve(char *name, char **argv, char **env,int pid)
{
- #ifdef LOG_SYSCALLS
- klog("execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv,env);
- #endif
-
+
int arg_count=0;
while(argv[arg_count]!=NULL)arg_count++;
- char **argv1=kballoc(1);
+ char **argv1=0x08000000;
if(argv!=NULL)
{
copy_args(argv,argv1);
}
+
else{
argv1=NULL;
}
- char **env1=kballoc(1);
+ char **env1=0x08020000;
if(env!=NULL)
{
copy_args(env,env1);
}
+
else{
env1=NULL;
}
@@ -209,17 +192,18 @@ int syscall_execve(char *name, char **argv, char **env)
if(!entry_global)
{
- #ifdef LOG_SYSCALLS
- klog("execve: bailing out!");
- #endif
+ kpanic("error loading %s",name);
return -1; // errror loading
}
+ task_reset(pid,entry_global,0x08fff000);
+ return 0;
+
/* try to move this to asm */
// asm volatile("jmp ."); // loop forever
//klog("returning to jump addy (0x%08X)", entry_global);
-
- asm volatile("mov $0x8fff000,%esp"); // set stack at high end of process image
+/*
+ asm volatile("mov $0x08fff000,%esp"); // set stack at high end of process image
asm volatile ("push %0" :: "r" (argv1));
asm volatile ("push %0" :: "r" (arg_count));
@@ -231,6 +215,7 @@ int syscall_execve(char *name, char **argv, char **env)
asm volatile ("sti");
asm volatile ("ret");
+ */
// this is never reached!
}
@@ -245,9 +230,6 @@ int get_max_fd()
// TODO: allow opening existing files/named pipes
int syscall_open(char *name, int flags, int mode)
{
- #ifdef LOG_SYSCALLS
- klog("open (name=0x%08X(\"%s\"), flags=%d, mode=%d)",name, name,flags,mode);
- #endif
if( next_fifo>=MAX_FIFOS || next_fd>=MAX_FD)kpanic("we ran out of fd's or fifo's");
@@ -258,13 +240,20 @@ int syscall_open(char *name, int flags, int mode)
}
else
{
- // FIRST TIME WE SEE THE GENIUS OF OUR ABSTRACTIONS (I HOPE...)
+
+ // HERE WE SEE THE GENIUS OF OUR ABSTRACTIONS (I HOPE...)
+
+ if (fb_addr<0x100000)
+ {
screen.put_char=console_put_char;
screen.update_cursor=update_cursor;
-
- // FIRST TIME WE SEE THE GENIUS OF OUR ABSTRACTIONS (I HOPE...)
+ }
+ else
+ {
screen.put_char=vesa_console_put_char;
screen.update_cursor=vesa_update_cursor;
+ }
+
tty1=terminal_init(&screen,NULL);
@@ -284,9 +273,6 @@ int syscall_open(char *name, int flags, int mode)
//
int syscall_close(int file,int none1,int none2)
{
- #ifdef LOG_SYSCALLS
- klog("close (file=%d)", file);
- #endif
//if(file!=0&&file!=1&&file!=2)
// kpanic("unhandled syscall: close");
@@ -297,9 +283,6 @@ int syscall_close(int file,int none1,int none2)
// TODO: check if file is termminal!
int syscall_isatty(int file,int none1,int none2)
{
- #ifdef LOG_SYSCALLS
- klog("isatty (file=%d)", file);
- #endif
return 1;
}
@@ -315,9 +298,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
task_set_brk(alloc);
- #ifdef LOG_SYSCALLS
- klog("sbrk (incr=%d) = 0x%08X", incr,oldalloc);
- #endif
return oldalloc;
}
@@ -325,10 +305,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
// stat, fstat, lstat
int syscall_stat(const char *path, struct stat *st,int none)
{
- #ifdef LOG_SYSCALLS
- klog("stat (path=0x%08X,stat=0x%08X)", path,st);
- #endif
-
st->st_mode = S_IFCHR;
return 0;
}
@@ -336,7 +312,7 @@ int syscall_stat(const char *path, struct stat *st,int none)
/// there also is task_fork, task_wait, task_exit.. which is in scheduler.c
////////////////////////////////////////
-uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3)
+uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid)
{
switch(nr){
@@ -345,9 +321,9 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3)
case SYSCALL_CLOSE :
return syscall_close(p1,p2,p3);
case SYSCALL_EXECVE :
- return syscall_execve(p1,p2,p3);
+ return syscall_execve(p1,p2,p3,pid);
case SYSCALL_FORK :
- return task_fork(p1,p2,p3);
+ return task_fork(pid);
case SYSCALL_GETPID :
// return syscall_getpid(p1,p2,p3);
return -1;