Re: issue about SHRD in Bochs

ht-lab <[email protected]> Fri, 10 May 2019 17:35:32 +0100
Newsgroups gmane.comp.emulators.bochs.devel
Organization ht-lab
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============0379694704036273498==
Content-Type: multipart/alternative;
 boundary="------------1B7EAB7020B8A7F17B8447CD"
Content-Language: en-GB

This is a multi-part message in MIME format.
--------------1B7EAB7020B8A7F17B8447CD
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi Ross,

Why does it matter? the behaviour is undefined so Bochs simply uses the 
same code. I suspect the hardware does exactly the same, they use the 
same hardware but the results are incorrect, hence undefined.

Are you trying to use the undefined behaviour to detect CPU type/make?

Regards,
Hans
www.ht-lab.com


On 10/05/2019 06:53, 温冀烨 via bochs-developers wrote:
>
> Hi guys,
>
> This is Ross. I’m an X86 programmer and quite interested in Bochs .
>
> Recent study on Intel SHRD instruction brought me some questions about 
> how does Bochs emulates the “undefined behaviors”described in Intel® 
> 64 and IA-32 Architectures Software Developer’s Manual.
>
> Follow statement talks that for shifts greater than 1 bit, the OF flag 
> is undefined.
>
> cid:[email protected]
>
> The read lines indicates that Bochs treats the OF flag in other way. 
>  So what’s your comments about? J
>
> /void BX_CPP_AttrRegparmN(1) BX_CPU_C::SHRD_EqGqR(bxInstruction_c *i)
> {
>   Bit64u op1_64, op2_64, result_64;
>   unsigned count;
>   unsigned cf, of;
>
> //…
>     result_64 = (op2_64 << (64 - count)) | (op1_64 >> count);
>     BX_WRITE_64BIT_REG(i->dst(), result_64);
>     SET_FLAGS_OSZAPC_LOGIC_64(result_64);
>
>     cf = (op1_64 >> (count - 1)) & 0x1;
>     of = ((result_64 << 1) ^ result_64) >> 63; // of = result62 ^ result63
>     BX_CPU_THIS_PTR oszapc.set_flags_OxxxxC(of, cf);
>   }
>
>   BX_NEXT_INSTR(i);
> }/
>
>
>
> _______________________________________________
> bochs-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bochs-developers


--------------1B7EAB7020B8A7F17B8447CD
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hi Ross,<br>
      <br>
      Why does it matter? the behaviour is undefined so Bochs simply
      uses the same code. I suspect the hardware does exactly the same,
      they use the same hardware but the results are incorrect, hence
      undefined. <br>
      <br>
      Are you trying to use the undefined behaviour to detect CPU
      type/make?<br>
      <br>
      Regards,<br>
      Hans<br>
      <a class="moz-txt-link-abbreviated" href="http://www.ht-lab.com">www.ht-lab.com</a><br>
      <br>
      <br>
      On 10/05/2019 06:53, 温冀烨 via bochs-developers wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:[email protected]">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]-->
      <style><!--
/* Font Definitions */
@font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:SimSun;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:DengXian;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:"Microsoft YaHei";
	panose-1:2 11 5 3 2 2 4 2 2 4;}
@font-face
	{font-family:SimSun;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
	{font-family:"Microsoft YaHei";}
@font-face
	{font-family:DengXian;
	panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	font-size:10.5pt;
	font-family:DengXian;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
.MsoChpDefault
	{mso-style-type:export-only;}
/* Page Definitions */
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style>
      <div class="WordSection1">
        <p class="MsoNormal"><span
            style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
            lang="EN-US">Hi guys,</span><span
            style="font-size:12.0pt;font-family:SimSun" lang="EN-US"><o:p></o:p></span></p>
        <p><span
            style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
            lang="EN-US">This is Ross. I</span><span
            style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif">’<span
              lang="EN-US">m an X86 programmer and quite interested in
              Bochs . </span></span></p>
        <div>
          <div>
            <p class="MsoNormal"
              style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
                lang="EN-US">Recent study on Intel SHRD instruction
                brought me some questions about how does Bochs emulates
                the </span><span
                style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif">“<span
                  lang="EN-US">undefined behaviors</span>”<span
                  lang="EN-US"> described in Intel® 64 and IA-32
                  Architectures Software Developer</span>’<span
                  lang="EN-US">s Manual. </span></span><span
                lang="EN-US"><o:p></o:p></span></p>
            <p class="MsoNormal"
              style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
                lang="EN-US"> </span><span lang="EN-US"><o:p></o:p></span></p>
            <p class="MsoNormal"
              style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
                lang="EN-US">Follow statement talks that for shifts
                greater than 1 bit, the OF flag is undefined. </span><span
                lang="EN-US"><o:p></o:p></span></p>
            <p><span
                style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
                lang="EN-US"><img style="width:7.4687in;height:1.302in"
                  id="_x0000_i1025"
                  src="cid:[email protected]"
                  alt="cid:[email protected]"
                  moz-do-not-send="true" width="717" height="125"></span></p>
            <p><span
style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif;color:red"
                lang="EN-US">The read lines indicates that Bochs treats
                the OF flag in other way.  So what</span><span
style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif;color:red">’<span
                  lang="EN-US">s your comments about? </span></span><span
                style="font-size:9.0pt;font-family:Wingdings;color:red"
                lang="EN-US">J</span></p>
            <p><i><span
                  style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif"
                  lang="EN-US">void BX_CPP_AttrRegparmN(1)
                  BX_CPU_C::SHRD_EqGqR(bxInstruction_c *i)<br>
                  {<br>
                    Bit64u op1_64, op2_64, result_64;<br>
                    unsigned count;<br>
                    unsigned cf, of;<br>
                  <br>
                    </span></i><i><span
                  style="font-size:9.0pt;font-family:&quot;微软雅黑&quot;,sans-serif">…<span
                    lang="EN-US"> <br>
                        result_64 = (op2_64 &lt;&lt; (64 - count)) |
                    (op1_64 &gt;&gt; count);<br>
                        BX_WRITE_64BIT_REG(i-&gt;dst(), result_64);<br>
                        SET_FLAGS_OSZAPC_LOGIC_64(result_64);<br>
                    <br>
                    <span style="color:red">    cf = (op1_64 &gt;&gt;
                      (count - 1)) &amp; 0x1;<br>
                          of = ((result_64 &lt;&lt; 1) ^ result_64)
                      &gt;&gt; 63; // of = result62 ^ result63<br>
                          BX_CPU_THIS_PTR oszapc.set_flags_OxxxxC(of,
                      cf);</span><br>
                      }<br>
                    <br>
                      BX_NEXT_INSTR(i);<br>
                    }</span></span></i></p>
          </div>
        </div>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
            style="font-size:12.0pt;font-family:SimSun;color:black"
            lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
bochs-developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/bochs-developers">https://lists.sourceforge.net/lists/listinfo/bochs-developers</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>

--------------1B7EAB7020B8A7F17B8447CD--


--===============0379694704036273498==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============0379694704036273498==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
bochs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bochs-developers

--===============0379694704036273498==--