Page 1 of 1

vm86 mode(problem with #gp)

Posted: Thu Apr 16, 2009 9:05 am
by ahmedhalawa
Hello every body i'm trying to write vm8086 program
it run very good i use int 0x10 i know it should go to
#Gp handler and thats happen the problem when it back
from #GP handler **0x10 handler doesn't run but #GP handler still
repeat himself :(
that is my code

#gp handler

Code: Select all

void GP::handle(regs r)
{   
    uchar *ip;
    regs *vr=&r;
    ushort *ivt=(ushort*)0x0;
    ip = (uchar*)r.eip;
    if(ip[0] = 0xCD)
    {
        vr->cs = ivt[ip[1]*2+1];
        vr->eip= ivt[ip[1] * 2];
        vr->eflags=0x23202;
        return;
    }
    while(1);
}
adding vm8086 code

Code: Select all

        tasks[id].uesp = (uint)kh.alloc(stacksz)+stacksz-1;
        tasks[id].kesp = (uint)kh.alloc(stacksz)-1;
        uint *stack = (uint*)tasks[id].uesp;
        *--stack = (ushort)(add >> 16);
        *--stack = (ushort)(add >> 16);
        *--stack = (ushort)(add >> 16);
        *--stack = (ushort)(add >> 16);
        *--stack = 0x10;
        *--stack=  0xFFFe;
        *--stack = 0x20202|0x200;
        *--stack = (ushort)add>>16;
        *--stack = (ushort)add&0xFFFF;
        *--stack = 0;
        *--stack = 0;
        *--stack = 0;
        *--stack = 0;
        *--stack = 0;
        *--stack = 0;
        *--stack = 0;
        *--stack =(iss)?0x10:0x10;
        *--stack =(iss)?0x10:0x10;
        *--stack =(iss)?0x10:0x10;
        *--stack =(iss)?0x10:0x10;
thanks

Re: vm86 mode(problem with #gp)

Posted: Thu Apr 16, 2009 3:39 pm
by Combuster
When the #GP runs again, what instruction is it pointing to?

Re: vm86 mode(problem with #gp)

Posted: Fri Apr 17, 2009 6:20 am
by ahmedhalawa
Hello
#Gp point the same address
instruction is : 0xCD
value is : 0x10
which my program has it
/*****************/
i think you want to be sur if my program chang ip and cs
in regs be sur that's happen because my program
print values from regs.eip and regs.cs
the values of this regs are differnet, it's not my
program ip and cs
/*****************/
sorry for my english

Re: vm86 mode(problem with #gp)

Posted: Sun Apr 19, 2009 8:30 am
by ahmedhalawa
Hello
does any one know the answer or no if no
pleas from any one give me all things about(rulls) it with small exampel

thanks

Re: vm86 mode(problem with #gp)

Posted: Sun Apr 19, 2009 8:45 am
by Hyperdrive
ahmedhalawa wrote:Hello
#Gp point the same address
instruction is : 0xCD
value is : 0x10
which my program has it
0xCD 0x10 is simply the mentioned "INT 0x10" instruction. You said that raises a GP (huh?), which you handle, then you return from the handler to the old faulting address again. Then, not very surprising, "INT 0x10" raises the GP again, which you handle, then you return from the handler to the old faulting address. Then, not very surprising, "INT 0x10" raises the GP again... I think you got it by now?!

--TS

Re: vm86 mode(problem with #gp)

Posted: Sun Apr 19, 2009 11:18 am
by ahmedhalawa
Hai do you looked to the code i know gp will repeat him self when int 0x10 happen my question is:why that happen pleas look to my code first

Re: vm86 mode(problem with #gp)

Posted: Sun Apr 19, 2009 12:43 pm
by Combuster
The answer has been given, I suggest you read it :roll:

Re: vm86 mode(problem with #gp)

Posted: Fri Aug 14, 2009 3:26 am
by ahmedhalawa
Sorry for re open this topic
I had write vm86 code then i tried it and it's work finaly
after 2 days without change any of code
it bochs and my pc give me #gnf in int 0x10
at this address 0xC000:0xFFFF
Bochs msg is

Code: Select all

Prefetch: Eip [00010000] > cs limit [ 0000FFFF]
Does any one know the reason :!: :?:

Re: vm86 mode(problem with #gp)

Posted: Fri Aug 14, 2009 10:55 am
by Combuster
Does any one know the reason
Prefetch: Eip [00010000] > cs limit [ 0000FFFF]
Asking answered question, no?


Question for you: what is the instruction pointer doing there? How does it get there? Is the bios actually mapped?

Re: vm86 mode(problem with #gp)

Posted: Fri Aug 14, 2009 11:37 am
by ahmedhalawa
I think you read this sentence
I had write vm86 code then i tried it and it's work finaly
after 2 days without change any of code
it bochs and my pc give me #gnf in int 0x10
Mr. Combuster or my best man :D
first pages from 0x00000000 to 0x00200000 mapped in to the same
address there some thing else it's happen after 40 instruction
exact after ret instruction May it happen because i put bad stack address then bois out bad values i donn't think so
i attachment gpf.cpp code you can look to it then give me reason