Page 1 of 6
How to generally enter virtual 8086 mode?
Posted: Mon Apr 04, 2022 9:37 am
by uruseiyatsura
Hello guys, i'm searching for a working code to switch into v8086. I found this on OSDev Wiki:
Code: Select all
; you should declare this function as :
; extern void enter_v86(uint32_t ss, uint32_t esp, uint32_t cs, uint32_t eip);
enter_v86:
mov ebp, esp ; save stack pointer
push dword [ebp+4] ; ss
push dword [ebp+8] ; esp
pushfd ; eflags
or dword [esp], (1 << 17) ; set VM flags
push dword [ebp+12] ; cs
push dword [ebp+16] ; eip
iret
But I'm so stupid
and so I can not understand how to use this function and how to exit from a v8086 task.
I need a help especially for activating VGA 256 colours mode, and floppy disk reading. I know you don't reccomend 8086 disk reading, but I don't care.
I'm a beginner in fact of OSDev programming.
Re: How to generally enter virtual 8086 mode?
Posted: Mon Apr 04, 2022 6:57 pm
by Octocontrabass
Entering virtual 8086 mode is the same as entering user mode. The only real difference between a virtual 8086 mode task and any other task is the state of EFLAGS.VM.
Exiting virtual 8086 mode is also the same as exiting user mode: the task will perform a system call, or the task will cause an exception, or external hardware will interrupt the CPU.
Reading the floppy disk requires IRQs, which means your kernel will need to catch the floppy disk IRQs (and possibly others, like timer IRQs) and redirect them into the virtual 8086 mode task. This is not exactly a beginner-level task...
Re: How to generally enter virtual 8086 mode?
Posted: Tue Apr 05, 2022 2:03 am
by rdos
I think calling real BIOS functions when developing support for V86 mode is not a good idea. You should start by calling V86 code that just does an iret. Note that you will need to handle exceptions from V86 mode, in particular those that affect flags and those that return back to your kernel.
You also need to create a stack for V86 mode, and then you need to push a reference to something that takes you back to your kernel. For instance, if you use iret to return (which a BIOS function will do), then you need to push 16-bit flags, cs and ip that reference some location in V86 mode that contains code that trigger you to return to your kernel. As an example, you could place an invalid instruction there and handle this exception in your kernel, and detect the source. Of course, you will need to unwind your exception handler and save the return position in your kernel so the exception handler can go there.
There actually is a big difference between calling V86 code and user mode. Generally, user mode code will use syscalls to access your kernel, which works fine with the normal flow. However, with V86 code, you want to "call" certain software in the BIOS, which is in the reverse direction and not part of the normal execution flow.
Re: How to generally enter virtual 8086 mode?
Posted: Tue Apr 05, 2022 11:48 pm
by MichaelPetch
I have a very basic sample here that enters V8086 mode. V8086 mode is simply exited with a UD2 instruction (not useful way of doing it but was meant as an example). It has very basic support for an INT N wrapper etc.
https://github.com/marleyd386/OSDev/tre ... -intn-iret
Re: How to generally enter virtual 8086 mode?
Posted: Wed Apr 06, 2022 6:38 am
by uruseiyatsura
thank you, but i still not understand.
i will study, then i will return on this thread.
goodbye guys
Re: How to generally enter virtual 8086 mode?
Posted: Wed Apr 06, 2022 8:48 am
by iansjack
Are you, unintentionally, making life difficult for yourself?
Set the VGA mode before you go into protected mode.
Write a protected mode floppy disk driver; it's probably easier than grappling with virtual 8086 mode (and getting real mode interrupts to work). When your OS grows up and wants to use 64-bit mode the virtual 8086 mode isn't available.
I know you don't reccomend 8086 disk reading, but I don't care.
Fair enough, but if you don't care why should anyone else care enough to help you?
Re: How to generally enter virtual 8086 mode?
Posted: Wed Apr 06, 2022 9:10 am
by uruseiyatsura
Are you, unintentionally, making life difficult for yourself?
Set the VGA mode before you go into protected mode.
Write a protected mode floppy disk driver; it's probably easier than grappling with virtual 8086 mode (and getting real mode interrupts to work). When your OS grows up and wants to use 64-bit mode the virtual 8086 mode isn't available.
How can I set a protected mode floppy driver so?
How can I set VGA mode when I use grub that automatically sets protected mode?
Re: How to generally enter virtual 8086 mode?
Posted: Wed Apr 06, 2022 9:24 am
by iansjack
You don't
get it, you
write it. That's what OS development is all about. Information here:
https://wiki.osdev.org/Floppy_Disk_Controller
Grub lets you specify the graphics mode:
https://www.gnu.org/software/grub/manua ... ation.html
Re: How to generally enter virtual 8086 mode?
Posted: Wed Apr 06, 2022 9:26 am
by uruseiyatsura
Thank you very much! But don't close this thread please.
Re: How to generally enter virtual 8086 mode?
Posted: Thu Apr 07, 2022 12:57 pm
by uruseiyatsura
Cannot find the GRUB option you said to exist. I'm using a multiboot kernel, this can help you if you want to help me, but actually I found nothing on that site.
Re: How to generally enter virtual 8086 mode?
Posted: Thu Apr 07, 2022 1:05 pm
by kzinti
To select the video mode in Grub, you use the gfxmode option. It took me all of 5 seconds to find it at the link you provided:
https://www.gnu.org/software/grub/manua ... ml#gfxmode
As to how you retrieve that info from multiboot, check the spec you are using (multiboot 1 or 2), it has the necessary information.
Re: How to generally enter virtual 8086 mode?
Posted: Fri Apr 08, 2022 10:16 am
by uruseiyatsura
This is my grub.cfg:
Code: Select all
GRUB_TERMINAL_OUTPUT=gfxmode
menuentry "KabiCOM Control Panel for Silly People" {
set gfxmode=320x200x8
multiboot (cd)/boot/CpSp.bin
}
it doesn't work
Re: How to generally enter virtual 8086 mode?
Posted: Fri Apr 08, 2022 10:20 am
by iProgramInCpp
uruseiyatsura wrote:
I need a help especially for activating VGA 256 colours mode
Do you really need BIOS interrupts? Because you can switch the VGA mode without them;
check
https://files.osdev.org/mirrors/geezer/ ... cs/modes.c for some code, and
https://wiki.osdev.org/VGA_Resources.
Every piece of hardware has an interface you can write a driver for, you should not need to depend on black-box code provided by the BIOS.
Re: How to generally enter virtual 8086 mode?
Posted: Fri Apr 08, 2022 10:25 am
by iProgramInCpp
uruseiyatsura wrote:
This is my grub.cfg:
Code: Select all
GRUB_TERMINAL_OUTPUT=gfxmode
menuentry "KabiCOM Control Panel for Silly People" {
set gfxmode=320x200x8
multiboot (cd)/boot/CpSp.bin
}
it doesn't work
Did you turn on
https://www.gnu.org/software/grub/manua ... ot_002eh-1 MULTIBOOT_VIDEO_MODE in your Multiboot header? This will allow you to use setgfxpayload, which will set the graphics payload. The menuentry is broken right now because you set gfxmode, not gfxpayload, and you don't call "boot", and the gfxpayload set is done before loading the kernel, when it should be after. Here's a fixed configuration:
Code: Select all
menuentry "KabiCOM Control Panel for Silly People" {
multiboot (cd)/boot/CpSp.bin
set gfxpayload=800x600x32
boot
}
One more thing, this will set a
VBE video mode, if you really want the 320x200 256 color screen mode I recommend checking the resources I posted earlier, or keeping on with V8086
Re: How to generally enter virtual 8086 mode?
Posted: Fri Apr 08, 2022 11:54 am
by rdos
Actually, if he just wants to set a video mode, then it would be much easier to do his own boot-loader, and in the boot process call BIOS to set the desired mode.
No real OS will depend on GRUB anyway. Takes away all the fun.