diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-10-23 08:41:34 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-10-23 08:41:34 +0200 |
| commit | 463736887fbb6439fe5e676f6fd7990adc6bb727 (patch) | |
| tree | 00dcb1fb5d426d13ef854820a8672470e49530a7 /userspace | |
| parent | fde24d20cd6a7d5fd1f1df71515e377586b91e24 (diff) | |
added execve syscall
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/Makefile | 18 | ||||
| -rw-r--r-- | userspace/foolshell.c | 7 | ||||
| -rw-r--r-- | userspace/simple.c | 18 | ||||
| -rw-r--r-- | userspace/syscalls.c | 112 |
4 files changed, 73 insertions, 82 deletions
diff --git a/userspace/Makefile b/userspace/Makefile index a26d554..ceba7d0 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -8,7 +8,7 @@ LDFLAGS=-L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/newlib/ \ -L/home/miguel/temp/fool-os-stuff/newlib-build-clean/i686-elf/libgloss/libnosys/ \ -lnosys -ext2.img: userprog +ext2.img: shell simple dd if=/dev/zero of=ext2.img bs=512 count=200 sudo mkfs.ext2 -O none ext2.img -F mkdir mnt @@ -17,16 +17,24 @@ ext2.img: userprog mkdir mnt/miguel echo "hello one" > mnt/miguel/test1.txt echo "hello two" > mnt/test2.txt - cp userprog mnt/shell + cp shell mnt + cp simple mnt sync sudo umount mnt rm mnt -rf -userprog: foolshell.o crt0.o - ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o userprog +shell: foolshell.o crt0.o + ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o shell + +simple: simple.o crt0.o + ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o simple clean: - -rm *.o *.out userprog ext2.img + -rm *.o *.out shell simple ext2.img + +umount: + sudo umount mnt + rm mnt -rf diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 8bf8288..3fe7353 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -86,7 +86,7 @@ int process(char *buf) if(!strcmp(command,"help")) { - puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', 'malloc [bytes]', 'free [address]', "); + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'ls [inode_nr]', exec [inode_nr],'malloc [bytes]', 'free [address]'"); } else if(!strcmp(command,"ls")) { @@ -101,6 +101,11 @@ int process(char *buf) } } + else if(!strcmp(command,"exec")) + { + execve(atoi(token[1]),0,0); + + } else if(!strcmp(command,"echo")) { printf("foolshell: \"%s\"\n",token[1]); diff --git a/userspace/simple.c b/userspace/simple.c new file mode 100644 index 0000000..36f0580 --- /dev/null +++ b/userspace/simple.c @@ -0,0 +1,18 @@ +#include "syscalls.c" + +int main(int argc, char **argv) +{ + syscalls_init(); + + int i; + + for(i=0;i<10;i++) + { + write(1,"dupa\n",5); + } + + // replace with foolshell after finishing! + execve(15,0,0); +} + + 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)); -} |
