This commit is contained in:
Robert Morris 2020-08-15 05:46:32 -04:00
parent 4a87a0ae8b
commit b154cf091c
3 changed files with 21 additions and 15 deletions

View file

@ -1,14 +1,8 @@
# qemu -kernel starts at 0x1000. the instructions # qemu -kernel loads the kernel at 0x80000000
# there seem to be provided by qemu, as if it # and causes each CPU to jump there.
# were a ROM. the code at 0x1000 jumps to # kernel.ld causes the following code to
# 0x80000000, the _start function here, # be placed at 0x80000000.
# in machine mode. each CPU starts here.
.section .data
.globl stack0
.section .text .section .text
.globl start
.section .text
.globl _entry
_entry: _entry:
# set up a stack for C. # set up a stack for C.
# stack0 is declared in start.c, # stack0 is declared in start.c,
@ -22,5 +16,5 @@ _entry:
add sp, sp, a0 add sp, sp, a0
# jump to start() in start.c # jump to start() in start.c
call start call start
junk: spin:
j junk j spin

View file

@ -31,8 +31,20 @@ main(void)
printf("init: exec sh failed\n"); printf("init: exec sh failed\n");
exit(1); exit(1);
} }
while((wpid=wait(0)) >= 0 && wpid != pid){
//printf("zombie!\n"); for(;;){
// this call to wait() returns if the shell exits,
// or if a parentless process exits.
wpid = wait((int *) 0);
if(wpid == pid){
// the shell exited; restart it.
break;
} else if(wpid < 0){
printf("init: wait returned an error\n");
exit(1);
} else {
// it was a parentless process; do nothing.
}
} }
} }
} }

View file

@ -1,4 +1,4 @@
# Initial process execs /init. # Initial process that execs /init.
# This code runs in user space. # This code runs in user space.
#include "syscall.h" #include "syscall.h"