diff options
author | rtm <rtm> | 2006-06-15 16:02:20 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-06-15 16:02:20 +0000 |
commit | a4c03dea09b7b5f2463147e979d20b035b81de96 (patch) | |
tree | 3ba362f412faf45f0fb0e93b72f613ecc3956193 /main.c | |
parent | cb83c71628378bc0e295dd71bf6641379fbcdf37 (diff) | |
download | xv6-labs-a4c03dea09b7b5f2463147e979d20b035b81de96.tar.gz xv6-labs-a4c03dea09b7b5f2463147e979d20b035b81de96.tar.bz2 xv6-labs-a4c03dea09b7b5f2463147e979d20b035b81de96.zip |
primitive fork and exit system calls
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -4,12 +4,16 @@ #include "proc.h" #include "defs.h" #include "x86.h" +#include "traps.h" +#include "syscall.h" extern char edata[], end[]; +int main() { struct proc *p; + int i; // clear BSS memset(edata, 0, end - edata); @@ -27,6 +31,7 @@ main() // create fake process zero p = &proc[0]; + curproc = p; p->state = WAITING; p->sz = PAGE; p->mem = kalloc(p->sz); @@ -39,14 +44,28 @@ main() p->tf->tf_eflags = FL_IF; setupsegs(p); - p = newproc(&proc[0]); - // xxx copy instructions to p->mem - p->mem[0] = 0x90; // nop - p->mem[1] = 0x90; // nop - p->mem[2] = 0x42; // inc %edx - p->mem[3] = 0x42; // inc %edx + p = newproc(); + + i = 0; + p->mem[i++] = 0x90; // nop + p->mem[i++] = 0xb8; // mov ..., %eax + p->mem[i++] = SYS_fork; + p->mem[i++] = 0; + p->mem[i++] = 0; + p->mem[i++] = 0; + p->mem[i++] = 0xcd; // int + p->mem[i++] = T_SYSCALL; + p->mem[i++] = 0xb8; // mov ..., %eax + p->mem[i++] = SYS_exit; + p->mem[i++] = 0; + p->mem[i++] = 0; + p->mem[i++] = 0; + p->mem[i++] = 0xcd; // int + p->mem[i++] = T_SYSCALL; p->tf->tf_eip = 0; p->tf->tf_esp = p->sz; - swtch(&proc[0]); + swtch(); + + return 0; } |