1#!/usr/bin/perl -w 2 3# Copyright 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. 4# 5# This file is part of the GNU MP Library. 6# 7# The GNU MP Library is free software; you can redistribute it and/or modify 8# it under the terms of the GNU Lesser General Public License as published 9# by the Free Software Foundation; either version 3 of the License, or (at 10# your option) any later version. 11# 12# The GNU MP Library is distributed in the hope that it will be useful, but 13# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15# License for more details. 16# 17# You should have received a copy of the GNU Lesser General Public License 18# along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. 19 20 21# Usage: slot.pl [filename.o]... 22# 23# Run "objdump" to produce a disassembly of the given object file(s) and 24# annotate the output with "U" or "L" slotting which Alpha EV6 will use. 25# 26# When an instruction is E (ie. either U or L), an "eU" or "eL" is shown, as 27# a reminder that it wasn't a fixed requirement that gave the U or L, but 28# the octaword slotting rules. 29# 30# If an instruction is not recognised, that octaword does not get any U/L 31# shown, only lower-case "u", "l" or "e" for the instructions which are 32# known. Add any unknown instructions to %optable below. 33 34 35use strict; 36 37# The U or L which various instructions demand, or E if either. 38# 39my %optable = 40 ( 41 'addq' => 'E', 42 'and' => 'E', 43 'beq' => 'U', 44 'bge' => 'U', 45 'bgt' => 'U', 46 'blt' => 'U', 47 'bne' => 'U', 48 'br' => 'L', 49 'clr' => 'E', 50 'cmpule' => 'E', 51 'cmpult' => 'E', 52 'cmpeq' => 'E', 53 'cmoveq' => 'E', 54 'cmovne' => 'E', 55 'ctpop' => 'U', 56 'ctlz' => 'U', 57 'cttz' => 'U', 58 'extbl' => 'U', 59 'extlh' => 'U', 60 'extll' => 'U', 61 'extqh' => 'U', 62 'extql' => 'U', 63 'extwh' => 'U', 64 'extwl' => 'U', 65 'jsr' => 'L', 66 'lda' => 'E', 67 'ldah' => 'E', 68 'ldbu' => 'L', 69 'ldl' => 'L', 70 'ldq' => 'L', 71 'ldt' => 'L', 72 'ret' => 'L', 73 'mov' => 'E', 74 'mulq' => 'U', 75 'negq' => 'E', 76 'nop' => 'E', 77 'not' => 'E', 78 's8addq' => 'E', 79 's8subq' => 'E', 80 # 'sextb' => ? 81 # 'sextl' => ? 82 'sll' => 'U', 83 'srl' => 'U', 84 'stq' => 'L', 85 'subq' => 'E', 86 'umulh' => 'U', 87 'unop' => 'E', 88 'xor' => 'E', 89 ); 90 91# Slottings used for a given pattern of U/L/E in an octaword. This is as 92# per the "Ebox Slotting" section of the EV6 hardware reference manual. 93# 94my %slottable = 95 ( 96 'EEEE' => 'ULUL', 97 'EEEL' => 'ULUL', 98 'EEEU' => 'ULLU', 99 'EELE' => 'ULLU', 100 'EELL' => 'UULL', 101 'EELU' => 'ULLU', 102 'EEUE' => 'ULUL', 103 'EEUL' => 'ULUL', 104 'EEUU' => 'LLUU', 105 'ELEE' => 'ULUL', 106 'ELEL' => 'ULUL', 107 'ELEU' => 'ULLU', 108 'ELLE' => 'ULLU', 109 'ELLL' => 'ULLL', 110 'ELLU' => 'ULLU', 111 'ELUE' => 'ULUL', 112 'ELUL' => 'ULUL', 113 114 'LLLL' => 'LLLL', 115 'LLLU' => 'LLLU', 116 'LLUE' => 'LLUU', 117 'LLUL' => 'LLUL', 118 'LLUU' => 'LLUU', 119 'LUEE' => 'LULU', 120 'LUEL' => 'LUUL', 121 'LUEU' => 'LULU', 122 'LULE' => 'LULU', 123 'LULL' => 'LULL', 124 'LULU' => 'LULU', 125 'LUUE' => 'LUUL', 126 'LUUL' => 'LUUL', 127 'LUUU' => 'LUUU', 128 'UEEE' => 'ULUL', 129 'UEEL' => 'ULUL', 130 'UEEU' => 'ULLU', 131 132 'ELUU' => 'LLUU', 133 'EUEE' => 'LULU', 134 'EUEL' => 'LUUL', 135 'EUEU' => 'LULU', 136 'EULE' => 'LULU', 137 'EULL' => 'UULL', 138 'EULU' => 'LULU', 139 'EUUE' => 'LUUL', 140 'EUUL' => 'LUUL', 141 'EUUU' => 'LUUU', 142 'LEEE' => 'LULU', 143 'LEEL' => 'LUUL', 144 'LEEU' => 'LULU', 145 'LELE' => 'LULU', 146 'LELL' => 'LULL', 147 'LELU' => 'LULU', 148 'LEUE' => 'LUUL', 149 'LEUL' => 'LUUL', 150 'LEUU' => 'LLUU', 151 'LLEE' => 'LLUU', 152 'LLEL' => 'LLUL', 153 'LLEU' => 'LLUU', 154 'LLLE' => 'LLLU', 155 156 'UELE' => 'ULLU', 157 'UELL' => 'UULL', 158 'UELU' => 'ULLU', 159 'UEUE' => 'ULUL', 160 'UEUL' => 'ULUL', 161 'UEUU' => 'ULUU', 162 'ULEE' => 'ULUL', 163 'ULEL' => 'ULUL', 164 'ULEU' => 'ULLU', 165 'ULLE' => 'ULLU', 166 'ULLL' => 'ULLL', 167 'ULLU' => 'ULLU', 168 'ULUE' => 'ULUL', 169 'ULUL' => 'ULUL', 170 'ULUU' => 'ULUU', 171 'UUEE' => 'UULL', 172 'UUEL' => 'UULL', 173 'UUEU' => 'UULU', 174 'UULE' => 'UULL', 175 'UULL' => 'UULL', 176 'UULU' => 'UULU', 177 'UUUE' => 'UUUL', 178 'UUUL' => 'UUUL', 179 'UUUU' => 'UUUU', 180 ); 181 182# Check all combinations of U/L/E are present in %slottable. 183sub coverage { 184 foreach my $a ('U', 'L', 'E') { 185 foreach my $b ('U', 'L', 'E') { 186 foreach my $c ('U', 'L', 'E') { 187 foreach my $d ('U', 'L', 'E') { 188 my $x = $a . $b . $c . $d; 189 if (! defined $slottable{$x}) { 190 print "slottable missing: $x\n" 191 } 192 } 193 } 194 } 195 } 196} 197 198# Certain consistency checks for %slottable. 199sub check { 200 foreach my $x (keys %slottable) { 201 my $a = substr($x,0,1); 202 my $b = substr($x,1,1); 203 my $c = substr($x,2,1); 204 my $d = substr($x,3,1); 205 my $es = ($a eq 'E') + ($b eq 'E') + ($c eq 'E') + ($d eq 'E'); 206 my $ls = ($a eq 'L') + ($b eq 'L') + ($c eq 'L') + ($d eq 'L'); 207 my $us = ($a eq 'U') + ($b eq 'U') + ($c eq 'U') + ($d eq 'U'); 208 209 my $got = $slottable{$x}; 210 my $want = $x; 211 212 if ($es == 0) { 213 214 } elsif ($es == 1) { 215 # when only one E, it's mapped to whichever of U or L is otherwise 216 # used the least 217 if ($ls > $us) { 218 $want =~ s/E/U/; 219 } else { 220 $want =~ s/E/L/; 221 } 222 } elsif ($es == 2) { 223 # when two E's and two U, then the E's map to L; vice versa for two E 224 # and two L 225 if ($ls == 2) { 226 $want =~ s/E/U/g; 227 } elsif ($us == 2) { 228 $want =~ s/E/L/g; 229 } else { 230 next; 231 } 232 } elsif ($es == 3) { 233 next; 234 235 } else { # $es == 4 236 next; 237 } 238 239 if ($want ne $got) { 240 print "slottable $x want $want got $got\n"; 241 } 242 } 243} 244 245sub disassemble { 246 my ($file) = @_; 247 248 open (IN, "objdump -Srfh $file |") || die "Cannot open pipe from objdump\n"; 249 250 my (%pre, %post, %type); 251 while (<IN>) { 252 my $line = $_ . ""; 253 254 if ($line =~ /(^[ \t]*[0-9a-f]*([0-9a-f]):[ \t]*[0-9a-f][0-9a-f] [0-9a-f][0-9a-f] [0-9a-f][0-9a-f] [0-9a-f][0-9a-f] )\t(([a-z0-9]+).*)/) { 255 my ($this_pre, $addr, $this_post, $opcode) = ($1, $2, $3, $4); 256 257 my $this_type = $optable{$opcode}; 258 if (! defined ($this_type)) { $this_type = ' '; } 259 260 $pre{$addr} = $this_pre; 261 $post{$addr} = $this_post; 262 $type{$addr} = $this_type; 263 264 if ($addr eq 'c') { 265 my %slot = ('0'=>' ', '4'=>' ', '8'=>' ', 'c'=>' '); 266 267 my $str = $type{'c'} . $type{'8'} . $type{'4'} . $type{'0'}; 268 $str = $slottable{$str}; 269 if (defined $str) { 270 $slot{'c'} = substr($str,0,1); 271 $slot{'8'} = substr($str,1,1); 272 $slot{'4'} = substr($str,2,1); 273 $slot{'0'} = substr($str,3,1); 274 } 275 276 foreach my $i ('0', '4', '8', 'c') { 277 if ($slot{$i} eq $type{$i}) { $type{$i} = ' '; } 278 print $pre{$i}, ' ', lc($type{$i}),$slot{$i}, ' ', $post{$i}, "\n"; 279 } 280 281 %pre = (); 282 %type = (); 283 %post = (); 284 } 285 } 286 } 287 288 close IN || die "Error from objdump (or objdump not available)\n"; 289} 290 291coverage(); 292check(); 293 294my @files; 295if ($#ARGV >= 0) { 296 @files = @ARGV; 297} else { 298 die 299} 300 301foreach (@files) { 302 disassemble($_); 303} 304