Unreal mode
Posted: Fri Nov 13, 2009 1:56 pm
Hi! I'm trying to support the unreal mode in my bootloader. Is there a way to use the old segment:offest notation up to the first megabyte and the physical for the upper addresses?
That sounded rather clueless. What do you want with *supporting* unreal mode? Is your OS based on Unreal Mode?trying to support the unreal mode
Do you know exactly what unreal mode is? Why do you want these "notations"?Karlosoft wrote:Hi! I'm trying to support the unreal mode in my bootloader. Is there a way to use the old segment:offest notation up to the first megabyte and the physical for the upper addresses?
Not entirely true. There are other methods. Unreal mode is one of the easier methods though.Karlosoft wrote:My bootloader loads files in the first mega and I want to copy them above it.
I've read that with the unreal mode I can use up to 4 gb so I need to switch the processor in this real mode to copy them.
He knows what real and unreal modes are, and listed a specific way he wants to use them. Apart from not knowing how to do this (which was his entire question and the purpose for this thread), what exactly was "clueless" about it?Combuster wrote: That sounded rather clueless.
The benefits of unreal mode are quite well known; access to the 32-bit address space while simultaneously being able to call bios and real mode programs.Combuster wrote: What do you want with *supporting* unreal mode?
Irrelevant; all we need to know is that he plans on using it at some point.Combuster wrote: Is your OS based on Unreal Mode?
I'll see your wiki-based page, and raise you this one:Combuster wrote: That aside, please search the wiki first: Descriptor Cache
The code on that page is rather crippled; it only sets one of the segment registers, and it is integrated into/mixed in with the test code (rather than being a separate function which can be copied standalone into a real mode program).Combuster wrote: Unreal Mode
Ok? Its purpose/advantage is [I stated this above in response to Combuster.] As long as it fulfills these goals, what does it matter whether it is technically a "mode" or not?Neon wrote: You do not "support" unreal mode because there is no such mode. Unreal mode is not a processor mode but rather a "trick"
Any particular reason you're against it?Neon wrote: (One I personally dont recommend, but its there.)
I mentioned the abilities of unreal mode above; all of them can be used (and are even necessary!) by the bootloader to do its job. Again, I don't see why you're against unreal mode being used by bootloaders.Neon wrote: Also, a bootloader should not "support" a mode, its only job, by its definition, is to get the system running.
System software can do whatever it wants, and so can the bootloader (while it's still running).Neon wrote: The system software can then provide support for the real processor modes: its primary mode (probably protected mode), real and/or v86 tasks, etc.
Huh??kmtdk wrote: However you may not change ds, as that causes a lot of trouble.
[...]
so changing ds will affect that "copy" and thereby causing unknown errors( i do not remember the error at this time)
Code: Select all
; call this function from real mode to
enter_unreal_mode:
; save the interrupt flag state
pushfd
; save the segment bases, since
; they get overwritten by the
; switch to unreal mode
push ds
push es
push fs
push gs
; interrupts can save/restore segment
; registers. The PE bit changes the
; meaning of writing to a segment register,
; i.e. allowing this to happen would result
; in the restored data meaning something
; different than the saved data.
cli
; set PE bit
mov eax,cr0
or al,1
mov cr0,eax
; change the segment limit, while
; keeping all other atrributes the same.
; Note: this overwrites the base address.
lgdt[cs:.gdt]
mov ax,8
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
; don't bother with cs or ss, since
; push/pop/call/jmp in real mode is
; limited to a 16-bit sp/ip
; done here, back to (altered) real mode
mov eax,cr0
and al,0xfe
mov cr0,eax
; restore the stuff that was saved
pop gs
pop fs
pop es
pop ds
popfd
ret
.gdt:
dw .end-.gdt-1
dd gdt
dw 0
dq 0x008f92000000ffff ;unreal mode data
.end:
Code: Select all
;one way:
mov ax,0
mov ds,ax
mov eax,0x200000
mov edx,[eax]
;another way to get the same address:
mov ax,0x1000
mov ds,ax
mov eax,0x1f0000
mov edx,[eax]
In unreal mode, both segment:offset and physical can be used for any address (not just the 1st meg), since the offset can now be 32 bits.Karlosoft wrote:Is there a way to use the old segment:offest notation up to the first megabyte and the physical for the upper addresses?
You could run your code in 32-bit pmode, and then switch back to unreal mode to call the bios. (disabling interrupts in pmode would probably be the easiest way to get this to work.) It is more complicated to set up, but it means you don't have to deal with the 16-bit stack/ip limitation.Karlosoft wrote:what are these other ways
Would like to see your code; unreal mode not working on some cpu's would be a pretty big deal...XanClic wrote:I don't suggest using unreal mode at all, because I'm pretty sure it doesn't work on my computer (and hence maybe on other CPUs, too).
Yes - its a hack; nonstandard. I dont care how supported it is - it can break at any time. Just because there is an easy way to do something, doesnt make it a good way.qqq wrote:Any particular reason you're against it?
As posted earlier, there are ways that you can load files in a bootloader > 1 MB. ie, mine loads files > 3GB without unreal mode using the BIOS and protected mode. You can even stick with protected mode all together.qqq wrote:I mentioned the abilities of unreal mode above; all of them can be used (and are even necessary!) by the bootloader to do its job. Again, I don't see why you're against unreal mode being used by bootloaders.
Unreal mode IS documented by Intel and AMD. They just call it SMM mode. BIOSes rely on it to operate. SMM was officially implemented with the 386. Unreal mode is simply the OS taking advantage of the 4gb limit in the same way the BIOS does under SMM mode.neon wrote:Hello,
Yes - its a hack; nonstandard. I dont care how supported it is - it can break at any time. Just because there is an easy way to do something, doesnt make it a good way.qqq wrote:Any particular reason you're against it?
As posted earlier, there are ways that you can load files in a bootloader > 1 MB. ie, mine loads files > 3GB without unreal mode using the BIOS and protected mode. You can even stick with protected mode all together.qqq wrote:I mentioned the abilities of unreal mode above; all of them can be used (and are even necessary!) by the bootloader to do its job. Again, I don't see why you're against unreal mode being used by bootloaders.