汇编程序编写的读取PCI配置空间信息的代码(通过IOCF8/IOCFC):

  1. ;------------------------------------------------
  2. ;功能: 读取PCI 配置信息,存入文件zpci_config.txt
  3. ;环境: DOS + MASM5
  4. ;时间: 2015/08
  5. ;说明: 通过端口CF8h / CFCh 来读取
  6. ;
  7. ;---------------------自定义宏结构-------------------
  8. ;功能: 在文件中换行
  9. nextrow macro
  10. mov buffer ,0dh
  11. mov buffer+,0ah
  12. mov dx,offset buffer
  13. mov cx,
  14. mov ah,40h
  15. int 21h
  16. endm
  17. ;功能:把ascii 表示的字符写入文件
  18. tofile macro ascii
  19. mov buffer,ascii
  20. mov dx,offset buffer
  21. mov cx,
  22. mov ah,40h
  23. int 21h
  24. endm
  25. ;------------------------------------------------
  26. .386P
  27. ;-------------------------------------------------
  28. dseg segment use16
  29. busnum dw 0000h ;总线号0 - 00FFh
  30. devnum dw 001fh ;设备号0 - 001Fh
  31. funnum dw 0007h ;功能号0 - 0007h
  32. regnum dw 00ffh ;寄存器0 - 00FFh
  33. ;
  34. config_addr dd 00000000h ;用来暂存eax中的地址
  35. buff_num db 'bus:device:function:'
  36. ;
  37. config_data dd 00000000h ;用来存放eax中的pci数据
  38. fname db '\zpci_config.txt', ;文件名
  39. buffer db
  40. dseg ends
  41. ;----------------------------------------------------
  42. ;----------------------------------------------------
  43. cseg segment use16
  44. assume cs:cseg, ds:dseg
  45. start:
  46. mov ax,dseg
  47. mov ds,ax
  48. ;
  49. mov dx,offset fname
  50. mov cx, ;common file
  51. mov ah,3ch ;creat file
  52. int 21h
  53. ;
  54. mov bx,ax ;save file handle
  55. ;
  56. mov busnum,0000h
  57. mov devnum,0000h
  58. mov funnum,0000h
  59. mov regnum,0000h
  60. ;-----------------------------------------
  61. call print_num ;打印busnum:devnum:funnum = 00:00:00
  62. nextrow ;换行
  63. nextreg:
  64. call pci_read ;读取pci 配置空间
  65. cmp regnum,00h
  66. jnz continue ;判断不是第一个寄存器
  67. cmp ax,0ffffh ;判断设备是否存在
  68. jz nextfun ;不存在,跳到下一个fun
  69. continue:
  70. call writefile
  71. add regnum, ;只能每次读4个寄存器
  72. cmp regnum,00ffh ;判断
  73. ja nextfun ;256B 已读完,跳到下一个function
  74. jmp nextreg ;否则,读下一个reg
  75. nextfun:
  76. nextrow
  77. ;
  78. mov regnum,0000h
  79. inc funnum
  80. cmp funnum,0007h
  81. ja nextdev ;funnum 大于 7,跳到下一个dev
  82. call print_num
  83. nextrow
  84. jmp nextreg
  85. nextdev:
  86. mov regnum,0000h
  87. mov funnum,0000h
  88. inc devnum
  89. cmp devnum,001fh
  90. ja nextbus ;devnum 大于 1fh,跳到下一个bus
  91. call print_num
  92. nextrow
  93. jmp nextreg
  94. nextbus:
  95. mov regnum,0000h
  96. mov funnum,0000h
  97. mov devnum,0000h
  98. inc busnum
  99. cmp busnum,0005h
  100. ja endd ;busnum 大于5,跳到结束
  101. call print_num
  102. nextrow
  103. jmp nextreg
  104. ;-----------------------结束------------------------
  105. endd:
  106. mov ah,3eh ;close file
  107. int 21h
  108. ;
  109. mov ah,4ch ;return DOS
  110. int 21h
  111. ;---------------------------------------------------
  112. ;--------------------------------------------------
  113. ;函数功能:打印busnum:devnum:funnum
  114. print_num proc
  115. mov config_addr,eax ;保护eax中的地址
  116. ;------------------------------------
  117. mov dx,offset buff_num
  118. mov cx,
  119. mov ah,40h
  120. int 21h
  121. ;----------busnum------------
  122. mov ax,busnum
  123. push ax
  124. shr al,
  125. call toascii
  126. tofile al
  127. pop ax
  128. call toascii
  129. tofile al
  130. tofile 2Dh
  131. ;----------devnum----------
  132. mov ax,devnum
  133. push ax
  134. shr al,
  135. call toascii
  136. tofile al
  137. pop ax
  138. call toascii
  139. tofile al
  140. tofile 2Dh
  141. ;-----------funnum---------
  142. mov ax,funnum
  143. push ax
  144. shr al,
  145. call toascii
  146. tofile al
  147. pop ax
  148. call toascii
  149. tofile al
  150. ;-----------
  151. mov eax,config_addr ;恢复eax
  152. ret
  153. print_num endp
  154. ;------------------------------------------------------
  155. ;---------------------- writefile ----------------------------
  156. ;函数功能: eax 中的值写入文件
  157. ;入口参数: eax
  158. ;出口参数:
  159. ;所用寄存器和存储单元:ebx,ecx,edx
  160. writefile proc
  161. mov config_data,eax ;用config_data暂存eax中的pci数据
  162. ;--------第一个字节-----
  163. push eax
  164. shr al,
  165. call toascii
  166. tofile al
  167. pop eax
  168. call toascii
  169. tofile al
  170. tofile 20h
  171. ;--------第二个字节------
  172. mov eax,config_data
  173. shr eax,
  174. ;
  175. push eax
  176. shr al,
  177. call toascii
  178. tofile al
  179. pop eax
  180. call toascii
  181. tofile al
  182. tofile 20h
  183. ;--------第三个字节-------
  184. mov eax,config_data
  185. shr eax,
  186. ;
  187. push eax
  188. shr al,
  189. call toascii
  190. tofile al
  191. pop eax
  192. call toascii
  193. tofile al
  194. tofile 20h
  195. ;--------第四个字节---------
  196. mov eax,config_data
  197. shr eax,
  198. ;
  199. push eax
  200. shr al,
  201. call toascii
  202. tofile al
  203. pop eax
  204. call toascii
  205. tofile al
  206. tofile 20h
  207. ret
  208. writefile endp
  209. ;---------------------------------------------------
  210. ;-----------------------toascii---------------------------
  211. ;子程序名: toascii
  212. ;功能: al的低4位的值转成ascii码,存入al
  213. ;入口参数: al
  214. ;出口参数: al
  215. toascii proc
  216. and al,0fh
  217. add al,90h
  218. daa
  219. adc al,40h
  220. daa
  221. ret
  222. toascii endp
  223. ;----------------------------------------------------
  224. ;----------------------pci_read---------------------------
  225. ;子程序名: pci_read
  226. ;功能: 根据eax中的地址读取pci的配置空间,并存入eax
  227. ;入口参数: busnumdevnumfunnumregnum
  228. ;出口参数: eax
  229. ;
  230. pci_read proc
  231. ;protect register
  232. push ebx
  233. push dx
  234. ;clear
  235. xor eax,eax
  236. xor ebx,ebx
  237. ;enable
  238. add eax,1h
  239. shl eax,
  240. ;bus number
  241. mov ebx,ds:[]
  242. and ebx,0ffh
  243. shl ebx,
  244. add eax,ebx
  245. ;device number
  246. xor ebx,ebx
  247. mov ebx,ds:[]
  248. and ebx,0ffh
  249. shl ebx,
  250. add eax,ebx
  251. ;function number
  252. xor ebx,ebx
  253. mov ebx,ds:[]
  254. and ebx,0ffh
  255. shl ebx,
  256. add eax,ebx
  257. ;register
  258. xor ebx,ebx
  259. mov ebx,ds:[]
  260. and ebx,0ffh
  261. add eax,ebx
  262. ;read IO
  263. mov dx,0cf8h
  264. out dx,eax
  265. mov dx,0cfch
  266. in eax,dx
  267. ;resume register
  268. pop dx
  269. pop ebx
  270. ret
  271. pci_read endp
  272. ;--------------------------------------------
  273. ;----------------------------------------------
  274. cseg ends
  275. end start

DOS下读取PCI配置空间信息的汇编程序(通过IOCF8/IOCFC)的更多相关文章

  1. DOS下读取spd信息的汇编程序(通过SMBus)

    汇编程序编写的读取spd信息的代码: ;----------------------------------------------------------- ;功能: 通过SMbus 读取内存的SP ...

  2. SpringBoot(十三)-- 不同环境下读取不同配置

    一.场景: 在开发过程中 会使用 开发的一套数据库,测试的时候 又会使用测试的数据库,生产环境中 又会切换到生产环境中.常用的方式是 注释掉一些配置,然后释放一下配置.SpringBoot提供了在不同 ...

  3. DOS下读取smbios的汇编程序(通过搜索memory)

    汇编程序编写的读取smbios的代码: ;------------------------------------------------- ;功能: 读取SMBIOS 的Entry Point ,并 ...

  4. [转]WinForm和WebForm下读取app.config web.config 中邮件配置的方法

    本文转自:http://blog.csdn.net/jinbinhan/article/details/1598386 1. 在WinForm下读取 App.config中的邮件配置语句如下: Con ...

  5. dos下的edit命令使用详解

    dos下的edit命令使用详解 来源:网络 作者:未知 edit命令是一个简单的编辑软件,我们经常用它来编辑一些程序和批处理文件. 比如,我想在c盘根目录下编辑一个简单的批处理文件,要求无论当前盘和当 ...

  6. PCI配置空间简介

    一.PCI配置空间简介 PCI有三个相互独立的物理地址空间:设备存储器地址空间.I/O地址空间和配置空间.配置空间是PCI所特有的一个物理空间.由于PCI支持设备即插即用,所以PCI设备不占用固定的内 ...

  7. Linux下Redis服务器安装配置

    说明:操作系统:CentOS1.安装编译工具yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel ...

  8. [C] zlstdint(让VC、TC等编译器自动兼容C99的整数类型)V1.0。支持Turbo C++ 3等DOS下的编译器

    作者:zyl910 以前我曾为了让VC++等编译器支持C99的整数类型,便编写了c99int库来智能处理(http://www.cnblogs.com/zyl910/p/c99int_v102.htm ...

  9. CentOS下Redis服务器安装配置

    说明: 操作系统:CentOS 1.安装编译工具 yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-de ...

随机推荐

  1. 亚马逊IOT-SDK,线程池数

    1111

  2. Jmeter测试报告

    服务器: 2个CPU,每个CPU 1个核,4G内存  20G硬盘 客户端(Jmeter):2个CPU,每个2个核,4+8内存   500G硬盘 ---------------------------- ...

  3. 新手详解JAVA+数据库+JSP完成简单页面

    本篇以数据库添加为例(本例中数据库名为“xinxi”表单名字为“stud”) 准备---实体层: package entity; public class Student { private Stri ...

  4. TensorFlow读取CSV数据

    代码来源于官方文档,做了一些小小的调整: # -*- coding:utf-8 -*- import tensorflow as tf filename_queue = tf.train.string ...

  5. cocos2dx 3.x(打开网页webView)

    #include "ui/CocosGUI.h" using namespace cocos2d::experimental::ui; WebView *webView = Web ...

  6. 如何解决“504 Gateway Time-out”错误

    做网站的同学经常会发现一些nginx服务器访问时候提示504 Gateway Time-out错误,一般情况下是由nginx默认的fastcgi进程响应慢引起的,但也有其他情况,这里我总结了一些解决办 ...

  7. react native 中使用swiper

    1.下载依赖 cnpm install react-native-swiper --save 2.在组件中使用 import React, { Component } from 'react'; im ...

  8. LeetCode118.杨辉三角

    给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1], [1,2,1], [ ...

  9. Web Audio初步介绍和实践

    Web Audio还是一个比较新的JavaScript API,它和HTML5中的<audio>是不同的,简单来说,<audio>标签是为了能在网页中嵌入音频文件,和播放器一样 ...

  10. Mvcpager以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”。

    解决办法如下: 1.在_Layout.cshtml布局body内,添加section,Scripts.Render和RenderSection标签示例代码如下: <body class=&quo ...