Page 1 of 1

Odd #GP occurred in IRQ0 routine...

Posted: Sun Feb 03, 2013 2:12 pm
by babel92
Hi there,

I just began to work on my task switching code which resides in the time interrupt, and got stuck for quite a while...
Here is the code:

00004a6d: ( ): push ds ; 1e
00004a6e: ( ): push es ; 06
00004a6f: ( ): push fs ; 0fa0
00004a71: ( ): push gs ; 0fa8
00004a73: ( ): pop gs ; 0fa9
00004a75: ( ): pop fs ; 0fa1
00004a77: ( ): pop es ; 07
00004a78: ( ): pop ds ; 1f
00004a79: ( ): iretd ; cf

When execution comes to the red line, bochs says:
"00051416079e[CPU0 ] load_seg_reg(GS, 0x0017): invalid segment"
The value 0x17 was initialized in a piece of code which I copied from the Linux 0.11 kernel in order to jump to ring 3:

Code: Select all

    __asm__ ("movl %%esp,%%eax\n\t" \
             "pushl $0x17\n\t" \
             "pushl %%eax\n\t" \
             "pushfl   \n\t" \
             "pushl $0xf\n\t" \
             "pushl $1f\n\t" \

             "iret\n" \
             "1:\tmovl $0x17,%%eax\n\t" \
             "movw %%ax,%%ds\n\t" \
             "movw %%ax,%%es\n\t" \
             "movw %%ax,%%fs\n\t" \
             "movw %%ax,%%gs" \
         :::"ax");
Could anybody tell me why the exception was thrown? I can't think out any of this....
Thanks.

Re: Odd #GP occurred in IRQ0 routine...

Posted: Sun Feb 03, 2013 2:27 pm
by Combuster
Read the error message, it says exactly what's wrong.

Read the manual, it tells exactly what pop gs/mov gs does and what exceptions are thrown in which cases


And I hope you realize afterwards why using magic numbers and copypasting code you don't understand is bad for you.

Re: Odd #GP occurred in IRQ0 routine...

Posted: Sun Feb 03, 2013 3:26 pm
by babel92
Combuster wrote:Read the error message, it says exactly what's wrong.

Read the manual, it tells exactly what pop gs/mov gs does and what exceptions are thrown in which cases


And I hope you realize afterwards why using magic numbers and copypasting code you don't understand is bad for you.
Thanks for your reply. I used to read the Intel manual but didn't get the point.
This time I made an effort and found out the reason... The segment selector has a different privilege level with the CPL...