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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

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

Post 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
Last edited by Bender on Fri Feb 21, 2014 5:50 am, edited 1 time in total.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

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

Post by Gigasoft »

Are you sure that the assembler is actually outputting anything? Try to get it to assemble without errors first.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

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

Post 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
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

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

Post 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
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
Post Reply