Page 1 of 1
Possible to run real mode code from 16bit gdt (not v86)
Posted: Thu Feb 19, 2009 11:02 pm
by earlz
Hi, I have been thinking recently.. there are quite a few pitfalls of virtual 8086 mode.. One of the big ones is its quite slow...
Well, I have been thinking if its really necessary for virtual 8086 mode to run BIOS code. Why can you setup a GDT with code segment of 16 bit, stack segment of 16 bit...
the code segment's number is 0xF000, and the size is 0xFFFF.. then you set all the GDT entries to where they have null selectors. This makes it so it generates a segment not present fault when accessing data. Then you would just generate a valid GDT entry for that selector(for speed purposes) and voila, everything works.. when real mode code changes selector again, just regenerate the GDT on first segment call... Also, I'm sure paging could also be used if needed... (also run real mode code at ring 0, because the BIOS is pretty trusted)
Is there a huge flaw with this method(other than possible being slower) cause I don't understand why people don't use this method..
Re: Possible to run real mode code from 16bit gdt (not v86)
Posted: Fri Feb 20, 2009 12:11 am
by eddyb
earlz wrote:Is there a huge flaw with this method(other than possible being slower) cause I don't understand why people don't use this method..
I'll tell you why: because the BIOS code is 16 bit
.
anyway, i was thinking if the BIOS is somewhere in the memory, you can use it...
basically, BIOS is a set of drivers that have their commands accessible via ints (what if someone would make a dissamble of it - i'm interested in the video part
)
Re: Possible to run real mode code from 16bit gdt (not v86)
Posted: Fri Feb 20, 2009 1:23 am
by Love4Boobies
earlz wrote:Hi, I have been thinking recently.. there are quite a few pitfalls of virtual 8086 mode.. One of the big ones is its quite slow...
Slow? Nonsense...
Well, I have been thinking if its really necessary for virtual 8086 mode to run BIOS code. Why can you setup a GDT with code segment of 16 bit, stack segment of 16 bit...
No, that won't work. There are BIOS interrupts that work with the 16-bit version of descriptors (16-bit pmode anyone?) but that's different. One of the reasons why this won't work is the way BIOS expects to set segment registers. Consider the following:
Now think of the differences. There are plenty of other reasons.
shiner wrote:basically, BIOS is a set of drivers that have their commands accessible via ints
No. BIOS is
much more than that. It initializes the system components (that means even DRAM, which is a pain since it must do so unsing only a handfull of registers, it can't use any variables or anything; the CPU usually talks to DRAM through the northbridge but to initalize it, it must also go through the southbridge). Aaand, BIOS even runs in parallel with the OS in SMM (this is why you aren't allowed to rewrite the EBDA). That's right, if it's buggy it can trash your whole OS even if the OS never uses it.
(what if someone would make a dissamble of it - i'm interested in the video part
)
There are plenty of BIOS source codes out there, starting with the PC, PC-XT, PC-ATs and coreboot BIOSes. I'm not sure what you'd do what the video code, though. It only has built-in VGA and code that hooks VBE from the video card...
Re: Possible to run real mode code from 16bit gdt (not v86)
Posted: Fri Feb 20, 2009 3:40 am
by jal
Love4Boobies wrote:I'm not sure what you'd do what the video code, though. It only has built-in VGA and code that hooks VBE from the video card...
I'm pretty sure the normal BIOS does not contain int 10h VGA stuff, that's all in the video ROM. On the original XT, the int 10h services of the BIOS controlled CGA only. I wouldn't be surprised if that's still in there, even in modern BIOSes.
JAL
Re: Possible to run real mode code from 16bit gdt (not v86)
Posted: Fri Feb 20, 2009 3:49 am
by jal
earlz wrote:there are quite a few pitfalls of virtual 8086 mode.. One of the big ones is its quite slow...
That is, as breastlover already explained, just not true.
the code segment's number is 0xF000, and the size is 0xFFFF.. then you set all the GDT entries to where they have null selectors. This makes it so it generates a segment not present fault when accessing data. Then you would just generate a valid GDT entry for that selector(for speed purposes) and voila, everything works..
Even if this would work (which it doesn't), this will be
much slower than using v86 mode.
Also, I'm sure paging could also be used if needed
Paging can also be used for x86 of course, otherwise you couldn't have more than one v86 task.
Is there a huge flaw with this method(other than possible being slower) cause I don't understand why people don't use this method..
In protected mode, the contents of the segment register is an index into the GDT, but there are more bits in there (most notably the first two) with different uses. So it's not possible to map real mode segments 1:1 with protected mode selectors (not to mention you'd need a *very* large GDT).
JAL
Re: Possible to run real mode code from 16bit gdt (not v86)
Posted: Fri Feb 20, 2009 7:42 am
by earlz
ok... thanks for the replies.. grr.. this forum always make my dreams fail in reality lol