?? call.asm
字號:
[bits 32]
[global start]
[extern _main]
%define KERNEL_CS_SEL 0x8
%define KERNEL_DS_SEL 0x10
%define IDT_SEL 0x20
%define KERNEL_STK_TOP 0x9ffff
%macro SETIDT 0 ;no arguments
mov word [es:edi],ax ;offset in target segment 15...0
shr eax,16 ;get the high word
mov word [es:edi+6],ax ;offset in target segment 31...16
mov word [es:edi+2],KERNEL_CS_SEL ;target segment selector: kernel cs
mov word [es:edi+4],0xee00 ;P|DPL3|i386 intr_gate
add edi,8 ;each gate descriptor is 8 bytes
%endmacro
%macro MASK 2 ;%1->IRQ line , %2 intr controller->0x21 | 0xA1
in al,%2
or al,(1<<%1) ;set the mask bit
out %2,al
%endmacro
%macro UNMASK 2 ;%1->IRQ line , %2 intr controller->0x21 | 0xA1
in al,%2
and al,(~(1<<%1)) ;clear the mask bit
out %2,al
%endmacro
%macro ACK_MASTER 0 ;acknowledge the pic
mov al,0x20 ;Non-specific EOI
out 0x20,al
%endmacro
%macro ACK_SLAVE 0
mov al,0x20
out 0xA0,al
%endmacro
%macro SAVE_ALL 0
push ds
push es
push fs
push gs
pushad
mov ax,KERNEL_DS_SEL
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
%endmacro
%macro RESTORE_ALL 0
popad
pop gs
pop fs
pop es
pop ds
%endmacro
jmp start
idtr: dw 7ffh ;IDT limit
dd 00001000h ;IDT base
ISR0:
SAVE_ALL
RESTORE_ALL
iretd
ISR1:
SAVE_ALL
RESTORE_ALL
iretd
ISR2:
SAVE_ALL
RESTORE_ALL
iretd
ISR3:
SAVE_ALL
RESTORE_ALL
iretd
ISR4:
SAVE_ALL
RESTORE_ALL
iretd
ISR5:
SAVE_ALL
RESTORE_ALL
iretd
ISR6:
SAVE_ALL
RESTORE_ALL
iretd
ISR7:
SAVE_ALL
RESTORE_ALL
iretd
ISR8:
SAVE_ALL
RESTORE_ALL
iretd
ISR9:
SAVE_ALL
RESTORE_ALL
iretd
ISR10:
SAVE_ALL
RESTORE_ALL
iretd
ISR11:
SAVE_ALL
RESTORE_ALL
iretd
ISR12:
SAVE_ALL
RESTORE_ALL
iretd
ISR13:
SAVE_ALL
jmp 0x38:0x0000
RESTORE_ALL
iretd
ISR14:
SAVE_ALL
RESTORE_ALL
iretd
ISR15:
SAVE_ALL
RESTORE_ALL
iretd
ISR16:
SAVE_ALL
RESTORE_ALL
iretd
ISR17:
SAVE_ALL
RESTORE_ALL
iretd
ISR18:
SAVE_ALL
RESTORE_ALL
iretd
ISR19:
SAVE_ALL
RESTORE_ALL
iretd
ISR20:
SAVE_ALL
RESTORE_ALL
iretd
ISR21:
SAVE_ALL
RESTORE_ALL
iretd
ISR22:
SAVE_ALL
RESTORE_ALL
iretd
ISR23:
SAVE_ALL
RESTORE_ALL
iretd
ISR24: ;timer
SAVE_ALL
RESTORE_ALL
iretd
;keyboard
ISR25:
SAVE_ALL
RESTORE_ALL
iretd
ISR26: ;slave pic
SAVE_ALL
RESTORE_ALL
iretd
ISR27: ;COM2 or COM4
SAVE_ALL
RESTORE_ALL
iretd
ISR28: ;COM1 or COM3
SAVE_ALL
RESTORE_ALL
iretd
ISR29: ;LPT2
SAVE_ALL
RESTORE_ALL
iretd
ISR30: ;floppy disk
SAVE_ALL
RESTORE_ALL
iretd
ISR31: ;LPT1
SAVE_ALL
RESTORE_ALL
iretd
ISR32: ;real time clock
SAVE_ALL
RESTORE_ALL
iretd
ISR33: ;software redirected to IRQ2
SAVE_ALL
RESTORE_ALL
iretd
ISR34: ;reserved
SAVE_ALL
RESTORE_ALL
iretd
ISR35: ;reserved
SAVE_ALL
RESTORE_ALL
iretd
ISR36: ;mouse interrupt
SAVE_ALL
RESTORE_ALL
iretd
ISR37: ;numeric coprocessor
SAVE_ALL
RESTORE_ALL
iretd
ISR38: ;fixed disk controller
SAVE_ALL
RESTORE_ALL
iretd
ISR39: ;reserved
SAVE_ALL
RESTORE_ALL
iretd
SYS_CALL: ;reserved
SAVE_ALL
RESTORE_ALL
iretd
UNHANDLED_INTR:
SAVE_ALL
RESTORE_ALL
iretd
start:
mov ax,KERNEL_DS_SEL ;set kernel segment regs
mov ss,ax
mov ds,ax
mov fs,ax
mov gs,ax
mov esp,KERNEL_STK_TOP ;set kernel stack
mov ax,IDT_SEL ;initialize IDT
mov es,ax ;es:edi : base of IDT
xor edi,edi
mov eax,ISR0 ;make physical addrs
SETIDT
mov eax,ISR1
SETIDT
mov eax,ISR2
SETIDT
mov eax,ISR3
SETIDT
mov eax,ISR4
SETIDT
mov eax,ISR5
SETIDT
mov eax,ISR6
SETIDT
mov eax,ISR7
SETIDT
mov eax,ISR8
SETIDT
mov eax,ISR9
SETIDT
mov eax,ISR10
SETIDT
mov eax,ISR11
SETIDT
mov eax,ISR12
SETIDT
mov eax,ISR13
SETIDT
mov eax,ISR14
SETIDT
mov eax,ISR15
SETIDT
mov eax,ISR16
SETIDT
mov eax,ISR17
SETIDT
mov eax,ISR18
SETIDT
mov eax,ISR19
SETIDT
mov eax,ISR20
SETIDT
mov eax,ISR21
SETIDT
mov eax,ISR22
SETIDT
mov eax,ISR23
SETIDT
mov eax,ISR24
SETIDT
mov eax,ISR25
SETIDT
mov eax,ISR26
SETIDT
mov eax,ISR27
SETIDT
mov eax,ISR28
SETIDT
mov eax,ISR29
SETIDT
mov eax,ISR30
SETIDT
mov eax,ISR31
SETIDT
mov eax,ISR32
SETIDT
mov eax,ISR33
SETIDT
mov eax,ISR34
SETIDT
mov eax,ISR35
SETIDT
mov eax,ISR36
SETIDT
mov eax,ISR37
SETIDT
mov eax,ISR38
SETIDT
mov eax,ISR39
SETIDT
mov eax,SYS_CALL
SETIDT
mov cx,215
loc1: mov eax,UNHANDLED_INTR
SETIDT
dec cx
cmp cx,0
jne loc1
mov ax,KERNEL_DS_SEL
mov es,ax
lidt [idtr] ;load IDTR
sti
call _main ;call kernel main
jmp $
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -