Hello,
There isn't anything i'm not sure about... (Read PMs, i said that i understand GDT very clear now, it's like some kind of memory protection).
Almost. The GDT has to do with
segmentation. Each entry in the GDT describes a
segment. (Think back to segments in real mode. Its almost the same idea here.) Segments can be anywhere and may overlap. A segment has a start address (this is the
base) and an ending address (this is
limit.) If you want a code segment, you would make it executable and read only. If you want a data segment, you want it to be non-executable but writable. If you want a stack segment, you would want the segment to grow
downward. Segments can be 16 bit or 32 bit. Segments can also be protected using a
Descriptor Privilege Level (DPL).
The GDT (and LDT) are from the days of 16 bit protected mode (think of DOS extenders.) Since no one uses segmentation anymore (what is the point when you can achieve the same benefits and more using paging without the problems with segments?) So all major operating systems just create different segments with the same base and limit (they can overlap, after all.) To make the CPU happy, we set CS to an executable segment and all data segments to non-execute read/write.
There is one more important deal - the selector registers CS, DS, ES, FS, GS, SS all have a specific format:
Code: Select all
Table Index (13 bits) | Table Type (1 bit) | RPL (2 bits)
Where Table Index (starts from 0) is the index into the table. Table Type is either 0 (for current GDT) or 1 (for current LDT), and the RPL is the
Requested Privilege Level. So, you tell the CPU what segments to use by writing to one of these registers. Don't worry about the LDT stuff unless you ever plan to use it.
For example, if your 32 bit code segment (with DPL 0) is at GDT index 1, you would tell the CPU to
select this segment by doing a
mov ax, 8 mov cs, ax. This selects GDT index 1, RPL 0, Table GDT. You won't have to worry about setting the RPL bits unless you plan to switch to a segment in a different privilege level (such as user mode).
In your specific case, you needed to create a new 16 bit code segment. To do this, you would
add the descriptor and
load CS like above to
select that new code segment in order to run 16 bit code.
In summary - yes, protection is a part of it. But the primary thing the GDT does is segmentation.
How to use V8086? Sounds like better idea than going to real mode and returning back to protected mode to set video mode
Unfortunately, virtual 8086 mode still requires you setting that 16 bit segment in the GDT (what you have been struggling with above.) It also requires supporting user mode (which in turn requires a basic (minimal though so don't worry too much) -- TSS. It isn't as much work as it might sound at first.
Work on the GDT stuff first though cus you'll need that for either supporting virtual 8086 mode or real mode anyways.
And hell no, i think that making driver for every ******* single graphics card isn't normal for homemade OS. There is over 10000 diffrent graphics cards!
Most hobbyist operating systems set the video mode once during boot and do not do what you are wanting to do.