什么是 IN &OUT 指令在 x86 中是做什么用的? [英] What are IN & OUT instructions in x86 used for?

查看:29
本文介绍了什么是 IN &OUT 指令在 x86 中是做什么用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将这些内容与 IN &在阅读Understanding Linux Kernel"一书时退出.我查过参考手册.

I've encoutered these to instructions IN & OUT while reading "Understanding Linux Kernel" book. I've looked up reference manual.

5.1.9 I/O 说明

这些指令在处理器的 I/O 端口和一个寄存器或内存.

These instructions move data between the processor’s I/O ports and a register or memory.

IN    Read from a port
OUT   Write to a port
INS/INSB  Input string from port/Input byte string from port 
INS/INSW  Input string from port/Input word string from port 
INS/INSD  Input string from port/Input doubleword string from port
OUTS/OUTSB    Output string to port/Output byte string to port 
OUTS/OUTSW    Output string to port/Output word string to port 
OUTS/OUTSD    Output string to port/Output doubleword string to port

我没有得到一些东西:

  1. 处理器的 I/O 端口".这些是什么?我们为什么要阅读 &将字符串"写入 &从这些端口?
  2. 我从未遇到过需要使用这些说明的场景.我什么时候需要这些?
  3. 举一些实际例子.

推荐答案

您知道内存寻址的工作原理吗?有地址总线、数据总线和一些控制线.CPU 将内存的一个字节(或起始字节)的地址放在地址总线上,然后升高 READ 信号,一些 RAM 芯片希望通过升高或降低单个行(对应于位)来返回该地址处的内存内容在数据总线上的字节中.这适用于 RAM 和 ROM.

You know how memory addressing works? There's an address bus, a data bus, and some control lines. The CPU puts the address of a byte (or a beginning byte) of memory on the address bus, then raises the READ signal, and some RAM chip hopefully returns the contents of memory at that address by raising or lowering individual lines (corresponding to bits in the byte(s)) on the data bus. This works for both RAM and ROM.

但是还有 I/O 设备:串行和并行端口、PC 微型内部扬声器的驱动程序、磁盘控制器、声音芯片等等.这些设备也可以读取和写入.它们还需要被寻址,以便 CPU 访问正确的设备和(通常)给定设备内的正确数据位置.

But then there are also I/O devices: Serial and parallel ports, the driver for a PC's tiny internal speaker, disk controllers, sound chips and so on. And those devices also get read from and written to. They also need to be addressed so the CPU accesses the correct device and (usually) the correct data location within a given device.

对于某些 CPU 型号,包括大多数现代"PC 中的 xxx86 系列,I/O 设备与内存共享地址空间.RAM/ROM 和 IO 设备都连接到相同的地址、数据和控制线.例如,COM1 的串行端口从 (hex) 03F8 开始寻址.但几乎可以肯定在同一地址有内存.

For some CPU models including the xxx86 series as found in most "modern" PCs, I/O devices share the address space with memory. Both RAM/ROM and IO devices are connected to the same address, data and control lines. For example, the serial port for COM1 is addressed starting at (hex) 03F8. But there's almost certainly memory at the same address.

这是一个非常简单的图表:

Here's a really simple diagram:

[]

很明显,CPU 需要与内存或 I/O 设备对话,而不是同时与两者对话.为了区分这两者,称为M/#IO"的控制线之一断言 CPU 想要与内存(line=high)还是 I/O 设备(line=low)交谈.

Clearly the CPU needs to talk to either memory or the I/O device, never both. To distinguish between the two, one of the control lines called "M/#IO" asserts whether the CPU wants to talk to memory (line=high) or an I/O device (line=low).

IN 指令从 I/O 设备读取,OUT 写入.当您使用 IN 或 OUT 指令时,M/#IO 不会断言(保持低电平),因此内存不会响应,而 I/O 芯片会响应.对于面向内存的指令,M/#IO 被断言,因此 CPU 与 RAM 对话,并且 IO 设备远离通信.

The IN instruction reads from an I/O device, OUT writes. When you use the IN or OUT instructions, the M/#IO is not asserted (held low), so memory doesn't respond and the I/O chip does. For the memory-oriented instructions, M/#IO is asserted so CPU talks to the RAM, and IO devices stay out of the communication.

在一定条件下,IO 设备可以驱动数据线,同时 RAM 可以读取它们.反之亦然.这就是所谓的 DMA.

Under certain conditions the IO devices can drive the data lines and the RAM can read them at the same time. And vice versa. It's called DMA.

传统上,串行和打印机端口以及键盘、鼠标、温度传感器等都是 I/O 设备.磁盘介于两者之间.数据传输将由 I/O 命令启动,但磁盘控制器通常会将其数据直接存放在系统内存中.

Traditionally, serial and printer ports, as well as keyboard, mouse, temperature sensors and so forth were I/O devices. Disks were sort of in between; data transfers would be initiated by I/O commands but the disk controller would usually direct-deposit its data in system memory.

在 Windows 或 Linux 等现代操作系统中,对 I/O 端口的访问隐藏在普通"用户程序之外,并且有软件层、特权指令和驱动程序来处理硬件.所以在本世纪,大多数程序员不处理这些指令.

In modern operating systems like Windows or Linux, access to I/O ports is hidden away from "normal" user programs, and there are layers of software, privileged instructions and drivers to deal with the hardware. So in this century, most programmers don't deal with those instructions.

这篇关于什么是 IN &OUT 指令在 x86 中是做什么用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