admin管理员组文章数量:1356753
Does this:
mov al, 0ffh
in al, dx
always do the same as this:
in al, dx
So, is the mov al, 0ffh
redundant, and does an in al, dx
instruction always set the value of AL, never keeping the previous value?
If there are differences within the CPU product line (8086, 186, 286, 386, 486, Pentium and beyond), please highlight them.
Does this:
mov al, 0ffh
in al, dx
always do the same as this:
in al, dx
So, is the mov al, 0ffh
redundant, and does an in al, dx
instruction always set the value of AL, never keeping the previous value?
If there are differences within the CPU product line (8086, 186, 286, 386, 486, Pentium and beyond), please highlight them.
Share Improve this question edited Mar 29 at 17:31 Sep Roland 39.9k10 gold badges48 silver badges88 bronze badges asked Mar 28 at 1:18 ptspts 87.7k23 gold badges115 silver badges198 bronze badges 2 |1 Answer
Reset to default 4in al, dx
always over writes AL, same as mov al, src
.
Unless it faults, in which case AL has its previous value when the CPU jumps to the fault handler.
In protected mode, user-space can't run I/O instructions like in
unless the IO privilege level is elevated to 0
, or if specific ports are allowed in an I/O bitmap. (Linux ioperm(2)
to allow specific ports in a limited range, iopl(2)
to change IO privilege level). IO privilege level is separate from the current privilege level in the low bits of the CS selector, so e.g. you can let user-space run cli
on this core (potentially getting it stuck other than NMIs) without letting it run invd
and break cache coherency system-wide.
So anyway, faulting with #GP(0)
due to privilege level is one way for in
to fault. Apparently (https://www.felixcloutier/x86/in#64-bit-mode-exceptions) it can also fault with #PF in protected or 64-bit mode. The description section doesn't say how; the port number is in I/O address-space so isn't translated. I wonder if maybe this entry used to also document (rep
) ins
which writes to ES:rDI
and thus can #PF on the memory destination, and maybe they fot to take out #PF
when splitting ins
to its own entry.
Protected mode was new in 286, and 386 changed it a bit.
In real mode, it can't fault other than with #UD
(if lock
prefix is used).
本文标签: assemblyDoes reading from an IO port on x86 always set ALStack Overflow
版权声明:本文标题:assembly - Does reading from an IO port on x86 always set AL? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744061197a2584153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
al
would be a default value. Far fetched, but possible. – Jester Commented Mar 28 at 1:38