how can switch back to real mode ?
how can switch back to real mode ?
hi.
please help to me , how can i switch back to real mode in C language and inline assembly ?
can you write an example here ?
please help to me , how can i switch back to real mode in C language and inline assembly ?
can you write an example here ?
Re: how can switch back to real mode ?
here goes...
MSVC++:
GCC:
If you are trying to execute BIOS interrupts, try v86 or unreal mode.
MSVC++:
Code: Select all
// enters pmode (leaves real mode)
_asm
{
mov eax, cr0
or al, 1
mov cr0, eax
}
// leaves pmode (enters real mode)
_asm
{
mov eax, cr0
and al, 0FEh
mov cr0, eax
}
Code: Select all
// enters pmode (leaves real mode)
unsigned int cr0;
asm volatile ("mov %%cr0, %0" : "=r"(cr0));
cr0 = cr0 | 1;
asm volatile ("mov %0, %%cr0" : : "r"(cr0));
// leaves pmode (enters real mode)
unsigned int cr0;
asm volatile ("mov %%cr0, %0" : "=r"(cr0));
cr0 = cr0 & 0xFE;
asm volatile ("mov %0, %%cr0" : : "r"(cr0));
Last edited by cr2 on Fri Aug 29, 2008 6:52 am, edited 1 time in total.
OS-LUX V0.0
Working on...
Memory management: the Pool
Working on...
Memory management: the Pool
Re: how can switch back to real mode ?
There is a bit more to it than that, of course, but it takes some setup.
After flipping the bit in CR0, you need to reset the segment registers, and you need to set up a stack.
Setting the CS register involves doing a far jump, to some code that is already stored in low memory (below 1M).
You probably also have to switch back to the Real Mode IVT (at physical address 0).
After flipping the bit in CR0, you need to reset the segment registers, and you need to set up a stack.
Setting the CS register involves doing a far jump, to some code that is already stored in low memory (below 1M).
You probably also have to switch back to the Real Mode IVT (at physical address 0).
Re: how can switch back to real mode ?
thanks for your info.
what is the v86 mode and how can i use that in pmode and call interrupts ?
please give me more info about that
what is the v86 mode and how can i use that in pmode and call interrupts ?
please give me more info about that
Re: how can switch back to real mode ?
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
The man who walks alone is likely to find himself in places
no one has ever been before.
Re: how can switch back to real mode ?
Note that v86 mode isn't a "fix all" solution. While it is useful for display functions (VESA), it may not be wise to use it for disk I/O. Also, if you ever try a 64 bit OS, v86 mode is not available. If you want something more general purpose, stick with switching to real mode.
In my (C++) second stage boot loader, I have a function called realMode (genius ) which is passed the address of a real mode function, parameter count and then a variable number of parameters. This (PMode) function automatically does the switch to real mode, converts to a 16 bit CS:IP, executes the function with given parameters and returns.
It's a bit of work setting up such a system but well worth it if you have a lot of real mode work to do.
Cheers,
Adam
In my (C++) second stage boot loader, I have a function called realMode (genius ) which is passed the address of a real mode function, parameter count and then a variable number of parameters. This (PMode) function automatically does the switch to real mode, converts to a 16 bit CS:IP, executes the function with given parameters and returns.
It's a bit of work setting up such a system but well worth it if you have a lot of real mode work to do.
Cheers,
Adam
Re: how can switch back to real mode ?
I can just recommend the switching instead of using v8086. Coding a macro or function that will temporarily jump to rmode and back will cost you about 10 minutes, with v8086 you need first to provide full multitasking and all that stuff
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English )
Derrick operating system: http://derrick.xf.cz (Slovak and English )
-
- Member
- Posts: 195
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: how can switch back to real mode ?
I am having trouble with switching back to RealMode, too.
I do the following in my BootLoader:
But in Bochs I always got a restart, because the segment registers are in 32Bit and cs=0xf0000000 and ip=0xFFFE0.
What did I wrong?
Sebihepp
I do the following in my BootLoader:
Code: Select all
[BITS 32]
[ORG 0x0000]
;Some Stuff
SwitchToRealMode:
mov eax, cr0
and al, 0xFE
mov cr0, eax
jmp 0x07C0:RealMode
[BITS 16]
RealMode:
call DisableA20Gate
jmp $
; the rest of the bootloader
What did I wrong?
Sebihepp
Re: how can switch back to real mode ?
Here is a vesa demo i wrote that switch to and from pmode to realmode for vesa mode switching, it may help.
http://dex4u.com/demos/VesaDemo.zip
http://dex4u.com/demos/VesaDemo.zip
Re: how can switch back to real mode ?
@Sebihepp: Make sure your code is under 640K, or relocate it there.
BTW you don't need to disable the A20 gate when entering real mode.
BTW you don't need to disable the A20 gate when entering real mode.
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English )
Derrick operating system: http://derrick.xf.cz (Slovak and English )
Re: how can switch back to real mode ?
You must set hidden part of segment registers.sebihepp wrote:What did I wrong?
Code: Select all
org 0
...
; descriptor for 16-bit code segment selected by CODE16
desc 0x7C00, 0xFFFF, \ ; base & limit
DF_PRESENT \ ; default
or DF_CODE or DF_DUALACTION \ ; i.e. readable code
or DF_USE16 or DF_BYTED ; default when granularity byte is equal to 0
; descriptor for 16-bit data segment selected by DATA16
desc 0x7C00, 0xFFFF, \ ; base & limit
DF_PRESENT \ ; default
or DF_DATA or DF_DUALACTION \ ; i.e. writable data
or DF_USE16 or DF_BYTED ; default when granularity byte is equal to 0
...
use32
SwitchToRealMode:
jmp CODE16:@f
use16
@@:
mov ax,DATA16
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
mov eax,cr0
and al,0xFE
mov cr0,eax
jmp 0x7C0:@f
@@:
mov ax,0x7C0
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ss,ax
If you have seen bad English in my words, tell me what's wrong, please.
-
- Member
- Posts: 195
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: how can switch back to real mode ?
Ah, okay. I think the descriptor of my code and the data was not set to 16 bit.
It was an 0x7C00 and has the size 0xFFFF and the size is counted in bytes.
I will try to set the descriptors to 16bit.
Thanks Sebihepp
It was an 0x7C00 and has the size 0xFFFF and the size is counted in bytes.
I will try to set the descriptors to 16bit.
Thanks Sebihepp