从何处获得硬件的I/O端口地址分配? [英] Where to get the I/O port addresses assignment for hardware?

查看:185
本文介绍了从何处获得硬件的I/O端口地址分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在学习汇编语言,而且我已经知道如何使用in/out命令.但是我有一些问题:

  • 端口地址从何而来,例如0x70?
  • 我怎么知道我的计算机有多少个端口及其地址?

我已经查看了英特尔开发人员手册,但是找不到答案.

解决方案

最多有65536个IO端口,并且大多数未使用.

现代PC上使用的IO端口可以分为两类:PCI设备和旧式设备.

对于PCI设备;每个设备(PCI规范所用术语中的功能")都有一些配置空间,其中包含"BAR"(基址寄存器).每个BAR表示设备使用的区域是在物理地址空间还是IO端口空间中;如果它在IO端口空间中,BAR会告诉您每个基本IO端口有多少个IO端口.可以将它们设置为任何值(如果有理由,软件可以更改设置-通常情况下,固件会在操作系统启动之前对其进行设置).

旧版设备(在采用PCI之前内置于主板或通过ISA总线连接的设备,但现在可能仍然存在)使用固定的IO端口.例如,主PIC控制器(如果存在)将始终使用IO端口0x20和0x21.理想地;您将决定支持旧版设备并查看其文档,其文档将告诉您要使用哪个IO端口以及它们的功能.请注意(由于ISA总线限制),所有这些IO端口都将小于或等于0x3FF.对于现代计算机,还应在尝试使用设备之前(使用ACPI表)检查该设备是否存在.当然,如果您不为旧版设备编写设备驱动程序,则实际上不需要关心其IO端口可能是什么.

注1:对于具有ISA插槽的计算机(例如,比1990年代中期更旧的计算机),您可以插入任何类型的ISA卡;而且,每张卡所使用的IO端口通常由卡本身上的一些"DIP开关"控制.软件(操作系统)无法自动检测设备的IO端口(也无法自动检测存在的设备).解决此问题的唯一方法是要求用户告诉您,并希望他们记住并正确设置(并将详细信息存储在配置文件中).这对每个人来说都是可怕的,幸运的是后来的总线(PCI)避免了这个问题.

注2:实际上有一个即插即用ISA"规范(来自Microsoft),添加了一种自动检测ISA设备及其资源(例如IO端口)的方法.对于支持此规范的ISA卡而言,无论是好是坏,这种情况都很少见.主要是因为PCI在大多数制造商试图支持它之前就已经出现了.既然ISA插槽已经过时了(我们剩下一些带有固定IO端口的主板内置部件),就没有必要支持它了(或者说是一般的ISA插槽).

注3:我忽略了某些PC上(简短地)存在的其他总线类型(EISA,MCA).这些在使用时并不常见,现在极少出现(例如,您可能会在博物馆的某个地方找到这样的作品,但是它们不会让您将其带回家以对其上的软件进行测试).

注4:一些CPU(主要是1980年代末和1990年代初来自Cryix和IBM的CPU)为CPU本身使用了一些IO端口,并将它们用作各种功能(CPU功能和缓存控制)的配置寄存器. .再次;现在太老了,没关系了.

I have been learning assembly language recently, and I already know how to use the in/out command. But I have some questions:

  • Where did the port addresses come from, like 0x70?
  • How do I know how many ports my computer has and the addresses of them?

I've checked the Intel developer's manual, but I can't find the answer.

解决方案

There's a maximum of 65536 IO ports, and most aren't used.

The IO ports that are used on a modern PC can be split into 2 categories: PCI devices and legacy devices.

For PCI devices; each device ("function" in the terminology used by PCI specs) has some configuration space which contains "BARs" (Base Address Register/s). Each BAR says if the area used by the device is in the physical address space or the IO port space; and if it's in the IO port space the BAR will tell you how many IO ports at which base IO port. These can be set to anything (and software can change the setting if it has a reason to - normally firmware sets them up before the OS starts).

Legacy devices (things that were built into the motherboard or connected via. ISA bus before PCI was adopted but may still exist now) use fixed IO ports. For example, the master PIC controller (if it exists) will always use IO ports 0x20 and 0x21. Ideally; you'd decide to support a legacy device and check its documentation, and its documentation will tell you which IO port/s to use and what they do. Note that (because of ISA bus restrictions) all of these IO ports will be less than or equal to 0x3FF. For modern computers, you should also check (using ACPI tables) that the device exists before attempting to use it. Of course if you're not writing a device driver for a legacy device you don't really need to care what its IO port/s might be.

Note 1: For a computer with ISA slots (e.g. older than mid 1990s) you could have any kind of ISA card plugged in; and the IO ports used by each card was often controlled by little "DIP swiches" on the card itself. There was no way for software (an OS) to auto-detect a device's IO ports (and no way to auto-detect that a device was present). The only way around this problem is to ask the user to tell you and hope they remember and get it right (and storing the details in a configuration file). This was horrible for everyone, and fortunately later buses (PCI) avoided the problem.

Note 2: There actually was a "Plug and Play ISA" specification (from Microsoft) to add a means of auto-detecting ISA devices and their resources (e.g. IO ports). For better or worse ISA cards that support this specification are extremely rare; mostly because PCI arrived before most manufacturers tried to support it. Now that ISA slots are obsolete (and we're left with a few legacy pieces built into the motherboard with fixed IO ports) there's no point supporting this (or ISA slots in general).

Note 3: I'm ignoring other bus types (EISA, MCA) that existed (briefly) on some PCs. These were uncommon when they were being used and extremely rare now (e.g. you might find one that works in a museum somewhere, but they won't let you take it home to test your software on it).

Note 4: Some CPUs (mostly from Cryix and IBM in the late 1980s and early 1990s) used a few IO ports for the CPU itself and used them as configuration registers for various things (CPU features and cache control). Again; it's all too old to matter now.

这篇关于从何处获得硬件的I/O端口地址分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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