x86 assembler updates: more instructions, new OPENSSL_instrument_halt
authorAndy Polyakov <appro@openssl.org>
Thu, 9 Sep 2004 14:50:32 +0000 (14:50 +0000)
committerAndy Polyakov <appro@openssl.org>
Thu, 9 Sep 2004 14:50:32 +0000 (14:50 +0000)
[for DJGPP]...

crypto/perlasm/x86ms.pl
crypto/perlasm/x86nasm.pl
crypto/perlasm/x86unix.pl
crypto/x86cpuid.pl

index 1de1277920c0a3f50386a7a42003447e8b5fa66e..3764760585d2469936401bc54a27ecb5729b593b 100644 (file)
@@ -133,6 +133,7 @@ sub main'xorb       { &out2("xor",@_); }
 sub main'add   { &out2("add",@_); }
 sub main'adc   { &out2("adc",@_); }
 sub main'sub   { &out2("sub",@_); }
+sub main'sbb   { &out2("sbb",@_); }
 sub main'rotl  { &out2("rol",@_); }
 sub main'rotr  { &out2("ror",@_); }
 sub main'exch  { &out2("xchg",@_); }
@@ -160,8 +161,8 @@ sub main'jne        { &out1("jne",@_); }
 sub main'jno   { &out1("jno",@_); }
 sub main'push  { &out1("push",@_); $stack+=4; }
 sub main'pop   { &out1("pop",@_); $stack-=4; }
-sub main'pushf { &out0("pushf"); $stack+=4; }
-sub main'popf  { &out0("popf"); $stack-=4; }
+sub main'pushf { &out0("pushfd"); $stack+=4; }
+sub main'popf  { &out0("popfd"); $stack-=4; }
 sub main'bswap { &out1("bswap",@_); &using486(); }
 sub main'not   { &out1("not",@_); }
 sub main'call  { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
@@ -172,6 +173,7 @@ sub main'bt { &out2("bt",@_); }
 sub main'leave { &out0("leave"); }
 sub main'cpuid  { &out0("DW\t0A20Fh"); }
 sub main'rdtsc  { &out0("DW\t0310Fh"); }
+sub main'halt  { &out0("hlt"); }
 
 # SSE2
 sub main'emms  { &out0("emms"); }
index b02de6452a49c820fb249fecfcd6ff6741544dde..27080a0f83099d1f94881f9fbd47db7b8665a0db 100644 (file)
@@ -147,6 +147,7 @@ sub main'xorb       { &out2("xor",@_); }
 sub main'add   { &out2("add",@_); }
 sub main'adc   { &out2("adc",@_); }
 sub main'sub   { &out2("sub",@_); }
+sub main'sbb   { &out2("sbb",@_); }
 sub main'rotl  { &out2("rol",@_); }
 sub main'rotr  { &out2("ror",@_); }
 sub main'exch  { &out2("xchg",@_); }
@@ -178,8 +179,8 @@ sub main'jno        { &out1("jno $near",@_); }
 
 sub main'push  { &out1("push",@_); $stack+=4; }
 sub main'pop   { &out1("pop",@_); $stack-=4; }
-sub main'pushf { &out0("pushf"); $stack+=4; }
-sub main'popf  { &out0("popf"); $stack-=4; }
+sub main'pushf { &out0("pushfd"); $stack+=4; }
+sub main'popf  { &out0("popfd"); $stack-=4; }
 sub main'bswap { &out1("bswap",@_); &using486(); }
 sub main'not   { &out1("not",@_); }
 sub main'call  { &out1("call",($_[0]=~/^\@L/?'':$under).$_[0]); }
@@ -190,6 +191,7 @@ sub main'bt { &out2("bt",@_); }
 sub main'leave { &out0("leave"); }
 sub main'cpuid { &out0("cpuid"); }
 sub main'rdtsc { &out0("rdtsc"); }
+sub main'halt  { &out0("hlt"); }
 
 # SSE2
 sub main'emms  { &out0("emms"); }
index c34cd74b7a1141730ab0618bd8f10546c949dde1..79c1abb99dad49f1e3e0b94f2384a79f4cd9b76d 100644 (file)
@@ -164,6 +164,7 @@ sub main'xorb       { &out2("xorb",@_); }
 sub main'add   { &out2("addl",@_); }
 sub main'adc   { &out2("adcl",@_); }
 sub main'sub   { &out2("subl",@_); }
+sub main'sbb   { &out2("sbbl",@_); }
 sub main'rotl  { &out2("roll",@_); }
 sub main'rotr  { &out2("rorl",@_); }
 sub main'exch  { &out2("xchg",@_); }
@@ -191,8 +192,8 @@ sub main'dec        { &out1("decl",@_); }
 sub main'inc   { &out1("incl",@_); }
 sub main'push  { &out1("pushl",@_); $stack+=4; }
 sub main'pop   { &out1("popl",@_); $stack-=4; }
-sub main'pushf { &out0("pushf"); $stack+=4; }
-sub main'popf  { &out0("popf"); $stack-=4; }
+sub main'pushf { &out0("pushfl"); $stack+=4; }
+sub main'popf  { &out0("popfl"); $stack-=4; }
 sub main'not   { &out1("notl",@_); }
 sub main'call  {       my $pre=$under;
                        foreach $i (%label)
@@ -206,6 +207,7 @@ sub main'bt { &out2("btl",@_); }
 sub main'leave { &out0("leave"); }
 sub main'cpuid { &out0(".word\t0xa20f"); }
 sub main'rdtsc { &out0(".word\t0x310f"); }
+sub main'halt  { &out0("hlt"); }
 
 # SSE2
 sub main'emms  { &out0("emms"); }
index da3e5bcaca185e112fdf1d869150251c113b9c44..894c49c0a3e359d53bd38df178235d2a6290c829 100644 (file)
@@ -38,6 +38,40 @@ require "x86asm.pl";
        &ret    ();
 &function_end_B("OPENSSL_rdtsc");
 
+# This works in Ring 0 only [read DJGPP+MS-DOS+privileged DPMI host],
+# but it's safe to call it on any [supported] 32-bit platform...
+# Just check for [non-]zero return value...
+&function_begin_B("OPENSSL_instrument_halt","EXTRN\t_OPENSSL_ia32cap_P:DWORD");
+       &picmeup("ecx","OPENSSL_ia32cap_P");
+       &bt     (&DWP(0,"ecx"),4);
+       &jnc    (&label("nohalt"));     # no TSC
+
+       &data_word(0x9058900e);         # push %cs; pop %eax
+       &and    ("eax",3);
+       &jnz    (&label("nohalt"));     # not enough privileges
+
+       &pushf  ();
+       &pop    ("eax")
+       &bt     ("eax",9);
+       &jnc    (&label("nohalt"));     # interrupts are disabled
+
+       &rdtsc  ();
+       &push   ("edx");
+       &push   ("eax");
+       &halt   ();
+       &rdtsc  ();
+
+       &sub    ("eax",&DWP(0,"esp"));
+       &sbb    ("edx",&DWP(4,"esp"));
+       &add    ("esp",8);
+       &ret    ();
+
+&set_label("nohalt");
+       &xor    ("eax","eax");
+       &xor    ("edx","edx");
+       &ret    ();
+&function_end_B("OPENSSL_instrument_halt");
+
 &initseg("OPENSSL_cpuid_setup");
 
 &asm_finish();