鱼C论坛

 找回密码
 立即注册
查看: 1942|回复: 0

写了个简单的键盘中断测试程序,系统总是报异常。

[复制链接]
发表于 2014-7-30 09:53:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
写了个简单的程序想看下键盘中断的响应过程,这个程序一敲击键盘,就会重启。和以前写成功过的程序核对过,没有出入,自己查看也木有发现什么!没事儿的朋友,可以看看!权当复习知识了!

org 0x7c00
        mov bx,cs
        mov es,bx
        mov bx,0x7e00
       
        mov ax,0x0212
        mov cx,2
        mov dx,0
       
        int 0x13
       
        jmp 0:0x7e00
       
times        510 - ($-$$) db 0
dw        0xaa55

        xor eax,eax
        mov ax,cs
        shl eax,4
        add eax,LABEL_SEG_CODE32
        mov [LABEL_DESC_CODE32 + 2],ax
        shr eax,16
        mov [LABEL_DESC_CODE32 + 4],al
        mov [LABEL_DESC_CODE32 + 7],ah
       
        xor eax,eax
        mov ax,cs
        shl eax,16
        add eax,LABEL_GDT
        mov [GdtPtr + 2],eax
       
        xor eax,eax
        mov ax,cs
        shl eax,16
        add eax,LABEL_IDT
        mov [IdtPtr + 2],eax
       
        cli
        lgdt [GdtPtr]
        lidt [IdtPtr]
       
        in al,0x92
        or al,2
        out 0x92,al
       
        mov eax,cr0
        or al,1
        mov cr0,eax
       
        jmp dword SelectorCode32:0
       
[bits 32]
[section .text]
LABEL_SEG_CODE32:
        mov ax,SelectorVideo
        mov gs,ax
        mov al,'P'
        mov ah,0xc
        mov [gs:0],ax
       
        call Init8259A
        sti
        hlt
       
Init8259A:
        mov al,0x11
        out 0x20,al
        call io_delay
       
        out 0xa0,al
        call io_delay
       
        mov al,0x20
        out 0x21,al
        call io_delay
       
        mov al,0x28
        out 0xa1,al
        call io_delay
       
        mov al,4
        out 0x21,al
        call io_delay
       
        mov al,2
        out 0xa1,al
        call io_delay
       
        mov al,1
        out 0x21,al
        call io_delay
       
        out 0xa1,al
        call io_delay
       
        mov al,1111_1101b
        out 0x21,al
        call io_delay
       
        mov al,1111_1111b
        out 0xa1,al
        call io_delay
       
        ret
       
io_delay:
        nop
        nop
        nop
        nop
        ret
       
_handler:
        handler        equ        _handler - $$
        inc byte [gs:0]
        in al,0x60
        mov al,0x20
        out 0x20,al
        iretd
       
        SegCode32Len equ $ - $$

LABEL_GDT                        dw        0,0,0,0
LABEL_DESC_CODE32        dw        SegCode32Len - 1,0,0x9800,0x0040
LABEL_DESC_VIDEO        dw        0xffff,0x8000,0x920b,0x0040

SelectorCode32        equ        LABEL_DESC_CODE32 - LABEL_GDT
SelectorVideo        equ        LABEL_DESC_VIDEO - LABEL_GDT

GdtLen        equ        $ - LABEL_GDT
GdtPtr        dw        GdtLen - 1
                dd        0
               
LABEL_IDT:
        %rep 0x21
                dw 0,0,0,0
        %endrep
        dw        handler,SelectorCode32,0x8e00,0x00
       
IdtLen        equ        $ - LABEL_IDT
IdtPtr        dw        IdtLen - 1
                dd        0
               
               


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-7 04:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表