diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/perlasm/alpha.pl | 434 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/cbc.pl | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86asm.pl | 11 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86ms.pl | 12 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86nasm.pl | 342 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86unix.pl | 42 |
6 files changed, 828 insertions, 15 deletions
diff --git a/src/lib/libcrypto/perlasm/alpha.pl b/src/lib/libcrypto/perlasm/alpha.pl new file mode 100644 index 0000000000..3dac571743 --- /dev/null +++ b/src/lib/libcrypto/perlasm/alpha.pl | |||
| @@ -0,0 +1,434 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | package alpha; | ||
| 4 | use Carp qw(croak cluck); | ||
| 5 | |||
| 6 | $label="100"; | ||
| 7 | |||
| 8 | $n_debug=0; | ||
| 9 | $smear_regs=1; | ||
| 10 | $reg_alloc=1; | ||
| 11 | |||
| 12 | $align="3"; | ||
| 13 | $com_start="#"; | ||
| 14 | |||
| 15 | sub main'asm_init_output { @out=(); } | ||
| 16 | sub main'asm_get_output { return(@out); } | ||
| 17 | sub main'get_labels { return(@labels); } | ||
| 18 | sub main'external_label { push(@labels,@_); } | ||
| 19 | |||
| 20 | # General registers | ||
| 21 | |||
| 22 | %regs=( 'r0', '$0', | ||
| 23 | 'r1', '$1', | ||
| 24 | 'r2', '$2', | ||
| 25 | 'r3', '$3', | ||
| 26 | 'r4', '$4', | ||
| 27 | 'r5', '$5', | ||
| 28 | 'r6', '$6', | ||
| 29 | 'r7', '$7', | ||
| 30 | 'r8', '$8', | ||
| 31 | 'r9', '$22', | ||
| 32 | 'r10', '$23', | ||
| 33 | 'r11', '$24', | ||
| 34 | 'r12', '$25', | ||
| 35 | 'r13', '$27', | ||
| 36 | 'r14', '$28', | ||
| 37 | 'r15', '$21', # argc == 5 | ||
| 38 | 'r16', '$20', # argc == 4 | ||
| 39 | 'r17', '$19', # argc == 3 | ||
| 40 | 'r18', '$18', # argc == 2 | ||
| 41 | 'r19', '$17', # argc == 1 | ||
| 42 | 'r20', '$16', # argc == 0 | ||
| 43 | 'r21', '$9', # save 0 | ||
| 44 | 'r22', '$10', # save 1 | ||
| 45 | 'r23', '$11', # save 2 | ||
| 46 | 'r24', '$12', # save 3 | ||
| 47 | 'r25', '$13', # save 4 | ||
| 48 | 'r26', '$14', # save 5 | ||
| 49 | |||
| 50 | 'a0', '$16', | ||
| 51 | 'a1', '$17', | ||
| 52 | 'a2', '$18', | ||
| 53 | 'a3', '$19', | ||
| 54 | 'a4', '$20', | ||
| 55 | 'a5', '$21', | ||
| 56 | |||
| 57 | 's0', '$9', | ||
| 58 | 's1', '$10', | ||
| 59 | 's2', '$11', | ||
| 60 | 's3', '$12', | ||
| 61 | 's4', '$13', | ||
| 62 | 's5', '$14', | ||
| 63 | 'zero', '$31', | ||
| 64 | 'sp', '$30', | ||
| 65 | ); | ||
| 66 | |||
| 67 | $main'reg_s0="r21"; | ||
| 68 | $main'reg_s1="r22"; | ||
| 69 | $main'reg_s2="r23"; | ||
| 70 | $main'reg_s3="r24"; | ||
| 71 | $main'reg_s4="r25"; | ||
| 72 | $main'reg_s5="r26"; | ||
| 73 | |||
| 74 | @reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8', | ||
| 75 | '$22','$23','$24','$25','$20','$21','$27','$28'); | ||
| 76 | |||
| 77 | |||
| 78 | sub main'sub { &out3("subq",@_); } | ||
| 79 | sub main'add { &out3("addq",@_); } | ||
| 80 | sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); } | ||
| 81 | sub main'or { &out3("bis",@_); } | ||
| 82 | sub main'bis { &out3("bis",@_); } | ||
| 83 | sub main'br { &out1("br",@_); } | ||
| 84 | sub main'ld { &out2("ldq",@_); } | ||
| 85 | sub main'st { &out2("stq",@_); } | ||
| 86 | sub main'cmpult { &out3("cmpult",@_); } | ||
| 87 | sub main'cmplt { &out3("cmplt",@_); } | ||
| 88 | sub main'bgt { &out2("bgt",@_); } | ||
| 89 | sub main'ble { &out2("ble",@_); } | ||
| 90 | sub main'blt { &out2("blt",@_); } | ||
| 91 | sub main'mul { &out3("mulq",@_); } | ||
| 92 | sub main'muh { &out3("umulh",@_); } | ||
| 93 | |||
| 94 | $main'QWS=8; | ||
| 95 | |||
| 96 | sub main'asm_add | ||
| 97 | { | ||
| 98 | push(@out,@_); | ||
| 99 | } | ||
| 100 | |||
| 101 | sub main'asm_finish | ||
| 102 | { | ||
| 103 | &main'file_end(); | ||
| 104 | print &main'asm_get_output(); | ||
| 105 | } | ||
| 106 | |||
| 107 | sub main'asm_init | ||
| 108 | { | ||
| 109 | ($type,$fn)=@_; | ||
| 110 | $filename=$fn; | ||
| 111 | |||
| 112 | &main'asm_init_output(); | ||
| 113 | &main'comment("Don't even think of reading this code"); | ||
| 114 | &main'comment("It was automatically generated by $filename"); | ||
| 115 | &main'comment("Which is a perl program used to generate the alpha assember."); | ||
| 116 | &main'comment("eric <eay\@cryptsoft.com>"); | ||
| 117 | &main'comment(""); | ||
| 118 | |||
| 119 | $filename =~ s/\.pl$//; | ||
| 120 | &main'file($filename); | ||
| 121 | } | ||
| 122 | |||
| 123 | sub conv | ||
| 124 | { | ||
| 125 | local($r)=@_; | ||
| 126 | local($v); | ||
| 127 | |||
| 128 | return($regs{$r}) if defined($regs{$r}); | ||
| 129 | return($r); | ||
| 130 | } | ||
| 131 | |||
| 132 | sub main'QWPw | ||
| 133 | { | ||
| 134 | local($off,$reg)=@_; | ||
| 135 | |||
| 136 | return(&main'QWP($off*8,$reg)); | ||
| 137 | } | ||
| 138 | |||
| 139 | sub main'QWP | ||
| 140 | { | ||
| 141 | local($off,$reg)=@_; | ||
| 142 | |||
| 143 | $ret="$off(".&conv($reg).")"; | ||
| 144 | return($ret); | ||
| 145 | } | ||
| 146 | |||
| 147 | sub out3 | ||
| 148 | { | ||
| 149 | local($name,$p1,$p2,$p3)=@_; | ||
| 150 | |||
| 151 | $p1=&conv($p1); | ||
| 152 | $p2=&conv($p2); | ||
| 153 | $p3=&conv($p3); | ||
| 154 | push(@out,"\t$name\t"); | ||
| 155 | $l=length($p1)+1; | ||
| 156 | push(@out,$p1.","); | ||
| 157 | $ll=3-($l+9)/8; | ||
| 158 | $tmp1=sprintf("\t" x $ll); | ||
| 159 | push(@out,$tmp1); | ||
| 160 | |||
| 161 | $l=length($p2)+1; | ||
| 162 | push(@out,$p2.","); | ||
| 163 | $ll=3-($l+9)/8; | ||
| 164 | $tmp1=sprintf("\t" x $ll); | ||
| 165 | push(@out,$tmp1); | ||
| 166 | |||
| 167 | push(@out,&conv($p3)."\n"); | ||
| 168 | } | ||
| 169 | |||
| 170 | sub out2 | ||
| 171 | { | ||
| 172 | local($name,$p1,$p2,$p3)=@_; | ||
| 173 | |||
| 174 | $p1=&conv($p1); | ||
| 175 | $p2=&conv($p2); | ||
| 176 | push(@out,"\t$name\t"); | ||
| 177 | $l=length($p1)+1; | ||
| 178 | push(@out,$p1.","); | ||
| 179 | $ll=3-($l+9)/8; | ||
| 180 | $tmp1=sprintf("\t" x $ll); | ||
| 181 | push(@out,$tmp1); | ||
| 182 | |||
| 183 | push(@out,&conv($p2)."\n"); | ||
| 184 | } | ||
| 185 | |||
| 186 | sub out1 | ||
| 187 | { | ||
| 188 | local($name,$p1)=@_; | ||
| 189 | |||
| 190 | $p1=&conv($p1); | ||
| 191 | push(@out,"\t$name\t".$p1."\n"); | ||
| 192 | } | ||
| 193 | |||
| 194 | sub out0 | ||
| 195 | { | ||
| 196 | push(@out,"\t$_[0]\n"); | ||
| 197 | } | ||
| 198 | |||
| 199 | sub main'file | ||
| 200 | { | ||
| 201 | local($file)=@_; | ||
| 202 | |||
| 203 | local($tmp)=<<"EOF"; | ||
| 204 | # DEC Alpha assember | ||
| 205 | # Generated from perl scripts contains in SSLeay | ||
| 206 | .file 1 "$file.s" | ||
| 207 | .set noat | ||
| 208 | EOF | ||
| 209 | push(@out,$tmp); | ||
| 210 | } | ||
| 211 | |||
| 212 | sub main'function_begin | ||
| 213 | { | ||
| 214 | local($func)=@_; | ||
| 215 | |||
| 216 | print STDERR "$func\n"; | ||
| 217 | local($tmp)=<<"EOF"; | ||
| 218 | .text | ||
| 219 | .align $align | ||
| 220 | .globl $func | ||
| 221 | .ent $func | ||
| 222 | ${func}: | ||
| 223 | ${func}..ng: | ||
| 224 | .frame \$30,0,\$26,0 | ||
| 225 | .prologue 0 | ||
| 226 | EOF | ||
| 227 | push(@out,$tmp); | ||
| 228 | $stack=0; | ||
| 229 | } | ||
| 230 | |||
| 231 | sub main'function_end | ||
| 232 | { | ||
| 233 | local($func)=@_; | ||
| 234 | |||
| 235 | local($tmp)=<<"EOF"; | ||
| 236 | ret \$31,(\$26),1 | ||
| 237 | .end $func | ||
| 238 | EOF | ||
| 239 | push(@out,$tmp); | ||
| 240 | $stack=0; | ||
| 241 | %label=(); | ||
| 242 | } | ||
| 243 | |||
| 244 | sub main'function_end_A | ||
| 245 | { | ||
| 246 | local($func)=@_; | ||
| 247 | |||
| 248 | local($tmp)=<<"EOF"; | ||
| 249 | ret \$31,(\$26),1 | ||
| 250 | EOF | ||
| 251 | push(@out,$tmp); | ||
| 252 | } | ||
| 253 | |||
| 254 | sub main'function_end_B | ||
| 255 | { | ||
| 256 | local($func)=@_; | ||
| 257 | |||
| 258 | $func=$under.$func; | ||
| 259 | |||
| 260 | push(@out,"\t.end $func\n"); | ||
| 261 | $stack=0; | ||
| 262 | %label=(); | ||
| 263 | } | ||
| 264 | |||
| 265 | sub main'wparam | ||
| 266 | { | ||
| 267 | local($num)=@_; | ||
| 268 | |||
| 269 | if ($num < 6) | ||
| 270 | { | ||
| 271 | $num=20-$num; | ||
| 272 | return("r$num"); | ||
| 273 | } | ||
| 274 | else | ||
| 275 | { return(&main'QWP($stack+$num*8,"sp")); } | ||
| 276 | } | ||
| 277 | |||
| 278 | sub main'stack_push | ||
| 279 | { | ||
| 280 | local($num)=@_; | ||
| 281 | $stack+=$num*8; | ||
| 282 | &main'sub("sp",$num*8,"sp"); | ||
| 283 | } | ||
| 284 | |||
| 285 | sub main'stack_pop | ||
| 286 | { | ||
| 287 | local($num)=@_; | ||
| 288 | $stack-=$num*8; | ||
| 289 | &main'add("sp",$num*8,"sp"); | ||
| 290 | } | ||
| 291 | |||
| 292 | sub main'swtmp | ||
| 293 | { | ||
| 294 | return(&main'QWP(($_[0])*8,"sp")); | ||
| 295 | } | ||
| 296 | |||
| 297 | # Should use swtmp, which is above sp. Linix can trash the stack above esp | ||
| 298 | #sub main'wtmp | ||
| 299 | # { | ||
| 300 | # local($num)=@_; | ||
| 301 | # | ||
| 302 | # return(&main'QWP(-($num+1)*4,"esp","",0)); | ||
| 303 | # } | ||
| 304 | |||
| 305 | sub main'comment | ||
| 306 | { | ||
| 307 | foreach (@_) | ||
| 308 | { | ||
| 309 | if (/^\s*$/) | ||
| 310 | { push(@out,"\n"); } | ||
| 311 | else | ||
| 312 | { push(@out,"\t$com_start $_ $com_end\n"); } | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | sub main'label | ||
| 317 | { | ||
| 318 | if (!defined($label{$_[0]})) | ||
| 319 | { | ||
| 320 | $label{$_[0]}=$label; | ||
| 321 | $label++; | ||
| 322 | } | ||
| 323 | return('$'.$label{$_[0]}); | ||
| 324 | } | ||
| 325 | |||
| 326 | sub main'set_label | ||
| 327 | { | ||
| 328 | if (!defined($label{$_[0]})) | ||
| 329 | { | ||
| 330 | $label{$_[0]}=$label; | ||
| 331 | $label++; | ||
| 332 | } | ||
| 333 | # push(@out,".align $align\n") if ($_[1] != 0); | ||
| 334 | push(@out,'$'."$label{$_[0]}:\n"); | ||
| 335 | } | ||
| 336 | |||
| 337 | sub main'file_end | ||
| 338 | { | ||
| 339 | } | ||
| 340 | |||
| 341 | sub main'data_word | ||
| 342 | { | ||
| 343 | push(@out,"\t.long $_[0]\n"); | ||
| 344 | } | ||
| 345 | |||
| 346 | @pool_free=(); | ||
| 347 | @pool_taken=(); | ||
| 348 | $curr_num=0; | ||
| 349 | $max=0; | ||
| 350 | |||
| 351 | sub main'init_pool | ||
| 352 | { | ||
| 353 | local($args)=@_; | ||
| 354 | local($i); | ||
| 355 | |||
| 356 | @pool_free=(); | ||
| 357 | for ($i=(14+(6-$args)); $i >= 0; $i--) | ||
| 358 | { | ||
| 359 | push(@pool_free,"r$i"); | ||
| 360 | } | ||
| 361 | print STDERR "START :register pool:@pool_free\n"; | ||
| 362 | $curr_num=$max=0; | ||
| 363 | } | ||
| 364 | |||
| 365 | sub main'fin_pool | ||
| 366 | { | ||
| 367 | printf STDERR "END %2d:register pool:@pool_free\n",$max; | ||
| 368 | } | ||
| 369 | |||
| 370 | sub main'GR | ||
| 371 | { | ||
| 372 | local($r)=@_; | ||
| 373 | local($i,@n,$_); | ||
| 374 | |||
| 375 | foreach (@pool_free) | ||
| 376 | { | ||
| 377 | if ($r ne $_) | ||
| 378 | { push(@n,$_); } | ||
| 379 | else | ||
| 380 | { | ||
| 381 | $curr_num++; | ||
| 382 | $max=$curr_num if ($curr_num > $max); | ||
| 383 | } | ||
| 384 | } | ||
| 385 | @pool_free=@n; | ||
| 386 | print STDERR "GR:@pool_free\n" if $reg_alloc; | ||
| 387 | return(@_); | ||
| 388 | } | ||
| 389 | |||
| 390 | sub main'NR | ||
| 391 | { | ||
| 392 | local($num)=@_; | ||
| 393 | local(@ret); | ||
| 394 | |||
| 395 | $num=1 if $num == 0; | ||
| 396 | ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free"; | ||
| 397 | while ($num > 0) | ||
| 398 | { | ||
| 399 | push(@ret,pop @pool_free); | ||
| 400 | $curr_num++; | ||
| 401 | $max=$curr_num if ($curr_num > $max); | ||
| 402 | $num-- | ||
| 403 | } | ||
| 404 | print STDERR "nr @ret\n" if $n_debug; | ||
| 405 | print STDERR "NR:@pool_free\n" if $reg_alloc; | ||
| 406 | return(@ret); | ||
| 407 | |||
| 408 | } | ||
| 409 | |||
| 410 | sub main'FR | ||
| 411 | { | ||
| 412 | local(@r)=@_; | ||
| 413 | local(@a,$v,$w); | ||
| 414 | |||
| 415 | print STDERR "fr @r\n" if $n_debug; | ||
| 416 | # cluck "fr @r"; | ||
| 417 | for $w (@pool_free) | ||
| 418 | { | ||
| 419 | foreach $v (@r) | ||
| 420 | { | ||
| 421 | croak "double register free of $v (@pool_free)" if $w eq $v; | ||
| 422 | } | ||
| 423 | } | ||
| 424 | foreach $v (@r) | ||
| 425 | { | ||
| 426 | croak "bad argument to FR" if ($v !~ /^r\d+$/); | ||
| 427 | if ($smear_regs) | ||
| 428 | { unshift(@pool_free,$v); } | ||
| 429 | else { push(@pool_free,$v); } | ||
| 430 | $curr_num--; | ||
| 431 | } | ||
| 432 | print STDERR "FR:@pool_free\n" if $reg_alloc; | ||
| 433 | } | ||
| 434 | 1; | ||
diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl index 2789305790..0145c4f0cc 100644 --- a/src/lib/libcrypto/perlasm/cbc.pl +++ b/src/lib/libcrypto/perlasm/cbc.pl | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/local/bin/perl |
| 2 | 2 | ||
| 3 | # void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | 3 | # void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) |
| 4 | # des_cblock (*input); | 4 | # des_cblock (*input); |
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl index 6a9156ae9a..44e330eb8d 100644 --- a/src/lib/libcrypto/perlasm/x86asm.pl +++ b/src/lib/libcrypto/perlasm/x86asm.pl | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/local/bin/perl |
| 2 | 2 | ||
| 3 | # require 'x86asm.pl'; | 3 | # require 'x86asm.pl'; |
| 4 | # &asm_init("cpp","des-586.pl"); | 4 | # &asm_init("cpp","des-586.pl"); |
| @@ -15,7 +15,7 @@ sub main'asm_finish | |||
| 15 | 15 | ||
| 16 | sub main'asm_init | 16 | sub main'asm_init |
| 17 | { | 17 | { |
| 18 | ($type,$fn)=@_; | 18 | ($type,$fn,$i386)=@_; |
| 19 | $filename=$fn; | 19 | $filename=$fn; |
| 20 | 20 | ||
| 21 | $cpp=$sol=$aout=$win32=0; | 21 | $cpp=$sol=$aout=$win32=0; |
| @@ -29,6 +29,8 @@ sub main'asm_init | |||
| 29 | { $cpp=1; require "x86unix.pl"; } | 29 | { $cpp=1; require "x86unix.pl"; } |
| 30 | elsif ( ($type eq "win32")) | 30 | elsif ( ($type eq "win32")) |
| 31 | { $win32=1; require "x86ms.pl"; } | 31 | { $win32=1; require "x86ms.pl"; } |
| 32 | elsif ( ($type eq "win32n")) | ||
| 33 | { $win32=1; require "x86nasm.pl"; } | ||
| 32 | else | 34 | else |
| 33 | { | 35 | { |
| 34 | print STDERR <<"EOF"; | 36 | print STDERR <<"EOF"; |
| @@ -38,6 +40,7 @@ Pick one target type from | |||
| 38 | sol - x86 solaris | 40 | sol - x86 solaris |
| 39 | cpp - format so x86unix.cpp can be used | 41 | cpp - format so x86unix.cpp can be used |
| 40 | win32 - Windows 95/Windows NT | 42 | win32 - Windows 95/Windows NT |
| 43 | win32n - Windows 95/Windows NT NASM format | ||
| 41 | EOF | 44 | EOF |
| 42 | exit(1); | 45 | exit(1); |
| 43 | } | 46 | } |
| @@ -75,7 +78,7 @@ sub asm_finish_cpp | |||
| 75 | #define TYPE(a,b) .type a,b | 78 | #define TYPE(a,b) .type a,b |
| 76 | #define SIZE(a,b) .size a,b | 79 | #define SIZE(a,b) .size a,b |
| 77 | 80 | ||
| 78 | #if defined(OUT) || defined(BSDI) | 81 | #if defined(OUT) || (defined(BSDI) && !defined(ELF)) |
| 79 | $tmp | 82 | $tmp |
| 80 | #endif | 83 | #endif |
| 81 | 84 | ||
| @@ -84,7 +87,7 @@ $tmp | |||
| 84 | #define ALIGN 4 | 87 | #define ALIGN 4 |
| 85 | #endif | 88 | #endif |
| 86 | 89 | ||
| 87 | #ifdef BSDI | 90 | #if defined(BSDI) && !defined(ELF) |
| 88 | #define OK 1 | 91 | #define OK 1 |
| 89 | #define ALIGN 4 | 92 | #define ALIGN 4 |
| 90 | #undef SIZE | 93 | #undef SIZE |
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl index 893b50b1a4..51dcce067f 100644 --- a/src/lib/libcrypto/perlasm/x86ms.pl +++ b/src/lib/libcrypto/perlasm/x86ms.pl | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/local/bin/perl |
| 2 | 2 | ||
| 3 | package x86ms; | 3 | package x86ms; |
| 4 | 4 | ||
| @@ -51,6 +51,16 @@ sub main'DWP | |||
| 51 | &get_mem("DWORD",@_); | 51 | &get_mem("DWORD",@_); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | sub main'BC | ||
| 55 | { | ||
| 56 | return @_; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub main'DWC | ||
| 60 | { | ||
| 61 | return @_; | ||
| 62 | } | ||
| 63 | |||
| 54 | sub main'stack_push | 64 | sub main'stack_push |
| 55 | { | 65 | { |
| 56 | local($num)=@_; | 66 | local($num)=@_; |
diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl new file mode 100644 index 0000000000..b4da364bbf --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86nasm.pl | |||
| @@ -0,0 +1,342 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | package x86nasm; | ||
| 4 | |||
| 5 | $label="L000"; | ||
| 6 | |||
| 7 | %lb=( 'eax', 'al', | ||
| 8 | 'ebx', 'bl', | ||
| 9 | 'ecx', 'cl', | ||
| 10 | 'edx', 'dl', | ||
| 11 | 'ax', 'al', | ||
| 12 | 'bx', 'bl', | ||
| 13 | 'cx', 'cl', | ||
| 14 | 'dx', 'dl', | ||
| 15 | ); | ||
| 16 | |||
| 17 | %hb=( 'eax', 'ah', | ||
| 18 | 'ebx', 'bh', | ||
| 19 | 'ecx', 'ch', | ||
| 20 | 'edx', 'dh', | ||
| 21 | 'ax', 'ah', | ||
| 22 | 'bx', 'bh', | ||
| 23 | 'cx', 'ch', | ||
| 24 | 'dx', 'dh', | ||
| 25 | ); | ||
| 26 | |||
| 27 | sub main'asm_init_output { @out=(); } | ||
| 28 | sub main'asm_get_output { return(@out); } | ||
| 29 | sub main'get_labels { return(@labels); } | ||
| 30 | |||
| 31 | sub main'external_label | ||
| 32 | { | ||
| 33 | push(@labels,@_); | ||
| 34 | foreach (@_) { | ||
| 35 | push(@out, "extern\t_$_\n"); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | sub main'LB | ||
| 40 | { | ||
| 41 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
| 42 | return($lb{$_[0]}); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub main'HB | ||
| 46 | { | ||
| 47 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
| 48 | return($hb{$_[0]}); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub main'BP | ||
| 52 | { | ||
| 53 | &get_mem("BYTE",@_); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub main'DWP | ||
| 57 | { | ||
| 58 | &get_mem("DWORD",@_); | ||
| 59 | } | ||
| 60 | |||
| 61 | sub main'BC | ||
| 62 | { | ||
| 63 | return "BYTE @_"; | ||
| 64 | } | ||
| 65 | |||
| 66 | sub main'DWC | ||
| 67 | { | ||
| 68 | return "DWORD @_"; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub main'stack_push | ||
| 72 | { | ||
| 73 | my($num)=@_; | ||
| 74 | $stack+=$num*4; | ||
| 75 | &main'sub("esp",$num*4); | ||
| 76 | } | ||
| 77 | |||
| 78 | sub main'stack_pop | ||
| 79 | { | ||
| 80 | my($num)=@_; | ||
| 81 | $stack-=$num*4; | ||
| 82 | &main'add("esp",$num*4); | ||
| 83 | } | ||
| 84 | |||
| 85 | sub get_mem | ||
| 86 | { | ||
| 87 | my($size,$addr,$reg1,$reg2,$idx)=@_; | ||
| 88 | my($t,$post); | ||
| 89 | my($ret)="["; | ||
| 90 | $addr =~ s/^\s+//; | ||
| 91 | if ($addr =~ /^(.+)\+(.+)$/) | ||
| 92 | { | ||
| 93 | $reg2=&conv($1); | ||
| 94 | $addr="_$2"; | ||
| 95 | } | ||
| 96 | elsif ($addr =~ /^[_a-zA-Z]/) | ||
| 97 | { | ||
| 98 | $addr="_$addr"; | ||
| 99 | } | ||
| 100 | |||
| 101 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
| 102 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
| 103 | if (($addr ne "") && ($addr ne 0)) | ||
| 104 | { | ||
| 105 | if ($addr !~ /^-/) | ||
| 106 | { $ret.="${addr}+"; } | ||
| 107 | else { $post=$addr; } | ||
| 108 | } | ||
| 109 | if ($reg2 ne "") | ||
| 110 | { | ||
| 111 | $t=""; | ||
| 112 | $t="*$idx" if ($idx != 0); | ||
| 113 | $reg1="+".$reg1 if ("$reg1$post" ne ""); | ||
| 114 | $ret.="$reg2$t$reg1$post]"; | ||
| 115 | } | ||
| 116 | else | ||
| 117 | { | ||
| 118 | $ret.="$reg1$post]" | ||
| 119 | } | ||
| 120 | return($ret); | ||
| 121 | } | ||
| 122 | |||
| 123 | sub main'mov { &out2("mov",@_); } | ||
| 124 | sub main'movb { &out2("mov",@_); } | ||
| 125 | sub main'and { &out2("and",@_); } | ||
| 126 | sub main'or { &out2("or",@_); } | ||
| 127 | sub main'shl { &out2("shl",@_); } | ||
| 128 | sub main'shr { &out2("shr",@_); } | ||
| 129 | sub main'xor { &out2("xor",@_); } | ||
| 130 | sub main'xorb { &out2("xor",@_); } | ||
| 131 | sub main'add { &out2("add",@_); } | ||
| 132 | sub main'adc { &out2("adc",@_); } | ||
| 133 | sub main'sub { &out2("sub",@_); } | ||
| 134 | sub main'rotl { &out2("rol",@_); } | ||
| 135 | sub main'rotr { &out2("ror",@_); } | ||
| 136 | sub main'exch { &out2("xchg",@_); } | ||
| 137 | sub main'cmp { &out2("cmp",@_); } | ||
| 138 | sub main'lea { &out2("lea",@_); } | ||
| 139 | sub main'mul { &out1("mul",@_); } | ||
| 140 | sub main'div { &out1("div",@_); } | ||
| 141 | sub main'dec { &out1("dec",@_); } | ||
| 142 | sub main'inc { &out1("inc",@_); } | ||
| 143 | sub main'jmp { &out1("jmp",@_); } | ||
| 144 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
| 145 | |||
| 146 | # This is a bit of a kludge: declare all branches as NEAR. | ||
| 147 | sub main'je { &out1("je NEAR",@_); } | ||
| 148 | sub main'jle { &out1("jle NEAR",@_); } | ||
| 149 | sub main'jz { &out1("jz NEAR",@_); } | ||
| 150 | sub main'jge { &out1("jge NEAR",@_); } | ||
| 151 | sub main'jl { &out1("jl NEAR",@_); } | ||
| 152 | sub main'jb { &out1("jb NEAR",@_); } | ||
| 153 | sub main'jc { &out1("jc NEAR",@_); } | ||
| 154 | sub main'jnc { &out1("jnc NEAR",@_); } | ||
| 155 | sub main'jnz { &out1("jnz NEAR",@_); } | ||
| 156 | sub main'jne { &out1("jne NEAR",@_); } | ||
| 157 | sub main'jno { &out1("jno NEAR",@_); } | ||
| 158 | |||
| 159 | sub main'push { &out1("push",@_); $stack+=4; } | ||
| 160 | sub main'pop { &out1("pop",@_); $stack-=4; } | ||
| 161 | sub main'bswap { &out1("bswap",@_); &using486(); } | ||
| 162 | sub main'not { &out1("not",@_); } | ||
| 163 | sub main'call { &out1("call",'_'.$_[0]); } | ||
| 164 | sub main'ret { &out0("ret"); } | ||
| 165 | sub main'nop { &out0("nop"); } | ||
| 166 | |||
| 167 | sub out2 | ||
| 168 | { | ||
| 169 | my($name,$p1,$p2)=@_; | ||
| 170 | my($l,$t); | ||
| 171 | |||
| 172 | push(@out,"\t$name\t"); | ||
| 173 | $t=&conv($p1).","; | ||
| 174 | $l=length($t); | ||
| 175 | push(@out,$t); | ||
| 176 | $l=4-($l+9)/8; | ||
| 177 | push(@out,"\t" x $l); | ||
| 178 | push(@out,&conv($p2)); | ||
| 179 | push(@out,"\n"); | ||
| 180 | } | ||
| 181 | |||
| 182 | sub out0 | ||
| 183 | { | ||
| 184 | my($name)=@_; | ||
| 185 | |||
| 186 | push(@out,"\t$name\n"); | ||
| 187 | } | ||
| 188 | |||
| 189 | sub out1 | ||
| 190 | { | ||
| 191 | my($name,$p1)=@_; | ||
| 192 | my($l,$t); | ||
| 193 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
| 194 | } | ||
| 195 | |||
| 196 | sub conv | ||
| 197 | { | ||
| 198 | my($p)=@_; | ||
| 199 | $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
| 200 | return $p; | ||
| 201 | } | ||
| 202 | |||
| 203 | sub using486 | ||
| 204 | { | ||
| 205 | return if $using486; | ||
| 206 | $using486++; | ||
| 207 | grep(s/\.386/\.486/,@out); | ||
| 208 | } | ||
| 209 | |||
| 210 | sub main'file | ||
| 211 | { | ||
| 212 | push(@out, "segment .text\n"); | ||
| 213 | } | ||
| 214 | |||
| 215 | sub main'function_begin | ||
| 216 | { | ||
| 217 | my($func,$extra)=@_; | ||
| 218 | |||
| 219 | push(@labels,$func); | ||
| 220 | my($tmp)=<<"EOF"; | ||
| 221 | global _$func | ||
| 222 | _$func: | ||
| 223 | push ebp | ||
| 224 | push ebx | ||
| 225 | push esi | ||
| 226 | push edi | ||
| 227 | EOF | ||
| 228 | push(@out,$tmp); | ||
| 229 | $stack=20; | ||
| 230 | } | ||
| 231 | |||
| 232 | sub main'function_begin_B | ||
| 233 | { | ||
| 234 | my($func,$extra)=@_; | ||
| 235 | my($tmp)=<<"EOF"; | ||
| 236 | global _$func | ||
| 237 | _$func: | ||
| 238 | EOF | ||
| 239 | push(@out,$tmp); | ||
| 240 | $stack=4; | ||
| 241 | } | ||
| 242 | |||
| 243 | sub main'function_end | ||
| 244 | { | ||
| 245 | my($func)=@_; | ||
| 246 | |||
| 247 | my($tmp)=<<"EOF"; | ||
| 248 | pop edi | ||
| 249 | pop esi | ||
| 250 | pop ebx | ||
| 251 | pop ebp | ||
| 252 | ret | ||
| 253 | EOF | ||
| 254 | push(@out,$tmp); | ||
| 255 | $stack=0; | ||
| 256 | %label=(); | ||
| 257 | } | ||
| 258 | |||
| 259 | sub main'function_end_B | ||
| 260 | { | ||
| 261 | $stack=0; | ||
| 262 | %label=(); | ||
| 263 | } | ||
| 264 | |||
| 265 | sub main'function_end_A | ||
| 266 | { | ||
| 267 | my($func)=@_; | ||
| 268 | |||
| 269 | my($tmp)=<<"EOF"; | ||
| 270 | pop edi | ||
| 271 | pop esi | ||
| 272 | pop ebx | ||
| 273 | pop ebp | ||
| 274 | ret | ||
| 275 | EOF | ||
| 276 | push(@out,$tmp); | ||
| 277 | } | ||
| 278 | |||
| 279 | sub main'file_end | ||
| 280 | { | ||
| 281 | } | ||
| 282 | |||
| 283 | sub main'wparam | ||
| 284 | { | ||
| 285 | my($num)=@_; | ||
| 286 | |||
| 287 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
| 288 | } | ||
| 289 | |||
| 290 | sub main'swtmp | ||
| 291 | { | ||
| 292 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
| 293 | } | ||
| 294 | |||
| 295 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
| 296 | #sub main'wtmp | ||
| 297 | # { | ||
| 298 | # my($num)=@_; | ||
| 299 | # | ||
| 300 | # return(&main'DWP(-(($num+1)*4),"esp","",0)); | ||
| 301 | # } | ||
| 302 | |||
| 303 | sub main'comment | ||
| 304 | { | ||
| 305 | foreach (@_) | ||
| 306 | { | ||
| 307 | push(@out,"\t; $_\n"); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 | sub main'label | ||
| 312 | { | ||
| 313 | if (!defined($label{$_[0]})) | ||
| 314 | { | ||
| 315 | $label{$_[0]}="\$${label}${_[0]}"; | ||
| 316 | $label++; | ||
| 317 | } | ||
| 318 | return($label{$_[0]}); | ||
| 319 | } | ||
| 320 | |||
| 321 | sub main'set_label | ||
| 322 | { | ||
| 323 | if (!defined($label{$_[0]})) | ||
| 324 | { | ||
| 325 | $label{$_[0]}="${label}${_[0]}"; | ||
| 326 | $label++; | ||
| 327 | } | ||
| 328 | push(@out,"$label{$_[0]}:\n"); | ||
| 329 | } | ||
| 330 | |||
| 331 | sub main'data_word | ||
| 332 | { | ||
| 333 | push(@out,"\tDD\t$_[0]\n"); | ||
| 334 | } | ||
| 335 | |||
| 336 | sub out1p | ||
| 337 | { | ||
| 338 | my($name,$p1)=@_; | ||
| 339 | my($l,$t); | ||
| 340 | |||
| 341 | push(@out,"\t$name\t ".&conv($p1)."\n"); | ||
| 342 | } | ||
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl index 6ee4dd3245..8c456b14af 100644 --- a/src/lib/libcrypto/perlasm/x86unix.pl +++ b/src/lib/libcrypto/perlasm/x86unix.pl | |||
| @@ -1,10 +1,4 @@ | |||
| 1 | #!/usr/bin/perl | 1 | #!/usr/local/bin/perl |
| 2 | |||
| 3 | # Because the bswapl instruction is not supported for old assembers | ||
| 4 | # (it was a new instruction for the 486), I've added .byte xxxx code | ||
| 5 | # to put it in. | ||
| 6 | # eric 24-Apr-1998 | ||
| 7 | # | ||
| 8 | 2 | ||
| 9 | package x86unix; | 3 | package x86unix; |
| 10 | 4 | ||
| @@ -90,7 +84,12 @@ sub main'DWP | |||
| 90 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | 84 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); |
| 91 | $ret.=$addr if ($addr ne "") && ($addr ne 0); | 85 | $ret.=$addr if ($addr ne "") && ($addr ne 0); |
| 92 | if ($reg2 ne "") | 86 | if ($reg2 ne "") |
| 93 | { $ret.="($reg1,$reg2,$idx)"; } | 87 | { |
| 88 | if($idx ne "") | ||
| 89 | { $ret.="($reg1,$reg2,$idx)"; } | ||
| 90 | else | ||
| 91 | { $ret.="($reg1,$reg2)"; } | ||
| 92 | } | ||
| 94 | else | 93 | else |
| 95 | { $ret.="($reg1)" } | 94 | { $ret.="($reg1)" } |
| 96 | return($ret); | 95 | return($ret); |
| @@ -101,6 +100,16 @@ sub main'BP | |||
| 101 | return(&main'DWP(@_)); | 100 | return(&main'DWP(@_)); |
| 102 | } | 101 | } |
| 103 | 102 | ||
| 103 | sub main'BC | ||
| 104 | { | ||
| 105 | return @_; | ||
| 106 | } | ||
| 107 | |||
| 108 | sub main'DWC | ||
| 109 | { | ||
| 110 | return @_; | ||
| 111 | } | ||
| 112 | |||
| 104 | #sub main'BP | 113 | #sub main'BP |
| 105 | # { | 114 | # { |
| 106 | # local($addr,$reg1,$reg2,$idx)=@_; | 115 | # local($addr,$reg1,$reg2,$idx)=@_; |
| @@ -153,12 +162,27 @@ sub main'dec { &out1("decl",@_); } | |||
| 153 | sub main'inc { &out1("incl",@_); } | 162 | sub main'inc { &out1("incl",@_); } |
| 154 | sub main'push { &out1("pushl",@_); $stack+=4; } | 163 | sub main'push { &out1("pushl",@_); $stack+=4; } |
| 155 | sub main'pop { &out1("popl",@_); $stack-=4; } | 164 | sub main'pop { &out1("popl",@_); $stack-=4; } |
| 156 | sub main'bswap { &out1("bswapl",@_); } | ||
| 157 | sub main'not { &out1("notl",@_); } | 165 | sub main'not { &out1("notl",@_); } |
| 158 | sub main'call { &out1("call",$under.$_[0]); } | 166 | sub main'call { &out1("call",$under.$_[0]); } |
| 159 | sub main'ret { &out0("ret"); } | 167 | sub main'ret { &out0("ret"); } |
| 160 | sub main'nop { &out0("nop"); } | 168 | sub main'nop { &out0("nop"); } |
| 161 | 169 | ||
| 170 | # The bswapl instruction is new for the 486. Emulate if i386. | ||
| 171 | sub main'bswap | ||
| 172 | { | ||
| 173 | if ($main'i386) | ||
| 174 | { | ||
| 175 | &main'comment("bswapl @_"); | ||
| 176 | &main'exch(main'HB(@_),main'LB(@_)); | ||
| 177 | &main'rotr(@_,16); | ||
| 178 | &main'exch(main'HB(@_),main'LB(@_)); | ||
| 179 | } | ||
| 180 | else | ||
| 181 | { | ||
| 182 | &out1("bswapl",@_); | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 162 | sub out2 | 186 | sub out2 |
| 163 | { | 187 | { |
| 164 | local($name,$p1,$p2)=@_; | 188 | local($name,$p1,$p2)=@_; |
