BITS 16
CONST_VID EQU 1A00H
CONST_DID EQU 8088H
ROM_START:
ROM_HEADER:
DB 55H ;; 00H: SIGNATURE 1
DB 0AAH ;; 01H: SIGNATURE 2
DB (ROM_END-ROM_START) / 512 ;; 02H: IMAGE_SIZE
JMP ROM_ENTRY ;; 03H: JUMP INSTRUCTION
times 12H DB 00H ;; 06H: PADDING
DW (PCI_DATA_STRUC-ROM_START) ;; 18H: PCI_DATA_STRUC POINTER
DW 0000H
PCI_DATA_STRUC:
DB 'PCIR' ;; 00H: device flag
DW CONST_VID ;; 04H: vendor ID
DW CONST_DID ;; 06H: device ID
DW 0000H ;; 08H: VPD pointer
DW 0018H ;; 0AH: PCI_DATA_STRUC's length
DB 00H ;; 0CH: PCI_DATA_STRUC's version
DB 00H,80H,01H ;; 0DH: device type.Class Code
DW (ROM_END-ROM_START) / 512 ;; 10H: Image length
DW 0000H ;; 12H: the version of the code data
DB 00H ;; 14H: the code type of ROM
DB 80H ;; 15H: the flag used to make sure if or not the last ROM image
DW 0000H ;; 16H: Reserved
Int19h_Hook_Hanlder:
jmp $ ;卡在这里,证明INT19H确实被执行了
int 89h
iret
Install_Int19h_Hook:
push ds
xor ax,ax
mov ds,ax
mov eax,[ds:(19h*4)]
mov [ds:(89h)*4],eax
mov word [ds:(19h*4)],Int19h_Hook_Hanlder
mov word [ds:(19h*4)+2],cs
pop ds
ret
ROM_ENTRY:
push ax ;AX=由BIOS传来的总线号/设备号/功能号
pusha
mov bx,ax
mov ax,0b109h
mov di,PC_BASE_ADDR ;读取扩展ROM卡的IO地址
int 1ah
and cx,0FFF0h
mov dx,cx
mov dl,CH367_GPIR
in al,dx ;读取J1引脚的状态,如果被短接则退出
and al,02h
jz Exit_Init_Rom
call PrintInt19h ;打印初始的INT19H地址
call Install_Int19h_Hook ;安装INT19h钩子
call PrintInt19h ;打印修改后的INT19H地址
Exit_Init_Rom:
popa
pop ax
retf
%include "CH360DEF.ASM"
%include "PCIE_CFG.ASM"
%include "ShowIVT.asm"
times 32*1024-($-$$) db 0
ROM_END: