summaryrefslogtreecommitdiff
path: root/kernel/syscalls.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/syscalls.c')
-rw-r--r--kernel/syscalls.c91
1 files changed, 31 insertions, 60 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 9ad07e2..0e4ee66 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -79,6 +79,20 @@ int syscall_unhandled(int nr)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"syscall: %d", nr);
panic(FOOLOS_MODULE_NAME,"unhandled syscall");
}
+
+int syscall_lseek(int file,int ptr,int dir)
+{
+
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
+ #endif
+
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
+ return 0;
+
+}
+
int syscall_write(int file, char *buf, int len)
{
@@ -86,6 +100,8 @@ int syscall_write(int file, char *buf, int len)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"write(file=%d, buf=0x%08X, len=%d)", file,buf,len);
#endif
+ if(file!=1&&file!=2) panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
// ALL output to stdout
for(int i=0;i<len;i++)
{
@@ -103,8 +119,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
+ if(file!=0) panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
// stdin TODO: other descroptiors!
- if(file==1||file!=1)
{
char c;
@@ -127,7 +144,7 @@ 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
@@ -214,11 +231,16 @@ int syscall_execve(char *name, char **argv, char **env)
// iterate over section headers
for(int phidx=0;phidx<elf->e_phnum;phidx++)
{
+ Elf32_Phdr *phdr=0x800000+elf->e_phoff+phidx*elf->e_phentsize;
+
+ if(phidx==0)
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"text: 0x%08X-0x%08X",phdr->p_vaddr,phdr->p_vaddr+phdr->p_filesz);
+ }
if(phidx==1)
{
- Elf32_Phdr *phdr=0x800000+elf->e_phoff+phidx*elf->e_phentsize;
/*
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"-- PROGRAMM HEADER %d --",phidx+1);
@@ -229,6 +251,7 @@ int syscall_execve(char *name, char **argv, char **env)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"p-memsz: 0x%08X",phdr->p_memsz);
*/
+
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"data: 0x%08X-0x%08X",phdr->p_vaddr,phdr->p_vaddr+phdr->p_filesz);
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bss: 0x%08X-0x%08X",phdr->p_vaddr+phdr->p_filesz,phdr->p_vaddr+phdr->p_memsz);
@@ -270,8 +293,8 @@ 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");
- return 99;
}
@@ -284,10 +307,13 @@ int syscall_close(int file,int none1,int none2)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"close (file=%d)", file);
#endif
+ if(file!=0&&file!=1&&file!=2)
+ panic(FOOLOS_MODULE_NAME,"unhandled syscall");
+
return -1;
}
-
+// TODO: check if file is termminal!
int syscall_isatty(int file,int none1,int none2)
{
#ifdef LOG_SYSCALLS
@@ -297,44 +323,9 @@ int syscall_isatty(int file,int none1,int none2)
return 1;
}
-
-int syscall_lseek(int file,int ptr,int dir)
-{
-
- #ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
- #endif
-/*
- if(dir==0)preread=ptr;
- else{ while(1);}
-*/
- return 0;
-
-}
-
-
uint32_t syscall_sbrk(int incr, int none1, int none2)
{
-
- // fool-os-convention to set bss_end:
- /*
- if(incr==0)
- {
- alloc=0;
- return 0;
- }
- if(alloc==0)
- {
- #ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sbrk RESET to 0x%08X", incr);
- #endif
-
- alloc=incr;
- return alloc;
- }
- */
-
uint32_t oldalloc=alloc;
alloc+=incr;
@@ -344,26 +335,6 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
return oldalloc;
- /*
-
- extern char end;
-// char _end;
- static char *heap_end;
- char *prev_heap_end;
-
- if (heap_end == 0) {
- heap_end = &end;
- }
- prev_heap_end = heap_end;
-
- if (heap_end + incr > stack_ptr) {
- write (1, "Heap and stack collision\n", 25);
- abort ();
- }
-
- heap_end += incr;
- return (caddr_t) prev_heap_end;
- */
}