Page 1 of 1

Interrupt Inaccessible Code Segment

Posted: Sat Dec 01, 2012 5:37 pm
by Geometrian
Hi,

I am trying to get interrupts working. In Bochs, however, I am getting the following:

Code: Select all

00089733886i[BIOS ] Booting from 0000:7c00
00089886116e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00089886116e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00089886116e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00089886116i[CPU0 ] CPU is in protected mode (active)
00089886116i[CPU0 ] CS.d_b = 32 bit
00089886116i[CPU0 ] SS.d_b = 32 bit
00089886116i[CPU0 ] EFER   = 0x00000000
00089886116i[CPU0 ] | RAX=0000000000000000  RBX=000000000000aa55
00089886116i[CPU0 ] | RCX=0000000000000019  RDX=00000000000a105d
00089886116i[CPU0 ] | RSP=000000000008ffd0  RBP=000000000008ffe8
00089886116i[CPU0 ] | RSI=0000000000007da3  RDI=0000000000000530
00089886116i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00089886116i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00089886116i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00089886116i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00089886116i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00089886116i[CPU0 ] | SEG selector     base    limit G D
00089886116i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00089886116i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 ffffffff 1 1
00089886116i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00089886116i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00089886116i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00089886116i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00089886116i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00089886116i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00089886116i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00089886116i[CPU0 ] | RIP=0000000000001ce6 (0000000000001ce6)
00089886116i[CPU0 ] | CR0=0x60000011 CR2=0x0000000000000000
00089886116i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00089886116i[CPU0 ] 0x0000000000001ce6>> int 0x13 : CD13
00089886116e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
According to the Wiki, this implies that the IDT is corrupt. However, I am not sure that is the problem--in the output above, CS does indeed seem to be 0x0008; furthermore, I issue a test interrupt immediately after loading the IDT.

Thanks,

Re: Interrupt Inaccessible Code Segment

Posted: Sat Dec 01, 2012 6:16 pm
by rdos
Why do you issue int 0x13 in protected mode, and have you setup a interrupt handler for it?

Re: Interrupt Inaccessible Code Segment

Posted: Sat Dec 01, 2012 7:31 pm
by Geometrian
rdos wrote:Why do you issue int 0x13 in protected mode, and have you setup a interrupt handler for it?
The 0x13 is just a random number; I'm not trying to accomplish anything using the interrupt yet.

I have set up a handler in the IDT, using almost exactly the same code as described here: http://www.jamesmolloy.co.uk/tutorial_html/4.-The%20GDT%20and%20IDT.html.

Re: Interrupt Inaccessible Code Segment

Posted: Sat Dec 01, 2012 8:34 pm
by Geometrian
I think I found the problem. The GDT was being allocated on the stack. When the IDT was set immediately after, it munged the GDT.

The solution was to move the GDT and IDT to be global variables.

Thanks,