Interrupts from usermode problem

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
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Interrupts from usermode problem

Post by FusT »

Hello fellow OS-devers,

For the past couple of months i've been working on my own OS.
I've been following JamesM's tutorial to understand how to get to usermode and do interrupts from there.

Now, I've run into a problem which I just can't seem to figure out.
I downloaded the complete tutorial code from the last tutorial page (usermode) and modified some things:
- removed the cli from the switch_to_usermode function
- added a function to timer.c to get the tick count
- added this function as a syscall
- added a Sleep() function (works in kernel mode!)
- added that as a syscall

Sleep function:

Code: Select all

void Sleep(int Ticks)
{
    int ETicks = 0;
    ETicks = Ticks + get_tick_count();
    do {} while(ETicks > get_tick_count());
}
Now, the problem is that when I use Sleep() from usermode it never exits.
When I add a monitor_write to the interrupt handler for the timer it stops writing the tick count to screen (see screenshot), leading me to beleive that interrupts somehow are not fired.
Strange thing is, syscalls are working, which suggests interrupts are working fine.
Also ISRs work fine, when I do a ASM sti from usermode it GPFs as expected.

Any suggestions are very much appreciated.

Image
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: Interrupts from usermode problem

Post by jnc100 »

Does your get_tick_count() rely on a timer interrupt periodically incrementing a counter? If so, does your interrupt gate for the syscall disable interrupts? If so, the tick count will never increment when you are running the Sleep() syscall. The main problem, however, is that a Sleep() syscall should never be implemented this way - for small sleeps you'd stay in user mode and periodically poll the timer (via a syscall), for longer sleeps you'd de-schedule the task until the timer had reached a certain value and run something else instead.

Regards,
John.
FusT
Member
Member
Posts: 91
Joined: Wed Sep 19, 2012 3:43 am
Location: The Netherlands

Re: Interrupts from usermode problem

Post by FusT »

Hi,

Thanks for your swift reply John, that actually makes sense.

Yes, the get_tick_count() relies on the timer interrupt incrementing a counter.
Yes, the interrupt gate for syscalls disables interrupts.

Just silly of me to not think about the fact that disabling interrupts for a syscall also disables the timer interrupt and thus never increments the tick counter.
Post Reply