1

rt, for example, in xv6 code mmu.h, segdesc is designed like this

struct segdesc {
  uint lim_15_0 : 16;  // Low bits of segment limit
  uint base_15_0 : 16; // Low bits of segment base address
  uint base_23_16 : 8; // Middle bits of segment base address
  uint type : 4;       // Segment type (see STS_ constants)
  uint s : 1;          // 0 = system, 1 = application
  uint dpl : 2;        // Descriptor Privilege Level
  uint p : 1;          // Present
  uint lim_19_16 : 4;  // High bits of segment limit
  uint avl : 1;        // Unused (available for software use)
  uint rsv1 : 1;       // Reserved
  uint db : 1;         // 0 = 16-bit segment, 1 = 32-bit segment
  uint g : 1;          // Granularity: limit scaled by 4K when set
  uint base_31_24 : 8; // High bits of segment base address
};

why base is defined as base_15_0, base_23_16, base_31_24, but not 'uint base'?

I guess it's partly due to the fact that each sub-field has special meaning, so store them separately rather than as a whole is convenient for access. But I'm not sure the guess is complete or right

Cœur
  • 37,241
  • 25
  • 195
  • 267
minglotus
  • 83
  • 6
  • I would guess it's reflective of some kind of history where initially only 16-bit addressing was considered, then 24-bit and finally 32-bit. But that would also just be a guess. – Damien_The_Unbeliever Oct 29 '14 at 09:14

1 Answers1

1

Because it is not an arbitrary nice-to-read internal data structure but exact description of data structure used by the hardware

enter image description here

Source: Intel® 64 and IA-32 Architectures Software Developer Manuals

See also: http://wiki.osdev.org/Global_Descriptor_Table

xmojmr
  • 8,073
  • 5
  • 31
  • 54