Chinaunix首页 | 论坛 | 博客
  • 博客访问: 153469
  • 博文数量: 53
  • 博客积分: 2042
  • 博客等级: 大尉
  • 技术积分: 425
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-15 21:39
文章存档

2011年(6)

2010年(47)

分类:

2011-05-02 17:47:56

 org  07c00h 
 
LABEL_START:
 mov ax, cs
 mov ds, ax
 mov es, ax
 mov ss, ax
 mov esp, 07c00h 
 mov eax, 0xB800
 mov gs, ax
 
 
;^^^^^^^^^^^^^^    填写中断向量表  ^^^^^^^^^^^^^^

mov ax, KBD
mov word [21h*4], ax
mov ax, 00h
mov word [21h*4+2], ax

mov ax, MOUSE
mov word [2ch*4], ax
mov ax, 00h
mov word [2ch*4+2], ax
 
;^^^^^^^^^^^^^^     填写中断向量表 结束  ^^^^^^^^^^^^^^
 

;==============  初始化 intel 8042  ============================
;mov EAX, 0a8h  ;允许鼠标接口
;out 064h, al

;mov al, 060h  ;使能鼠标 和 允许鼠标中断
;out 064h, al
;mov al, 47h
;out 060h, al
; 以上操作在VMware里已经由BIOS初始化了(应该是吧),所以不用再初始化一遍,
; 但是在VirtualPC里要把注释去掉。
 
mov al, 0d4h  ;告诉8042,下一个发往60h的数据是发给鼠标的
out 064h, al
mov al, 0f4h  ;告诉鼠标可以发数据了
out 060h, al
in  al, 060h  ;最好读一下鼠标的应答,
;(有时向鼠标发送完数据/命令后,不读鼠标的回复的数据,
;  可能鼠标就不会再发送数据了,中断也产生不了了)

;==============  8042 end ============================
 
 
 

;++++++++++++  8259  ++++++++++++++++++++
;1  ---------------------- 请参考《自己编写操作系统》第3章 3.4节
mov al, 011h
out 020h, al
out 0A0h, al
;2  ----------------------
mov al, 020h  ;主8255中断号码
out 021h, al
mov al, 028h  ;从8255中断号码
out 0A1h, al
;3  ----------------------
mov al, 004h
out 021h, al
mov al, 002h
out 0A1h, al
;4  ----------------------
mov al, 0011h
out 021h, al
mov al, 001h
out 0A1h, al
;5  屏蔽 OCW1  ----------------------
mov al, 0b  ;使能主从8255所有中断
out 021h, al
out 0A1h, al
;++++++++++++++ 8259 end ++++++++++++++++++
 

jmp $
 
 
 
MOUSE:
 
inc byte [gs:(80*2+70)]
inc byte [gs:(80*1+70)]
 
in   al, 60h
in   al, 60h
in   al, 60h
in   al, 60h ; 至少读取一次,一般读取3-4次获得所有鼠标移动的数据
 
MOV AL,20H
OUT 020H,AL ;主8255的EOI

MOV AL,20H
OUT 0A0H,AL ;从8255的EOI

iret
 
;===============================================================
KBD:            ;键盘中断处理程序
inc byte [gs:(80*0+70)]
inc byte [gs:(80*3+70)]
 
MOV AL,20H
OUT 20H,AL

in   al, 60h  ;读取扫描码, 必须读取一次
in  al, 61h
or al, 80h
out 61h, al
 
iret
 
times  1474560-($-$$) db 0 
;offered by LX from xidian university in xi'an   2011-5-2 
;this program only pass the test in VMware
;original
;use command "nasm.exe kbd-mous.asm -o kbd-mous.bin"
 
; Suggestion: you can try to test how many interrupts the 8255 can save/hold/keep when the 8255 set OCW1  to inhibit/enable all the interrupts,and then enable all the interruptd to deal the interrupts .
 
 
阅读(1074) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

网络安全服务2011-06-15 11:47:52