3

In an MIT course section on bootloaders, the following code is used to set up kernel code segment and data segment selectors:

.set PROT_MODE_CSEG, 0x8         # kernel code segment selector
.set PROT_MODE_DSEG, 0x10        # kernel data segment selector

The full code can be found here.

What is the meaning behind these particular segment selectors? Why are they 0x8 and 0x10? The documentation suggests that they are "32-bit code segments". What makes them 32-bit code segments?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Alexander Guyer
  • 2,063
  • 1
  • 14
  • 20
  • 4
    They are the selectors that reference descriptor entries in the GDT (Global Descriptor Table). The descriptor entries in the GDT (and/or LDT) give the access rights, attributes, base address, size etc of a given segment. You can find the GDT defined down at the bottom of `boot.S` where the label `gdt:` is. Each entry is 8 bytes. The first entry is the NULL selector then they define a 32-bit code segment (starting at offset 0x08 of the GDT) and a 32-bit data segment (starting at offset 0x10 of the GDT). – Michael Petch Apr 02 '20 at 19:00
  • There is a Wiki article with additional links to reference materials at the bottom about the GDT: https://en.wikipedia.org/wiki/Global_Descriptor_Table . – Michael Petch Apr 02 '20 at 19:05
  • These are the two first selectors in the GDT. These can be set up as desired by the operating system. This one chose to use them for code and data segment. – fuz Apr 02 '20 at 21:39

0 Answers0