summaryrefslogtreecommitdiff
path: root/userspace/syscalls.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-10-23 08:41:34 +0200
committerMichal Idziorek <m.i@gmx.at>2014-10-23 08:41:34 +0200
commit463736887fbb6439fe5e676f6fd7990adc6bb727 (patch)
tree00dcb1fb5d426d13ef854820a8672470e49530a7 /userspace/syscalls.c
parentfde24d20cd6a7d5fd1f1df71515e377586b91e24 (diff)
added execve syscall
Diffstat (limited to 'userspace/syscalls.c')
-rw-r--r--userspace/syscalls.c112
1 files changed, 36 insertions, 76 deletions
diff --git a/userspace/syscalls.c b/userspace/syscalls.c
index 11976bc..b5959eb 100644
--- a/userspace/syscalls.c
+++ b/userspace/syscalls.c
@@ -10,36 +10,58 @@ static int preread;
static int alloc;
easywrite(char *c);
+// init syscalls
void syscalls_init()
{
- preread=0;
+ // TODO dynamic!
alloc=0x300000;
}
-//
+// generic syscall interface!
+int syscall(int call, int p1, int p2, int p3)
+{
+ int ebx; // will hold return value;
+
+ asm("pusha");
+
+ // select syscall
+ asm("mov %0, %%eax"::"m"(call));
+
+ // pass params
+ asm("mov %0,%%edx"::"m"(p1));
+ asm("mov %0,%%ecx"::"m"(p2));
+ asm("mov %0,%%ebx"::"m"(p3));
+ // interrrupt
+ asm("int $0x80");
+
+ // get return value
+ asm("mov %%ebx, %0": "=b" (ebx));
+
+ asm("popa");
+
+ return ebx;
+}
+
+//
int close(int file)
{
-// easywrite("syscall: close\n");
return -1;
}
int fstat(int file, struct stat *st)
{
-// easywrite("syscall: fstat\n");
st->st_mode = S_IFCHR;
return 0;
}
int isatty(int file)
{
-// easywrite("syscall: isatty\n");
return 1;
}
int lseek(int file, int ptr, int dir)
{
-// printf("syscall: lseek %i %i %i",file,ptr,dir);
if(dir==0)preread=ptr;
else{ puts("other modes unsupported sorry"); while(1);}
return preread;
@@ -47,86 +69,29 @@ int lseek(int file, int ptr, int dir)
int read(int file, char *ptr, int len)
{
- int ebx; // will hold return value;
-
- asm("pusha");
-
- // select syscall
- asm("mov $62,%eax");
-
- // pass params
- asm("mov %0,%%edx"::"m"(file));
- asm("mov %0,%%ecx"::"m"(ptr));
- asm("mov %0,%%ebx"::"m"(len));
-
- // interrrupt
- asm("int $0x80");
-
- // get return value
- asm("mov %%ebx, %0": "=b" (ebx));
-
- asm("popa");
-
- return ebx;
+ return syscall(62,file,ptr,len);
}
int readdir(const char *name,fs_dirent *dirs,int max)
{
- int ebx; // WILL Hold return value;
-
- asm("pusha");
-
- // select syscall
- asm("mov $63,%eax");
-
- // pass params
- asm("mov %0,%%edx"::"m"(name));
- asm("mov %0,%%ecx"::"m"(dirs));
- asm("mov %0,%%ebx"::"m"(max));
-
- // interrrupt
- asm("int $0x80");
-
- // get return value
- asm("mov %%ebx, %0": "=b" (ebx));
-
- asm("popa");
-
- return ebx;
+ return syscall(63,name,dirs,max);
}
int open(const char *name, int flags, int mode)
{
-// easywrite("syscall: open\n");
- return 99;
- return -1;
+ return name;
}
int write(int file, char *ptr, int len)
{
+ return syscall(61,file,ptr,len);
+}
- int ebx; // will hold return value;
-
- asm("pusha");
-
- // select syscall
- asm("mov $61,%eax");
-
- // pass params
- asm("mov %0,%%edx"::"m"(file));
- asm("mov %0,%%ecx"::"m"(ptr));
- asm("mov %0,%%ebx"::"m"(len));
-
- // interrupt
- asm("int $0x80");
-
- // get return value
- asm("mov %%ebx, %0": "=b" (ebx));
+int execve(char *name, char **argv, char **env)
+{
- asm("popa");
-
- return ebx;
+ return syscall(64,name,argv,env);
}
@@ -160,8 +125,3 @@ caddr_t sbrk(int incr)
}
//
-// helpers
-easywrite(char *c)
-{
- write(1,c,strlen(c));
-}