assembly - 如何在 MS-DOS x86 汇编语言中检测 16550 UART 芯片?
问题描述
我正在尝试研究如何在 MS-DOS 程序集中编写代码来检测是否安装了 16550 UART 芯片(串行控制器),或者是否有通用方法来检测安装的 UART 芯片的型号。
到目前为止,我已经检查了以下资源:
- 高级 MS-DOS 编程第二版
- 编写 MS-DOS 设备驱动程序
- Ralf Brown 的中断列表(虽然它可能在这里,但我尝试在其中搜索序列号和 16550 并没有找到)
- 已通过 DosBox 源代码搜索线索,因为我知道它已经实现了这一点,但找不到在哪里
- https://wiki.osdev.org/Serial_Ports
一直找不到 MS-DOS 的 16550 编程手册的副本。我初始化串口,向它发送/接收数据没有问题,挑战是如何检测特定芯片或至少确认芯片是否为16550型号。
解决方案
虽然不在汇编程序中,但可以将其转换为汇编程序。在 C 中来自http://www.sci.muni.cz/docs/pc/serport.txt
int detect_UART(unsigned baseaddr)
{
// this function returns 0 if no UART is installed.
// 1: 8250, 2: 16450 or 8250 with scratch reg., 3: 16550, 4: 16550A
int x,olddata;
// check if a UART is present anyway
olddata=inp(baseaddr+4);
outp(baseaddr+4,0x10);
if ((inp(baseaddr+6)&0xf0)) return 0;
outp(baseaddr+4,0x1f);
if ((inp(baseaddr+6)&0xf0)!=0xf0) return 0;
outp(baseaddr+4,olddata);
// next thing to do is look for the scratch register
olddata=inp(baseaddr+7);
outp(baseaddr+7,0x55);
if (inp(baseaddr+7)!=0x55) return 1;
outp(baseaddr+7,0xAA);
if (inp(baseaddr+7)!=0xAA) return 1;
outp(baseaddr+7,olddata); // we don't need to restore it if it's not there
// then check if there's a FIFO
outp(baseaddr+2,1);
x=inp(baseaddr+2);
// some old-fashioned software relies on this!
outp(baseaddr+2,0x0);
if ((x&0x80)==0) return 2;
if ((x&0x40)==0) return 3;
return 4;
}
推荐阅读
- c++ - 如何在遍历时添加要设置的元素?
- json - JSON.parse 从 Web api 返回 undefined
- xamarin - Xamarin 使用 Skia Sharp 形成 Dotted Circle
- javascript - 谷歌分析没有收集任何网站速度数据
- cplex - 使用 cplex OPL 对时空网络进行建模
- git - 除了最后一次提交删除之前的所有提交
- c# - 使用 Excel 互操作时忽略 Excel 中设置的日期格式
- batch-file - 我们可以在不使用 for 循环的情况下仅提取字符串“04.07.2019 16:56:21”中的年份吗?
- javascript - 如何获取函数的返回错误值?(反应原生)
- java - giving child of firebase database name equal to USER ID key