标签:
实验二 PCI设备操作
(一)配置空间读取
示例代码在书上,粘一下在此~
STACK SEGMENT PARA STACK
DW 128H DUP(0)
STACK ENDS
DATA SEGMENT
NOFOUND DB ‘NOT FOUND!‘,0DH,0AH,‘$‘
IO DB 0DH,0AH,‘IO ADDRESS IS: $‘
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,SS:STACK,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV AH,0B1H
MOV AL,2
MOV CX,9050H
MOV DX,10B5H
MOV SI,0
INT 1AH
CMP AH,0
JZ GOT
MOV DX,OFFSET NOFOUND
MOV AH,9
INT 21H
JMP GOUT
GOT: MOV AX,BX
CALL DISP
MOV DL,0DH
MOV AH,2
INT 21H
MOV DL,0AH
INT 21H
MOV DI,0
LOOP1: MOV AX,0B109H
INT 1AH
MOV AX,CX
CALL DISP
MOV DL,‘ ‘
MOV AH,2
INT 21H
INC DI
INC DI
CMP DI,40H
JL LOOP1
MOV DX,OFFSET IO
MOV AH,9
INT 21H
MOV AX,0B109H
MOV DI,1CH
INT 1AH
AND CX,0FFFEH
MOV AX,CX
CALL DISP
GOUT: MOV AH,4CH
INT 21H
DISP PROC NEAR
PUSH BX
PUSH CX
MOV BX,AX
MOV CX,4
LLOOP1: MOV AX,BX
CALL DISP2
PUSH CX
MOV CL,4
SHL BX,CL
POP CX
LOOP LLOOP1
POP CX
POP BX
RET
DISP ENDP
DISP2 PROC NEAR
PUSH DX
PUSH CX
AND AH,0F0H
MOV CL,4
SHR AH,CL
MOV DL,AH
CMP DL,9
JLE NUM
ADD DL,7
NUM: ADD DL,30H
MOV AH,02H
INT 21H
POP CX
POP DX
RET
DISP2 ENDP
CODE ENDS
END START
(二)列举全部PCI设备
我觉得注释挺详细的了
STACK SEGMENT PARA STACK
DW 128H DUP(0)
STACK ENDS
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,SS:STACK,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV BX,0 ;BX为循环变量,也是PCI BIOS系统调用的参数
NEXT: CMP BX,0900H
JNZ NOEXIT ;枚举总线号、设备号和功能号并进入循环内部
MOV AX,4C00H ;循环结束
INT 21H
NOEXIT:
MOV AX,0B109H
MOV DI,0
INT 1AH ;参数为BX,DI = 0的读配置字系统调用
MOV AX,CX ;CX中存放着读出的配置字,即供应商ID
CMP AX,0FFFFH
JZ LABEL1 ;若供应商ID为0FFFFH,说明插槽没有安装板卡,此时BX+1,并返回循环开始
CALL DISP ;若供应商ID不为0FFFFH,则输出Vendor ID
MOV DL,‘ ‘
MOV AH,2
INT 21H ;输出一个空格
MOV AX,0B109H
MOV DI,2
INT 1AH ;参数仍为BX,DI = 2的读配置字系统调用
MOV AX,CX ;CX中存放着读出的配置字,此次是设备ID
;CMP AX,0FFFFH
;JZ LABEL1
CALL DISP ;输出Device ID
MOV AH,2
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H ;输出回车,即换行
MOV CX,BX
AND CX,07H ;取出BX的低三位,即功能号
CMP CX,0 ;判断功能号是否为0
JNZ LABEL1 ;若功能号不为0,说明该设备是多功能设备,所以顺序枚举BX,BX+1并返回循环开始
MOV AX,0B108H ;若功能号为0,则需读取其首部类型进行判断
MOV DI,0EH ;READ HEADER TYPE
INT 1AH ;参数为BX,DI = 0EH的读配置字节的系统调用
MOV AL,CL ;CL中存放着读出的配置字节,即首部类型
AND AL,80H
CMP AL,0 ;判断首部类型最高位是否为0
JZ LABEL2 ;若为0,说明该设备为单功能设备,无需枚举8个功能号,所以BX+8并返回循环开始
LABEL1: INC BX
JMP NEXT
LABEL2: ADD BX,8
JMP NEXT
DISP PROC NEAR ;将AX寄存器里的数据转化为ASCII码并显示
PUSH BX
PUSH CX
MOV BX,AX
MOV CX,4
LLOOP1: MOV AX,BX
CALL DISP2
PUSH CX
MOV CL,4
SHL BX,CL
POP CX
LOOP LLOOP1
POP CX
POP BX
RET
DISP ENDP
DISP2 PROC NEAR ;显示AH的高四位
PUSH DX
PUSH CX
AND AH,0F0H
MOV CL,4
SHR AH,CL
MOV DL,AH
CMP DL,9
JLE NUM
ADD DL,7
NUM: ADD DL,30H
MOV AH,02H
INT 21H
POP CX
POP DX
RET
DISP2 ENDP
CODE ENDS
END START
标签:
原文地址:http://blog.csdn.net/m2mshirley/article/details/51352690