tools/a7out: Added the creat() system call.
This commit is contained in:
+48
-18
@@ -454,6 +454,7 @@ sub cal {
|
|||||||
3 => \&sys_open,
|
3 => \&sys_open,
|
||||||
4 => \&sys_read,
|
4 => \&sys_read,
|
||||||
5 => \&sys_write,
|
5 => \&sys_write,
|
||||||
|
6 => \&sys_creat,
|
||||||
9 => \&sys_close,
|
9 => \&sys_close,
|
||||||
14 => \&sys_exit,
|
14 => \&sys_exit,
|
||||||
);
|
);
|
||||||
@@ -525,6 +526,29 @@ sub sys_close {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Common code for creat and open
|
||||||
|
sub creatopen {
|
||||||
|
my ($filename, $readorwrite)= @_;
|
||||||
|
|
||||||
|
# Open the file
|
||||||
|
if ( open( my $FH, $readorwrite, $filename ) ) {
|
||||||
|
|
||||||
|
# Find a place in the @FD array to store this filehandle.
|
||||||
|
# 99 is arbitrary
|
||||||
|
foreach my $fd ( 0 .. 99 ) {
|
||||||
|
if ( !defined( $FD[$fd] ) ) {
|
||||||
|
$FD[$fd] = $FH;
|
||||||
|
$AC = $fd;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# No filehandle, so it's an error
|
||||||
|
dprintf("open failed: $!\n");
|
||||||
|
$AC = MAXINT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Open system call
|
# Open system call
|
||||||
sub sys_open {
|
sub sys_open {
|
||||||
|
|
||||||
@@ -546,25 +570,31 @@ sub sys_open {
|
|||||||
# Bump up the PC
|
# Bump up the PC
|
||||||
$PC += 3;
|
$PC += 3;
|
||||||
|
|
||||||
# Open the file
|
# Now open the file and return
|
||||||
if ( open( my $FH, $readorwrite, $filename ) ) {
|
creatopen($filename, $readorwrite);
|
||||||
|
}
|
||||||
|
|
||||||
# Find a place in the @FD array to store this filehandle.
|
# Creat system call
|
||||||
# 99 is arbitrary
|
sub sys_creat {
|
||||||
foreach my $fd ( 0 .. 99 ) {
|
# Open seems to have 1 arguments: PC+1 is a pointer to the filename.
|
||||||
if ( !defined( $FD[$fd] ) ) {
|
# Some programs seem to have a second argument always set to 0.
|
||||||
$FD[$fd] = $FH;
|
# AC is the opened fd on success, or -1 on error
|
||||||
$AC = $fd;
|
|
||||||
last;
|
# Get the start address of the string
|
||||||
}
|
my $start = $Mem[ $PC + 1 ];
|
||||||
}
|
|
||||||
return;
|
# Convert this to a sensible ASCII filename
|
||||||
} else {
|
my $filename = mem2arg($start);
|
||||||
# No filehandle, so it's an error
|
|
||||||
dprintf("open failed: $!\n");
|
# Choose to open write-only
|
||||||
$AC = MAXINT;
|
my $readorwrite = ">";
|
||||||
return;
|
dprintf( "creat: base %06o, file %s\n", $start, $filename );
|
||||||
}
|
|
||||||
|
# Bump up the PC
|
||||||
|
$PC += 2;
|
||||||
|
|
||||||
|
# Now open the file and return
|
||||||
|
creatopen($filename, $readorwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Read system call
|
# Read system call
|
||||||
|
|||||||
Reference in New Issue
Block a user