masking interrupts
Posted: Fri Apr 11, 2003 4:03 pm
how do i disable int 0x20/IRQ0?
The Place to Start for Operating System Developers
https://forum.osdev.org/
Code: Select all
ISR20:
pusha
push gs
push fs
push es
push ds
[extern _isr_20]
call _isr_20
pop ds
pop es
pop fs
pop gs
popa
iret
void isr_20()
{
print("timer\n");
portout(0x20,0x20); //EOI
};
_mark() wrote: If in real-mode with a largish kernel, you may need far calls:
call far _isr_20
This of course is if you are in realmode, and depends on the compiler you are using.
The only other thing I can see is you might want to disable and re-enable interrupts while processing the ISR:
ISR20:
CLI ; maybe this - disable interrupts
STI ; if using CLI above, reenable interrupts
iret
_mark()
Code: Select all
;---------------------------begin---------------------------
[org 0x7c00] ;bios loads to this loaction
jmp start ;jump over data
;--------------------------constants--------------------------
GDTpointer:
GDTlim DW ENDGDT-GDT-1
GDTbase DD 0x500 ;we will be moving GDT to 0x50:0x0
GDT_Selectors: ;used as offset from start of GDT
NULLsel EQU 0x0
CODEsel EQU 0x0008
DATAsel EQU 0x0010
;----------------------------strings------------------------
msg_title db 'os'
msg_done db 'done'
msg_gdt0 db 'relocate gdt...'
msg_gdt1 db 'load gdt....'
msg_a20 db 'enable a20...'
msg_ker db 'load kernel...'
msg_idt db 'load idt...';
curpos dw 0x00 ;current text position
;--------------------------gdt-------------------------------
GDT: ;flat memory model
;NULLsel ;required
DD 0x00
DD 0x00
;CODEsel
DW 0xFFFF
DW 0x00
DB 0x00
DB 0x9A
DB 0xCF
DB 0x00
;DATAsel
DW 0xFFFF
DW 0x00
DB 0x00
DB 0x92
DB 0xCF
DB 0x00
ENDGDT:
;------------------------main code--------------------------
start: ;begin code
XOR AX, AX ;AX=0
MOV AX, 0x9000
MOV SS, AX
MOV SP, 0x9000
MOV AX, CS
MOV DS, AX ;update data seg
call clear
MOV CX, 2
MOV AX, 0x00
MOV SI, msg_title
call print
MOV CX, 15
MOV AX, 320
MOV SI, msg_gdt0
call print
;------------------relocate gdt--------------------
XOR AX, AX
MOV DS, AX
mov ES, ax
mov DI, 0x500 ;0x50:0x00
mov SI, GDT ;start of GDT
mov cx, [GDTlim] ; size of GDT
moveit: ; movsb increments the registers for you. i just learned this after errors
movsb
loop moveit
MOV CX, 4
MOV AX, [curpos]
MOV SI, msg_done
call print
MOV CX, 13
MOV AX, 480
MOV SI, msg_a20
call print
;-------------------enable a20 line------------------------
jmp enable_a20
wait_for_controller: ;this waits for kbd controller to process data
xor al, al
in al, 0x64 ;check port 0x64
test al, 0x02 ;check for bit 1=1
jnz wait_for_controller ;if not 1, loop until 1
ret
enable_a20: ;begin a20 enable
cli ;disable interrupts
call wait_for_controller
mov al, 0xD1 ;send 0xD1
out 0x64, al
call wait_for_controller
mov al, 0xDF ;send 0xDF
out 0x60, al
call wait_for_controller
sti
MOV CX, 4
MOV AX, [curpos]
MOV SI, msg_done
call print
MOV CX, 14
MOV AX, 640
MOV SI, msg_ker
call print
;--------------------load kernel file------------------------
mov bx, 0xffff
mov es, bx ;es:bx-> mem location
mov bx, 0x10
mov ah, 2 ;function
mov al, 12 ;num sectors
mov ch, 0 ;track
mov cl, 2 ;sector
mov dh, 0 ;head
mov dl, 0 ;drive
int 0x13
MOV CX, 4
MOV AX, [curpos]
MOV SI, msg_done
call print
MOV CX, 11
MOV AX, 800
MOV SI, msg_idt
call print
jmp gopmode
;------------------------------print---------------------
print:
MOV BX, 0xb800 ;CX len of string
MOV ES, BX ;AX position
MOV BX, AX
printit:
lodsb
MOV byte [ES:BX], AL
INC BX
MOV byte [ES:BX], 0x07
INC BX
loop printit
MOV word [curpos], BX
ret
;------------------------------clear---------------------
clear:
MOV BX, 0xb800
MOV ES, BX
MOV BX, 0x00
MOV CX, 4000
clearit:
MOV byte [ES:BX], ' '
INC BX
MOV byte [ES:BX], 0x07
INC BX
loop clearit
ret
;-----------------enter pmode--------------------------
gopmode:
cli ;disable interrupts
lgdt [GDTpointer] ;load GDT
mov eax,cr0 ;set pmode bit in cr0 register
or al,1
mov cr0,eax
jmp CODEsel:CONT ;will set CS to proper segment
[bits 32] ;we in pmode now
CONT:
turnofffloppy: ;floppy light needs to go off
mov dl, 0
mov edx, 0x3f2
mov al, 0x0c
out dx, al
UPDATEDATAREGS: ;update data registers
mov eax,DATAsel
mov ds,eax
mov es,eax
mov ss,eax ;reset stack
mov esp,0x9FFFF
;--------------jump to code--------------------
jmp 0x100000
done:
jmp done
;---------------------file format------------------
TIMES 510-($-$$) DB 0 ;fill empty bytes with 0
DB 0x55 ;end with signature
DB 0xAA