No interrupts when running in ring 3.

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
Cecil
Posts: 2
Joined: Wed Sep 22, 2010 11:46 am

No interrupts when running in ring 3.

Post by Cecil »

So I'm building an os (based off JamesM's excellent tutorials).

I have interrupts, paging, and multitasking (with ring0 threads) working well. I can enter ring 3 from ring 0 and I can make and return from syscalls using software interrupt 0x80.

However, when I switch to ring 3 interrupts no longer fire. I don't get keyboard input or PIC ticks - so I can't multitask my ring 3 processes.

Code: Select all

switch_to_user_mode()
{
        uint32_t *p_esp0 = get_tss_kernel_esp0_location();
        (*p_esp0) = current_task->kernel_stack + KERNEL_STACK_SIZE;

        asm volatile("          \
                cli;            \
                mov $0x23, %eax;\
                mov %eax, %ds;  \
                mov %eax, %es;  \
                mov %eax, %fs;  \
                mov %eax, %gs;  \
                                \
                pushl $0x23;    \
                                \
                mov 0x1fffffff, %eax; \
                pushl %eax;     \
                                \
                pushf;          \
                pop %eax;       \
                or %eax, 0x200; \
                push %eax;      \
                                \
                pushl $0x1B;    \
                                \
                push $1f;       \
                                \
                iret;   \
                1:      \
");
}
If I remove the CLI instruction from the start of the asm section interrupts work properly even in ring 3, but that seems like an unsafe thing to do.

Doesn't "pushf; pop %eax; or %eax, 0x200; push %eax;" re-enable the interrupts when iret is called?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: No interrupts when running in ring 3.

Post by gerryg400 »

Code: Select all

                or %eax, 0x200; \
You left off the dollar sign, try

Code: Select all

                or $0x200, %eax; \
Last edited by gerryg400 on Wed Sep 22, 2010 12:37 pm, edited 1 time in total.
If a trainstation is where trains stop, what is a workstation ?
Cecil
Posts: 2
Joined: Wed Sep 22, 2010 11:46 am

Re: No interrupts when running in ring 3.

Post by Cecil »

Well that's embarrassing.

Thanks, works great now. :)
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: No interrupts when running in ring 3.

Post by Owen »

I can't help but think

Code: Select all

                pushf;          \
                orl $0x200, (%esp); \
Would be better (though my memory is hazy as to if thats permitted)
Post Reply