diff options
Diffstat (limited to 'userspace/syscalls.c')
| -rw-r--r-- | userspace/syscalls.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/userspace/syscalls.c b/userspace/syscalls.c index 7b0f563..f4e77a1 100644 --- a/userspace/syscalls.c +++ b/userspace/syscalls.c @@ -45,23 +45,27 @@ int lseek(int file, int ptr, int dir) int read(int file, char *ptr, int len) { -// easywrite("syscall: read\n"); + int ebx; // will hold return value; + + asm("pusha"); + + // select syscall + asm("mov $62,%eax"); - int i; - char buf[]="++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."; + // pass params + asm("mov %0,%%edx"::"m"(file)); + asm("mov %0,%%ecx"::"m"(ptr)); + asm("mov %0,%%ebx"::"m"(len)); - if(preread>=strlen(buf)){ -// easywrite("syscall: read = EOF\n"); - return 0; //EOF - } + // interrrupt + asm("int $0x80"); - for(i=0;i<len;i++) - { - if(preread>=strlen(buf))return i; - ptr[i]=buf[preread++]; - } + // get return value + asm("mov %%ebx, %0": "=b" (ebx)); + + asm("popa"); - return len; + return ebx; } int open(const char *name, int flags, int mode) @@ -73,28 +77,28 @@ int open(const char *name, int flags, int mode) int write(int file, char *ptr, int len) { - int todo; - for (todo = 0; todo < len; todo++) - { - - char byte=(*ptr++); - int byt=byte; int ebx; // will hold return value; - // system call + asm("pusha"); - asm("mov $61,%eax"); // select syscall) + + // select syscall + asm("mov $61,%eax"); - asm("mov %0,%%edx"::"m"(byt)); - //asm("mov $88,%edx"); + // 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)); - asm("int $0x80"); // actual syscall ! interrupt - asm("mov %%ebx, %0": "=b" (ebx)); asm("popa"); - // - } - return len; + return ebx; } |
