remzi-arpacidusseau / ostep-typos

51 stars 44 forks source link

16.2 Which Segment Are We Referring To? #31

Closed adammccartney closed 1 year ago

adammccartney commented 3 years ago

Hi Remzi,

great work on the book - really learning a lot from it. The code examples are also great! I think I might have possibly found a minor typo in section 16.2.

In the preceeding section 16.1 the book refers to the heap segment as beginning at 4KB.

Assuming that section 16.2 tries to use the same values for the specific examples in the c code, the value for SEG_MASK should be set to the start of the heap. Book uses possibly incorrect value of 0x3000 (12288) for SEG_MASK. Heap starts at 0x1000 (4096) (4KB).

Cheers, Adam

remzi-arpacidusseau commented 1 year ago

Thanks for the kind words! I think the book is correct, though. SEG_MASK is just used to get those top two bits (bits 13 and 12) out of the virtual address, as done in this line of code: Segment = (VirtualAddress & SEG_MASK) >> SEG_SHIFT. The & (masking) gets bits 13 and 12, and the shift moves them down so that we get a proper segment number (00, 01, 10, or 11, or more plainly, 0, 1, 2, or 3). Make sense?

adammccartney commented 1 year ago

thanks for your help, it seems like I might have misunderstood the section then. Will be revising the memory hierarchy over the coming week for a computer architecture class, so I'll revisit the section from your book after that and hopefully be able to understand more clearly.