OSTEP / Persistence-Disk




  1. memory bus 连接内存和CPU
  2. general IO bus(PCI) 接入一些高性能IO设备比如显卡. 通常这些设备体积不大.
  3. peripheral IO bus(SATA/USB) 接入一些慢速设备比如键盘和鼠标等.

CPU和设备交互方式通常有两种: Port IO和MMIO(Memory Mapped IO).

I/O作为CPU和外设交流的一个渠道,主要分为两种,一种是Port I/O,一种是MMIO(Memory mapping I/O)。


Port I/O和MMIO的主要区别在于1)前者不占用CPU的物理地址空间,后者占有(这是对x86架构说的,一些架构,如IA64,port I/O占用物理地址空间)。2)前者是顺序访问。也就是说在一条I/O指令完成前,下一条指令不会执行。例如通过Port I/O对设备发起了操作,造成了设备寄存器状态变化,这个变化在下一条指令执行前生效。uncache的MMIO通过uncahce memory的特性保证顺序性。

驱动程序代码在内核代码中占相当大的比例, 也是许多内核bug的根源.

Interestingly, because device drivers are needed for any device you might plug into your system, over time they have come to represent a huge percentage of kernel code. Studies of the Linux kernel reveal that over 70% of OS code is found in device drivers [C01]; for Windows-based systems, it is likely quite high as well. Thus, when people tell you that the OS has millions of lines of code, what they are really saying is that the OS has millions of lines of device-driver code. Of course, for any given installation, most of that code may not be active (i.e., only a few devices are connected to the system at a time). Perhaps more depressingly, as drivers are often written by “amateurs” (instead of full-time kernel developers), they tend to have many more bugs and thus are a primary contributor to kernel crashes [S03].