summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/perlasm/x86asm.pl
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
committercvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
commit726818f36b5221c023cd04c4b90bdbc08e94cd96 (patch)
treecf8221f3aa5bf5a578ddf1ecf5677ad08c04d342 /src/lib/libcrypto/perlasm/x86asm.pl
parent3b6d92e82b1421b811bcdec7f7fdfb31eeef18de (diff)
downloadopenbsd-OPENBSD_5_5_BASE.tar.gz
openbsd-OPENBSD_5_5_BASE.tar.bz2
openbsd-OPENBSD_5_5_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_5_BASE'.OPENBSD_5_5_BASE
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/perlasm/x86asm.pl274
1 files changed, 0 insertions, 274 deletions
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl
deleted file mode 100644
index bf783cff26..0000000000
--- a/src/lib/libcrypto/perlasm/x86asm.pl
+++ /dev/null
@@ -1,274 +0,0 @@
1#!/usr/bin/env perl
2
3# require 'x86asm.pl';
4# &asm_init(<flavor>,"des-586.pl"[,$i386only]);
5# &function_begin("foo");
6# ...
7# &function_end("foo");
8# &asm_finish
9
10$out=();
11$i386=0;
12
13# AUTOLOAD is this context has quite unpleasant side effect, namely
14# that typos in function calls effectively go to assembler output,
15# but on the pros side we don't have to implement one subroutine per
16# each opcode...
17sub ::AUTOLOAD
18{ my $opcode = $AUTOLOAD;
19
20 die "more than 4 arguments passed to $opcode" if ($#_>3);
21
22 $opcode =~ s/.*:://;
23 if ($opcode =~ /^push/) { $stack+=4; }
24 elsif ($opcode =~ /^pop/) { $stack-=4; }
25
26 &generic($opcode,@_) or die "undefined subroutine \&$AUTOLOAD";
27}
28
29sub ::emit
30{ my $opcode=shift;
31
32 if ($#_==-1) { push(@out,"\t$opcode\n"); }
33 else { push(@out,"\t$opcode\t".join(',',@_)."\n"); }
34}
35
36sub ::emitraw
37{ my $opcode=shift;
38
39 if ($#_==-1) { push(@out,"$opcode\n"); }
40 else { push(@out,"$opcode\t".join(',',@_)."\n"); }
41}
42
43sub ::LB
44{ $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'low byte'";
45 $1."l";
46}
47sub ::HB
48{ $_[0] =~ m/^e?([a-d])x$/o or die "$_[0] does not have a 'high byte'";
49 $1."h";
50}
51sub ::stack_push{ my $num=$_[0]*4; $stack+=$num; &sub("esp",$num); }
52sub ::stack_pop { my $num=$_[0]*4; $stack-=$num; &add("esp",$num); }
53sub ::blindpop { &pop($_[0]); $stack+=4; }
54sub ::wparam { &DWP($stack+4*$_[0],"esp"); }
55sub ::swtmp { &DWP(4*$_[0],"esp"); }
56
57sub ::bswap
58{ if ($i386) # emulate bswap for i386
59 { &comment("bswap @_");
60 &xchg(&HB(@_),&LB(@_));
61 &ror (@_,16);
62 &xchg(&HB(@_),&LB(@_));
63 }
64 else
65 { &generic("bswap",@_); }
66}
67# These are made-up opcodes introduced over the years essentially
68# by ignorance, just alias them to real ones...
69sub ::movb { &mov(@_); }
70sub ::xorb { &xor(@_); }
71sub ::rotl { &rol(@_); }
72sub ::rotr { &ror(@_); }
73sub ::exch { &xchg(@_); }
74sub ::halt { &hlt; }
75sub ::movz { &movzx(@_); }
76sub ::pushf { &pushfd; }
77sub ::popf { &popfd; }
78
79# 3 argument instructions
80sub ::movq
81{ my($p1,$p2,$optimize)=@_;
82
83 if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
84 # movq between mmx registers can sink Intel CPUs
85 { &::pshufw($p1,$p2,0xe4); }
86 else
87 { &::generic("movq",@_); }
88}
89
90# SSE>2 instructions
91my %regrm = ( "eax"=>0, "ecx"=>1, "edx"=>2, "ebx"=>3,
92 "esp"=>4, "ebp"=>5, "esi"=>6, "edi"=>7 );
93sub ::pextrd
94{ my($dst,$src,$imm)=@_;
95 if ("$dst:$src" =~ /(e[a-dsd][ixp]):xmm([0-7])/)
96 { &::data_byte(0x66,0x0f,0x3a,0x16,0xc0|($2<<3)|$regrm{$1},$imm); }
97 else
98 { &::generic("pextrd",@_); }
99}
100
101sub ::pinsrd
102{ my($dst,$src,$imm)=@_;
103 if ("$dst:$src" =~ /xmm([0-7]):(e[a-dsd][ixp])/)
104 { &::data_byte(0x66,0x0f,0x3a,0x22,0xc0|($1<<3)|$regrm{$2},$imm); }
105 else
106 { &::generic("pinsrd",@_); }
107}
108
109sub ::pshufb
110{ my($dst,$src)=@_;
111 if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/)
112 { &data_byte(0x66,0x0f,0x38,0x00,0xc0|($1<<3)|$2); }
113 else
114 { &::generic("pshufb",@_); }
115}
116
117sub ::palignr
118{ my($dst,$src,$imm)=@_;
119 if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/)
120 { &::data_byte(0x66,0x0f,0x3a,0x0f,0xc0|($1<<3)|$2,$imm); }
121 else
122 { &::generic("palignr",@_); }
123}
124
125sub ::pclmulqdq
126{ my($dst,$src,$imm)=@_;
127 if ("$dst:$src" =~ /xmm([0-7]):xmm([0-7])/)
128 { &::data_byte(0x66,0x0f,0x3a,0x44,0xc0|($1<<3)|$2,$imm); }
129 else
130 { &::generic("pclmulqdq",@_); }
131}
132
133sub ::rdrand
134{ my ($dst)=@_;
135 if ($dst =~ /(e[a-dsd][ixp])/)
136 { &::data_byte(0x0f,0xc7,0xf0|$regrm{$dst}); }
137 else
138 { &::generic("rdrand",@_); }
139}
140
141# label management
142$lbdecor="L"; # local label decoration, set by package
143$label="000";
144
145sub ::islabel # see is argument is a known label
146{ my $i;
147 foreach $i (values %label) { return $i if ($i eq $_[0]); }
148 $label{$_[0]}; # can be undef
149}
150
151sub ::label # instantiate a function-scope label
152{ if (!defined($label{$_[0]}))
153 { $label{$_[0]}="${lbdecor}${label}${_[0]}"; $label++; }
154 $label{$_[0]};
155}
156
157sub ::LABEL # instantiate a file-scope label
158{ $label{$_[0]}=$_[1] if (!defined($label{$_[0]}));
159 $label{$_[0]};
160}
161
162sub ::static_label { &::LABEL($_[0],$lbdecor.$_[0]); }
163
164sub ::set_label_B { push(@out,"@_:\n"); }
165sub ::set_label
166{ my $label=&::label($_[0]);
167 &::align($_[1]) if ($_[1]>1);
168 &::set_label_B($label);
169 $label;
170}
171
172sub ::wipe_labels # wipes function-scope labels
173{ foreach $i (keys %label)
174 { delete $label{$i} if ($label{$i} =~ /^\Q${lbdecor}\E[0-9]{3}/); }
175}
176
177# subroutine management
178sub ::function_begin
179{ &function_begin_B(@_);
180 $stack=4;
181 &push("ebp");
182 &push("ebx");
183 &push("esi");
184 &push("edi");
185}
186
187sub ::function_end
188{ &pop("edi");
189 &pop("esi");
190 &pop("ebx");
191 &pop("ebp");
192 &ret();
193 &function_end_B(@_);
194 $stack=0;
195 &wipe_labels();
196}
197
198sub ::function_end_A
199{ &pop("edi");
200 &pop("esi");
201 &pop("ebx");
202 &pop("ebp");
203 &ret();
204 $stack+=16; # readjust esp as if we didn't pop anything
205}
206
207sub ::asciz
208{ my @str=unpack("C*",shift);
209 push @str,0;
210 while ($#str>15) {
211 &data_byte(@str[0..15]);
212 foreach (0..15) { shift @str; }
213 }
214 &data_byte(@str) if (@str);
215}
216
217sub ::asm_finish
218{ &file_end();
219 print @out;
220}
221
222sub ::asm_init
223{ my ($type,$fn,$cpu)=@_;
224
225 $filename=$fn;
226 $i386=$cpu;
227
228 $elf=$cpp=$coff=$aout=$macosx=$win32=$netware=$mwerks=$openbsd=$android=0;
229 if (($type eq "elf"))
230 { $elf=1; require "x86gas.pl"; }
231 elsif (($type eq "a\.out"))
232 { $aout=1; require "x86gas.pl"; }
233 elsif (($type eq "coff" or $type eq "gaswin"))
234 { $coff=1; require "x86gas.pl"; }
235 elsif (($type eq "win32n"))
236 { $win32=1; require "x86nasm.pl"; }
237 elsif (($type eq "nw-nasm"))
238 { $netware=1; require "x86nasm.pl"; }
239 #elsif (($type eq "nw-mwasm"))
240 #{ $netware=1; $mwerks=1; require "x86nasm.pl"; }
241 elsif (($type eq "win32"))
242 { $win32=1; require "x86masm.pl"; }
243 elsif (($type eq "macosx"))
244 { $aout=1; $macosx=1; require "x86gas.pl"; }
245 elsif (($type eq "openbsd-elf"))
246 { $openbsd=$elf=1; require "x86gas.pl"; }
247 elsif (($type eq "openbsd-a.out"))
248 { $openbsd=1; require "x86gas.pl"; }
249 elsif (($type eq "android"))
250 { $elf=1; $android=1; require "x86gas.pl"; }
251 else
252 { print STDERR <<"EOF";
253Pick one target type from
254 elf - Linux, FreeBSD, Solaris x86, etc.
255 a.out - DJGPP, elder OpenBSD, etc.
256 coff - GAS/COFF such as Win32 targets
257 win32n - Windows 95/Windows NT NASM format
258 openbsd-elf - OpenBSD elf
259 openbsd-a.out - OpenBSD a.out
260 nw-nasm - NetWare NASM format
261 macosx - Mac OS X
262EOF
263 exit(1);
264 }
265
266 $pic=0;
267 for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
268
269 ::emitraw("#include <machine/asm.h>\n") if $openbsd;
270 $filename =~ s/\.pl$//;
271 &file($filename);
272}
273
2741;