CPU如何与外围设备通信? [英] How does cpu communicate with peripherals?

查看:243
本文介绍了CPU如何与外围设备通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假设cpu可以直接访问主板的BIOS和RAM。(如果我错了,请纠正我)

i assume cpu has direct access to motherboard's BIOS and RAM.(correct me if i'm wrong)

但是cpu如何与其他硬件(例如hdds)通信,扩展卡,外围设备,其他BIOS等。

But how does cpu communicate with other hardware like hdds, expansion cards, peripherals, other BIOSes etc.?

我了解OS及其驱动程序,但它们是软件-它们位于RAM中。
cpu如何在硬件级别上与所有这些硬件通信?
不仅限于主板的BIOS和RAM吗?

I know about OS and its drivers, but they are software- they're in RAM. How does cpu communicate with all this hardware on hardware level? Isn't it limited to only motherboard's BIOS and RAM?

推荐答案

在较旧的体系结构中,外设是通过a具有特殊I / O指令的独立的内存访问机制。在x86上,存在(现在仍然是!) in和 out指令,用于在CPU和外围设备之间传输字节。为外围设备分配了地址,例如键盘的0x80。简化很多,执行 in 0x80将从键盘控制器读取一个字节到CPU寄存器 AL。

In older architectures, peripherals were accessed via a separate mechanism to memory access with special I/O instructions. On x86, there were (and still are!) "in" and "out" instructions for transferring bytes between the CPU and a peripheral. Peripherals were given addresses, for example 0x80 for the keyboard. Simplifying a lot, doing "in 0x80" would read a byte from the keyboard controller to CPU register "AL".

在现代体系结构中,以类似方式访问外设到内存:通过总线上的映射内存地址。您不应该将总线视为访问内存的一种方式。这是一种解决单个外围设备的方法,其中的内存(RAM / DDR)只是其中一种。例如,您可能在地址0x00000000..0x7fffffff处有2GB的RAM。之后,您可能会在0x80000000..0x80001fff处拥有一张图形卡。总线控制器(PCIe或其他)知道哪个地址范围到达哪个外围设备。

On modern architectures, peripherals are accessed in a similar way to memory: via mapped memory addresses on a bus. You shouldn't think of a bus as a way to access memory. It's more a way to address individual peripherals, of which memory (RAM/DDR) is just one type. For example, you might have 2GB of RAM at addresses 0x00000000..0x7fffffff. After that you might have a graphics card at 0x80000000..0x80001fff. The bus controller (PCIe or whatever) knows which address ranges go to which peripheral.

内存通常很特殊,因为它可以缓存,因此可以对内存进行单独的读/写操作往往不会直接转换为对RAM芯片的单独读取/写入。外围设备被标记为特殊设备-CPU访问应该完全按照您的程序中的说明进行。

Memory is usually special in that it can be cached, so individual reads/writes to memory tend not to translate directly to individual reads/writes to the RAM chips. Peripherals are marked as special - CPU accesses should go out to the peripheral exactly as written in your program.

您与外围设备通信的语言是临时的,具体取决于在设备上。一般主题是外围设备映射到内存中的某个位置(例如,上面的几个KB为0x80000000),状态的各个位和操作由不同的字控制(通常为32位或64位)。串行端口为0x80000000的一个神话示例:

The language you talk to peripherals with is pretty much ad-hoc depending on the device. The general theme is that the peripheral is mapped somewhere in memory (e.g 0x80000000 for a few KB as above), with individual bit of state and actions controlled by different words (usually 32 or 64bit). A mythical example of a serial port at 0x80000000:


  • 将32位字 A写为0x80000000,将其中的字符 A排队输出FIFO。

  • 将32位字0x1写入0x80000004,告诉串行端口发送其队列。

完全是为了弥补问题,但真正的串行端口(uart)并没有什么不同。

Again, totally made up just for sake of example, but a real serial port (uart) isn't all that different.

麻烦是您由于存在虚拟内存,因此在现代操作系统中实际上不会查看任何上述内存布局。上面的地址将被称为物理内存地址(或总线地址)-传到总线上的实际地址。 CPU而是查看虚拟内存地址。各个外围设备将需要映射到虚拟地址空间。这种解释很复杂,在另一个问题中可能最好解决,但要点是,您不太可能通过现代操作系统中的外围设备实际物理地址来访问它。

The trouble is you won't actually see any of the above memory layout in a modern OS, because of virtual memory. The addresses above would be referred to as "physical memory addresses" (or bus addresses) - the actual addresses that go out onto the bus. The CPU instead sees virtual memory addresses. Individual peripherals will need to be mapped into virtual address space. This is kind of complicated to explain and probably best off in another Question, but the point is you're unlikely to access a peripheral by its actual physical address in a modern OS.

这篇关于CPU如何与外围设备通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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