.model small
.386
DATAS SEGMENT
;此处输入数据段代码
BUF1 db ' ---------------------------------------',0dh,0ah
db ' read: 1.io_port ',0dh,0ah
db ' 2.memory ',0dh,0ah
db ' 3.isa ',0dh,0ah
db ' 4.pci ',0dh,0ah
db ' write: 5.io_port ',0dh,0ah
db ' 6.memory ',0dh,0ah
db ' 7.isa ',0dh,0ah
db ' 8.pci ',0dh,0ah
db ' 9.List all pci device ',0dh,0ah
db ' 0.List routing table ',0dh,0ah
db ' ---------------------------------------','$'
MESG_SPACE DB ' $'
MESG_ITEM11 DB 'Please choice your operiaton or enter the "ESC" to exit> $'
MESG_INPUT_IO DB 'Please enter the I/O address (0~FFFF) > $'
MESG_INPUT_Memery DB 'Please enter the Memery address (0~FFFFFFFF) > $'
MESG_INPUT_ISA DB 'Please enter the ISA address $'
MESG_INPUT_ISA_inde DB ' ---- index port > $'
MESG_INPUT_ISA_data DB ' ---- data port > $'
MESG_INPUT_ISA_oset DB ' ---- offset address > $'
MESG_INPUT_PCI DB 'Please enter the PCI address $'
MESG_INPUT_PCI_addr DB ' ---- Config address port > $'
MESG_INPUT_PCI_data DB ' ---- Config data port > $'
MESG_INPUT_PCI_Bus DB ' ---- Bus address > $'
MESG_INPUT_PCI_Dev DB ' ---- Dev address > $'
MESG_INPUT_PCI_Fun DB ' ---- Fun address > $'
MESG_INPUT_PCI_Reg DB ' ---- Reg address > $'
MESG_DATA_NUM DB 'Please enter how many data you want to read (0~FF) > $'
MESG_DATA DB 'Please enter the data you want to write (0~FF) > $'
MESG_sorry DB 'Sorry,There is an error! Please check what you input $'
MESG_ESC_CONTINUE2 DB 'Please enter the "ESC" to exit,enter the "1" to see again,other key to continue > $'
MESG_ESC_CONTINUE DB 'Please enter the "ESC" to exit,other key to continue > $'
MESG_READ_DATA DB 'The read data : $'
MESG_write_success DB 'Write successlly!!!! $'
BUS_DEVICE_NUM DB 'BUS# DEVICE# FUN# VENDER ID DEVICE ID$'
BUS_SPACE DB ' $'
Nextrow DB 0AH,0DH,24H
Data_buf1 DB 40 DUP(?)
Data_buf2 DB 10 DUP(?)
Data_buf3 DB 10 DUP(?)
Data_buf4 DB 10 DUP(?)
Data_buf5 DB 10 DUP(?)
Data_buf6 DB 10 DUP(?)
Data_buf7 DB 10 DUP(?)
Data_buf8 DB 10 DUP(?)
DATAS ENDS
;=========================================================================================
STACKS SEGMENT PARA STACK 'STACK '
DB 1024 DUP(?) ;此处输入堆栈段代码
STACKS ENDS
;=========================================================================================
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
;*********************************************
;此处输入代码段代码
;----Display_head---------------------------
Display_head:
;----display head-------
MOV AH,9
MOV DX,OFFSET BUF1
INT 21H
MOV AH,9
MOV DX,OFFSET NEXTROW
INT 21H
;------waiting for key input-----------------
MOV AH,01H
INT 21H
CMP AL,'1'
JZ Read_IO
CMP AL,'2'
JZ Read_Memery
CMP AL,'3'
JZ Read_ISA
CMP AL,'4'
JZ Read_PCI
CMP AL,'5'
JZ Write_IO
CMP AL,'6'
JZ Write_Memery
CMP AL,'7'
JZ Write_ISA
CMP AL,'8'
JZ Write_PCI
CMP AL,'9'
JZ LIST_ALL_PCI
CMP AL,'0'
JZ LIST_ROUNTING_TABLE
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
;--- if you put a worry num --------
JMP Display_head ;GO BACK
;******* Read_IO ***************************************************************
Read_IO:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please input the I/O address (0~FFFF) > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_IO
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],5 ; the data length is 4 , The last data is 0D
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if FF mean the string is not hex, else right
JZ WRONG_Read_IO
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf2
MOV [DI],DX ; store address !!!!!!!!1
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " The read data is : "------
MOV DX,OFFSET MESG_READ_DATA
MOV AH,9
INT 21H
MOV AX,0
MOV CX,100H
LOOP_READ_IO:
PUSH CX
PUSH AX
MOV DL,16
DIV DL
CMP AH,0
JNZ NO_NEXTROW_IO
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
NO_NEXTROW_IO:
;---------action---------------------
MOV DI,OFFSET Data_buf2
MOV DX,[DI]
POP AX
ADD DX,AX
PUSH AX
; read io
IN AL,DX
; display the data just read
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH ;
INT 10H
MOV AL,BL
MOV AH,0EH ;
INT 10H
MOV AL,20H ;SPACE
MOV AH,0EH
INT 10H
POP AX
POP CX
INC AX
LOOP LOOP_READ_IO
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE2
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
CMP AL,'1'
JZ LOOP_IO
JMP Display_head
LOOP_IO:MOV AX,0
MOV CX,100H
JMP LOOP_READ_IO
WRONG_Read_IO:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Read_IO ;GO BACK to Read_IO
;******* Read_Memery *****************************************************
Read_Memery:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the Memery address (0~FFFFFFFF) > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_Memery
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV EDX,OFFSET Data_buf1
MOV [DI],9 ; the data length is 8
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_Memery
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf2
MOV [DI],EDX ; Store addr !!!!!!!!!!
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " The read data is : "------
MOV DX,OFFSET MESG_READ_DATA
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------action---------------------
; read Memery
MOV DI,OFFSET Data_buf2
MOV EBX,[DI] ; read the address
MOV DX,1
MOV CX,100H
LOOP_READ_Memery:
PUSH DS
PUSH CX
MOV CX,16
MOV EAX,EBX
SHR EAX,CL
POP CX
MOV DS,AX
MOV AL,DS:[BX] ; read the data
POP DS
; display the data just read
PUSH BX
PUSH CX
CALL CONVERT_16_TO_STRING_DISPLAY
POP CX
MOV AH,0EH ;
INT 10H
MOV AL,BL
MOV AH,0EH ;
INT 10H
POP BX
MOV AL,20H ;SPACE
MOV AH,0EH
INT 10H
PUSH DX
MOV AX,DX
MOV DL,16
DIV DL
CMP AH,0
JNZ NO_NEXTROW_Memery
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
NO_NEXTROW_Memery:
POP DX
INC DX
INC EBX
LOOP LOOP_READ_Memery
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE2
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
CMP AL,'1'
JZ LOOP_MEMERY
JMP Display_head
LOOP_MEMERY:
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV DI,OFFSET Data_buf2
MOV EBX,[DI]
MOV DX,1
MOV CX,100H
JMP LOOP_READ_MEMERY
WRONG_Read_Memery:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Read_Memery ;GO BACK to Read_Memery
;******* Read_ISA **********************************
Read_ISA:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the ISA address > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— index port > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA_inde
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_ISA
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf3
MOV [DI],DL ; Store index port !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— data port > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA_data
INT 21H
; read data port
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_ISA
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf4
MOV [DI],DL ; Store data port !!!!!!!!!!!!!!!!!!!!!
;-------next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " The read data : "------
MOV DX,OFFSET MESG_READ_DATA
MOV AH,9
INT 21H
;---------action---------------------
; read ISA
MOV CX,100H
MOV AX,0
LOOP_READ_ISA:
PUSH CX
PUSH AX
MOV BL,16
DIV BL
CMP AH,0
JNZ LOOP_LOOP_READ_ISA
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
LOOP_LOOP_READ_ISA:
MOV DX,0
MOV DI,OFFSET Data_buf3 ; index port
MOV Dl,[DI] ; index port
POP AX
PUSH AX
OUT DX,AL
MOV DI,OFFSET Data_buf4 ; data port
MOV Dl,[DI] ; data port
IN AL,DX
; display the data just read
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
POP AX
INC AX
POP CX
LOOP LOOP_READ_ISA
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE2
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,'1'
JZ LOOP_ISA
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
LOOP_ISA:
MOV CX,100H
MOV AX,0
JMP LOOP_READ_ISA
WRONG_Read_ISA:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Read_ISA ;GO BACK to Read_ISA
;******* Read_PCI ********************
Read_PCI:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the PCI address > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI
INT 21H
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— BUS address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Bus
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_PCI
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf4
MOV [DI],BL ; Store BUS address !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— Dev address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Dev
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_PCI
CALL CONVERT_STRING_TO_16
CMP DX,32
JG WRONG_Read_PCI
MOV DI,OFFSET Data_buf5
MOV [DI],BL ; Store Dev address !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— Fun address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Fun
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_PCI
CALL CONVERT_STRING_TO_16
CMP DX,7
JG WRONG_Read_PCI
MOV DI,OFFSET Data_buf6
MOV [DI],BL ; Store Fun address !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— Reg address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Reg
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Read_PCI
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf7
MOV [DI],DL ; Store Reg address !!!!!!!!!!!!!!!!!!!!!
;-------next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " The read data : "------
MOV DX,OFFSET MESG_READ_DATA
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------action---------------------
; read PCI
;--- ADDRASS-----
MOV EBX,0
MOV DI,OFFSET Data_buf4 ; Bus
MOV BL,[DI]
MOV CL,16
SHL EBX,CL
ADD EBX,80000000H
MOV DI,OFFSET Data_buf5 ; Dev
MOV AX,[DI]
MOV CL,3
SHL AX,CL
MOV DI,OFFSET Data_buf6 ; Fun
MOV DX,[DI]
ADD AX,DX
MOV BH,AL
MOV DI,OFFSET Data_buf7 ; Reg
MOV BL,[DI]
AND EBX,0FFFFFFFCH
MOV DI,OFFSET Data_buf8 ; address
MOV [DI],EBX
MOV CX,64 ; 64*4=256
;------------------------
LOOP_READ_PCI:
PUSH CX
MOV AX,CX
MOV DL,4
DIV DL
CMP AH,0
JNZ LOOP_NO_ROW_PCI
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
LOOP_NO_ROW_PCI:
MOV DI,OFFSET Data_buf8 ;
MOV EAX,[DI]
MOV DX,0CF8H
OUT DX,EAX ; Write address
ADD EAX,4
MOV DI,OFFSET Data_buf8 ;
MOV [DI],EAX
MOV CX,4
MOV DX,0
LOOP_4_IN:
PUSH DX
ADD DX,0CFCH
IN AL,DX ; read data
; display the data just read
PUSH CX
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
POP CX
POP DX
INC DX
LOOP LOOP_4_IN
POP CX
LOOP LOOP_READ_PCI
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE2
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,'1'
JZ LOOP_PCI
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
LOOP_PCI:
MOV EBX,0
MOV DI,OFFSET Data_buf4 ; Bus
MOV BL,[DI]
MOV CL,24
SHL EBX,CL
ADD EBX,80000000H
MOV DI,OFFSET Data_buf5 ; Dev
MOV AL,[DI]
MOV CL,3
SHL AL,CL
MOV DI,OFFSET Data_buf6 ; Fun
MOV DL,[DI]
ADD AL,DL
MOV BH,AL
MOV DI,OFFSET Data_buf7 ; Reg
MOV BL,[DI]
AND EBX,0FFFFFFFCH
MOV DI,OFFSET Data_buf8 ; address
MOV [DI],EBX
MOV CX,64 ; 64*4=256
JMP LOOP_READ_PCI
WRONG_Read_PCI:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Read_PCI ;GO BACK to Read_PCI
;******* Read_IO ********************
Write_IO:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please input the I/O address (0~FFFF) > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_IO
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],5 ; the data length is 4 , The last data is 0D
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if FF mean the string is not hex, else right
JZ WRONG_Write_IO
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf2 ; store
MOV [DI],DX
;---------display msg " Please enter the data you want to write (0~FF) > "
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_DATA
INT 21H
; read data
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2 , The last data is 0D
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if FF mean the string is not hex, else right
JZ WRONG_Write_IO
CALL CONVERT_STRING_TO_16
MOV AX,DX
;---------action---------------------
; write io
MOV DI,OFFSET Data_buf2
MOV DX,[DI]
OUT DX,AL
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Write successlly!!!! "------
MOV DX,OFFSET MESG_write_success
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
WRONG_Write_IO:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Write_IO ;GO BACK to Read_IO
;******* Read_IO ********************
Write_Memery:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the Memery address (0~FFFFFFFF) > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_Memery
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],9 ; the data length is 8
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_Memery
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf2
MOV [DI],EDX ; Store addr !!!!!!!!!!
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the data you want to write (0~FF) > "
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_DATA
INT 21H
; read data
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_Memery
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf3
MOV [DI],DL ;; Store data !!!!!!!!!!
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------action---------------------
; Write_Memery
MOV DI,OFFSET Data_buf2
MOV EBX,[DI] ; READ addr !!!!!!!!!!
MOV EAX,EBX
PUSH CX
MOV CX,16
SHR EAX,CL
POP CX
PUSH DS
MOV DI,OFFSET Data_buf3 ; read data !!!!!!!!!!
MOV DX,[DI]
MOV DS,AX
MOV DS:[BX],DX
POP DS
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Write successlly!!!! "------
MOV DX,OFFSET MESG_write_success
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
WRONG_Write_Memery:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Write_Memery ;GO BACK to Read_Memery
;******* Read_IO ********************
Write_ISA:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the ISA address > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— index port > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA_inde
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_ISA
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf3
MOV [DI],DL ; Store index port !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— data port > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA_data
INT 21H
; read data port
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_ISA
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf4
MOV [DI],DL ; Store data port !!!!!!!!!!!!!!!!!!!!!
;-------next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— offset address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_ISA_oset
INT 21H
; read data port
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_ISA
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf5
MOV [DI],DL ; Store offset address !!!!!!!!!!!!!!!!!!!!!
;-------next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the data you want to write (0~FF) > "
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_DATA
INT 21H
; read data
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_ISA
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf2
MOV [DI],DL ;; Store data !!!!!!!!!!
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------action---------------------
MOV DI,OFFSET Data_buf5 ; offset address
MOV AL,[DI]
MOV DI,OFFSET Data_buf3 ; index port
MOV DL,[DI]
MOV DH,0
OUT DX,AL
MOV DI,OFFSET Data_buf2 ; data
MOV AL,[DI]
MOV DI,OFFSET Data_buf4 ; data port
MOV DL,[DI]
MOV DH,0
OUT DX,AL
;---display msg " Write successlly!!!! "------
MOV DX,OFFSET MESG_write_success
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
WRONG_Write_ISA:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Write_ISA
;******* Read_IO ********************
Write_PCI:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the PCI address > "
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI
INT 21H
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— BUS address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Bus
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_PCI
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf4
MOV [DI],BL ; Store BUS address !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— Dev address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Dev
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_PCI
CALL CONVERT_STRING_TO_16
CMP DX,32
JG WRONG_Write_PCI
MOV DI,OFFSET Data_buf5
MOV [DI],BL ; Store Dev address !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— Fun address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Fun
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_PCI
CALL CONVERT_STRING_TO_16
CMP DX,7
JG WRONG_Write_PCI
MOV DI,OFFSET Data_buf6
MOV [DI],BL ; Store Fun address !!!!!!!!!!!!!!!!!!!!!
;-----next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " —— Reg address > $"
MOV AH,9
MOV DX,OFFSET MESG_INPUT_PCI_Reg
INT 21H
; read addr
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_PCI
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf7
MOV [DI],DL ; Store Reg address !!!!!!!!!!!!!!!!!!!!!
;-------next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;-------next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---------display msg " Please enter the data you want to write (0~FF) > "
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_DATA
INT 21H
; read data
MOV AH,0AH
MOV DI,OFFSET Data_buf1
MOV DX,OFFSET Data_buf1
MOV [DI],3 ; the data length is 2
INT 21H
CALL JUDGE_16_convert_10
CMP BL,0FFH ; if 0xff mean the string is not hex, else right
JZ WRONG_Write_PCI
CALL CONVERT_STRING_TO_16
MOV DI,OFFSET Data_buf2
MOV [DI],DL ;; Store data !!!!!!!!!!
;---------action---------------------
; Write_PCI
;--- ADDRASS-----
MOV EBX,0
MOV DI,OFFSET Data_buf4 ; Bus
MOV BL,[DI]
MOV CL,24
SHL EBX,CL
ADD EBX,80000000H
MOV DI,OFFSET Data_buf5 ; Dev
MOV AL,[DI]
MOV CL,3
SHL AL,CL
MOV DI,OFFSET Data_buf6 ; Fun
MOV DL,[DI]
ADD AL,DL
MOV BH,AL
MOV DI,OFFSET Data_buf7 ; Reg
MOV BL,[DI]
AND EBX,0FFFFFFFCH
;------------------------
MOV DX,0CF8H
MOV EAX,EBX
OUT DX,EAX ; Write address
MOV DI,OFFSET Data_buf2 ; data
MOV AL,[DI]
MOV DX,0CFCH
OUT DX,AL ; Write data
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Write successlly!!!! "------
MOV DX,OFFSET MESG_write_success
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
WRONG_Write_PCI:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
MOV AH,9
MOV DX,OFFSET MESG_sorry
INT 21H
JMP Write_PCI
;*****************************************
List_all_PCI:
MOV ECX,10000H
MOV EBX,80000000H
MOV DX,OFFSET Bus_DEVICE_NUM
MOV AH,9
INT 21H
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
Lookup_Dev:
MOV EAX,EBX
PUSH EBX
MOV DX,0CF8H
OUT DX,EAX ; Write address
MOV DX,0CFCH
IN EAX,DX ; Read data
CMP EAX,0FFFFFFFFH
JZ Dev_non_exist
CMP EAX,0
JZ Dev_non_exist
mov bx,ax
MOV DI,OFFSET Data_buf8 ; EBX
MOV [DI],EBX
; next row
; --display "Bus # = "
PUSH CX
MOV CX,16
MOV EAX,EBX
SHR EAX,CL
CALL PLAY
; --display " Dev # = "
MOV DX,OFFSET BUS_SPACE
MOV AH,9
INT 21H
MOV CX,11
MOV EAX,EBX
SHR AX,CL
CALL PLAY
MOV DX,OFFSET BUS_SPACE
MOV AH,9
INT 21H
MOV CX,8
MOV EAX,EBX
SHR AX,CL
AND AX,07H
CALL PLAY
CALL LOOPUP_dEV2
POP CX
MOV DX,OFFSET NEXTROW
MOV AH,9
INT 21H
Dev_non_exist:
POP EBX
ADD EBX,100H
LOOP Lookup_Dev
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
;******List_Rounting_table******************************************************
LOOPUP_DEV2 PROC NEAR
MOV DX,OFFSET BUS_SPACE
MOV AH,9
INT 21H
MOV DI,OFFSET DATA_BUF8
MOV EBX,[DI]
PUSH BX
MOV AL,BH
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
POP BX
MOV AL,BL
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
; --display "Devive ID = "
MOV DX,OFFSET BUS_SPACE
MOV AH,9
INT 21H
MOV CX,16
MOV EBX,EAX
SHR EBX,CL
PUSH BX
MOV AL,BH
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
POP BX
MOV AL,BL
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
RET
LOOPUP_DEV2 ENDP
PLAY PROC NEAR
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH
INT 10H
MOV AL,BL
MOV AH,0EH
INT 10H
RET
PLAY ENDP
List_Rounting_table:
PUSH DS
MOV AX,0F000H
MOV DS,AX
MOV CX,0FFFFH
MOV DI,0
LOOP_FIND_PIR:
MOV AL,DS:[DI]
CMP AL,24H
JNZ NO_FIND
MOV AL,DS:[DI+1]
CMP AL,50H
JNZ NO_FIND
MOV AL,DS:[DI+2]
CMP AL,49H
JNZ NO_FIND
MOV AL,DS:[DI+3]
CMP AL,52H
JNZ NO_FIND
JMP FIND_IT
NO_FIND:
INC DI
LOOP LOOP_FIND_PIR
POP DS
JMP NO_FIND_ROUNTING_ESC
FIND_IT:
POP DS
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;-----OK!!------------------------
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,24H;display $
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,50H;display P
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,49H;display I
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
MOV AL,52H;display R
MOV AH,0EH
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
; ---display rounting header --------
MOV CX,27
MOV BX,4
LOOP_ROUTING_HEADER:
MOV AX,0F000H
PUSH DS
MOV DS,AX
MOV AL,DS:[DI+BX]
POP DS
PUSH CX
PUSH BX
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH ;display
INT 10H
MOV AL,BL
MOV AH,0EH;display
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
POP BX
PUSH BX
MOV AX,BX
MOV BL,15
DIV BL
CMP AH,0
JNZ NO_ListHEADER_NEXT_ROW
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
NO_ListHEADER_NEXT_ROW:
POP BX
INC BX
POP CX
LOOP LOOP_ROUTING_HEADER
;----display data---------------------------------
MOV AX,0F000H
PUSH DS
MOV DS,AX
MOV CX,DS:[DI+6] ; read size
;MOV CX,0FFH
POP DS
MOV BX,32
LOOP_LIST_DATA:
PUSH CX
MOV AX,0F000H
PUSH DS
MOV DS,AX
MOV AL,DS:[DI+BX]
POP DS
PUSH BX
CALL CONVERT_16_TO_STRING_DISPLAY
MOV AH,0EH ;display
INT 10H
MOV AL,BL
MOV AH,0EH;display
INT 10H
MOV AL,20H ;display SPACE
MOV AH,0EH
INT 10H
POP BX
MOV AX,BX
PUSH BX
MOV BL,16
DIV BL
CMP AH,0
JNZ NO_Listdata_NEXT_ROW
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
NO_Listdata_NEXT_ROW:
POP BX
INC BX
POP CX
LOOP LOOP_LIST_DATA
NO_FIND_ROUNTING_ESC:
; next row
MOV DX,OFFSET Nextrow
MOV AH,9
INT 21H
;---display msg " Please enter the "ESC" to exit,other key to continue > "------
MOV DX,OFFSET MESG_ESC_CONTINUE
MOV AH,9
INT 21H
; read keybord
MOV AH,7
INT 21H
; judge key
CMP AL,27 ; press "ESC"
JZ BACK_TO_DOS
JMP Display_head
BACK_TO_DOS:
MOV AH,4CH
INT 21H
;*****************************************
;---------output BL==0FFH mean wrong -----------------
JUDGE_16_convert_10 PROC NEAR
MOV DI,OFFSET Data_buf1
MOV CX,0
INC DI
MOV CL,[DI] ; data num
;-------Judge weather 0~9,A~F,a~f ----------------------
LP_JUDGE:
INC DI
MOV AL,[DI]
CMP AL,30H
JB WORRY_16_RET ; Smaller than 0
CMP AL,39H
JBE RIGHT_0_9 ; Smaller than 9 or equal
CMP AL,41H
JB WORRY_16_RET ; Smaller than A
CMP AL,46H
JBE RIGHT_A_F ; Smaller than F or equal
CMP AL,61H
JB WORRY_16_RET ; Smaller than a
CMP AL,66H
JBE RIGHT_a_f_ ; Smaller than f
JMP WORRY_16_RET ; Others are wrong
;------convert ASCII to 16-HEX---------------
RIGHT_0_9:
SUB AL,30H
JMP STORE_16_HEX
RIGHT_A_F:
SUB AL,55
JMP STORE_16_HEX
RIGHT_a_f_:
SUB AL,87
STORE_16_HEX:
MOV [DI],AL ; store 16 hex
LOOP LP_JUDGE
MOV BL,0 ; the flag
JMP JUDGE_16_convert_10_RET
WORRY_16_RET:
MOV BL,0FFH ; the flag
JUDGE_16_convert_10_RET:
RET
JUDGE_16_convert_10 ENDP
;----------------------------------------------
;-------OUTOUT: EDX ----------------------------
CONVERT_STRING_TO_16 PROC NEAR
MOV DI,OFFSET Data_buf1
MOV CX,0 ; clear
INC DI
MOV CL,[DI] ;the data num
MOV EAX,0 ; clear
MOV SI,OFFSET Data_buf8
MOV [SI],EAX
CMP CL,1 ;when cl==1 "SHL DX,0" so it can't
JZ DATA_NUM_1
MOV BL,1
DEC CX
LOOP_SHIFT:
MOV SI,OFFSET Data_buf1
ADD SI,CX
INC SI
MOV EDX,0 ; clear
MOV DL,[SI] ; copy the data ,Last the first
MOV AL,4 ; shift left 4 bits
MUL BL
INC BL
PUSH CX
MOV CL,AL
SHL EDX,CL
POP CX
MOV SI,OFFSET Data_buf8
MOV EAX,[SI]
ADD EAX,EDX
MOV SI,OFFSET Data_buf8
MOV [SI],EAX
LOOP LOOP_SHIFT
DATA_NUM_1:
MOV DI,OFFSET Data_buf1
INC DI
MOV CX,0
MOV CL,[DI] ;the data num
ADD DI,CX
MOV BL,[DI] ; the first(last) data ,AL(EAX)
AND BL,0FH
AND AL,0F0H
ADD AL,BL
CONVERT_STRING_TO_16_RET:
MOV EDX,EAX
RET
CONVERT_STRING_TO_16 ENDP
;-------INPUT : AL ------------------------------------
;-------OUTOUT: AL BL ----------------------------
CONVERT_16_TO_STRING_DISPLAY PROC NEAR
MOV BL,AL
MOV CX,4
SHR AL,CL
CMP AL,9
JBE CONVERT_16_RIGHT_0_9_AL ; Smaller than 9 or equal
ADD AL,55
JMP CONVERT_16_TO_STRING_BL
CONVERT_16_RIGHT_0_9_AL:
ADD AL,30H
CONVERT_16_TO_STRING_BL:
AND BL,0FH
;-------Judge weather 0~9,A~F --convert 16-HEX to ASCII ------------------
CMP BL,9
JBE CONVERT_16_RIGHT_0_9_BL ; Smaller than 9 or equal
ADD BL,55
JMP CONVERT_16_TO_STRING_RET
CONVERT_16_RIGHT_0_9_BL:
ADD BL,30H
CONVERT_16_TO_STRING_RET:
RET
CONVERT_16_TO_STRING_DISPLAY ENDP
CODES ENDS
END START
;========================================================================