DOS下读取PCI配置空间信息的汇编程序(通过IOCF8/IOCFC)
汇编程序编写的读取PCI配置空间信息的代码(通过IOCF8/IOCFC):
;------------------------------------------------
;功能: 读取PCI 配置信息,存入文件zpci_config.txt
;环境: DOS + MASM5
;时间: 2015/08
;说明: 通过端口CF8h / CFCh 来读取
;
;---------------------自定义宏结构-------------------
;功能: 在文件中换行
nextrow macro
mov buffer ,0dh
mov buffer+,0ah
mov dx,offset buffer
mov cx,
mov ah,40h
int 21h
endm
;功能:把ascii 表示的字符写入文件
tofile macro ascii
mov buffer,ascii
mov dx,offset buffer
mov cx,
mov ah,40h
int 21h
endm
;------------------------------------------------
.386P
;-------------------------------------------------
dseg segment use16
busnum dw 0000h ;总线号0 - 00FFh
devnum dw 001fh ;设备号0 - 001Fh
funnum dw 0007h ;功能号0 - 0007h
regnum dw 00ffh ;寄存器0 - 00FFh
;
config_addr dd 00000000h ;用来暂存eax中的地址
buff_num db 'bus:device:function:'
;
config_data dd 00000000h ;用来存放eax中的pci数据
fname db '\zpci_config.txt', ;文件名
buffer db
dseg ends
;----------------------------------------------------
;----------------------------------------------------
cseg segment use16
assume cs:cseg, ds:dseg
start:
mov ax,dseg
mov ds,ax
;
mov dx,offset fname
mov cx, ;common file
mov ah,3ch ;creat file
int 21h
;
mov bx,ax ;save file handle
;
mov busnum,0000h
mov devnum,0000h
mov funnum,0000h
mov regnum,0000h
;-----------------------------------------
call print_num ;打印busnum:devnum:funnum = 00:00:00
nextrow ;换行
nextreg:
call pci_read ;读取pci 配置空间
cmp regnum,00h
jnz continue ;判断不是第一个寄存器
cmp ax,0ffffh ;判断设备是否存在
jz nextfun ;不存在,跳到下一个fun
continue:
call writefile
add regnum, ;只能每次读4个寄存器
cmp regnum,00ffh ;判断
ja nextfun ;256B 已读完,跳到下一个function
jmp nextreg ;否则,读下一个reg
nextfun:
nextrow
;
mov regnum,0000h
inc funnum
cmp funnum,0007h
ja nextdev ;funnum 大于 7,跳到下一个dev
call print_num
nextrow
jmp nextreg
nextdev:
mov regnum,0000h
mov funnum,0000h
inc devnum
cmp devnum,001fh
ja nextbus ;devnum 大于 1fh,跳到下一个bus
call print_num
nextrow
jmp nextreg
nextbus:
mov regnum,0000h
mov funnum,0000h
mov devnum,0000h
inc busnum
cmp busnum,0005h
ja endd ;busnum 大于5,跳到结束
call print_num
nextrow
jmp nextreg
;-----------------------结束------------------------
endd:
mov ah,3eh ;close file
int 21h
;
mov ah,4ch ;return DOS
int 21h
;---------------------------------------------------
;--------------------------------------------------
;函数功能:打印busnum:devnum:funnum
print_num proc
mov config_addr,eax ;保护eax中的地址
;------------------------------------
mov dx,offset buff_num
mov cx,
mov ah,40h
int 21h
;----------busnum------------
mov ax,busnum
push ax
shr al,
call toascii
tofile al
pop ax
call toascii
tofile al
tofile 2Dh
;----------devnum----------
mov ax,devnum
push ax
shr al,
call toascii
tofile al
pop ax
call toascii
tofile al
tofile 2Dh
;-----------funnum---------
mov ax,funnum
push ax
shr al,
call toascii
tofile al
pop ax
call toascii
tofile al
;-----------
mov eax,config_addr ;恢复eax
ret
print_num endp
;------------------------------------------------------
;---------------------- writefile ----------------------------
;函数功能: 把eax 中的值写入文件
;入口参数: eax
;出口参数: 无
;所用寄存器和存储单元:ebx,ecx,edx
writefile proc
mov config_data,eax ;用config_data暂存eax中的pci数据
;--------第一个字节-----
push eax
shr al,
call toascii
tofile al
pop eax
call toascii
tofile al
tofile 20h
;--------第二个字节------
mov eax,config_data
shr eax,
;
push eax
shr al,
call toascii
tofile al
pop eax
call toascii
tofile al
tofile 20h
;--------第三个字节-------
mov eax,config_data
shr eax,
;
push eax
shr al,
call toascii
tofile al
pop eax
call toascii
tofile al
tofile 20h
;--------第四个字节---------
mov eax,config_data
shr eax,
;
push eax
shr al,
call toascii
tofile al
pop eax
call toascii
tofile al
tofile 20h
ret
writefile endp
;---------------------------------------------------
;-----------------------toascii---------------------------
;子程序名: toascii
;功能: 把al的低4位的值转成ascii码,存入al
;入口参数: al
;出口参数: al
toascii proc
and al,0fh
add al,90h
daa
adc al,40h
daa
ret
toascii endp
;----------------------------------------------------
;----------------------pci_read---------------------------
;子程序名: pci_read
;功能: 根据eax中的地址读取pci的配置空间,并存入eax
;入口参数: busnum、devnum、funnum、regnum
;出口参数: eax
;
pci_read proc
;protect register
push ebx
push dx
;clear
xor eax,eax
xor ebx,ebx
;enable
add eax,1h
shl eax,
;bus number
mov ebx,ds:[]
and ebx,0ffh
shl ebx,
add eax,ebx
;device number
xor ebx,ebx
mov ebx,ds:[]
and ebx,0ffh
shl ebx,
add eax,ebx
;function number
xor ebx,ebx
mov ebx,ds:[]
and ebx,0ffh
shl ebx,
add eax,ebx
;register
xor ebx,ebx
mov ebx,ds:[]
and ebx,0ffh
add eax,ebx
;read IO
mov dx,0cf8h
out dx,eax
mov dx,0cfch
in eax,dx
;resume register
pop dx
pop ebx
ret
pci_read endp
;--------------------------------------------
;----------------------------------------------
cseg ends
end start
DOS下读取PCI配置空间信息的汇编程序(通过IOCF8/IOCFC)的更多相关文章
- DOS下读取spd信息的汇编程序(通过SMBus)
汇编程序编写的读取spd信息的代码: ;----------------------------------------------------------- ;功能: 通过SMbus 读取内存的SP ...
- SpringBoot(十三)-- 不同环境下读取不同配置
一.场景: 在开发过程中 会使用 开发的一套数据库,测试的时候 又会使用测试的数据库,生产环境中 又会切换到生产环境中.常用的方式是 注释掉一些配置,然后释放一下配置.SpringBoot提供了在不同 ...
- DOS下读取smbios的汇编程序(通过搜索memory)
汇编程序编写的读取smbios的代码: ;------------------------------------------------- ;功能: 读取SMBIOS 的Entry Point ,并 ...
- [转]WinForm和WebForm下读取app.config web.config 中邮件配置的方法
本文转自:http://blog.csdn.net/jinbinhan/article/details/1598386 1. 在WinForm下读取 App.config中的邮件配置语句如下: Con ...
- dos下的edit命令使用详解
dos下的edit命令使用详解 来源:网络 作者:未知 edit命令是一个简单的编辑软件,我们经常用它来编辑一些程序和批处理文件. 比如,我想在c盘根目录下编辑一个简单的批处理文件,要求无论当前盘和当 ...
- PCI配置空间简介
一.PCI配置空间简介 PCI有三个相互独立的物理地址空间:设备存储器地址空间.I/O地址空间和配置空间.配置空间是PCI所特有的一个物理空间.由于PCI支持设备即插即用,所以PCI设备不占用固定的内 ...
- Linux下Redis服务器安装配置
说明:操作系统:CentOS1.安装编译工具yum install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel ...
- [C] zlstdint(让VC、TC等编译器自动兼容C99的整数类型)V1.0。支持Turbo C++ 3等DOS下的编译器
作者:zyl910 以前我曾为了让VC++等编译器支持C99的整数类型,便编写了c99int库来智能处理(http://www.cnblogs.com/zyl910/p/c99int_v102.htm ...
- CentOS下Redis服务器安装配置
说明: 操作系统:CentOS 1.安装编译工具 yum install wget make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-de ...
随机推荐
- [django]drf知识点梳理-搜索
什么是搜索? 譬如http://127.0.0.1:8000/User/?username=maotai-0 可以检索出想要的. 自己实现原始的搜索 重写下get_queryset方法 class U ...
- Python 深浅copy 和文件操作
深浅copy 1,先看赋值运算. l1 = [1,2,3,['barry','alex']] l2 = l1 l1[0] = 111 print(l1) # [111, 2, 3, ['barry', ...
- [LeetCode] 154. Find Minimum in Rotated Sorted Array II_Hard
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...
- java json Gson
引入 Gson 到 pom.xml <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <de ...
- .net委托链
委托链可以增加方法,可以移除方法,如果是无返回值的方法,我们把它们都绑定到一个委托上面的话,直接调用,那么调用此委托就会依次调用其中的方法:但是如果是多个有返回值的委托链,如果我们不采用特殊手段,直接 ...
- JS引擎的执行机制
深入理解JS引擎的执行机制 1.灵魂三问 : JS为什么是单线程的? 为什么需要异步? 单线程又是如何实现异步的呢? 2.JS中的event loop(1) 3.JS中的event loop(2) 4 ...
- MyBatis基础入门《六》Like模糊查询
MyBatis基础入门<六>Like模糊查询 描述: 未改动的文件,不再粘贴出来.项目中SQL的xml映射文件重要标签如下: mapper namespace cache 配置给定命令空间 ...
- Lambda表达式语法
基础语法:‘->’Lambda操作符* 左侧:Lambda表达式的参数列表 对应接口中方法中的参数列表中的参数(比如nice1中MyPredict这个接口中的方法)* 右侧:Lambda表达式中 ...
- Eclipse 在Debug调试中用到的快捷键
作用域 功能 快捷键 全局 单步返回 F7 全局 单步跳过 F6 全局 单步跳入 F5 全局 单步跳入选择 Ctrl+F5 全局 调试上次启动 F11 全局 继续 F8 全局 使用过滤器单步执行 Sh ...
- 《大话设计模式》c++实现 模版方法模式
模板方法模式:定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤. 角色: (1)AbstractClass:是抽象类,其实也 ...