Possible to run real mode code from 16bit gdt (not v86)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Possible to run real mode code from 16bit gdt (not v86)

Post 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..
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: Possible to run real mode code from 16bit gdt (not v86)

Post 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 :P .
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 :twisted: )
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Possible to run real mode code from 16bit gdt (not v86)

Post 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:

Code: Select all

XOR AX,AX
MOV SS,AX
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 :twisted: )
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...
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Possible to run real mode code from 16bit gdt (not v86)

Post 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
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Possible to run real mode code from 16bit gdt (not v86)

Post 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
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Possible to run real mode code from 16bit gdt (not v86)

Post by earlz »

ok... thanks for the replies.. grr.. this forum always make my dreams fail in reality lol
Post Reply