Browse Source

Allow CALL and other non-relative branches to generate lables too

master
Gavan Fantom 13 years ago
parent
commit
20b7191ecf
  1. 61
      disassem.pl

61
disassem.pl

@ -254,10 +254,12 @@ sub decode_instruction
local $amode = undef; local $amode = undef;
local @operands = (); local @operands = ();
local $comment = ""; local $comment = "";
local $branch = 0;
if ($byte == 0x00) { if ($byte == 0x00) {
output_instruction("NOP"); output_instruction("NOP");
} elsif ($byte == 0x01) { } elsif ($byte == 0x01) {
branch();
output_instruction("INT9"); output_instruction("INT9");
} elsif ($byte == 0x02) { } elsif ($byte == 0x02) {
set_operand("A"); set_operand("A");
@ -302,6 +304,7 @@ sub decode_instruction
set_operand("A"); set_operand("A");
output_instruction("SUBDC"); output_instruction("SUBDC");
} elsif ($byte == 0x13) { } elsif ($byte == 0x13) {
branch();
set_operand('@A'); set_operand('@A');
output_instruction("JCTX"); output_instruction("JCTX");
} elsif ($byte == 0x14) { } elsif ($byte == 0x14) {
@ -431,6 +434,7 @@ sub decode_instruction
read_operand_imm16(); read_operand_imm16();
output_instruction("SUBW"); output_instruction("SUBW");
} elsif ($byte == 0x3A) { } elsif ($byte == 0x3A) {
branch();
set_operand("A"); set_operand("A");
read_operand_imm16(); read_operand_imm16();
read_operand_rel(); read_operand_rel();
@ -575,46 +579,59 @@ sub decode_instruction
read_operand_rlst(); read_operand_rlst();
output_instruction("POPW"); output_instruction("POPW");
} elsif ($byte == 0x60) { } elsif ($byte == 0x60) {
branch();
read_operand_rel(); read_operand_rel();
unconditional_branch(); unconditional_branch();
output_instruction("BRA"); output_instruction("BRA");
} elsif ($byte == 0x61) { } elsif ($byte == 0x61) {
branch();
set_operand('@A'); set_operand('@A');
unconditional_branch(); unconditional_branch();
output_instruction("JMP"); output_instruction("JMP");
} elsif ($byte == 0x62) { } elsif ($byte == 0x62) {
branch();
read_operand_addr16(); read_operand_addr16();
unconditional_branch(); unconditional_branch();
output_instruction("JMP"); output_instruction("JMP");
} elsif ($byte == 0x63) { } elsif ($byte == 0x63) {
branch();
read_operand_addr24(); read_operand_addr24();
unconditional_branch(); unconditional_branch();
output_instruction("JMPP"); output_instruction("JMPP");
} elsif ($byte == 0x64) { } elsif ($byte == 0x64) {
branch();
read_operand_addr16(); read_operand_addr16();
output_instruction("CALL"); output_instruction("CALL");
} elsif ($byte == 0x65) { } elsif ($byte == 0x65) {
branch();
read_operand_addr24(); read_operand_addr24();
output_instruction("CALL"); output_instruction("CALL");
} elsif ($byte == 0x66) { } elsif ($byte == 0x66) {
branch();
unconditional_branch(); unconditional_branch();
output_instruction("RETP"); output_instruction("RETP");
} elsif ($byte == 0x67) { } elsif ($byte == 0x67) {
branch();
unconditional_branch(); unconditional_branch();
output_instruction("RET"); output_instruction("RET");
} elsif ($byte == 0x68) { } elsif ($byte == 0x68) {
branch();
read_operand_vct8(); read_operand_vct8();
output_instruction("INT"); output_instruction("INT");
} elsif ($byte == 0x68) { } elsif ($byte == 0x68) {
branch();
read_operand_vct8(); read_operand_vct8();
output_instruction("INT"); output_instruction("INT");
} elsif ($byte == 0x69) { } elsif ($byte == 0x69) {
branch();
read_operand_addr16(); read_operand_addr16();
output_instruction("INT"); output_instruction("INT");
} elsif ($byte == 0x6A) { } elsif ($byte == 0x6A) {
branch();
read_operand_addr24(); read_operand_addr24();
output_instruction("INTP"); output_instruction("INTP");
} elsif ($byte == 0x6B) { } elsif ($byte == 0x6B) {
branch();
unconditional_branch(); unconditional_branch();
output_instruction("RETI"); output_instruction("RETI");
} elsif ($byte == 0x6C) { } elsif ($byte == 0x6C) {
@ -700,54 +717,71 @@ sub decode_instruction
set_operand_imm4($byte & 0xf); set_operand_imm4($byte & 0xf);
output_instruction("MOVN"); output_instruction("MOVN");
} elsif (($byte & 0xf0) == 0xE0) { } elsif (($byte & 0xf0) == 0xE0) {
branch();
set_operand_imm4($byte & 0xf); set_operand_imm4($byte & 0xf);
output_instruction("CALLV"); output_instruction("CALLV");
} elsif ($byte == 0xF0) { } elsif ($byte == 0xF0) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BZ"); output_instruction("BZ");
} elsif ($byte == 0xF1) { } elsif ($byte == 0xF1) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BNZ"); output_instruction("BNZ");
} elsif ($byte == 0xF2) { } elsif ($byte == 0xF2) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BC"); output_instruction("BC");
} elsif ($byte == 0xF3) { } elsif ($byte == 0xF3) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BNC"); output_instruction("BNC");
} elsif ($byte == 0xF4) { } elsif ($byte == 0xF4) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BN"); output_instruction("BN");
} elsif ($byte == 0xF5) { } elsif ($byte == 0xF5) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BP"); output_instruction("BP");
} elsif ($byte == 0xF6) { } elsif ($byte == 0xF6) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BV"); output_instruction("BV");
} elsif ($byte == 0xF7) { } elsif ($byte == 0xF7) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BNV"); output_instruction("BNV");
} elsif ($byte == 0xF8) { } elsif ($byte == 0xF8) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BT"); output_instruction("BT");
} elsif ($byte == 0xF9) { } elsif ($byte == 0xF9) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BNT"); output_instruction("BNT");
} elsif ($byte == 0xFA) { } elsif ($byte == 0xFA) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BLT"); output_instruction("BLT");
} elsif ($byte == 0xFB) { } elsif ($byte == 0xFB) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BGE"); output_instruction("BGE");
} elsif ($byte == 0xFC) { } elsif ($byte == 0xFC) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BLE"); output_instruction("BLE");
} elsif ($byte == 0xFD) { } elsif ($byte == 0xFD) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BGT"); output_instruction("BGT");
} elsif ($byte == 0xFE) { } elsif ($byte == 0xFE) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BLS"); output_instruction("BLS");
} elsif ($byte == 0xFF) { } elsif ($byte == 0xFF) {
branch();
read_operand_rel(); read_operand_rel();
output_instruction("BHI"); output_instruction("BHI");
} else { } else {
@ -801,26 +835,32 @@ sub decode_bit_manipulation
read_operand_addr16_bp($byte & 0x7); read_operand_addr16_bp($byte & 0x7);
output_instruction("SETB"); output_instruction("SETB");
} elsif (($byte & 0xf8) == 0x80) { } elsif (($byte & 0xf8) == 0x80) {
branch();
read_operand_io_bp($byte & 0x7); read_operand_io_bp($byte & 0x7);
read_operand_rel(); read_operand_rel();
output_instruction("BBC"); output_instruction("BBC");
} elsif (($byte & 0xf8) == 0x88) { } elsif (($byte & 0xf8) == 0x88) {
branch();
read_operand_dir_bp($byte & 0x7); read_operand_dir_bp($byte & 0x7);
read_operand_rel(); read_operand_rel();
output_instruction("BBC"); output_instruction("BBC");
} elsif (($byte & 0xf8) == 0x98) { } elsif (($byte & 0xf8) == 0x98) {
branch();
read_operand_addr16_bp($byte & 0x7); read_operand_addr16_bp($byte & 0x7);
read_operand_rel(); read_operand_rel();
output_instruction("BBC"); output_instruction("BBC");
} elsif (($byte & 0xf8) == 0xA0) { } elsif (($byte & 0xf8) == 0xA0) {
branch();
read_operand_io_bp($byte & 0x7); read_operand_io_bp($byte & 0x7);
read_operand_rel(); read_operand_rel();
output_instruction("BBS"); output_instruction("BBS");
} elsif (($byte & 0xf8) == 0xA8) { } elsif (($byte & 0xf8) == 0xA8) {
branch();
read_operand_dir_bp($byte & 0x7); read_operand_dir_bp($byte & 0x7);
read_operand_rel(); read_operand_rel();
output_instruction("BBS"); output_instruction("BBS");
} elsif (($byte & 0xf8) == 0xB8) { } elsif (($byte & 0xf8) == 0xB8) {
branch();
read_operand_addr16_bp($byte & 0x7); read_operand_addr16_bp($byte & 0x7);
read_operand_rel(); read_operand_rel();
output_instruction("BBS"); output_instruction("BBS");
@ -1012,6 +1052,7 @@ sub decode_ea_70
output_instruction("SUBL"); output_instruction("SUBL");
} elsif ($op == 0x40) { } elsif ($op == 0x40) {
set_operand_ea("RW", $byte); set_operand_ea("RW", $byte);
branch();
read_operand_imm16(); read_operand_imm16();
read_operand_rel(); read_operand_rel();
output_instruction("CWBNE"); output_instruction("CWBNE");
@ -1033,6 +1074,7 @@ sub decode_ea_70
output_instruction("XORL"); output_instruction("XORL");
} elsif ($op == 0xE0) { } elsif ($op == 0xE0) {
set_operand_ea("R", $byte); set_operand_ea("R", $byte);
branch();
read_operand_imm8(); read_operand_imm8();
read_operand_rel(); read_operand_rel();
output_instruction("CBNE"); output_instruction("CBNE");
@ -1046,10 +1088,12 @@ sub decode_ea_71
my $byte = getbyte(); my $byte = getbyte();
my $op = $byte & 0xe0; my $op = $byte & 0xe0;
if ($op == 0x00) { if ($op == 0x00) {
branch();
set_operand_ea('@RL', $byte); set_operand_ea('@RL', $byte);
unconditional_branch(); unconditional_branch();
output_instruction("JMPP"); output_instruction("JMPP");
} elsif ($op == 0x20) { } elsif ($op == 0x20) {
branch();
set_operand_ea('@RL', $byte); set_operand_ea('@RL', $byte);
output_instruction("CALLP"); output_instruction("CALLP");
} elsif ($op == 0x40) { } elsif ($op == 0x40) {
@ -1121,10 +1165,12 @@ sub decode_ea_73
my $byte = getbyte(); my $byte = getbyte();
my $op = $byte & 0xe0; my $op = $byte & 0xe0;
if ($op == 0x00) { if ($op == 0x00) {
branch();
set_operand_ea('@RW', $byte); set_operand_ea('@RW', $byte);
unconditional_branch(); unconditional_branch();
output_instruction("JMP"); output_instruction("JMP");
} elsif ($op == 0x20) { } elsif ($op == 0x20) {
branch();
set_operand_ea('@RW', $byte); set_operand_ea('@RW', $byte);
output_instruction("CALL"); output_instruction("CALL");
} elsif ($op == 0x40) { } elsif ($op == 0x40) {
@ -1188,6 +1234,7 @@ sub decode_ea_74
output_instruction("XOR"); output_instruction("XOR");
} elsif ($op == 0xE0) { } elsif ($op == 0xE0) {
set_operand_ea("R", $byte); set_operand_ea("R", $byte);
branch();
read_operand_rel(); read_operand_rel();
output_instruction("DBNZ"); output_instruction("DBNZ");
} else { } else {
@ -1268,6 +1315,7 @@ sub decode_ea_76
output_instruction("XORW"); output_instruction("XORW");
} elsif ($op == 0xE0) { } elsif ($op == 0xE0) {
set_operand_ea("RW", $byte); set_operand_ea("RW", $byte);
branch();
read_operand_rel(); read_operand_rel();
output_instruction("DWBNZ"); output_instruction("DWBNZ");
} else { } else {
@ -1475,7 +1523,13 @@ sub read_operand_addr16
my $byte2 = getbyte(); my $byte2 = getbyte();
my $addr = $byte1; my $addr = $byte1;
$addr += $byte2 << 8; $addr += $byte2 << 8;
set_operand(sprintf("%sD:0x%.4x", $at, $addr)); if ($branch) {
$addr = ($addr & 0xffff) | ($address & ~0xffff);
set_operand(sprintf("%s%s", $at, get_label($addr)));
add_comment(sprintf("0x%.6x", $addr));
} else {
set_operand(sprintf("%sD:0x%.4x", $at, $addr));
}
} }
sub read_operand_addr16_bp sub read_operand_addr16_bp
@ -1662,6 +1716,11 @@ sub set_operand_ea
} }
} }
sub branch
{
$branch = 1;
}
sub unconditional_branch sub unconditional_branch
{ {
# $finish_disassembly = 1; # $finish_disassembly = 1;

Loading…
Cancel
Save