ISRs Not Working!

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

ISRs Not Working!

Post by pcmattman »

Hi all... I've written the following ISR for interrupt 1C (NASM):

Code: Select all

timerInt:

	pusha

	inc word [tc]					; increment the counter

	popa

	iret
There is no evidence at all of the incrementing of the value, and the only way I've been able to test that the ISR is firing is by adding in code to print the current value of tc, which works but because my ISR runs every time a timer interrupt happens, thousands of numbers just fill the screen...

Any ideas?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

1. One thought about the debugging - if you print a dot between each number and run in an emulator, when you pause the emulator you will be able to see if the number really does increment by one every time.

2. If you are not using any registers in your ISR, do you need to pusha and popa?

3. Is a word value enough to hold your system's tick counter?

4. If you are trying to read the value 'tc' in c (i assume you're not yet as there is no leading underscore), be careful that you are reading the value from memory every time. If you have just set up a loop to check the value, most compilers will just move the value to a register and keep reading the value from there. Use of the word 'volatile' will prevent this.

Hope some of this helps!
Cheers,
Adam
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post by mathematician »

How many segments do you have? The isr contains no code to load ds, or use a segment override.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I've since modified the code to load the correct data segment, thinking it might be that. I've tried this:

Code: Select all

timerInt:

	pusha
	push ds

	mov ds,word [tc_ds]

	mov al,'.'
	mov ah,0x0e
	mov bx,0x0007
	int 0x10

	inc word [ds:tc]

	pop ds
	popa

	iret
This works, but again, the counter is not incremented globally. I've tried putting it into the 'uninitialized data' section ie. bss but it still does not increment. It seems the only way I can access the data is from inside the ISR...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Problem solved, just had to change

Code: Select all

inc word [ds:tc]
to

Code: Select all

inc word [cs:tc]
Does anyone know the clock rate on a 2 year old pc? And what is the clock rate in QEMU?
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

Okay one thing I can add to this post is that creating variables in your code segment specially when all scattered around is a bad practice. Your code would easily get unaligned and you will run into troubles every now and then specially in real mode. It would be better if you could put all your data in your Data Segment and thus use the default addressing mode rather than specifying the code segment explicitly.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Good idea! Didn't think of doing that because I was using a header from another assembly kernel. Now I can say it's officially my kernel :D .
Post Reply