Odd #GP occurred in IRQ0 routine...

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.
Locked
babel92
Posts: 8
Joined: Thu Oct 25, 2012 9:21 am

Odd #GP occurred in IRQ0 routine...

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
babel92
Posts: 8
Joined: Thu Oct 25, 2012 9:21 am

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

Post 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...
Locked