<div class="gmail_quote">On Wed, Aug 10, 2011 at 11:54 AM, Andreas Färber <span dir="ltr"><<a href="mailto:andreas.faerber@web.de">andreas.faerber@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Am 10.08.2011 um 17:48 schrieb William Hahne:<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, Aug 10, 2011 at 6:00 AM, Mark Cave-Ayland <<a href="mailto:mark.cave-ayland@siriusit.co.uk" target="_blank">mark.cave-ayland@siriusit.co.<u></u>uk</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 09/08/11 22:55, William Hahne wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It is possible for BootX to purposefully divide by zero expecting 0 as<br>
the result.<br>
<br>
Index: kernel/forth.c<br>
==============================<u></u>==============================<u></u>=======<br>
--- kernel/forth.c (revision 1041)<br>
+++ kernel/forth.c (working copy)<br>
@@ -1157,6 +1157,12 @@<br>
 {<br>
const ucell b = POP();<br>
const ducell a = DPOP();<br>
+<br>
+ if (b == 0) { // can't divide by zero<br>
+            PUSH(0);<br>
+            DPUSH(0);<br>
+            return;<br>
+ }<br>
 #ifdef NEED_FAKE_INT128_T<br>
         if (a.hi != 0) {<br>
             fprintf(stderr, "mudivmod called (0x%016llx %016llx /<br>
0x%016llx)\n",<br>
</blockquote>
<br>
There is something wrong here: nothing will purposefully divide by zero as it will invoke a trap somewhere. Again, I think this is hiding another bug somewhere and is not necessarily the correct fix.<br>
</blockquote>
<br>
You would be surprised then, if you type "0 0 /" into a OF mac you will get 0. I thought it was a bug as well at first but after carefully looking at the source code for BootX I found that it wasn't. This is probably just a peculiarity of Apple's OF implementation.<br>

</blockquote>
<br></div>
I'd rather think this is an architectural difference: On ppc, divwo sets the OV bit in XER but divw doesn't, PowerISA 2.06B saying that the result of the division is undefined in both cases.<br>
<br>
On POWER5 I do get zero as well, so it's not just Apple.<br>
<br>
0 > 0 0 /  ok<br>
1 > . 0  ok<br>
<br>
I'd suggest to stick the new code fragment into an appropriate ppc #ifdef if sparc does it differently.<br><font color="#888888">
<br>
Andreas</font><div><div></div><div class="h5"><br></div></div></blockquote><div><br></div><div>That makes sense. Here is a patch with an appropriate #ifdef added.</div><div> </div><div><div>Index: kernel/forth.c</div><div>
===================================================================</div><div>--- kernel/forth.c      (revision 1046)</div><div>+++ kernel/forth.c      (working copy)</div><div>@@ -1157,6 +1157,17 @@</div><div> {</div><div>
        const ucell b = POP();</div><div>        const ducell a = DPOP();</div><div>+</div><div>+#if defined(CONFIG_PPC) || defined(CONFIG_PPC64)</div><div>+       /* PPC OF provides a result of 0 after a division by zero</div>
<div>+           rather than an exception */</div><div>+        if (b == 0) {</div><div>+            PUSH(0);</div><div>+            DPUSH(0);</div><div>+            return;</div><div>+       }</div><div>+#endif</div><div>
+</div><div> #ifdef NEED_FAKE_INT128_T</div><div>         if (a.hi != 0) {</div><div>             fprintf(stderr, "mudivmod called (0x%016llx %016llx / 0x%016llx)\n",</div></div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div class="h5">
<br>
-- <br>
OpenBIOS                 <a href="http://openbios.org/" target="_blank">http://openbios.org/</a><br>
Mailinglist:  <a href="http://lists.openbios.org/mailman/listinfo" target="_blank">http://lists.openbios.org/<u></u>mailman/listinfo</a><br>
Free your System - May the Forth be with you<br></div></div></blockquote><div><br></div><div>William Hahne </div></div><br>