Bochs: fetch_raw_descriptor??

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.
Post Reply
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Bochs: fetch_raw_descriptor??

Post by LordMage »

I am trying to configure the PICs using the code from brans tutorial. here is the code and the error any help would be greatly appreciated:

Code: Select all


void irq_remap(void)
{
     outportb(0x20, 0x11);
     outportb(0xA0, 0x11);
     outportb(0x21, 0x20);
     outportb(0xA1, 0x28);
     outportb(0x21, 0x04);
     outportb(0xA1, 0x02);
     outportb(0x21, 0x01);
     outportb(0xA1, 0x01);
     outportb(0x21, 0x0);
     outportb(0xA1, 0x0);
}

Now unless I'm missing something that is exactly what he had and here is the debug in Bochs:

Code: Select all


[BIOS] Booting from 0000:7C00
[CPU0] fetch_raw_descriptor: GDT: index (447)88 > limit (17)
[CPU0] >>PANIC<< fetch_raw_descriptor: LDTR.valid=0

Any Ideas?? I can post more code if it might be something else, but the error happens when I try to run that function
Getting back in the game.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

im certainly no bochs expert, but that output looks like you tried to load a segment into one of the segment registers... but the segment number was higher than your current GDT.limit (which if i read it correctly is 17?)

it looks to me like your trying to execute invalid memory (perhaps data or just random memory addresses...) -- make sure all your asm jumps and branches are going to the correct place, and that your code is being linked and/or relocated at the correct addresses
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

Okay, what does the far jump when loading the GDT do??

Code: Select all


.
.
.
mov ss, ax
jmp 0x08:flush2

flush2:
.
.

Because I can't do it. I just can't figure it out using VC++. I finally got it to far jump but it is to the wrong location. I am using inline asm for everything.

I don't know if that is the problem but it is all I can think. the error actually shows up when I execute the outportb(0x21, 0x20). Here is the code from my outportb() function, might help but I doubt it.

Code: Select all


inline void _cdecl outportb (unsigned short portid, unsigned char value)
{
    _asm
    {
           mov al, [value]
           mov dx, [portid]
           out dx, al
     }
}

Getting back in the game.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Bochs: fetch_raw_descriptor??

Post by JamesM »

Now unless I'm missing something that is exactly what he had and here is the debug in Bochs:

Code: Select all


[BIOS] Booting from 0000:7C00
[CPU0] fetch_raw_descriptor: GDT: index (447)88 > limit (17)
[CPU0] >>PANIC<< fetch_raw_descriptor: LDTR.valid=0

Any Ideas?? I can post more code if it might be something else, but the error happens when I try to run that function
That error is to do with the GDT and has nothing to do with remapping the IRQs.
Okay, what does the far jump when loading the GDT do??

Code: Select all

. 
. 
. 
mov ss, ax 
jmp 0x08:flush2 

flush2: 
. 
.
With all segment registers except the CS, you can just load a new value in. You cannot do this with the CS. To change it, you must 'far jump' or 'far call', that is, jump or call to a different segment.

In this code snippet a far jump is being done to 'flush2', which is just after the current instruction. The side effect of this is the CS gets changed to 0x08, which is what you want.

Your code will not work without this functionality.

Good luck!
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post by LordMage »

okay, I was thinking something along those lines. My next question is how do I do a far jump using VC++ inline asm I tried what I could find on MS Sites and google searches but I am either not doing it right or couldn't find the right procedure. If anyone knows I would appreciate knowing very much

Thanks
Getting back in the game.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

What syntax does VC++ use? If it's AT&T syntax you want the 'ljmp <addr>, <segment>' pseudoinstruction.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

JamesM wrote:What syntax does VC++ use? If it's AT&T syntax you want the 'ljmp <addr>, <segment>' pseudoinstruction.
VC++ uses MASM -- that is intel syntax (or something like it -- iirc MASM is a little more complicated than NASM/FASM, but the same code should work essentially the same)

Code: Select all

jmp 0x08:flush2
this is standard intel ASM, but MASM might require use of the FAR keyword... (because it does expect to run in flat PMode)

you might want to try it with the FAR keyword (FAR means with segment, near means without segment, and short means as an offset from current eIP):

Code: Select all

jmp FAR 0x08:flush2
Post Reply