Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
81 lines (75 sloc) 2.15 KB
use strict;
use warnings;
use List::Util qw(max);
my %arith = ( # imm, r imm, r/m r, r/m r/m, r
add => [ undef, [0x81, 0], 0x01, 0x03 ],
and => [ undef, [0x81, 4], 0x21, 0x23 ],
cmp => [ undef, [0x81, 7], 0x39, 0x3B ],
lea => [ undef, undef, undef, 0x8D ],
mov => [ 0xB8, [0xC7, 0], 0x89, 0x8B ],
or => [ undef, [0x81, 1], 0x09, 0x0B ],
sub => [ undef, [0x81, 5], 0x29, 0x2B ],
test => [ undef, [0xF7, 0], 0x85, undef ],
xor => [ undef, [0x81, 6], 0x31, 0x33 ]
);
my %shifts = ( # CL imm8
shl => [[0xD3, 4], [0xC1, 4]],
shr => [[0xD3, 5], [0xC1, 5]],
sar => [[0xD3, 7], [0xC1, 7]],
);
sub h($) {sprintf "0x%02x", shift}
print <<END_WARNING;
/***********************************************************************
* This file is AUTOMATICALLY GENERATED. Do not edit
* This file is produced by the script `insts.pl'
***********************************************************************/
END_WARNING
sub line {
printf ' typedef %-17s %s;'."\n", $_[0], $_[1];
}
sub no_opcode {
line('no_opcode', $_[0]);
}
sub has_opcode {
line((sprintf 'has_opcode<0x%x>', $_[0]), $_[1]);
}
sub one {
my $name = shift;
my $opc = shift;
if ($opc) {
has_opcode($opc, "op_$name");
} else {
no_opcode("op_$name");
}
}
sub pair {
my $name = shift;
my $opc = shift;
if ($opc) {
has_opcode($opc->[0], "op_$name");
has_opcode($opc->[1], "subop_$name");
} else {
no_opcode("op_$name");
no_opcode("subop_$name");
}
}
sub begin {
print "struct X86" . ucfirst(shift) . " {\n";
}
sub end {
print "};\n\n";
}
while (my ($mnm, $opc) = each %arith) {
begin($mnm);
one("imm_r", shift @$opc);
pair("imm_rm", shift @$opc);
one("r_rm", shift @$opc);
one("rm_r", shift @$opc);
end();
}
while (my ($mnm, $opc) = each %shifts) {
begin(uc $mnm);
pair("cl", shift @$opc);
pair("imm", shift @$opc);
end();
}