summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/perlasm/x86ms.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/perlasm/x86ms.pl')
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl122
1 files changed, 107 insertions, 15 deletions
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl
index b6bd744057..a0be2934c2 100644
--- a/src/lib/libcrypto/perlasm/x86ms.pl
+++ b/src/lib/libcrypto/perlasm/x86ms.pl
@@ -27,7 +27,13 @@ $label="L000";
27sub main'asm_init_output { @out=(); } 27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); } 28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); } 29sub main'get_labels { return(@labels); }
30sub main'external_label { push(@labels,@_); } 30sub main'external_label
31{
32 push(@labels,@_);
33 foreach (@_) {
34 push(@out, "EXTRN\t_$_:DWORD\n");
35 }
36}
31 37
32sub main'LB 38sub main'LB
33 { 39 {
@@ -51,6 +57,11 @@ sub main'DWP
51 &get_mem("DWORD",@_); 57 &get_mem("DWORD",@_);
52 } 58 }
53 59
60sub main'QWP
61 {
62 &get_mem("QWORD",@_);
63 }
64
54sub main'BC 65sub main'BC
55 { 66 {
56 return @_; 67 return @_;
@@ -87,7 +98,7 @@ sub get_mem
87 $reg2=&conv($1); 98 $reg2=&conv($1);
88 $addr="_$2"; 99 $addr="_$2";
89 } 100 }
90 elsif ($addr =~ /^[_a-zA-Z]/) 101 elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
91 { 102 {
92 $addr="_$addr"; 103 $addr="_$addr";
93 } 104 }
@@ -128,12 +139,14 @@ sub main'xorb { &out2("xor",@_); }
128sub main'add { &out2("add",@_); } 139sub main'add { &out2("add",@_); }
129sub main'adc { &out2("adc",@_); } 140sub main'adc { &out2("adc",@_); }
130sub main'sub { &out2("sub",@_); } 141sub main'sub { &out2("sub",@_); }
142sub main'sbb { &out2("sbb",@_); }
131sub main'rotl { &out2("rol",@_); } 143sub main'rotl { &out2("rol",@_); }
132sub main'rotr { &out2("ror",@_); } 144sub main'rotr { &out2("ror",@_); }
133sub main'exch { &out2("xchg",@_); } 145sub main'exch { &out2("xchg",@_); }
134sub main'cmp { &out2("cmp",@_); } 146sub main'cmp { &out2("cmp",@_); }
135sub main'lea { &out2("lea",@_); } 147sub main'lea { &out2("lea",@_); }
136sub main'mul { &out1("mul",@_); } 148sub main'mul { &out1("mul",@_); }
149sub main'imul { &out2("imul",@_); }
137sub main'div { &out1("div",@_); } 150sub main'div { &out1("div",@_); }
138sub main'dec { &out1("dec",@_); } 151sub main'dec { &out1("dec",@_); }
139sub main'inc { &out1("inc",@_); } 152sub main'inc { &out1("inc",@_); }
@@ -155,26 +168,54 @@ sub main'jne { &out1("jne",@_); }
155sub main'jno { &out1("jno",@_); } 168sub main'jno { &out1("jno",@_); }
156sub main'push { &out1("push",@_); $stack+=4; } 169sub main'push { &out1("push",@_); $stack+=4; }
157sub main'pop { &out1("pop",@_); $stack-=4; } 170sub main'pop { &out1("pop",@_); $stack-=4; }
171sub main'pushf { &out0("pushfd"); $stack+=4; }
172sub main'popf { &out0("popfd"); $stack-=4; }
158sub main'bswap { &out1("bswap",@_); &using486(); } 173sub main'bswap { &out1("bswap",@_); &using486(); }
159sub main'not { &out1("not",@_); } 174sub main'not { &out1("not",@_); }
160sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); } 175sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
176sub main'call_ptr { &out1p("call",@_); }
161sub main'ret { &out0("ret"); } 177sub main'ret { &out0("ret"); }
162sub main'nop { &out0("nop"); } 178sub main'nop { &out0("nop"); }
179sub main'test { &out2("test",@_); }
180sub main'bt { &out2("bt",@_); }
181sub main'leave { &out0("leave"); }
182sub main'cpuid { &out0("DW\t0A20Fh"); }
183sub main'rdtsc { &out0("DW\t0310Fh"); }
184sub main'halt { &out0("hlt"); }
163sub main'movz { &out2("movzx",@_); } 185sub main'movz { &out2("movzx",@_); }
186sub main'neg { &out1("neg",@_); }
187sub main'cld { &out0("cld"); }
188
189# SSE2
190sub main'emms { &out0("emms"); }
191sub main'movd { &out2("movd",@_); }
192sub main'movq { &out2("movq",@_); }
193sub main'movdqu { &out2("movdqu",@_); }
194sub main'movdqa { &out2("movdqa",@_); }
195sub main'movdq2q{ &out2("movdq2q",@_); }
196sub main'movq2dq{ &out2("movq2dq",@_); }
197sub main'paddq { &out2("paddq",@_); }
198sub main'pmuludq{ &out2("pmuludq",@_); }
199sub main'psrlq { &out2("psrlq",@_); }
200sub main'psllq { &out2("psllq",@_); }
201sub main'pxor { &out2("pxor",@_); }
202sub main'por { &out2("por",@_); }
203sub main'pand { &out2("pand",@_); }
164 204
165sub out2 205sub out2
166 { 206 {
167 local($name,$p1,$p2)=@_; 207 local($name,$p1,$p2)=@_;
168 local($l,$t); 208 local($l,$t,$line);
169 209
170 push(@out,"\t$name\t"); 210 $line="\t$name\t";
171 $t=&conv($p1).","; 211 $t=&conv($p1).",";
172 $l=length($t); 212 $l=length($t);
173 push(@out,$t); 213 $line.="$t";
174 $l=4-($l+9)/8; 214 $l=4-($l+9)/8;
175 push(@out,"\t" x $l); 215 $line.="\t" x $l;
176 push(@out,&conv($p2)); 216 $line.=&conv($p2);
177 push(@out,"\n"); 217 if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; }
218 push(@out,$line."\n");
178 } 219 }
179 220
180sub out0 221sub out0
@@ -214,7 +255,9 @@ sub main'file
214 local($tmp)=<<"EOF"; 255 local($tmp)=<<"EOF";
215 TITLE $file.asm 256 TITLE $file.asm
216 .386 257 .386
217.model FLAT 258.model FLAT
259_TEXT\$ SEGMENT PAGE 'CODE'
260
218EOF 261EOF
219 push(@out,$tmp); 262 push(@out,$tmp);
220 } 263 }
@@ -226,7 +269,6 @@ sub main'function_begin
226 push(@labels,$func); 269 push(@labels,$func);
227 270
228 local($tmp)=<<"EOF"; 271 local($tmp)=<<"EOF";
229_TEXT SEGMENT
230PUBLIC _$func 272PUBLIC _$func
231$extra 273$extra
232_$func PROC NEAR 274_$func PROC NEAR
@@ -244,7 +286,6 @@ sub main'function_begin_B
244 local($func,$extra)=@_; 286 local($func,$extra)=@_;
245 287
246 local($tmp)=<<"EOF"; 288 local($tmp)=<<"EOF";
247_TEXT SEGMENT
248PUBLIC _$func 289PUBLIC _$func
249$extra 290$extra
250_$func PROC NEAR 291_$func PROC NEAR
@@ -264,7 +305,6 @@ sub main'function_end
264 pop ebp 305 pop ebp
265 ret 306 ret
266_$func ENDP 307_$func ENDP
267_TEXT ENDS
268EOF 308EOF
269 push(@out,$tmp); 309 push(@out,$tmp);
270 $stack=0; 310 $stack=0;
@@ -277,7 +317,6 @@ sub main'function_end_B
277 317
278 local($tmp)=<<"EOF"; 318 local($tmp)=<<"EOF";
279_$func ENDP 319_$func ENDP
280_TEXT ENDS
281EOF 320EOF
282 push(@out,$tmp); 321 push(@out,$tmp);
283 $stack=0; 322 $stack=0;
@@ -300,6 +339,20 @@ EOF
300 339
301sub main'file_end 340sub main'file_end
302 { 341 {
342 # try to detect if SSE2 or MMX extensions were used...
343 my $xmmheader=<<___;
344.686
345.XMM
346IF \@Version LT 800
347XMMWORD STRUCT 16
348 DQ 2 dup (?)
349XMMWORD ENDS
350ENDIF
351___
352 if (grep {/\b[x]?mm[0-7]\b/i} @out) {
353 grep {s/\.[3-7]86/$xmmheader/} @out;
354 }
355 push(@out,"_TEXT\$ ENDS\n");
303 push(@out,"END\n"); 356 push(@out,"END\n");
304 } 357 }
305 358
@@ -331,6 +384,12 @@ sub main'comment
331 } 384 }
332 } 385 }
333 386
387sub main'public_label
388 {
389 $label{$_[0]}="_$_[0]" if (!defined($label{$_[0]}));
390 push(@out,"PUBLIC\t$label{$_[0]}\n");
391 }
392
334sub main'label 393sub main'label
335 { 394 {
336 if (!defined($label{$_[0]})) 395 if (!defined($label{$_[0]}))
@@ -348,19 +407,37 @@ sub main'set_label
348 $label{$_[0]}="\$${label}${_[0]}"; 407 $label{$_[0]}="\$${label}${_[0]}";
349 $label++; 408 $label++;
350 } 409 }
410 if ($_[1]!=0 && $_[1]>1)
411 {
412 main'align($_[1]);
413 }
351 if((defined $_[2]) && ($_[2] == 1)) 414 if((defined $_[2]) && ($_[2] == 1))
352 { 415 {
353 push(@out,"$label{$_[0]}::\n"); 416 push(@out,"$label{$_[0]}::\n");
354 } 417 }
418 elsif ($label{$_[0]} !~ /^\$/)
419 {
420 push(@out,"$label{$_[0]}\tLABEL PTR\n");
421 }
355 else 422 else
356 { 423 {
357 push(@out,"$label{$_[0]}:\n"); 424 push(@out,"$label{$_[0]}:\n");
358 } 425 }
359 } 426 }
360 427
428sub main'data_byte
429 {
430 push(@out,"\tDB\t".join(',',@_)."\n");
431 }
432
361sub main'data_word 433sub main'data_word
362 { 434 {
363 push(@out,"\tDD\t$_[0]\n"); 435 push(@out,"\tDD\t".join(',',@_)."\n");
436 }
437
438sub main'align
439 {
440 push(@out,"\tALIGN\t$_[0]\n");
364 } 441 }
365 442
366sub out1p 443sub out1p
@@ -368,7 +445,7 @@ sub out1p
368 local($name,$p1)=@_; 445 local($name,$p1)=@_;
369 local($l,$t); 446 local($l,$t);
370 447
371 push(@out,"\t$name\t ".&conv($p1)."\n"); 448 push(@out,"\t$name\t".&conv($p1)."\n");
372 } 449 }
373 450
374sub main'picmeup 451sub main'picmeup
@@ -378,3 +455,18 @@ sub main'picmeup
378 } 455 }
379 456
380sub main'blindpop { &out1("pop",@_); } 457sub main'blindpop { &out1("pop",@_); }
458
459sub main'initseg
460 {
461 local($f)=@_;
462 local($tmp)=<<___;
463OPTION DOTNAME
464.CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'
465EXTRN _$f:NEAR
466DD _$f
467.CRT\$XCU ENDS
468___
469 push(@out,$tmp);
470 }
471
4721;