|
| 1 | +*Concepts you may want to Google beforehand: GDT* |
| 2 | + |
| 3 | +**Goals: program the GDT** |
| 4 | + |
| 5 | +Remember segmentation from lesson 6? The offset was left shifted |
| 6 | +to address an extra level of indirection. |
| 7 | + |
| 8 | +In 32-bit mode, segmentation works differently. Now, the offset becomes an |
| 9 | +index to a segment descriptor (SD) in the GDT. This descriptor defines |
| 10 | +the base address (32 bits), the size (20 bits) and some flags, like |
| 11 | +readonly, permissions, etc. To add confusion, the data structures are split, |
| 12 | +so open the os-dev.pdf file and check out the figure on page 34 or the |
| 13 | +Wikipedia page for the GDT. |
| 14 | + |
| 15 | +The easiest way to program the GDT is to define two segments, one for code |
| 16 | +and another for data. These can overlap which means there is no memory protection, |
| 17 | +but it's good enough to boot, we'll fix this later with a higher language. |
| 18 | + |
| 19 | +As a curiosity, the first GDT entry must be `0x00` to make sure that the |
| 20 | +programmer didn't make any mistakes managing addresses. |
| 21 | + |
| 22 | +Furthermore, since the CPU needs to know how long the GDT is, we'll use |
| 23 | +a meta structure called the "GDT descriptor" with the size (16b) and address |
| 24 | +(32b) of our actual GDT. |
| 25 | + |
| 26 | +Let's directly jump to the GDT code in assembly. Again, to understand |
| 27 | +all the segment flags, refer to the os-dev.pdf document. The theory for |
| 28 | +this lesson is quite complex. |
| 29 | + |
| 30 | +In the next lesson we will make the switch to 32-bit protected mode |
| 31 | +and test our code from these lessons. |
0 commit comments