Page 1 of 1

IRQ0 does not fire. (Am I missing something) but IRQ1 does.

Posted: Thu Feb 20, 2014 10:25 am
by Bender
Hi,
After playing a little bit with Descriptors and Interrupts I finally
decided to start with my "sleep" function, for which I am planning
to use IRQ0 which is Programmable Interval Timer.
Reading the wiki and JamesM Tutorials I do the following things:
-Set entry 32 in IDT for the timer IRQ
-Program the PIT to 100Hz
-Unmask IRQ0
-Unmask IRQ1
My IRQ0 Timer does the following:
-Increments the uptime by 1
-If the delay is 0, then returns else decrements the delay and returns.
Although code isn't really relevant here but I'll post it.

Code: Select all

;; PIT Timer IRQ0
pit_timer:
	pushad
	push ds
	push es
	inc dword [system_uptime]
	;; How many delays we've?
	cmp dword [delay_count], 0
	je .done
	;; Else Decrement the Delay Flag
	dec dword [delay_count]
.done:
	;; Tell PIC We're done.
	call send_eoi
	pop es
	pop ds
	popad
	iret
;; Delay Function
;; INIT_TIMER ECX = Number of seconds
init_timer:
	mov	dword [delay_count], ecx		      
.loop:
   cli
	cmp	  [delay_flag], 0
	je	  .done
	sti
	jmp .loop
.done:
	sti
	ret
UNMASK_PIT:
   pushad
	;; Unmasks the Timer IRQ
   in al, PIC1+1
   and al, 11111110b
   out PIC1+1, al
	out32 PIC1+1, 0xFD
	;; Enables interrupts 
	sti
   popad
	ret
pit_init:
      ;; Set frequency to 100Hz.
      mov al, 0x36
      out32 0x43, al    
 
      mov ax, 11931
      out32 0x40, al    
      out32 0x40, ah
      ret    
I have tested the delay function, which causes an infinite loop as the IRQ is not fired and the "delay_count" is never
zeroed. The only help that I can expect is "Am I missing something?".
As for the IDT it looks somewhat like this:

Code: Select all

......
.entry_0:
.......
.......
.entry_32:
		dw pit_timer
		dw CODE_SEL
		db 0x00
		db 0x8E
		dw 0
As for the interrupts I can receive both Hardware and Software Interrupts, since I my keyboard and mouse work fine.
-Bender

Re: IRQ0 does not fire. (Am I missing something) but IRQ1 do

Posted: Thu Feb 20, 2014 12:51 pm
by Gigasoft
Are you sure that the assembler is actually outputting anything? Try to get it to assemble without errors first.

Re: IRQ0 does not fire. (Am I missing something) but IRQ1 do

Posted: Thu Feb 20, 2014 10:48 pm
by Brendan
Hi,

Here's the likely cause of the problem:

Code: Select all

UNMASK_PIT:
   pushad
	;; Unmasks the Timer IRQ
   in al, PIC1+1
   and al, 11111110b
   out PIC1+1, al
	out32 PIC1+1, 0xFD     ;MASK THE PIT AND UNMASK THE KEYBOARD

Cheers,

Brendan

Re: IRQ0 does not fire. (Am I missing something) but IRQ1 do

Posted: Fri Feb 21, 2014 12:53 am
by Bender
Hi,
Sorry for replying a little late.
Brendan wrote: out32 PIC1+1, 0xFD ;MASK THE PIT AND UNMASK THE KEYBOARD
I see. So this code tells the PIC to unmask IRQ1 and mask IRQ0?
EDIT:
My mistake should've read the wiki.
When I try to enable the PIT, the keyboard doesn't work anymore
A common mistake is that people reload the mask with 0xFE when they want to add timer, but doing this actually enables only the timer and disables the keyboard (bit #1 of 0xFE is set!) The correct value for enabling both keyboard and timer is 0xFC.
Thanks.
-Bender

Re: IRQ0 does not fire. (Am I missing something) but IRQ1 do

Posted: Fri Feb 21, 2014 5:50 am
by Bender
Hi,
Gigasoft wrote:Are you sure that the assembler is actually outputting anything? Try to get it to assemble without errors first.
Sorry for double posting.
Yes. Thanks for pointing out.

Code: Select all

out 0x40, ah
Should be:

Code: Select all

out32 0x40, ah
Post edited.
-Bender