I added smes and rmes system calls to a7out and wrote some code
in src/other/fork_test.s to test it. It's not working quite right yet, we keep getting wait() returning -1 in a7out even though there is a child process.
This commit is contained in:
@@ -7,14 +7,33 @@ main:
|
|||||||
child:
|
child:
|
||||||
lac d1
|
lac d1
|
||||||
sys write; childmsg; 3
|
sys write; childmsg; 3
|
||||||
|
sys smes
|
||||||
sys exit
|
sys exit
|
||||||
|
|
||||||
parent:
|
parent:
|
||||||
|
dac pid " save the childs pid
|
||||||
lac d1
|
lac d1
|
||||||
sys write; parentmsg; 4
|
sys write; parentmsg; 4
|
||||||
|
|
||||||
|
sys rmes " wait for the child to exit
|
||||||
|
sad pid " did we get the same pid back?
|
||||||
|
jmp ok
|
||||||
|
|
||||||
|
wrong:
|
||||||
|
lac d1
|
||||||
|
sys write; badpid; 4
|
||||||
|
sys exit
|
||||||
|
|
||||||
|
ok:
|
||||||
|
lac d1
|
||||||
|
sys write; goodpid; 4
|
||||||
sys exit
|
sys exit
|
||||||
|
|
||||||
d1: 1 " stdout fd
|
d1: 1 " stdout fd
|
||||||
|
pid: 0 " child's pid
|
||||||
|
|
||||||
parentmsg: <pa>; <re>; <nt>; 012000
|
parentmsg: <pa>; <re>; <nt>; 012000
|
||||||
childmsg: <ch>; <il>; <d 012
|
childmsg: <ch>; <il>; <d 012
|
||||||
|
|
||||||
|
goodpid: <go>; <od>; <pi>; <d 012
|
||||||
|
badpid: <ba>; <dp>; <id>; 012000
|
||||||
|
|||||||
+26
-2
@@ -537,6 +537,8 @@ sub cal {
|
|||||||
17 => \&sys_chdir,
|
17 => \&sys_chdir,
|
||||||
18 => \&sys_chmod,
|
18 => \&sys_chmod,
|
||||||
19 => \&sys_chown,
|
19 => \&sys_chown,
|
||||||
|
27 => \&sys_rmes,
|
||||||
|
28 => \&sys_smes,
|
||||||
29 => \&sys_fork,
|
29 => \&sys_fork,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -551,7 +553,7 @@ sub cal {
|
|||||||
|
|
||||||
# Exit system call
|
# Exit system call
|
||||||
sub sys_exit {
|
sub sys_exit {
|
||||||
dprintf("exit system call\n");
|
dprintf("exit system call, pid %06o\n", $$);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,13 +570,35 @@ sub sys_fork {
|
|||||||
|
|
||||||
# Fork and get the child's process-id back, or zero if we are the child
|
# Fork and get the child's process-id back, or zero if we are the child
|
||||||
my $pid= fork();
|
my $pid= fork();
|
||||||
$AC= $pid;
|
$AC= $pid & MAXINT;
|
||||||
|
dprintf( "fork, got id %06o\n", $AC);
|
||||||
|
|
||||||
# The parent returns back to PC+1, the child returns to PC+2
|
# The parent returns back to PC+1, the child returns to PC+2
|
||||||
$PC += ($pid) ? 1 : 2;
|
$PC += ($pid) ? 1 : 2;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Smes system call. Because we fake rmes with wait(),
|
||||||
|
# there is no need for sms. When the child does
|
||||||
|
# sys exit, that's going to wake wait() up and do the
|
||||||
|
# rmes anyway.
|
||||||
|
sub sys_smes {
|
||||||
|
# For now, do nothing
|
||||||
|
dprintf("smes system call\n");
|
||||||
|
$PC += 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Rmes system call. We simply call wait and
|
||||||
|
# return the process-id in AC
|
||||||
|
sub sys_rmes {
|
||||||
|
my $pid= wait();
|
||||||
|
dprintf("rmes system call, got pid $pid\n");
|
||||||
|
$AC= $pid & MAXINT;
|
||||||
|
$PC += 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
# Close system call
|
# Close system call
|
||||||
sub sys_close {
|
sub sys_close {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user