cfenollosa_os-tutorial/09-32bit-gdt
Hennik Hunsaker 7d932d43b3 Add Pandoc Support
- Add a Pandoc defaults file
- Add a Pandoc template based on the default one
- Add chapter headers to each section

### Usage

To use, install Pandoc and ConTeXt, then simply run
`pandoc -d ./pandoc.yaml` from the repo root.

### Maintenance

When new chapters get added, the `pandoc.yaml` will need to be updated
to include each new chapter's markdown file(s).

### Miscellaneous Notes

- The PDF generated complies with PDF/A 1b:2005 by default.
- The PDF also contains the source markdown files as attachments
- All links are fully functional!
- Includes a table of contents! With links to each section!

### Conclusion

Enjoy!
2023-09-05 01:46:32 -06:00
..
32bit-gdt.asm lessons 8, 9, 10, entering 32-bit mode 2014-10-09 11:38:11 +02:00
README.md Add Pandoc Support 2023-09-05 01:46:32 -06:00

32-bit: GDT

Concepts you may want to Google beforehand: GDT

Goal: program the GDT

Remember segmentation from lesson 6? The offset was left shifted to address an extra level of indirection.

In 32-bit mode, segmentation works differently. Now, the offset becomes an index to a segment descriptor (SD) in the GDT. This descriptor defines the base address (32 bits), the size (20 bits) and some flags, like readonly, permissions, etc. To add confusion, the data structures are split, so open the os-dev.pdf file and check out the figure on page 34 or the Wikipedia page for the GDT.

The easiest way to program the GDT is to define two segments, one for code and another for data. These can overlap which means there is no memory protection, but it's good enough to boot, we'll fix this later with a higher language.

As a curiosity, the first GDT entry must be 0x00 to make sure that the programmer didn't make any mistakes managing addresses.

Furthermore, the CPU can't directly load the GDT address, but it requires a meta structure called the "GDT descriptor" with the size (16b) and address (32b) of our actual GDT. It is loaded with the lgdt operation.

Let's directly jump to the GDT code in assembly. Again, to understand all the segment flags, refer to the os-dev.pdf document. The theory for this lesson is quite complex.

In the next lesson we will make the switch to 32-bit protected mode and test our code from these lessons.