OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 12:30 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 79 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: How to generally enter virtual 8086 mode?
PostPosted: Mon Apr 04, 2022 9:37 am 
Offline

Joined: Mon Apr 04, 2022 9:20 am
Posts: 16
Hello guys, i'm searching for a working code to switch into v8086. I found this on OSDev Wiki:
Code:
; 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 :mrgreen: 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. :lol:
I'm a beginner in fact of OSDev programming.


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Mon Apr 04, 2022 6:57 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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...


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Tue Apr 05, 2022 2:03 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3191
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.


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Tue Apr 05, 2022 11:48 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Wed Apr 06, 2022 6:38 am 
Offline

Joined: Mon Apr 04, 2022 9:20 am
Posts: 16
thank you, but i still not understand. [-X i will study, then i will return on this thread.
goodbye guys


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Wed Apr 06, 2022 8:48 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.

Quote:
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?


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Wed Apr 06, 2022 9:10 am 
Offline

Joined: Mon Apr 04, 2022 9:20 am
Posts: 16
Quote:
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? :?: :cry:
How can I set VGA mode when I use grub that automatically sets protected mode? [-X [-o<


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Wed Apr 06, 2022 9:24 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Wed Apr 06, 2022 9:26 am 
Offline

Joined: Mon Apr 04, 2022 9:20 am
Posts: 16
Quote:
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

Thank you very much! But don't close this thread please.


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Thu Apr 07, 2022 12:57 pm 
Offline

Joined: Mon Apr 04, 2022 9:20 am
Posts: 16
iansjack wrote:
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


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.


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Thu Apr 07, 2022 1:05 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
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.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Fri Apr 08, 2022 10:16 am 
Offline

Joined: Mon Apr 04, 2022 9:20 am
Posts: 16
kzinti wrote:
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


This is my grub.cfg:
Code:
GRUB_TERMINAL_OUTPUT=gfxmode
menuentry "KabiCOM Control Panel for Silly People" {
   set gfxmode=320x200x8
   multiboot (cd)/boot/CpSp.bin
}

it doesn't work


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Fri Apr 08, 2022 10:20 am 
Offline
Member
Member

Joined: Sun Apr 21, 2019 7:39 am
Posts: 76
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/osd/graphics/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.

_________________
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Fri Apr 08, 2022 10:25 am 
Offline
Member
Member

Joined: Sun Apr 21, 2019 7:39 am
Posts: 76
uruseiyatsura wrote:
kzinti wrote:
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


This is my grub.cfg:
Code:
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/manual/multiboot/multiboot.html#multiboot_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:
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

_________________
Hey! I'm developing two operating systems:

NanoShell --- A 32-bit operating system whose GUI takes inspiration from Windows 9x and early UNIX desktop managers.
Boron --- A portable SMP operating system taking inspiration from the design of the Windows NT kernel.


Top
 Profile  
 
 Post subject: Re: How to generally enter virtual 8086 mode?
PostPosted: Fri Apr 08, 2022 11:54 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3191
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. ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 79 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 89 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group