help me in vm86

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
TheLoST
Posts: 4
Joined: Tue May 03, 2011 5:40 pm

help me in vm86

Post by TheLoST »

hello , im new in this forum , my problem exactly
after i create a vm86 task and execute iret

Code: Select all

  mov ss , tss.ss0 ; 0x18
                 mov esp , tss.esp0 ; 0x1F000              
                 push vm86task.gs ; 0x0900
                 push vm86task.fs ; 0x0900
		 push vm86task.ds ; 0x0900
		 push vm86task.es ; 0x0900
		 push vm86task.ss ; 0x0800
		 push vm86task.esp ; 0xFFFF
		 push vm86task.eflags ; 0x20202
                 push vm86task.cs ;  0x0900
		 push vm86task.eip ; 0x0
                 iret
vm86task start correctly and work to int 0x10 for now its cool
my problem at GP exception the stack frame contain

Code: Select all

 0x0900 ; gs
                    0x0900 ; fs
                    0x0900 ; ds
                    0x0900 ; es
                    0x180800 ; ???????????????????????????????????????? 
                    0x20202 ; eflags
                    0x0900 ; cs
                    0xb ; eip
i dont understand whay th cpu dont pop correct before exception handle
in some book and tuto like this http://www.logix.cz/michal/doc/i386/chp15-03.htm
info :
_ qemu emulator /Oracle virtualBox
_ gcc compilator
_ ubuntu
thnx , sorry for my english is not good :)
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: help me in vm86

Post by b.zaar »

Code: Select all

                    0x0900 ; gs
                    0x0900 ; fs
                    0x0900 ; ds
                    0x0900 ; es
                    0x180800 ; ???????????????????????????????????????? 
                    0x20202 ; eflags
                    0x0900 ; cs
                    0xb ; eip
You're mixing the ss and esp values together.

should be something like the following

Code: Select all

                    0x0900 ; gs
                    0x0900 ; fs
                    0x0900 ; ds
                    0x0900 ; es
                    0x0800 ; ss
                    0x???? ; esp
                    0x20202 ; eflags
                    0x0900 ; cs
                    0xb ; eip
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
TheLoST
Posts: 4
Joined: Tue May 03, 2011 5:40 pm

Re: help me in vm86

Post by TheLoST »

b.zaar wrote:

Code: Select all

                    0x0900 ; gs
                    0x0900 ; fs
                    0x0900 ; ds
                    0x0900 ; es
                    0x180800 ; ???????????????????????????????????????? 
                    0x20202 ; eflags
                    0x0900 ; cs
                    0xb ; eip
You're mixing the ss and esp values together.

should be something like the following

Code: Select all

                    0x0900 ; gs
                    0x0900 ; fs
                    0x0900 ; ds
                    0x0900 ; es
                    0x0800 ; ss
                    0x???? ; esp
                    0x20202 ; eflags
                    0x0900 ; cs
                    0xb ; eip
thnx b.zaar , bat this is my problem the CPU has mixing the ss with ss0 because ss0 value as 0x18 , i dont understande whay the CPU in GP as mixing this value , i need the old esp and old ss to run the vm86 monitor
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: help me in vm86

Post by b.zaar »

I think you should be ignoring the 0x18xxxx of ss as it's above the 16 bit limit of a vm86 stack structure, do something like 0x180800 & 0xFFFF to get the low 16 bit value you need.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
TheLoST
Posts: 4
Joined: Tue May 03, 2011 5:40 pm

Re: help me in vm86

Post by TheLoST »

b.zaar wrote:I think you should be ignoring the 0x18xxxx of ss as it's above the 16 bit limit of a vm86 stack structure, do something like 0x180800 & 0xFFFF to get the low 16 bit value you need.
thnx b.zaar it work my first problem ase resolved now my problem with I/O port

the eflags value : 0x23202 : iopl as 3 but all time i have GP exception , in the monitor i emulate just this instruction

cli , sti , popf pushf , int x , iret , 0xef , 0xed :

