Programming Interrupt Controller for Clock's specified freq

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
Jane1991c
Posts: 22
Joined: Mon Oct 21, 2013 3:48 pm

Programming Interrupt Controller for Clock's specified freq

Post by Jane1991c »

Hey,
I have got a problem with timer (8253) to set interrupts correctly. I want to run interrupt with frequency 20Hz, so it means I want specified procedure to be run 20 times per second.

Here are steps I have done so far:


Programming Interrupt Controller:

Code: Select all

  MOV DX,20H			;init		
  MOV AL,11H			;icw1=11h       			
  OUT DX,AL                						
  INC DX                   						
  MOV AL,20H			;icw2=20h (interrupt vector's offset)
  OUT DX,AL                						
  MOV AL,4			;icw3=04h (master system)		
  OUT DX,AL                 						
  MOV AL,1			;icw4=01h (mode 8086/88)		
  OUT DX,AL               							
  MOV AL, 0xfc			;ocw1=0fdh (interrupt mask - master) 
  OUT DX,AL                       					
  MOV DX,0A1H			;mask interrupt– slave		
  MOV AL,0FFH              						
  OUT DX,AL 

Configure clock:

Code: Select all

MOV AL, 00110100B
  OUT 43H, AL
I want to run 8253 with 20Hz so I set timer with value 1193181/20=59659,05. Remove .05 part and set timer value to 59659 (dec) = 1110100100001011 (bin) and my code is:

Code: Select all

  MOV AL, 000001011b
  OUT 40H, AL
  MOV AL, 011101001b
  OUT 40H, AL
My IDT entry for clock is set like:

Code: Select all

dw 0
dw 8
db 0
db 010001110b
dw 0
and then i set base address whichc is set properly becouse i have checked it at bochs, screen:
http://s24.postimg.org/g9chkxmg5/clock86.jpg (interrupt number 31 = 20h)

It's set correcly, nasm output:
207 interruptt0:
208 ;mov eax, 14h
209 00000151 43 inc ebx
210
211 00000152 B060 mov al, 0x20 ; tell pic that interrupt
212 00000154 E620 out 0x20, al ; was served
213 00000156 CF iret
And it seems it's all my code for it.

After I run bochs i set break point to 0x8151 (0x8000 is base of my CS segment) (using 'lb 0x8151' command)
Then I press "continute" and no interrupt from 8253 clock come, but when i break i see ebx register increasing very fast like about 300 (dec) per second. Anyway it's definitly too fast it should increase 20 (dec) per second.

Why breakpoint for 0x8151 is not working ? It seems to be executed anyway, why ?

Why is it increasing EBX register for 300 +/- (dec) per second, not 20 per second ?

Hope you will be able to help me, becouse I have no idea where is mistake.

Thank you for help.
Last edited by Jane1991c on Sun Nov 10, 2013 6:08 pm, edited 1 time in total.
Jane1991c
Posts: 22
Joined: Mon Oct 21, 2013 3:48 pm

Re: Programming Interrupt Controller for Clock's specified f

Post by Jane1991c »

Bump for help, whole next day spent solving this problem, and still no result... :x

I gave you a lot of info about what I am working on, hope you will help me find bug
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Programming Interrupt Controller for Clock's specified f

Post by thepowersgang »

1. Are you running in protected or real mode? You mention your breakpoint being at CS*16+ofs, which does not apply in protected mode.
2. Your PIT values look sane, but maybe double check them (or even better, use NASM's pre-processor to calculate the divisor)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Jane1991c
Posts: 22
Joined: Mon Oct 21, 2013 3:48 pm

Re: Programming Interrupt Controller for Clock's specified f

Post by Jane1991c »

thepowersgang wrote:1. Are you running in protected or real mode? You mention your breakpoint being at CS*16+ofs, which does not apply in protected mode.
I set values for idt and programming interrupt controller in real mode, then i run protected mode and enable interrupts.
thepowersgang wrote:or even better, use NASM's pre-processor to calculate the divisor
How to do this and what for ? I don't understand this way to calculate divisor, because i have checked in debugger and correct values are set to port 40h.

I put it right this way:

Code: Select all

  MOV AL, 000001011b
  OUT 40H, AL
  MOV AL, 011101001b
  OUT 40H, AL
where 01110100100001011 = 59659 = divisor, becouse I want to get 20Hz interrupt frequency, so I calculate it in this way:

divisor = 1193181 / 20 = 59659

so it's correct, i think...

Any other ideas ?
Jane1991c
Posts: 22
Joined: Mon Oct 21, 2013 3:48 pm

Re: Programming Interrupt Controller for Clock's specified f

Post by Jane1991c »

Ok i have done it, raeson was bochs config, code etc. was fine :P
Post Reply