我正在编写一个中断服务例程,它应该使用 int 70h 和 IRQ8 处理由 RTC 引起的中断,以便与某些计时器一起使用。不幸的是,我一直有很多问题,所以我决定将问题分成几个较小的问题,然后独立解决每个问题。首先,我放弃了硬件部分,决定先用软件实现中断。
现在,我正在使用 NASM 和 DosBox。
这是 ISR 代码:
segment .code
; ----------------------------------------------
; writes a message on the screen
; every time interrupt is called
; ----------------------------------------------
INT_CODE equ 070h
my_int:
pusha ;saves all registers on stack so they get preserved
;EDIT1
xor ax, ax ;sets ax to zero
mov es, ax ;puts zero into extra segment register
mov bx, [es:INT_CODE*4+2] ;this should give us the sergment of the ISR
mov ds, bx ;the segment is now in ds
;END OF EDIT1
;mov ax, 0 ;cleans any garbage in ax
;mov ah, 09h ;preparing to call DOS system call, remove later
mov ax, string_s
mov si, ax
call _print_string
;int 021h ;this should hopefully work
mov al, 0Ch ; Accessing RTC
out 070h, al ; register C should be read
in al, 071h ;or there won't be any new interrupts (or so it's supposed to be)
;mov ax, 0 ; again we clear anything left in ax, just in case
;mov ah, 09h ; preparing to write string
mov ax, string_e
mov si, ax
call _print_string
;int 021h ; this should work
mov al, 20h ;we're letting PICs know the interrupt ended
out 0A0h, al ;notifying second PIC
out 020h, al ;notifying first PIC
popa ;application gets its registers back
iret
_inst_70:
cli ;hardware interrupts are now stopped
xor ax, ax
mov es, ax
mov bx, [es:INT_CODE*4]
mov [old_int70_off], bx
mov bx, [es:INT_CODE*4+2]
mov [old_int70_seg], bx
; adding our routine to interrupt vector table
mov dx, my_int
mov [es:INT_CODE*4], dx
mov ax, cs
mov [es:INT_CODE*4+2], ax
sti
;mov ah, 09h
mov ax, string_inst
mov si, ax
call _print_string
;int 021h
ret
; -----------------------------------------------------------------------------
; return old int 70 h
_uninst_70:
cli
xor ax, ax
mov es, ax
mov ax, [old_int70_seg]
mov [es:INT_CODE*4+2], ax
mov dx, [old_int70_off]
mov [es:INT_CODE*4], dx
sti
ret
_print_string:
pusha
mov ah, 0Eh ; BIOS INT 10h teletype (TTY) function
.Repeat:
lodsb ; takes one character from a string
cmp al, 0
je .End ; If it's zero, end of string
int 10h ; if not, call BIOS
jmp .Repeat ; and go to next character
.End:
popa
ret
segment .data
string_s: db 'We're in ISR',0
string_e: db 'It's working',0
string_inst: db 'Installed',0
old_int70_seg: dw 0
old_int70_off: dw 0
我正在使用以下程序测试此中断:
;myint
org 100h;installs the interrupt
segment .code
main:
call _inst_70
;call _uninst_70 ; THIS IS ON PURPOSE!
ret
%include "myint.asm"
和
;int70h
org 100h ;calls the interrupt
segment .code
mov ah, 09h ; getting ready to print string
mov dx, string1
int 21h
;mov ax, 0 ;getting rid of the last message
;mov dx, 0
int 070h ;calling the interrupt
mov ah, 09h
mov dx, string2;
int 21h
ret
segment .data
string1: db 'Testing!',0
string2: db 'int 70h working',0
_print_string:
pusha
mov ah, 0Eh ; BIOS INT 10h teletype (TTY) function
.Repeat:
lodsb ; takes one character from a string
cmp al, 0
je .End ; If it's zero, end of string
int 10h ; if not, call BIOS
jmp .Repeat ; and go to next character
.End:
popa
ret
现在我们进入有趣的部分。
当我调用安装程序时,我收到安装中断并且程序似乎结束正常的消息。
当我调用 INT70H.COM 时,我得到了似乎是一个内存区域的转储。其中唯一可读的东西是:
Testing!Testing!int 70h working
和C:\NASM-DOS\NASM.EXE
。
当我取消注释 INT70H 中的mov ax, 0
和mov dx, 0
行时,我得到Testing!
并且 DosBox 挂起,有时会崩溃。VMware 和 VirtualBox 也是如此。
当我用来自 INT70H 的两个 mov 注释掉读取 RTC 寄存器 C 的行时,我得到Testing!Testing!int 70h working
并且 DosBox 挂起。VirtualBox 和 VMware 也会发生同样的事情。如果 INT70H 中的两个 mov 未注释,我得到Testing!
并挂起。
这让我相信它可能是一些 DOS 系统调用(我不应该在最终产品中使用)可能会做坏事,但即使它们被注释掉,当我运行 INT70H 时,计算机也会挂起。
我的主要问题是,现在我完全不知道如何开始解决这个问题。