Really strange problem...

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.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Really strange problem...

Post 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?
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
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: Really strange problem...

Post by Combuster »

Why there is this exception?
check_cs(0x0008): not a valid code segment !
Bochs debugger, hint hint :wink:
"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 ]
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Really strange problem...

Post by Jeko »

Combuster wrote:Bochs debugger, hint hint :wink:
How can I use it?
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
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: Really strange problem...

Post by Combuster »

Have you even tried figuring that out?
"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 ]
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Really strange problem...

Post 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...)
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
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: Really strange problem...

Post 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.
"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 ]
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Really strange problem...

Post 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
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: Really strange problem...

Post 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.
Last edited by cr2 on Fri Oct 24, 2008 6:08 pm, edited 2 times in total.
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Really strange problem...

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
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: Really strange problem...

Post by Combuster »

I get the idea someone forgot to map the GDT...
"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 ]
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Really strange problem...

Post 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.
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Really strange problem...

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Really strange problem...

Post 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.
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Really strange problem...

Post by pcmattman »

Code: Select all

CR2=0x00000000d00044d0
PF followed by unavailable IDT meaning double fault, then GPF (hence triple fault and reboot)?
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Really strange problem...

Post 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.
Rewriting virtual memory manager - Working on ELF support - Working on Device Drivers Handling

http://sourceforge.net/projects/jeko - Jeko Operating System
Post Reply