in vm task test i call int 10 its work correctly just i dont semilate 0xee , 0xec instruction in google i understand this opcode its

in/out
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: help me in vm86

Post by b.zaar »

TheLoST wrote:
b.zaar wrote:I think you should be ignoring the 0x18xxxx of ss as it's above the 16 bit limit of a vm86 stack structure, do something like 0x180800 & 0xFFFF to get the low 16 bit value you need.
thnx b.zaar it work my first problem ase resolved now my problem with I/O port

the eflags value : 0x23202 : iopl as 3 but all time i have GP exception , in the monitor i emulate just this instruction

cli , sti , popf pushf , int x , iret , 0xef , 0xed :

in vm task test i call int 10 its work correctly just i dont semilate 0xee , 0xec instruction in google i understand this opcode its

in/out
IOPL = 3 works differently between vm86 mode and protected mode and a vm86 task requires a valid I/O permission bitmap in the task state segment.
Read the section - 17.2.8.1 I/O-Port-Mapped I/O - in the intel manuals from Vol 3 - System Programming Guide.
section - 15.5.1 I/O-Mapped I/O - from you link to the original 386 programmers guide.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
TheLoST
Posts: 4
Joined: Tue May 03, 2011 5:40 pm

Re: help me in vm86

Post by TheLoST »

b.zaar wrote: IOPL = 3 works differently between vm86 mode and protected mode and a vm86 task requires a valid I/O permission bitmap in the task state segment.
Read the section - 17.2.8.1 I/O-Port-Mapped I/O - in the intel manuals from Vol 3 - System Programming Guide.
section - 15.5.1 I/O-Mapped I/O - from you link to the original 386 programmers guide.
i extend my tss with 1869 byts like this

Code: Select all

struct tss {
	u16 previous_task, __previous_task_unused;
	u32 esp0;
	u16 ss0, __ss0_unused;
	u32 esp1;
	u16 ss1, __ss1_unused;
	u32 esp2;
	u16 ss2, __ss2_unused;
	u32 cr3;
	u32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
	u16 es, __es_unused;
	u16 cs, __cs_unused;
	u16 ss, __ss_unused;
	u16 ds, __ds_unused;
	u16 fs, __fs_unused;
	u16 gs, __gs_unused;
	u16 ldt_selector, __ldt_sel_unused;
	u16 debug_flag, io_map;
} __attribute__ ((packed));


struct extand_tss{
struct tss tss0;
u32 iobitmap[256];
} __attribute__((packed));

struct extand_tss default_tss;
in gdt
i put the desc of tss like this
base : &default_tss
limit : 0x467
default_tss.tss0.io_map = 0x67;

but in my vm86 task i have int 0x10 is not work correctly
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: help me in vm86

Post by b.zaar »

TheLoST wrote:i extend my tss with 1869 byts like this

Code: Select all

struct tss {
   u16 previous_task, __previous_task_unused;
   u32 esp0;
   u16 ss0, __ss0_unused;
   u32 esp1;
   u16 ss1, __ss1_unused;
   u32 esp2;
   u16 ss2, __ss2_unused;
   u32 cr3;
   u32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
   u16 es, __es_unused;
   u16 cs, __cs_unused;
   u16 ss, __ss_unused;
   u16 ds, __ds_unused;
   u16 fs, __fs_unused;
   u16 gs, __gs_unused;
   u16 ldt_selector, __ldt_sel_unused;
   u16 debug_flag, io_map;
} __attribute__ ((packed));


struct extand_tss{
struct tss tss0;
u32 iobitmap[256];
} __attribute__((packed));

struct extand_tss default_tss;


in gdt
i put the desc of tss like this
base : &default_tss
limit : 0x467
default_tss.tss0.io_map = 0x67;

but in my vm86 task i have int 0x10 is not work correctly
Your io_map address should be 0x68, the first byte past the tss, also make sure you clear all the memory in the io_map. The rest looks alright.
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Post Reply