Replace invalid characters with HTML entities

— with —
’ with ’
+ with +
× with x
ç with ç
“ with “
” with ”
‘ with ‘
• with •
– with -
µ with µ
† with †
Fix C++
θ with θ
Yen symbol instead of times
Fix broken apos
Bullet again
E-circumflex
This commit is contained in:
James Gregory 2013-12-30 12:50:32 +11:00
commit 500e7f5654
353 changed files with 5091 additions and 5091 deletions

View file

@ -36,12 +36,12 @@
</TABLE>
</CENTER>
<P><BR></P>
<P>Well, there&#146;s only one instruction other than <B>POPF</B> that loads the FLAGS register directly from the stack, and that&#146;s <B>IRET</B>, which loads the FLAGS register from the stack as it branches, as shown in Figure 11.5. iret has no known bugs of the sort that plague <B>POPF</B>, so it&#146;s certainly a candidate to replace popf in non-interruptible applications. Unfortunately, <B>IRET</B> loads the FLAGS register with the <I>third</I> word down on the stack, not the word on top of the stack, as is the case with <B>POPF</B>; the far return address that <B>IRET</B> pops into CS:IP lies between the top of the stack and the word popped into the FLAGS register.</P>
<P>Obviously, the segment:offset that <B>IRET</B> expects to find on the stack above the pushed flags isn&#146;t present when the stack is set up for <B>POPF</B>, so we&#146;ll have to adjust the stack a bit before we can substitute <B>IRET</B> for <B>POPF</B>. What we&#146;ll have to do is push the segment:offset of the instruction after our workaround code onto the stack right above the pushed flags. <B>IRET</B> will then branch to that address and pop the flags, ending up at the instruction after the workaround code with the flags popped. That&#146;s just the result that would have occurred had we executed <B>POPF</B>&#151;WITH the bonus that no interrupts can accidentally occur when the Interrupt flag is 0 both before and after the pop.</P>
<P>Well, there&rsquo;s only one instruction other than <B>POPF</B> that loads the FLAGS register directly from the stack, and that&rsquo;s <B>IRET</B>, which loads the FLAGS register from the stack as it branches, as shown in Figure 11.5. iret has no known bugs of the sort that plague <B>POPF</B>, so it&rsquo;s certainly a candidate to replace popf in non-interruptible applications. Unfortunately, <B>IRET</B> loads the FLAGS register with the <I>third</I> word down on the stack, not the word on top of the stack, as is the case with <B>POPF</B>; the far return address that <B>IRET</B> pops into CS:IP lies between the top of the stack and the word popped into the FLAGS register.</P>
<P>Obviously, the segment:offset that <B>IRET</B> expects to find on the stack above the pushed flags isn&rsquo;t present when the stack is set up for <B>POPF</B>, so we&rsquo;ll have to adjust the stack a bit before we can substitute <B>IRET</B> for <B>POPF</B>. What we&rsquo;ll have to do is push the segment:offset of the instruction after our workaround code onto the stack right above the pushed flags. <B>IRET</B> will then branch to that address and pop the flags, ending up at the instruction after the workaround code with the flags popped. That&rsquo;s just the result that would have occurred had we executed <B>POPF</B>&mdash;WITH the bonus that no interrupts can accidentally occur when the Interrupt flag is 0 both before and after the pop.</P>
<P><A NAME="Fig4"><!-- </A><A HREF="javascript:displayWindow('images/11-04.jpg',412,383 )"> --><IMG SRC="images/11-04.jpg"><BR><!-- </A>
<BR><A HREF="javascript:displayWindow('images/11-04.jpg',412,383)"> --><FONT COLOR="#000077"><B>Figure 11.4</B></FONT></A>&nbsp;&nbsp;<I>The operation of POPF.</I>
</P>
<P>How can we push the segment:offset of the next instruction? Well, finding the offset of the next instruction by performing a near call to that instruction is a tried-and-true trick. We can do something similar here, but in this case we need a far call, since <B>IRET</B> requires both a segment and an offset. We&#146;ll also branch backward so that the address pushed on the stack will point to the instruction we want to continue with. The code works out like this:</P>
<P>How can we push the segment:offset of the next instruction? Well, finding the offset of the next instruction by performing a near call to that instruction is a tried-and-true trick. We can do something similar here, but in this case we need a far call, since <B>IRET</B> requires both a segment and an offset. We&rsquo;ll also branch backward so that the address pushed on the stack will point to the instruction we want to continue with. The code works out like this:</P>
<!-- CODE //-->
<PRE>
jmpshort popfskip
@ -81,25 +81,25 @@ popfskip:
endm
</PRE>
<!-- END CODE //-->
<P>By the way, the flags can be popped much more quickly if you&#146;re willing to alter a register in the process. For example, the following macro emulates <B>POPF</B> with just one branch, but wipes out AX:</P>
<P>By the way, the flags can be popped much more quickly if you&rsquo;re willing to alter a register in the process. For example, the following macro emulates <B>POPF</B> with just one branch, but wipes out AX:</P>
<!-- CODE SNIP //-->
<PRE>
EMULATE_POPF_TRASH_AX macro
push cs
mov ax,offset $&#43;5
mov ax,offset $+5
push ax
iret
endm
</PRE>
<!-- END CODE SNIP //-->
<P>It&#146;s not a perfect substitute for <B>POPF</B>, since <B>POPF</B> doesn&#146;t alter any registers, but it&#146;s faster and shorter than <B>EMULATE_POPF</B> when you can spare the register. If you&#146;re using 286-specific instructions, you can use which is shorter still, alters no registers, and branches just once. (Of course, this version of <B>EMULATE_POPF</B> won&#146;t work on an 8088.)</P>
<P>It&rsquo;s not a perfect substitute for <B>POPF</B>, since <B>POPF</B> doesn&rsquo;t alter any registers, but it&rsquo;s faster and shorter than <B>EMULATE_POPF</B> when you can spare the register. If you&rsquo;re using 286-specific instructions, you can use which is shorter still, alters no registers, and branches just once. (Of course, this version of <B>EMULATE_POPF</B> won&rsquo;t work on an 8088.)</P>
<!-- CODE SNIP //-->
<PRE>
.286
:
EMULATE_POPFmacro
pushcs
pushoffset $&#43;4
pushoffset $+4
iret
endm
</PRE>
@ -107,8 +107,8 @@ EMULATE_POPFmacro
<P><A NAME="Fig6"><!-- </A><A HREF="javascript:displayWindow('images/11-06.jpg',409,447 )"> --><IMG SRC="images/11-06.jpg"><BR><!-- </A>
<BR><A HREF="javascript:displayWindow('images/11-06.jpg',409,447)"> --><FONT COLOR="#000077"><B>Figure 11.6</B></FONT></A>&nbsp;&nbsp;<I>Workaround code for the POPF bug.</I>
</P>
<P>The standard version of <B>EMULATE_POPF</B> is 6 bytes longer than <B>POPF</B> and much slower, as you&#146;d expect given that it involves three branches. Anyone in his/her right mind would prefer <B>POPF</B> to a larger, slower, three-branch macro&#151;given a choice. In noncode, however, there&#146;s no choice here; the safer&#151;if slower&#151;approach is the best. (Having people associate your programs with crashed computers is <I>not</I> a desirable situation, no matter how unfair the circumstances under which it occurs.)</P>
<P>And now you know the nature of and the workaround for the <B>POPF</B> bug. Whether you ever need the workaround or not, it&#146;s a neatly packaged example of the tremendous flexibility of the x86 instruction set.</P><P><BR></P>
<P>The standard version of <B>EMULATE_POPF</B> is 6 bytes longer than <B>POPF</B> and much slower, as you&rsquo;d expect given that it involves three branches. Anyone in his/her right mind would prefer <B>POPF</B> to a larger, slower, three-branch macro&mdash;given a choice. In noncode, however, there&rsquo;s no choice here; the safer&mdash;if slower&mdash;approach is the best. (Having people associate your programs with crashed computers is <I>not</I> a desirable situation, no matter how unfair the circumstances under which it occurs.)</P>
<P>And now you know the nature of and the workaround for the <B>POPF</B> bug. Whether you ever need the workaround or not, it&rsquo;s a neatly packaged example of the tremendous flexibility of the x86 instruction set.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>