@@ -1,2 +1,3 @@
|
|||||||
|
system:system:system:777777
|
||||||
ken:ken:ken:12
|
ken:ken:ken:12
|
||||||
dmr:dmr:dmr:14
|
dmr:dmr:dmr:14
|
||||||
|
|||||||
+147
-110
@@ -37,9 +37,12 @@ maxargs=8
|
|||||||
|
|
||||||
newline:
|
newline:
|
||||||
lac d1; sys write; prompt; 1 " output prompt
|
lac d1; sys write; prompt; 1 " output prompt
|
||||||
jms rline " read line into ibuf
|
jms rline " read (edited) line into lbuf
|
||||||
lac iipt
|
lac ilpt
|
||||||
dac ipt
|
dac lpt " reset line pointer
|
||||||
|
|
||||||
|
" parse new command from current input line
|
||||||
|
" (after ';' or '&')
|
||||||
newcom:
|
newcom:
|
||||||
dzm char " clear saved char
|
dzm char " clear saved char
|
||||||
dzm infile " clear input redirect file name
|
dzm infile " clear input redirect file name
|
||||||
@@ -68,12 +71,12 @@ newarg:
|
|||||||
|
|
||||||
jms blank " skip whitespace
|
jms blank " skip whitespace
|
||||||
jms delim " command sep?
|
jms delim " command sep?
|
||||||
jmp eol " yes
|
jmp eoc " yes
|
||||||
sad lt " input redirect?
|
sad lt " input redirect?
|
||||||
jmp redirin
|
jmp redirin " yes
|
||||||
sad gt " output redirect?
|
sad gt " output redirect?
|
||||||
jmp redirout
|
jmp redirout " yes
|
||||||
jmp 3f
|
jmp savechar " no: save as filename
|
||||||
|
|
||||||
redirin: " saw <
|
redirin: " saw <
|
||||||
dac redirect " flag redirect
|
dac redirect " flag redirect
|
||||||
@@ -87,40 +90,43 @@ redirout: " saw >
|
|||||||
dac opt
|
dac opt
|
||||||
" fall
|
" fall
|
||||||
|
|
||||||
newchar:
|
newchar: " loop reading a file name
|
||||||
jms getc
|
jms getc
|
||||||
sad o40 " space?
|
sad o40 " space?
|
||||||
jmp eoname " yes
|
jmp eoname " yes
|
||||||
jms delim
|
jms delim " no: end of line?
|
||||||
jmp eoname
|
jmp eoname " yes
|
||||||
3: jms putc " save
|
savechar:
|
||||||
|
jms putc " no: save
|
||||||
isz bcount " loop unless full
|
isz bcount " loop unless full
|
||||||
jmp newchar
|
jmp newchar
|
||||||
|
|
||||||
" here after 8 chars: discard until terminator seen
|
" here after 8 chars: discard until terminator seen
|
||||||
discard:
|
1: jms getc
|
||||||
jms getc
|
|
||||||
jms delim " end of line?
|
jms delim " end of line?
|
||||||
jmp eoname
|
jmp 2f
|
||||||
sad o40
|
sad o40
|
||||||
jmp eoname
|
jmp 2f
|
||||||
jmp discard
|
jmp 1b
|
||||||
|
|
||||||
|
2:
|
||||||
|
dac char " save terminator
|
||||||
|
jmp full
|
||||||
|
|
||||||
" name ended (short) with whitespace or delim
|
" name ended (short) with whitespace or delim
|
||||||
" pad out last name to 8 with spaces
|
" pad out last name to 8 with spaces
|
||||||
" XXX check if ANYTHING read
|
|
||||||
eoname:
|
eoname:
|
||||||
dac char " save terminator
|
dac char " save terminator
|
||||||
1: lac o40
|
1: lac o40
|
||||||
jms putc " no: copy into argv
|
jms putc " copy into argv
|
||||||
isz bcount " loop until full
|
isz bcount " loop until full
|
||||||
jmp 1b
|
jmp 1b
|
||||||
|
full:
|
||||||
" saw end of name
|
lac redirect
|
||||||
2: lac redirect
|
|
||||||
sza
|
sza
|
||||||
jmp 2f " last name was a redirect file, skip increment
|
jmp 2f " last name was a redirect file, skip increment
|
||||||
|
|
||||||
|
" file was not a redirection:
|
||||||
lac argc " increment argc
|
lac argc " increment argc
|
||||||
tad d4
|
tad d4
|
||||||
dac argc
|
dac argc
|
||||||
@@ -131,31 +137,31 @@ eoname:
|
|||||||
2:
|
2:
|
||||||
dzm redirect " clear redirect flag
|
dzm redirect " clear redirect flag
|
||||||
lac nextarg
|
lac nextarg
|
||||||
dac opt
|
dac opt " set output pointer
|
||||||
|
|
||||||
lac char
|
lac char " get terminator
|
||||||
jms delim
|
jms delim " end of command?
|
||||||
jmp eol
|
jmp eoc " yes
|
||||||
|
|
||||||
lac argc
|
lac argc " another arg
|
||||||
sad maxargwords
|
sad maxargwords " full up?
|
||||||
skp
|
skp " yes
|
||||||
jmp newarg
|
jmp newarg " no: get another
|
||||||
|
|
||||||
" too many args, (complain?). for now eat rest of line
|
" too many args
|
||||||
4: jms getc
|
4: jms getc
|
||||||
jms delim
|
jms delim
|
||||||
skp
|
skp
|
||||||
jmp 4b
|
jmp 4b
|
||||||
lac d1; sys write; toomany; ltoomany
|
lac d1; sys write; toomany; ltoomany
|
||||||
jmp newline
|
jmp newline " ignore rest of line
|
||||||
|
|
||||||
" here at end of line
|
" here at end of command
|
||||||
eol:
|
eoc:
|
||||||
sad delimchar " save eol character
|
dac delimchar " save command delimiter
|
||||||
lac argc " check for empty command line
|
lac argc " check for empty command line
|
||||||
sna " get anything?
|
sna " get anything?
|
||||||
jmp 2f " no, go back for another
|
jmp nextcmd " no, go back for another
|
||||||
|
|
||||||
" check for built-in "chdir" command
|
" check for built-in "chdir" command
|
||||||
lac argv0
|
lac argv0
|
||||||
@@ -170,40 +176,37 @@ eol:
|
|||||||
sad chdirstr+2
|
sad chdirstr+2
|
||||||
jmp changedir
|
jmp changedir
|
||||||
|
|
||||||
1:
|
" here to execute command (not a builtin)
|
||||||
" comment these out to test "exec" w/o fork
|
1: sys fork
|
||||||
sys fork
|
|
||||||
jmp parent
|
jmp parent
|
||||||
|
|
||||||
|
child: " debug symbol
|
||||||
sys open; argv0; 0 " try cwd (no link required)
|
sys open; argv0; 0 " try cwd (no link required)
|
||||||
sma
|
sma " error?
|
||||||
jmp 1f
|
jmp 1f " no
|
||||||
" jmp cmderr
|
|
||||||
|
|
||||||
sys unlink; exectemp " remove old temp file, if any
|
sys link; system; argv0; argv0
|
||||||
sys link; system; argv0; exectemp
|
|
||||||
spa
|
spa
|
||||||
jmp cmderr
|
jmp cmderr
|
||||||
sys open; exectemp; 0
|
sys open; argv0; 0
|
||||||
spa
|
spa
|
||||||
jmp cmderr
|
jmp cmderr
|
||||||
dac cmdfd
|
dac cmdfd
|
||||||
sys unlink; exectemp
|
sys unlink; argv0
|
||||||
skp
|
skp
|
||||||
|
|
||||||
1: dac cmdfd " save command file descriptor
|
1: dac cmdfd " save command file descriptor
|
||||||
cla " check for input redirection
|
cla " check for input redirection
|
||||||
sad infile " input redirct?
|
sad infile " input redirct?
|
||||||
jmp 1f " no
|
jmp 1f " no
|
||||||
sys close " close fd 0
|
sys close " close fd 0
|
||||||
sys open; infile; 0 " open redirected
|
sys open; infile; 0 " open new stdin
|
||||||
spa sna
|
spa
|
||||||
jmp inerror
|
jmp inerror
|
||||||
cla
|
cla
|
||||||
1: sad outfile " output redirec?
|
1: sad outfile " output redirect?
|
||||||
jmp exec " no
|
jmp exec " no
|
||||||
lac d1; sys close " close fd 1
|
lac d1; sys close " close fd 1
|
||||||
lac o17; sys creat; outfile " open output redirect
|
lac o17; sys creat; outfile " open new stdout
|
||||||
spa
|
spa
|
||||||
jmp outerror
|
jmp outerror
|
||||||
|
|
||||||
@@ -225,7 +228,7 @@ exec:
|
|||||||
|
|
||||||
" copied up to bootloc in high memory (below argc)
|
" copied up to bootloc in high memory (below argc)
|
||||||
boot:
|
boot:
|
||||||
sys read; userbase; userlen " read executable in
|
sys read; userbase; userlen " read executable in (check for non-zero ret?)
|
||||||
lacq " Get the fd back and close the file
|
lacq " Get the fd back and close the file
|
||||||
sys close " close command file
|
sys close " close command file
|
||||||
jmp userbase " and jump to the beginning of the executable
|
jmp userbase " and jump to the beginning of the executable
|
||||||
@@ -245,31 +248,34 @@ error: " error in child: filename pointer in AC
|
|||||||
lac d1; sys write; 1: 0; 4
|
lac d1; sys write; 1: 0; 4
|
||||||
lac d1; sys write; qmnl; 1
|
lac d1; sys write; qmnl; 1
|
||||||
lac d2; sys close " close executable, if any
|
lac d2; sys close " close executable, if any
|
||||||
sys exit
|
sys exit " performs implicit rmes
|
||||||
|
|
||||||
" chdir command: executed in shell process
|
" chdir command: executed in shell process
|
||||||
|
" takes a series of directory names to chdir to in turn
|
||||||
changedir:
|
changedir:
|
||||||
" XXX check if argc == 4 (no directories) and complain??
|
lac argc
|
||||||
|
sad d4
|
||||||
|
jmp qm " need at least one arg!
|
||||||
lac argv0p
|
lac argv0p
|
||||||
skp
|
skp
|
||||||
1: lac 0f " increment argvp
|
1: lac 0f " increment dir pointer
|
||||||
tad d4
|
tad d4
|
||||||
dac 0f
|
dac 0f
|
||||||
-4 " decrement argc
|
-4 " decrement argc
|
||||||
tad argc
|
tad argc
|
||||||
dac argc
|
dac argc
|
||||||
sna " done?
|
sna " done?
|
||||||
jmp 2f " yes: join parent code
|
jmp nextcmd " yes: join parent code
|
||||||
sys chdir; 0:0
|
sys chdir; 0:0
|
||||||
sma " error?
|
sma " error?
|
||||||
jmp 1b " no: look for another directory
|
jmp 1b " no: look for another directory
|
||||||
|
|
||||||
" chdir call failed
|
|
||||||
lac 0b
|
lac 0b " chdir failed: get offending name
|
||||||
dac 0f
|
dac 0f " store for write
|
||||||
lac d1; sys write; 0:0; 4
|
lac d1; sys write; 0:0; 4 " complain
|
||||||
lac d1; sys write; qmnl; 1
|
qm:lac d1; sys write; qmnl; 1
|
||||||
jmp 2f " join parent code
|
jmp nextcmd " join parent code
|
||||||
|
|
||||||
" here in parent, child pid in AC
|
" here in parent, child pid in AC
|
||||||
parent:
|
parent:
|
||||||
@@ -290,9 +296,11 @@ parent:
|
|||||||
jmp newcom " yes: go back without wait
|
jmp newcom " yes: go back without wait
|
||||||
lac pid " no: get pid
|
lac pid " no: get pid
|
||||||
sys smes " hang until child exits
|
sys smes " hang until child exits
|
||||||
2: lac delimchar
|
nop
|
||||||
|
nextcmd:
|
||||||
|
lac delimchar
|
||||||
sad o73 " semi?
|
sad o73 " semi?
|
||||||
jmp newcom " yes: look for another command w/o prompt
|
jmp newcom " yes: look for another command on line
|
||||||
jmp newline " no: output prompt
|
jmp newline " no: output prompt
|
||||||
|
|
||||||
" ================
|
" ================
|
||||||
@@ -318,46 +326,70 @@ delim: 0
|
|||||||
isz delim " ran the gauntlet: skip home
|
isz delim " ran the gauntlet: skip home
|
||||||
jmp delim i
|
jmp delim i
|
||||||
|
|
||||||
" get character from ibuf
|
" get character from lbuf
|
||||||
getc: 0
|
getc: 0
|
||||||
lac ipt i " fetch char
|
lac lpt i " fetch char from line buffer
|
||||||
isz ipt " increment pointer
|
isz lpt " increment pointer
|
||||||
jmp getc i
|
jmp getc i
|
||||||
|
|
||||||
" from init.s rline: read line from tty into ibuf
|
" from init.s rline: read line into lbuf with editing
|
||||||
" (store one character per word)
|
" (store one character per word)
|
||||||
rline: 0
|
rline: 0
|
||||||
law ibuf-1 " Store ibuf pointer in location 8
|
law lbuf-1 " pointer in location 8
|
||||||
dac 8
|
dac 8
|
||||||
1:
|
1: jms readc
|
||||||
cla; sys read; char; 1 " Read in one character from stdin
|
jmp quit " EOF
|
||||||
sna " read ok?
|
sad o100 " '@' (kill) character?
|
||||||
jmp quit " no
|
jmp rline+1 " yes: start from scratch
|
||||||
lac char
|
sad o43 " '#' (erase) character?
|
||||||
lrss 9 " Get it and shift down 9 bits
|
jmp 2f " yes: handle below
|
||||||
sad o100 " '@' (kill) character?
|
dac 8 i " Store the character in the buffer
|
||||||
jmp rline+1 " yes: start from scratch
|
sad o12 " Newline?
|
||||||
sad o43 " '#' (erase) character?
|
jmp rline i " yes: return
|
||||||
jmp 2f " yes: handle below
|
jmp 1b " no: keep going
|
||||||
|
|
||||||
dac 8 i " Store the character in the buffer
|
|
||||||
sad o12 " Newline?
|
|
||||||
jmp rline i " yes: return
|
|
||||||
jmp 1b " no: keep going
|
|
||||||
2:
|
2:
|
||||||
law ibuf-1 " # handling. Do nothing if at start of the buffer
|
law lbuf-1 " # (erase) handling
|
||||||
sad 8
|
sad 8 " at start?
|
||||||
jmp 1b " and loop back
|
jmp 1b " yes: noop, loop back
|
||||||
-1
|
-1 " no: decrement poiner
|
||||||
tad 8 " Otherwise, move the pointer in location 8 back one
|
tad 8
|
||||||
dac 8
|
dac 8
|
||||||
jmp 1b " and loop back
|
jmp 1b
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
lac d1; sys smes " wake up init
|
lac d1; sys smes " wake up init
|
||||||
sys exit
|
sys exit
|
||||||
|
|
||||||
" copied from cat.s:
|
" copied from cat.s
|
||||||
|
|
||||||
|
" was "getc"
|
||||||
|
readc: 0
|
||||||
|
lac ipt " Load the pointer to the next word in the buffer
|
||||||
|
sad eipt
|
||||||
|
jmp 1f " We've reached the end of the buffer, so read more
|
||||||
|
dac 2f " Save the pointer
|
||||||
|
add o400000 " Flip the msb and save into ipt
|
||||||
|
dac ipt
|
||||||
|
ral " Move the msb into the link register
|
||||||
|
lac 2f i " Load the word from the buffer
|
||||||
|
szl " Skip if this is the second character in the word
|
||||||
|
lrss 9 " It's the first char, shift down the top character
|
||||||
|
and o177 " Keep the lowest 7 bits
|
||||||
|
sna
|
||||||
|
jmp readc+1 " Skip a NUL characters and read another one
|
||||||
|
isz readc " give skip return
|
||||||
|
jmp readc i " Return the character from the subroutine
|
||||||
|
1:
|
||||||
|
cla " Buffer is empty, read 64 chars from stdin
|
||||||
|
sys read; iipt+1; 64
|
||||||
|
sna
|
||||||
|
jmp readc i " No characters read: return without skip
|
||||||
|
tad iipt " Add the word count to the base of the buffer
|
||||||
|
dac eipt " and store in the end buffer pointer
|
||||||
|
lac iipt " Reset the ipt to the base of the buffer
|
||||||
|
dac ipt
|
||||||
|
jmp readc+1 " and loop back to get one character
|
||||||
|
|
||||||
putc: 0
|
putc: 0
|
||||||
and o177 " Keep the lowest 7 bits and save into 2f+1
|
and o177 " Keep the lowest 7 bits and save into 2f+1
|
||||||
dac 2f+1
|
dac 2f+1
|
||||||
@@ -378,17 +410,22 @@ putc: 0
|
|||||||
jmp putc i " No, so return (more room still in the buffer)
|
jmp putc i " No, so return (more room still in the buffer)
|
||||||
|
|
||||||
2: 0;0 " pointer, char
|
2: 0;0 " pointer, char
|
||||||
|
ipt: 0 " Current input buffer base
|
||||||
|
eipt: 0 " Pointer to end of data read in input buffer
|
||||||
|
iipt: .+1; .=.+64 " 64 word input buffer and pointer to it
|
||||||
|
" end from cat.s
|
||||||
|
|
||||||
" literals
|
" literals
|
||||||
d1: 1
|
d1: 1
|
||||||
d2: 2
|
d2: 2
|
||||||
o4:d4: 4
|
o4:d4: 4
|
||||||
|
dm8: -8
|
||||||
o12: 012 " newline
|
o12: 012 " newline
|
||||||
o17: 017
|
o17: 017
|
||||||
o40: 040 " space
|
o40: 040 " space
|
||||||
o43: 043 " #
|
o43: 043 " #
|
||||||
o46: 046 " ampersand
|
o46: 046 " ampersand
|
||||||
o73: 046 " semi
|
o73: 073 " semi
|
||||||
o74:lt: 074 " <
|
o74:lt: 074 " <
|
||||||
o76:gt: 076 " >
|
o76:gt: 076 " >
|
||||||
o100: 0100 " @
|
o100: 0100 " @
|
||||||
@@ -401,9 +438,6 @@ qmnl: <? 012 " question mark, newline
|
|||||||
system:
|
system:
|
||||||
<sy>;<st>;<em>; 040040
|
<sy>;<st>;<em>; 040040
|
||||||
|
|
||||||
exectemp:
|
|
||||||
<ex>;<ec>;<te>;<mp> " temporary link for file being exec'ed
|
|
||||||
|
|
||||||
chdirstr:
|
chdirstr:
|
||||||
<ch>;<di>;<r 040
|
<ch>;<di>;<r 040
|
||||||
|
|
||||||
@@ -419,7 +453,7 @@ argcptr: argc
|
|||||||
infilep: infile
|
infilep: infile
|
||||||
outfilep: outfile
|
outfilep: outfile
|
||||||
|
|
||||||
iipt: ibuf
|
ilpt: lbuf " initial line buffer pointer
|
||||||
iopt:argv0p: argv0 " initial value for nextarg, opt
|
iopt:argv0p: argv0 " initial value for nextarg, opt
|
||||||
|
|
||||||
" ################ variables
|
" ################ variables
|
||||||
@@ -429,9 +463,9 @@ prompt: <@ 040 " v1 prompt!
|
|||||||
redirect: .=.+1 " last file was a redirect (lt or gt)
|
redirect: .=.+1 " last file was a redirect (lt or gt)
|
||||||
nextarg: .=.+1 " next slot in argv to fill
|
nextarg: .=.+1 " next slot in argv to fill
|
||||||
bcount: .=.+1 " byte counter for current filename
|
bcount: .=.+1 " byte counter for current filename
|
||||||
opt: .=.+1 " "output pointer" (may point to in/outfile or into argv)
|
opt: .=.+1 " "output pointer" (in/outfile or into argv)
|
||||||
delimchar: .=.+1 " character that terminated line
|
delimchar: .=.+1 " character that terminated line
|
||||||
char: .=.+1 " char that terminated word
|
char: .=.+1 " char that terminated word (merge w/ delimchar?)
|
||||||
|
|
||||||
outfile: .=.+4 " buffer for output redirect file name
|
outfile: .=.+4 " buffer for output redirect file name
|
||||||
infile: .=.+4 " buffer for input redirect file name
|
infile: .=.+4 " buffer for input redirect file name
|
||||||
@@ -439,17 +473,20 @@ pid: .=.+1 " "other" pid
|
|||||||
cmdfd: .=.+1 " fd for executable
|
cmdfd: .=.+1 " fd for executable
|
||||||
bootcount: .=.+1 " loop count for "boot" copy
|
bootcount: .=.+1 " loop count for "boot" copy
|
||||||
|
|
||||||
ipt: .=.+1 " input buf pointer
|
lpt: .=.+1 " line buf pointer
|
||||||
ibuf: " input line stored here, one character per word
|
lbuf: " edited line, one char per word
|
||||||
|
|
||||||
|
" enter addresses into namelist:
|
||||||
|
.=017777 " last word points to argc + argv data
|
||||||
|
argptr:
|
||||||
|
|
||||||
|
.=argptr-maxargs-maxargs-maxargs-maxargs-1 " argc followed by argv
|
||||||
|
argc: .=.+1
|
||||||
|
argv0: " 4 word blocks following argc
|
||||||
|
|
||||||
|
" "bootstrap" (reads executable into userbase) copied JUST below argc
|
||||||
|
.=argc-bootlen
|
||||||
|
bootloc:
|
||||||
|
|
||||||
userbase=010000 " user starts at 4K
|
userbase=010000 " user starts at 4K
|
||||||
argptr=017777 " last word points to argc + argv data
|
|
||||||
argc=argptr-maxargs-maxargs-maxargs-maxargs-1 " argc followed by argv
|
|
||||||
|
|
||||||
" arguments in 4 word blocks follow argc
|
|
||||||
argv0=argc+1
|
|
||||||
|
|
||||||
" "bootstrap" (reads executable into userbase) JUST below argc
|
|
||||||
bootloc=argc-bootlen " location of bootstrap
|
|
||||||
|
|
||||||
userlen=bootloc-userbase " max executable
|
userlen=bootloc-userbase " max executable
|
||||||
|
|||||||
@@ -196,8 +196,8 @@ usage() if ( @ARGV < 1 );
|
|||||||
);
|
);
|
||||||
|
|
||||||
# Parse all the files
|
# Parse all the files
|
||||||
|
print STDERR "I\n"; # like the real as
|
||||||
foreach my $file (@ARGV) {
|
foreach my $file (@ARGV) {
|
||||||
print STDERR "I $file\n"; # like the real as
|
|
||||||
parse_file($file);
|
parse_file($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,8 +206,9 @@ $Var{'.'} = $BASE;
|
|||||||
$stage = 2;
|
$stage = 2;
|
||||||
open(my $OUT, ">$output") || die "$output";
|
open(my $OUT, ">$output") || die "$output";
|
||||||
|
|
||||||
|
print STDERR "II\n"; # like the real as
|
||||||
foreach my $file (@ARGV) {
|
foreach my $file (@ARGV) {
|
||||||
print STDERR "II $file\n"; # like the real as
|
print STDERR "$file\n"; # like the real as
|
||||||
parse_file($file);
|
parse_file($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user