# NCR 53c810 script assembler # Sponsored by # iX Multiuser Multitasking Magazine # # Copyright 1993, Drew Eckhardt # Visionary Computing # (Unix and Linux consulting and custom programming) # drew@Colorado.EDU # +1 (303) 786-7975 # # Support for 53c710 (via -ncr7x0_family switch) added by Richard # Hirst <richard@sleepie.demon.co.uk> - 15th March 1997 # # TolerANT and SCSI SCRIPTS are registered trademarks of NCR Corporation. #
# # Basically, I follow the NCR syntax documented in the NCR53c710 # Programmer's guide, with the new instructions, registers, etc. # from the NCR53c810. # # Differences between this assembler and NCR's are that # 1. PASS, REL (data, JUMPs work fine), and the option to start a new # script, are unimplemented, since I didn't use them in my scripts. # # 2. I also emit a script_u.h file, which will undefine all of # the A_*, E_*, etc. symbols defined in the script. This # makes including multiple scripts in one program easier # # 3. This is a single pass assembler, which only emits # .h files. #
# XXX - set these with command line options
$debug = 0; # Print general debugging messages
$debug_external = 0; # Print external/forward reference messages
$list_in_array = 1; # Emit original SCRIPTS assembler in comments in # script.h #$prefix; # (set by perl -s) # define all arrays having this prefix so we # don't have name space collisions after # assembling this file in different ways for # different host adapters
%symbol_values = (%registers) ; # Traditional symbol table
%symbol_references = () ; # Table of symbol references, where # the index is the symbol name, # and the contents a white space # delimited list of address,size # tuples where size is in bytes.
printf STDERR "New code : %08x\n", $code[$address] if ($debug);
}
# &parse_value($value, $word, $offset, $length) where $value is # an identifier or constant, $word is the word offset relative to # $address, $offset is the starting byte within that word, and # $length is the length of the field in bytes. # # Side effects are that the bytes are combined into the @code array # relative to $address, and that the %symbol_references table is # updated as appropriate.
sub parse_value {
local ($value, $word, $offset, $length) = @_;
local ($tmp);
$need_data = 0; if ($conditional =~ /^ATN\s*(.*)/i) {#
die "$0 : syntax error in line $lineno : $_
WHEN conditional is incompatible with ATN " if (!$allow_atn);
$code[$address] |= 0x00_02_00_00;
$conditional = $1;
print STDERR "$0 : parsed ATN\n"if ($debug);
} elsif ($conditional =~ /^($phase)\s*(.*)/i) {
$phase_index = "\U$1\E";
$p = $scsi_phases{$phase_index};
$code[$address] |= $p | 0x00_02_00_00;
$conditional = $2;
print STDERR "$0 : parsed phase $phase_index\n"if ($debug);
} else {
$other = '';
$need_data = 1;
}
print STDERR "Parsing conjunction, expecting $other\n"if ($debug); if ($conditional =~ /^(AND|OR)\s*(.*)/i) {
$conjunction = $1;
$conditional = $2;
$need_data = 1;
die "$0 : syntax error in line $lineno : $_
Illegal use of $1. Valid uses are ".$not."<phase> $1 data ".$not."ATN $1 data " if ($other eq '');
die "$0 : syntax error in line $lineno : $_
Illegal use of $conjunction. Valid syntaxes are
NOT <phase>|ATN OR data
<phase>|ATN AND data " if ($conjunction !~ /\s*$other\s*/i);
print STDERR "$0 : parsed $1\n"if ($debug);
}
if ($need_data) {
print STDERR "looking for data in $conditional\n"if ($debug); if ($conditional=~ /^($value)\s*(.*)/i) {
$code[$address] |= 0x00_04_00_00;
$conditional = $2;
&parse_value($1, 0, 0, 1);
print STDERR "$0 : parsed data\n"if ($debug);
} else {
die "$0 : syntax error in line $lineno : $_
expected <data>. ";
}
}
if ($conditional =~ /^\s*,\s*(.*)/) {
$conditional = $1; if ($conditional =~ /^AND\s\s*MASK\s\s*($value)\s*(.*)/i) {
&parse_value ($1, 0, 1, 1);
print STDERR "$0 parsed AND MASK $1\n"if ($debug);
die "$0 : syntax error in line $lineno : $_
expected end of line, not \"$2\" " if ($2 ne '');
} else {
die "$0 : syntax error in line $lineno : $_
expected \",AND MASK \", not \"$2\" ";
}
} elsif ($conditional !~ /^\s*$/) {
die "$0 : syntax error in line $lineno : $_
expected end of line" . (($need_data) ? " or \"AND MASK \"" : "") . "
not \"$conditional\" ";
}
}
# Parse command line
$output = shift;
$outputu = shift;
# Main loop while (<STDIN>) {
$lineno = $lineno + 1;
$list[$address] = $list[$address].$_;
s/;.*$//; # Strip comments
chop; # Leave new line out of error messages
# Handle symbol definitions of the form label: if (/^\s*($identifier)\s*:(.*)/) { if (!defined($symbol_values{$1})) {
$symbol_values{$1} = $address * 4; # Address is an index into delete $forward{$1}; # an array of longs
push (@label, $1);
$_ = $2;
} else {
die "$0 : redefinition of symbol $1 in line $lineno : $_\n";
}
}
# Handle symbol definitions of the form ABSOLUTE or RELATIVE identifier = # value if (/^\s*(ABSOLUTE|RELATIVE)\s+(.*)/i) {
$is_absolute = $1;
$rest = $2; foreach $rest (split (/\s*,\s*/, $rest)) { if ($rest =~ /^($identifier)\s*=\s*($constant)\s*$/) {
local ($id, $cnst) = ($1, $2); if ($symbol_values{$id} eq undef) {
$symbol_values{$id} = eval $cnst; delete $forward{$id}; if ($is_absolute =~ /ABSOLUTE/i) {
push (@absolute , $id);
} else {
push (@relative, $id);
}
} else {
die "$0 : redefinition of symbol $id in line $lineno : $_\n";
}
} else {
die "$0 : syntax error in line $lineno : $_
expected <identifier> = <value> ";
}
}
} elsif (/^\s*EXTERNAL\s+(.*)/i) {
$externals = $1; foreach $external (split (/,/,$externals)) { if ($external =~ /\s*($identifier)\s*$/) {
$external = $1;
push (@external, $external); delete $forward{$external}; if (defined($symbol_values{$external})) {
die "$0 : redefinition of symbol $1 in line $lineno : $_\n";
}
$symbol_values{$external} = $external;
print STDERR "defined external $1 to $external\n"if ($debug_external);
} else {
die "$0 : syntax error in line $lineno : $_
expected <identifier>, got $external ";
}
} # Process ENTRY identifier declarations
} elsif (/^\s*ENTRY\s+(.*)/i) { if ($1 =~ /^($identifier)\s*$/) {
push (@entry, $1);
} else {
die "$0 : syntax error in line $lineno : $_
expected ENTRY <identifier> ";
} # Process MOVE length, address, WITH|WHEN phase instruction
} elsif (/^\s*MOVE\s+(.*)/i) {
$rest = $1; if ($rest =~ /^FROM\s+($value)\s*,\s*(WITH|WHEN)\s+($phase)\s*$/i) {
$transfer_addr = $1;
$with_when = $2;
$scsi_phase = $3;
print STDERR "Parsing MOVE FROM $transfer_addr, $with_when $3\n"if ($debug);
$code[$address] = 0x18_00_00_00 | (($with_when =~ /WITH/i) ?
0x00_00_00_00 : 0x08_00_00_00) | $scsi_phases{$scsi_phase};
&parse_value ($transfer_addr, 1, 0, 4);
$address += 2;
} elsif ($rest =~ /^($value)\s*,\s*(PTR\s+|)($value)\s*,\s*(WITH|WHEN)\s+($phase)\s*$/i) {
$transfer_len = $1;
$ptr = $2;
$transfer_addr = $3;
$with_when = $4;
$scsi_phase = $5;
$code[$address] = (($with_when =~ /WITH/i) ? 0x00_00_00_00 :
0x08_00_00_00) | (($ptr =~ /PTR/i) ? (1 << 29) : 0) |
$scsi_phases{$scsi_phase};
&parse_value ($transfer_len, 0, 0, 3);
&parse_value ($transfer_addr, 1, 0, 4);
$address += 2;
} elsif ($rest =~ /^MEMORY\s+(.*)/i) {
$rest = $1;
$code[$address] = 0xc0_00_00_00; if ($rest =~ /^($value)\s*,\s*($value)\s*,\s*($value)\s*$/) {
$count = $1;
$source = $2;
$dest = $3;
print STDERR "Parsing MOVE MEMORY $count, $source, $dest\n"if ($debug);
&parse_value ($count, 0, 0, 3);
&parse_value ($source, 1, 0, 4);
&parse_value ($dest, 2, 0, 4);
printf STDERR "Move memory instruction = %08x,%08x,%08x\n",
$code[$address], $code[$address+1], $code[$address +2] if
($debug);
$address += 3;
if (!$force && $src =~
/^($register)\s+(-|$operator)\s+($value)\s*$/i) {
print STDERR "register operand data8 source\n"if ($debug);
$src_reg = "\U$1\E";
$op = "\U$2\E"; if ($op ne '-') {
$data8 = $3;
} else {
die "- is not implemented yet.\n"
}
} elsif ($src =~ /^($register)\s*$/i) {
print STDERR "register source\n"if ($debug);
$src_reg = "\U$1\E"; # Encode register to register move as a register | 0 # move to register. if (!$force) {
$op = '|';
}
$data8 = 0;
} elsif (!$force && $src =~ /^($value)\s*$/i) {
print STDERR "data8 source\n"if ($debug);
$src_reg = undef;
$op = 'NONE';
$data8 = $1;
} else { if (!$force) {
die "$0 : syntax error in line $lineno : $_
expected <register>
<data8>
<register> <operand> <data8> ";
} else {
die "$0 : syntax error in line $lineno : $_
expected <register> ";
}
} if ($rest =~ /^($register)\s*(.*)$/i) {
$dst_reg = "\U$1\E";
$rest = $2;
} else {
die "$0 : syntax error in $lineno : $_
expected <register>, got $rest ";
}
if ($rest =~ /^WITH\s+CARRY\s*(.*)/i) {
$rest = $1; if ($op eq '+') {
$code[$address] |= 0x01_00_00_00;
} else {
die "$0 : syntax error in $lineno : $_
WITH CARRY option is incompatible with the $op operator. ";
}
}
if ($rest !~ /^\s*$/) {
die "$0 : syntax error in $lineno : $_
Expected end of line, got $rest ";
}
print STDERR "source = $src_reg, data = $data8 , destination = $dst_reg\n" if ($debug); # Note that Move data8 to reg is encoded as a read-modify-write # instruction. if (($src_reg eq undef) || ($src_reg eq $dst_reg)) {
$code[$address] |= 0x38_00_00_00 |
($registers{$dst_reg} << 16);
} elsif ($dst_reg =~ /SFBR/i) {
$code[$address] |= 0x30_00_00_00 |
($registers{$src_reg} << 16);
} elsif ($src_reg =~ /SFBR/i) {
$code[$address] |= 0x28_00_00_00 |
($registers{$dst_reg} << 16);
} else {
die "$0 : Illegal combination of registers in line $lineno : $_
Either source and destination registers must be the same,
or either source or destination register must be SFBR. ";
}
$code[$address] |= $operators{$op};
&parse_value ($data8, 0, 1, 1);
$code[$address] |= $operators{$op};
$code[$address + 1] = 0x00_00_00_00;# Reserved
$address += 2;
} else {
die "$0 : syntax error in line $lineno : $_
expected (initiator) <length>, <address>, WHEN <phase>
(target) <length>, <address>, WITH <phase>
MEMORY <length>, <source>, <destination>
<expression> TO <register> ";
} # Process SELECT {ATN|} id, fail_address
} elsif (/^\s*(SELECT|RESELECT)\s+(.*)/i) {
$rest = $2; if ($rest =~ /^(ATN|)\s*($value)\s*,\s*($identifier)\s*$/i) {
$atn = $1;
$id = $2;
$alt_addr = $3;
$code[$address] = 0x40_00_00_00 |
(($atn =~ /ATN/i) ? 0x01_00_00_00 : 0);
$code[$address + 1] = 0x00_00_00_00;
&parse_value($id, 0, 2, 1);
&parse_value($alt_addr, 1, 0, 4);
$address += 2;
} elsif ($rest =~ /^(ATN|)\s*FROM\s+($value)\s*,\s*($identifier)\s*$/i) {
$atn = $1;
$addr = $2;
$alt_addr = $3;
$code[$address] = 0x42_00_00_00 |
(($atn =~ /ATN/i) ? 0x01_00_00_00 : 0);
$code[$address + 1] = 0x00_00_00_00;
&parse_value($addr, 0, 0, 3);
&parse_value($alt_addr, 1, 0, 4);
$address += 2;
} else {
die "$0 : syntax error in line $lineno : $_
expected SELECT id, alternate_address or
SELECT FROM address, alternate_address or
RESELECT id, alternate_address or
RESELECT FROM address, alternate_address ";
}
} elsif (/^\s*WAIT\s+(.*)/i) {
$rest = $1;
print STDERR "Parsing WAIT $rest\n"if ($debug); if ($rest =~ /^DISCONNECT\s*$/i) {
$code[$address] = 0x48_00_00_00;
$code[$address + 1] = 0x00_00_00_00;
$address += 2;
} elsif ($rest =~ /^(RESELECT|SELECT)\s+($identifier)\s*$/i) {
$alt_addr = $2;
$code[$address] = 0x50_00_00_00;
&parse_value ($alt_addr, 1, 0, 4);
$address += 2;
} else {
die "$0 : syntax error in line $lineno : $_
expected (initiator) WAIT DISCONNECT or
(initiator) WAIT RESELECT alternate_address or
(target) WAIT SELECT alternate_address ";
} # Handle SET and CLEAR instructions. Note that we should also do something # with this syntax to set target mode.
} elsif (/^\s*(SET|CLEAR)\s+(.*)/i) {
$set = $1;
$list = $2;
$code[$address] = ($set =~ /SET/i) ? 0x58_00_00_00 :
0x60_00_00_00; foreach $arg (split (/\s+AND\s+/i,$list)) { if ($arg =~ /ATN/i) {
$code[$address] |= 0x00_00_00_08;
} elsif ($arg =~ /ACK/i) {
$code[$address] |= 0x00_00_00_40;
} elsif ($arg =~ /TARGET/i) {
$code[$address] |= 0x00_00_02_00;
} elsif ($arg =~ /CARRY/i) {
$code[$address] |= 0x00_00_04_00;
} else {
die "$0 : syntax error in line $lineno : $_
expected $set followed by a AND delimited list of one or
more strings from the list ACK, ATN, CARRY, TARGET. ";
}
}
$code[$address + 1] = 0x00_00_00_00;
$address += 2;
} elsif (/^\s*(JUMP|CALL|INT)\s+(.*)/i) {
$instruction = $1;
$rest = $2; if ($instruction =~ /JUMP/i) {
$code[$address] = 0x80_00_00_00;
} elsif ($instruction =~ /CALL/i) {
$code[$address] = 0x88_00_00_00;
} else {
$code[$address] = 0x98_00_00_00;
}
print STDERR "parsing JUMP, rest = $rest\n"if ($debug);
foreach $label (@label) { if ($symbol_references{$label} ne undef) { for $reference (split(/\s+/,$symbol_references{$label})) {
$reference =~ /(REL|ABS),(.*),(.*)/;
$type = $1;
$address = $2;
$length = $3;
if ((($address % 4) !=0) || ($length != 4)) {
die "$0 : symbol $label has invalid reference at $1, size $2\n";
}
if ($type eq 'ABS') {
$code[$address / 4] += $symbol_values{$label};
push (@label_patches, $address / 4);
} else { # # - The address of the reference should be in the second and last word # of an instruction # - Relative jumps, etc. are relative to the DSP of the _next_ instruction # # So, we need to add four to the address of the reference, to get # the address of the next instruction, when computing the reference.
$tmp = $symbol_values{$label} -
($address + 4);
die # Relative addressing is limited to 24 bits. "$0 : symbol $label is too far ($tmp) from $address to reference as
relative/\n" if (($tmp >= 0x80_00_00) || ($tmp < -0x80_00_00));
$code[$address / 4] = $tmp & 0x00_ff_ff_ff;
}
}
}
}
# Output SCRIPT[] array, one instruction per line. Optionally # print the original code too.
open (OUTPUT, ">$output") || die "$0 : can't open $output for writing\n";
open (OUTPUTU, ">$outputu") || die "$0 : can't open $outputu for writing\n";
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.