Debian Codegraph @

test/jmpxx.pl

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use integer;
5
6 my $bw = 1;
7 my @errs = ();
8 foreach my $errf (@ARGV) {
9 if (open(my $e, '<', $errf)) {
10 while (defined(my $l = <$e>)) {
11 if ($l =~ /^.*?\:([0-9]+)\:/) {
12 $errs[$1] |= $bw;
13 }
14 }
15 close($e);
16 }
17 $bw <<= 1;
18 }
19
20 my $ln = 0;
21
22 $ln++; print "%pragma list options -befms\n";
23 $ln++; print "%ifndef ERR\n";
24 $ln++; print " %define ERR 0\n";
25 $ln++; print "%endif\n";
26
27 my @nots = ('');
28
29 for (my $cc = 1; $cc < 7; $cc++) {
30 my $ss = 'no';
31 $ss .= 'w' if ($cc & 1);
32 $ss .= 'd' if ($cc & 2);
33 $ss .= 'q' if ($cc & 4);
34 $ln++; print "%macro $ss 1+.nolist\n";
35 $ln++; printf " %%if ERR || !(__BITS__ & 0x%02x)\n", $cc << 4;
36 $ln++; print "\t%1\n";
37 $ln++; print " %endif\n";
38 $ln++; print "%endmacro\n";
39 push(@nots, "$ss");
40 }
41 $ln++; print "%macro bogus 1+.nolist\n";
42 $ln++; printf " %%if ERR\n";
43 $ln++; print "\t%1\n";
44 $ln++; print " %endif\n";
45 $ln++; print "%endmacro\n";
46 push(@nots, 'bogus');
47
48 $ln++; print "\n";
49
50 $ln++; print "\tsection text1\n";
51 $ln++; print "top:\n";
52 $ln++; print "\ttimes 128 nop\n";
53 $ln++; print "\n";
54
55 foreach my $insn ('jmp', 'call', 'jz', 'jcxz', 'jecxz', 'jrcxz',
56 'loop', 'loope', 'loopne') {
57 $ln++; print "here_$insn:\n";
58
59 foreach my $tgt ('$', 'top', 'there') {
60 foreach my $str ('', 'strict') {
61 foreach my $sz ('', 'byte', 'word', 'dword', 'qword') {
62 foreach my $o ('', 'o16', 'o32', 'o64') {
63 foreach my $sn ('', 'short', 'near') {
64 my $is_short =
65 ($sn eq 'short' || $insn =~ /^(j\w?cxz|loop\w*)$/);
66
67 $ln++;
68 $errs[$ln] |= 3 if ($sz eq 'qword' || $o eq 'o64'
69 || $insn eq 'jrcxz');
70 $errs[$ln] |= 4 if ($sz =~ /^d?word$'/ || $o =~ /^o(16|32)$/ ||
71 $insn eq 'jcxz');
72 if (($sz eq 'word' && $o =~ /^o(32|64)$/) ||
73 ($sz eq 'dword' && $o =~ /^o(16|64)$/) ||
74 ($sz eq 'qword' && $o =~ /^o(16|32)$/) ||
75 ($sz eq 'byte') ||
76 ($is_short &&
77 ($sn eq 'near' || $tgt ne '$' || $insn eq 'call'))) {
78 $errs[$ln] |= 7;
79 }
80
81 my $is_short =
82
83 printf " %-5s %s\n",
84 $nots[$errs[$ln]],
85 join(' ', grep { $_ ne '' }
86 ($o,$insn,$str,$sz,$sn,$tgt));
87 }
88 }
89 }
90 }
91 }
92 }
93
94 $ln++; print "\n";
95 $ln++; print "\tsection text2\n";
96 $ln++; print "there:\n";
97 $ln++; print "\tret\n";