Page 1 of 3

Really strange problem...

Posted: Mon Oct 20, 2008 2:35 pm
by Jeko
I've had a really strange problem while developing my floppy driver...

To recalibrate the floppy drive I do:

Code: Select all

...

FdcMotorOn(fdc);

while(fdc->op != 0);

...
With this code, there are these bochs outs:

Code: Select all

00075643171i[FDD  ] controller reset in software
00075769487e[CPU0 ] check_cs(0x0008): not a valid code segment !
00075769487e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00075769487i[CPU0 ] CPU is in protected mode (active)
00075769487i[CPU0 ] CS.d_b = 32 bit
00075769487i[CPU0 ] SS.d_b = 32 bit
00075769487i[CPU0 ] EFER   = 0x00000000
00075769487i[CPU0 ] | RAX=0000000000000001  RBX=0000000000000000
00075769487i[CPU0 ] | RCX=0000000000000730  RDX=00000000000003f2
00075769487i[CPU0 ] | RSP=00000000c004af88  RBP=00000000c004afac
00075769487i[CPU0 ] | RSI=00000000d0000560  RDI=00000000e0002031
00075769487i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00075769487i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00075769487i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00075769487i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00075769487i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf AF pf cf
00075769487i[CPU0 ] | SEG selector     base    limit G D
00075769487i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00075769487i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00075769487i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00075769487i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00075769487i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00075769487i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00075769487i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00075769487i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00075769487i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00075769487i[CPU0 ] | RIP=00000000c0000149 (00000000c0000149)
00075769487i[CPU0 ] | CR0=0xe0010011 CR1=0x0 CR2=0x00000000d0004490
00075769487i[CPU0 ] | CR3=0x00003000 CR4=0x00000280
00075769487i[CPU0 ] >> iretd  : CF
00075769487p[CPU0 ] >>PANIC<< exception(): 3rd (13) exception with no resolution
Instead:

Code: Select all

...

FdcMotorOn(fdc);
//while(fdc->op != 0);

...
With this code, the kernel continues to run without any exception, and when I shutdown Bochs there are these lines:

Code: Select all

00102883897i[FDD  ] controller reset in software
00131377500p[XGUI ] >>PANIC<< POWER button turned off.
00131377500i[CPU0 ] CPU is in protected mode (active)
00131377500i[CPU0 ] CS.d_b = 32 bit
00131377500i[CPU0 ] SS.d_b = 32 bit
00131377500i[CPU0 ] EFER   = 0x00000000
00131377500i[CPU0 ] | RAX=0000000000000000  RBX=00000000c00514b0
00131377500i[CPU0 ] | RCX=0000000000000780  RDX=0000000000000000
00131377500i[CPU0 ] | RSP=00000000c004afb4  RBP=00000000c004afdc
00131377500i[CPU0 ] | RSI=00000000e000201d  RDI=00000000e0002031
00131377500i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00131377500i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00131377500i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00131377500i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00131377500i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df IF tf sf ZF af PF cf
00131377500i[CPU0 ] | SEG selector     base    limit G D
00131377500i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00131377500i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00131377500i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00131377500i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00131377500i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00131377500i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00131377500i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00131377500i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00131377500i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00131377500i[CPU0 ] | RIP=00000000c00019aa (00000000c00019aa)
00131377500i[CPU0 ] | CR0=0xe0010011 CR1=0x0 CR2=0x00000000d0004490
00131377500i[CPU0 ] | CR3=0x00003000 CR4=0x00000280
The only differences are these:

Code: Select all

00075769487e[CPU0 ] check_cs(0x0008): not a valid code segment !
00075769487e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
...
00075769487i[CPU0 ] >> iretd  : CF
00075769487p[CPU0 ] >>PANIC<< exception(): 3rd (13) exception with no resolution
Why there is this exception?

Re: Really strange problem...

Posted: Mon Oct 20, 2008 2:42 pm
by Combuster
Why there is this exception?
check_cs(0x0008): not a valid code segment !
Bochs debugger, hint hint :wink:

Re: Really strange problem...

Posted: Mon Oct 20, 2008 2:48 pm
by Jeko
Combuster wrote:Bochs debugger, hint hint :wink:
How can I use it?

Re: Really strange problem...

Posted: Mon Oct 20, 2008 2:53 pm
by Combuster
Have you even tried figuring that out?

Re: Really strange problem...

Posted: Mon Oct 20, 2008 4:03 pm
by Jeko
Thank you for your help...
Now it works, without any modification... I've changed only the bochs configuration file...
Really really strange...

Now I'll go to implement EXT3... If I'll have problems (and I'll have) I'll post here my questions... (hoping bochs won't make fun of me...)

Re: Really strange problem...

Posted: Mon Oct 20, 2008 4:09 pm
by Combuster
Jeko wrote:(hoping bochs won't make fun of me...)
I will, for not killing temporal bugs on sight :evil:

Expect it to come back and haunt you.

Re: Really strange problem...

Posted: Thu Oct 23, 2008 7:31 am
by Jeko
Combuster wrote:Expect it to come back and haunt you.
You were right...
This is my problem:

Code: Select all

00056657374i[FDD  ] controller reset in software
00095824087i[FDD  ] io_write: config control register: 0x00
00095830533e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00095830533e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00095830533e[CPU0 ] interrupt(): not accessable or not code segment cs=0x0008
00095830533i[CPU0 ] CPU is in protected mode (active)
00095830533i[CPU0 ] CS.d_b = 32 bit
00095830533i[CPU0 ] SS.d_b = 32 bit
00095830533i[CPU0 ] EFER   = 0x00000000
00095830533i[CPU0 ] | RAX=000000000000000f  RBX=00000000c00075e9
00095830533i[CPU0 ] | RCX=00000000000006a5  RDX=00000000000003d5
00095830533i[CPU0 ] | RSP=00000000c004ae04  RBP=00000000c004ae04
00095830533i[CPU0 ] | RSI=00000000d0000af0  RDI=00000000c000798c
00095830533i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00095830533i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00095830533i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00095830533i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00095830533i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf sf zf af PF CF
00095830533i[CPU0 ] | SEG selector     base    limit G D
00095830533i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00095830533i[CPU0 ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 1 1
00095830533i[CPU0 ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00095830533i[CPU0 ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00095830533i[CPU0 ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 1 1
00095830533i[CPU0 ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00095830533i[CPU0 ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 1 1
00095830533i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00095830533i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00095830533i[CPU0 ] | RIP=00000000c0003283 (00000000c0003283)
00095830533i[CPU0 ] | CR0=0xe0010011 CR1=0x0 CR2=0x00000000d00044d0
00095830533i[CPU0 ] | CR3=0x00003000 CR4=0x00000280
00095830533i[CPU0 ] >> mov dl, 0xd4 : B2D4
00095830533p[CPU0 ] >>PANIC<< exception(): 3rd (13) exception with no resolution

Re: Really strange problem...

Posted: Thu Oct 23, 2008 7:29 pm
by cr2
'Tis a page fault... check your paging code, and try mappin' all the physical address space to the kernel's virtual address space.

Re: Really strange problem...

Posted: Thu Oct 23, 2008 8:38 pm
by Brendan
Hi,
cr2 wrote:'Tis a page fault... check your paging code, and try mappin' all the physical address space to the kernel's virtual address space.
Um - to me it looks like an IRQ, where the CPU is having problems when it tries to load the interrupt handler's CS and generates an (unhandled) general protection fault....


Cheers,

Brendan

Re: Really strange problem...

Posted: Fri Oct 24, 2008 2:19 am
by Combuster
I get the idea someone forgot to map the GDT...

Re: Really strange problem...

Posted: Fri Oct 24, 2008 3:38 pm
by Jeko
Combuster wrote:I get the idea someone forgot to map the GDT...
No, the GDT is mapped. In fact IRQs are issued, and some of them work without any error.

Re: Really strange problem...

Posted: Fri Oct 24, 2008 3:58 pm
by neon
Is fdc->op modified by an external device or interrupt? I ask this because your while loop would be an infinity loop otherwise.

I would put a breakpoint right before that loop to see exactally what gets executed and when before the #GPF.

Re: Really strange problem...

Posted: Fri Oct 24, 2008 4:31 pm
by Jeko
neon wrote:Is fdc->op modified by an external device or interrupt? I ask this because your while loop would be an infinity loop otherwise.

I would put a breakpoint right before that loop to see exactally what gets executed and when before the #GPF.
Yes, it's modified with an interrupt...
However now that code works, it's another thing after that doesn't work, but the error is similar as you see...

But I think the error isn't due to floppy driver, but to my kernel functions... Only that I don't know what can cause this error.

Re: Really strange problem...

Posted: Fri Oct 24, 2008 5:09 pm
by pcmattman

Code: Select all

CR2=0x00000000d00044d0
PF followed by unavailable IDT meaning double fault, then GPF (hence triple fault and reboot)?

Re: Really strange problem...

Posted: Sat Oct 25, 2008 5:49 am
by Jeko
pcmattman wrote:

Code: Select all

CR2=0x00000000d00044d0
PF followed by unavailable IDT meaning double fault, then GPF (hence triple fault and reboot)?
I have an IDT, it isn't unavailable. In fact, normally, exceptions and IRQs work fine. They work to a certain extent (infact the floppy's motor is started and stopped), and after there is that error.