Page 1 of 1

No interrupts when running in ring 3.

Posted: Wed Sep 22, 2010 12:07 pm
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?

Re: No interrupts when running in ring 3.

Posted: Wed Sep 22, 2010 12:33 pm
by gerryg400

Code: Select all

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

Code: Select all

                or $0x200, %eax; \

Re: No interrupts when running in ring 3.

Posted: Wed Sep 22, 2010 12:35 pm
by Cecil
Well that's embarrassing.

Thanks, works great now. :)

Re: No interrupts when running in ring 3.

Posted: Thu Sep 23, 2010 8:28 am
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)