I'm receiving general protection fault with error code 24 on iretq instruction. Error code isn't equal to zero so exception is segment related. This error code means fifth descriptor in GDT, but my GDT has only three descriptors: null, code and date.
Why do I have this error and how can I fix it?
general protection fault on iretq
-
- Member
- Posts: 5575
- Joined: Mon Mar 25, 2013 7:01 pm
Re: general protection fault on iretq
Why did you make a new thread for this?
What's on the stack when IRETQ faults?
What's on the stack when IRETQ faults?
Re: general protection fault on iretq
Although I can't verify, I would assume that everything that gets pushed on the stack isn't getting popped off. Iretq is then loading bogus values in the registers. This might solve your problem.
Re: general protection fault on iretq
In the previous topic I asked about valid IDT descriptor, but it turned out that the problem is completely unrelated to this so I created new topic for the real problem I'm facing.Why did you make a new thread for this?
Here you have:What's on the stack when IRETQ faults?
Code: Select all
0x000000000000fff0 in ?? ()
(gdb) b kernel_start
Breakpoint 1 at 0x1255e0: file kernel.c, line 7.
(gdb) b irq1
Breakpoint 2 at 0x125830
(gdb) b exc13
Breakpoint 3 at 0x125ea4
(gdb) c
Continuing.
Breakpoint 1, kernel_start (mbd=0x132c4c, magic=732803074) at kernel.c:7
7 vga_init();
(gdb) x/100xd $sp
0x12b018: 1048760 0 0 0
0x12b028 <vga_mem>: 0 0 0 0
0x12b038: 0 0 0 0
0x12b048 <buf_p1>: 0 0 0 0
0x12b058: 0 0 0 0
0x12b068 <kbd_buffer+8>: 0 0 0 0
0x12b078 <kbd_buffer+24>: 0 0 0 0
0x12b088 <kbd_buffer+40>: 0 0 0 0
0x12b098 <kbd_buffer+56>: 0 0 0 0
0x12b0a8 <idt+8>: 0 0 0 0
0x12b0b8 <idt+24>: 0 0 0 0
0x12b0c8 <idt+40>: 0 0 0 0
0x12b0d8 <idt+56>: 0 0 0 0
0x12b0e8 <idt+72>: 0 0 0 0
0x12b0f8 <idt+88>: 0 0 0 0
0x12b108 <idt+104>: 0 0 0 0
0x12b118 <idt+120>: 0 0 0 0
0x12b128 <idt+136>: 0 0 0 0
0x12b138 <idt+152>: 0 0 0 0
0x12b148 <idt+168>: 0 0 0 0
0x12b158 <idt+184>: 0 0 0 0
0x12b168 <idt+200>: 0 0 0 0
0x12b178 <idt+216>: 0 0 0 0
0x12b188 <idt+232>: 0 0 0 0
0x12b198 <idt+248>: 0 0 0 0
(gdb) c
Continuing.
Breakpoint 2, 0x0000000000125830 in irq1 ()
(gdb) x/100xd $sp
0x12afb8: 1202424 0 8 0
0x12afc8: 582 0 1224680 0
0x12afd8: 24 0 0 0
0x12afe8: 1202136 0 1256524 0
0x12aff8: 0 0 0 0
0x12b008: 0 0 0 0
0x12b018: 1048760 0 720 0
0x12b028 <vga_mem>: 753664 0 0 0
0x12b038: 0 0 0 0
0x12b048 <buf_p1>: 0 0 0 0
0x12b058: 0 0 0 0
0x12b068 <kbd_buffer+8>: 0 0 0 0
0x12b078 <kbd_buffer+24>: 0 0 0 0
0x12b088 <kbd_buffer+40>: 0 0 0 0
0x12b098 <kbd_buffer+56>: 0 0 548263 1216000
0x12b0a8 <idt+8>: 0 0 548288 1216000
0x12b0b8 <idt+24>: 0 0 548313 1216000
0x12b0c8 <idt+40>: 0 0 0 0
0x12b0d8 <idt+56>: 0 0 0 0
0x12b0e8 <idt+72>: 0 0 0 0
0x12b0f8 <idt+88>: 0 0 548338 1216000
0x12b108 <idt+104>: 0 0 0 0
0x12b118 <idt+120>: 0 0 548363 1216000
0x12b128 <idt+136>: 0 0 0 0
0x12b138 <idt+152>: 0 0 0 0
(gdb) c
Continuing.
Breakpoint 3, 0x0000000000125ea4 in exc13 ()
(gdb) x/100xd $sp
0x12aef0: 24 0 1202257 0
0x12af00: 8 0 147 0
0x12af10: 1224488 0 24 0
0x12af20: 1202257 0 24 0
0x12af30: 24 0 0 0
0x12af40: 1202400 0 1205156 0
0x12af50: 1200832 0 1224744 0
0x12af60: 1208320 0 1224736 0
0x12af70: 1200400 0 1224576 0
0x12af80: 1201184 0 980 0
0x12af90: 1224772 0 0 0
0x12afa0: 1224776 0 1201584 0
0x12afb0: 0 0 1202424 0
0x12afc0: 8 0 582 0
0x12afd0: 1224680 0 24 0
0x12afe0: 0 0 1202136 0
0x12aff0: 1256524 0 0 0
0x12b000: 0 0 0 0
0x12b010: 0 0 1048760 0
0x12b020 <cursor>: 720 0 753664 0
0x12b030: 0 0 0 0
0x12b040 <kbd_status.1178>: 0 1 0 0
0x12b050: 0 0 0 0
0x12b060 <kbd_buffer>: 10 0 0 0
0x12b070 <kbd_buffer+16>: 0 0 0 0
(gdb) q
-
- Member
- Posts: 5575
- Joined: Mon Mar 25, 2013 7:01 pm
Re: general protection fault on iretq
Code: Select all
0x12afb8: 1202424 0 8 0
0x12afc8: 582 0 1224680 0
0x12afd8: 24 0 0 0
Code: Select all
0x12afb8: 0x00000000001258f8 -> RIP
0x12afc0: 0x0000000000000008 -> CS
0x12afc8: 0x0000000000000246 -> RFLAGS
0x12afd0: 0x000000000012afe8 -> RSP
0x12afd8: 0x0000000000000018 -> SS
Re: general protection fault on iretq
It was so from beginning. Since GRUB called my kernel. I didn't even touch this register.Why was there an invalid selector in SS?
Re: general protection fault on iretq
Setting ds and ss to 16 solved the problem. I didn't know they had to be set. This wasn't described in guide I followed when writing my first OS. Do I also need to set other segment registers (gs, fs etc.)?