Virtual mode - 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.
Post Reply
Kernel32.pl
Posts: 2
Joined: Sat Feb 24, 2007 2:08 pm
Location: Poland - Jaworzno

Virtual mode - problem

Post by Kernel32.pl »

Hello.

Code: Select all

[ORG 0x7C00]
[BITS 16]
start:
	mov ax, 0x1000
	mov ss, ax
	xor esp, esp

	mov ax, cs
	mov ds, ax
	mov es, ax

	mov	ax, 3h
	int	10h
	
	xor ax, ax
	mov ds, ax

	lgdt [gdt_descr]

	mov eax, cr0
	or eax, 1
	mov cr0, eax

	jmp 0x08:start32

vm86:		;v8086 mode - 16-bits
	mov ax, 3h
	int 16h			;it's ok without this

vm86_stop:
jmp vm86_stop

[BITS 32]
start32:
	mov ax, 10h
	mov ss, ax
	mov ds, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	mov esp, 0x10000
	
	push dword 0	;real_mode_gs 
	push dword 0	;real_mode_fs 
	push dword 0	;real_mode_ds 
	push dword 0	;real_mode_es 
	push dword 0	;real_mode_ss 
	push dword 0	;real_mode_esp
	;===EFLAGS===
					;pushfd ;(with vm86 bit = 1) 
	push dword 0x20000	;0x23202
	
	push dword 0	;real_mode_cs
	push dword vm86	;real_mode_eip 
	iretd 
	
gdt:
	dd 0					; NULL Descriptor
	dd 0

	dw 0xFFFF
	dw 0
	db 0
	db 10011010b
	db 11001111b
	db 0

	dw 0xFFFF
	dw 0
	db 0
	db 10010010b
	db 11001111b
	db 0
gdt_end:

gdt_descr:
	dw gdt_end - gdt - 1
	dd gdt
  
times 510 - ($ - $$) db 0
dw 0xAA55

I have a problem with vm86 in my system.
I try to turn on and make a brake in this simple programe.
I can turn on the virtual state but when I try to get the brake I get in the Bochs somthing like this
"exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting".
Please help.
digo_rp
Member
Member
Posts: 233
Joined: Sun Jun 05, 2005 11:00 pm

Post by digo_rp »

correct me if I´m wrong, int 16h take one byte from keyboard, right ?

you need to redirect all of yours IRQ_handlers to your IVT when a irq occurs "happens" sorry for my poor english, you have to do it like when a int instuction happens in your v86 monitor.

try to get from www.osdever.net the pmtuts all 17 tuts from alexey.

that should helps you alot.
xyz1
Posts: 14
Joined: Fri Jan 05, 2007 8:15 am

one more question

Post by xyz1 »

To not start new thread, I will ask here.

I have strong problems. I want to test v86 mode in one old menuetos version. My code is something like this:
v86_bios:
push dword 0x1000 ;gs
push dword 0x1000 ;fs
push dword 0x1000 ;ds
push dword 0x1000 ;es
push dword 0x2000 ;ss
push dword 0x0 ;sp
push dword 0x23202 ;flags
push dword 0x1000 ;cs
push dword vm86-0x10000 ;ip
iret
.exit:
;pop stack ...
add esp,9*4
ret

use16
vm86:
int 0x40
jmp $
use32
and I start this code with system call (int 0x40). If I test this code under QEMU there is some (only) problems:
1. In this form QEMU halts, and do not working.
2. If I remove "int 0x40" after label vm86, than OS stops, but QEMU working, as usual - for example I can close window.
3. If I replace "iret" with "jump $", than only call application stops, and of cource, if I remove "iret" - everything working.

It seems, that QEMU enter in V86 mode, since 1. and 2. make different thinks. I know that in 1. that I must catch "general protection falure", but it seems, that this is not working. Why all os stops?
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Post by deadmutex »

@Kernel.pl and xyz1 - Do you have a V86 mode monitor to emulate the "int" instruction? In v86 mode, a GPF is generated on a sensitive instruction and it's up to the vmm to emulate the instruction(if it's valid) and continue.

Check the External links on wiki: http://www.osdev.org/wiki/Virtual_8086_Mode.

The first one really helped me out when I was making my monitor.

EDIT: Oh yeah, like digo_rp said, make sure your real mode IVT is intact if you want to use the BIOS interrupts.
xyz1
Posts: 14
Joined: Fri Jan 05, 2007 8:15 am

Post by xyz1 »

Do you have a V86 mode monitor to emulate the "int" instruction?
Yes I have - it must only print an error! But this is not happen.
Check the External links on wiki: http://www.osdev.org/wiki/Virtual_8086_Mode.
The first one really helped me out when I was making my monitor.
I alredy read this link, but it is not help me.
EDIT: Oh yeah, like digo_rp said, make sure your real mode IVT is intact if you want to use the BIOS interrupts.
BIOS call are step 2. My code do not working even in "enter & exit fron v86 mode".

About example above, want to note, that line "push dword 0x23202 ;flags" is not correct. It must be "push dword 0x20000 ;flags". If I set IF flag in this line (+0x200) then qemu works like in "1.", even if there is not "int 0x40" in v86 code.
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:

Post by Combuster »

Why do my eyes see no IDT code here? (triplefault2go4)
"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 ]
Kernel32.pl
Posts: 2
Joined: Sat Feb 24, 2007 2:08 pm
Location: Poland - Jaworzno

Post by Kernel32.pl »

In my system I have redirected all of the breakes in IDT to make a information box on the screen. I get the same error in my simple program when I turn on the pageing of the memmory it blows an exeption 14.
Maybe the error is in the IVT because I don't know how to use pmode.

Thanks for the links but they didn't help me :D
Post Reply