Chinaunix首页 | 论坛 | 博客
  • 博客访问: 806690
  • 博文数量: 489
  • 博客积分: 475
  • 博客等级: 下士
  • 技术积分: 3087
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 16:28
文章分类

全部博文(489)

文章存档

2013年(7)

2012年(301)

2011年(181)

分类:

2012-01-03 12:41:33

中断好像书上描述的比较少,最近由于工作需要要看android

一个操作系统的实现就这个没有那么多的时间看了,看到突破512B限制的时候看得有点蒙了,FAT12的格式书上介绍的不是很清楚。

中断的使用

1、  增加IDT20h号和80h号中断

; IDT

[SECTION .idt]

ALIGN    32

[BITS     32]

LABEL_IDT:

;                         目标选择子,            偏移, DCount, 属性

%rep 32

              Gate SelectorCode32, SpuriousHandler,      0, DA_386IGate

%endrep

.020h:            Gate SelectorCode32,    ClockHandler,      0, DA_386IGate

%rep 95

              Gate SelectorCode32, SpuriousHandler,      0, DA_386IGate

%endrep

.080h:            Gate SelectorCode32,  UserIntHandler,      0, DA_386IGate

 

IdtLen            equ  $ - LABEL_IDT

IdtPtr             dw   IdtLen - 1       ; 段界限

              dd    0            ; 基地址

; END of [SECTION .idt]

 

2、选择子

; int handler ---------------------------------------------------------------

_ClockHandler:

ClockHandler  equ  _ClockHandler - $$

       inc   byte [gs:((80 * 0 + 70) * 2)]  ; 屏幕第 0 , 70 列。

       mov al, 20h

       out   20h, al                          ; 发送 EOI

       iretd

 

_UserIntHandler:

UserIntHandler       equ  _UserIntHandler - $$

       mov ah, 0Ch                        ; 0000: 黑底    1100: 红字

       mov al, 'I'

       mov [gs:((80 * 0 + 70) * 2)], ax   ; 屏幕第 0 , 70 列。

       iretd

 

_SpuriousHandler:

SpuriousHandler     equ  _SpuriousHandler - $$

       mov ah, 0Ch                        ; 0000: 黑底    1100: 红字

       mov al, '!'

       mov [gs:((80 * 0 + 75) * 2)], ax   ; 屏幕第 0 , 75 列。

       jmp  $

       iretd

; ---------------------------------------------------------------------------

 

38259A的初始化

 

; Init8259A ---------------------------------------------------------------------------------------------

Init8259A:

       mov al, 011h

       out   020h, al   ; 8259, ICW1.

       call  io_delay

 

       out   0A0h, al  ; 8259, ICW1.

       call  io_delay

 

       mov al, 020h   ; IRQ0 对应中断向量 0x20

       out   021h, al   ; 8259, ICW2.

       call  io_delay

 

       mov al, 028h   ; IRQ8 对应中断向量 0x28

       out   0A1h, al  ; 8259, ICW2.

       call  io_delay

 

       mov al, 004h   ; IR2 对应从8259

       out   021h, al   ; 8259, ICW3.

       call  io_delay

 

       mov al, 002h   ; 对应主8259 IR2

       out   0A1h, al  ; 8259, ICW3.

       call  io_delay

 

       mov al, 001h

       out   021h, al   ; 8259, ICW4.

       call  io_delay

 

       out   0A1h, al  ; 8259, ICW4.

       call  io_delay

 

       ;mov       al, 11111111b   ; 屏蔽主8259所有中断

       mov al, 11111110b   ; 仅仅开启定时器中断

       out   021h, al   ; 8259, OCW1.

       call  io_delay

 

       mov al, 11111111b   ; 屏蔽从8259所有中断

       out   0A1h, al  ; 8259, OCW1.

       call  io_delay

 

       ret

; Init8259A ---------------------------------------------------------------------------------------------

 

4、加载IDT

 

       ; 为加载 IDTR 作准备

       xor  eax, eax

       mov ax, ds

       shl   eax, 4

       add  eax, LABEL_IDT          ; eax <- idt 基地址

       mov dword [IdtPtr + 2], eax  ; [IdtPtr + 2] <- idt 基地址

 

       ; 保存 IDTR

       sidt  [_SavedIDTR]

 

       ; 保存中断屏蔽寄存器(IMREG)

       in     al, 21h

       mov [_SavedIMREG], al

 

       ; 加载 GDTR

       lgdt  [GdtPtr]

 

       ; 关中断

       ;cli

 

       ; 加载 IDTR

       lidt   [IdtPtr]

 

中断使用

       call  Init8259A

 

       int    080h

       sti

       jmp  $

阅读(419) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~