Page 1 of 1

masking interrupts

Posted: Fri Apr 11, 2003 4:03 pm
by slacker
how do i disable int 0x20/IRQ0?

Re:masking interrupts

Posted: Fri Apr 11, 2003 4:38 pm
by _mark
I'm not sure if there is a better way, but to disable any indavidual interrupt, I just re-program then to call my null_interrupt function which in turn just keeps a counter of un-handled interrupts.

_mark()

Re:masking interrupts

Posted: Fri Apr 11, 2003 5:47 pm
by slacker
why would i get exception 6:invalid opcode after my IRQ0 runs once and prints "timer". i always get the exception after the ISR for IRQ0 runs once.

Re:masking interrupts

Posted: Fri Apr 11, 2003 6:12 pm
by slacker
p.s. i dont get the exception in bochs. here is some code:

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
};


Re:masking interrupts

Posted: Fri Apr 11, 2003 7:00 pm
by _mark
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
pusha
push gs
push fs
push es
push ds
[extern _isr_20]
call _isr_20
pop ds
pop es
pop fs
pop gs
popa
STI ; if using CLI above, reenable interrupts
iret

_mark()

Re:masking interrupts

Posted: Fri Apr 11, 2003 7:25 pm
by slacker
this also does not work. xsism tryed it on a 133mhz pc and it worked

Re:masking interrupts

Posted: Fri Apr 11, 2003 9:15 pm
by slacker
i can provide more of my code if anyone needs it...

Re:masking interrupts

Posted: Sat Apr 12, 2003 9:29 am
by Pype.Clicker
_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()

mark, please STOP using this approach of clearing the interrupt flag at the start of an interrupt handler ... this just makes no sense : the CPU has already cleared it when it called the handler and it will be re-enabled once the interrupt exits (as the previous value of eflags is stored on the stack prior to calling the handler ...)

Re:masking interrupts

Posted: Sat Apr 12, 2003 9:30 am
by _mark
Are you using GRUB, or your own bootloader? Because it sounds like a bootloader problem to me.

_mark()

Re:masking interrupts

Posted: Mon Apr 14, 2003 11:51 am
by slacker
i am using my own bootloader: (but i dont think it has a problem)

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

Re:masking interrupts

Posted: Mon Apr 14, 2003 12:18 pm
by slacker
also if anyone knows a site or has some code to disable IRQ0/timer i would like to see it because i was thinking that this timer exception might be firing quicker than the processor can actually read the CODE for the timer ISR which was cause an error. maybe disableing the timer would help. thank you.

Re:masking interrupts

Posted: Mon Apr 14, 2003 12:40 pm
by slacker
also do i have to do anything with non maskable interrupts? i have just learned that these are NOT IRQs....?

Re:masking interrupts

Posted: Tue Apr 15, 2003 9:01 am
by Pype.Clicker
hum, i don't think a repeated IRQ0 could lead to "invalid opcode" (unless your stack grows so far that it override the code itself :O -- but there is little chance that this could occur in only *one* interrupt)

You should also know that IRQ are disabled by the cpu when a IRQ is serviced, unless your code explicitly do a "STI" ... so the worst case you could meet is equivalent to a loop that would call the IRQ0-handler forever.

Imho, what is more likely to occur is that you're missing something in your pushes/pops and when you call IRET, it jumps to a wrong location ...

Re:masking interrupts

Posted: Tue Apr 15, 2003 11:02 am
by slacker
when i remap pic, i get the opcode error but if i let irq0 be int8(default) then i dont get the error.

Re:masking interrupts

Posted: Tue Apr 15, 2003 3:05 pm
by Pype.Clicker
maybe you could try to keep interrupts disabled in your main code and try a "INT 0x20" instruction, to see whether it is the remapping or the handler that has a problem ...