Memory management (segmentation and paging) in 80286 and 80386: How does it work?

2

I found lots of Web sites and books explaining how memory management worked on the 8086 and later x86 CPUs in Real Mode. I understand, I think, how two 16 bit values, segment address and offset are combined to get a linear 20 bit physical address (shift segment four bits to the left, add offset; segments are 64K and start every 16 bytes).

But I couldn't find any good Web sites or books that explained how memory management works in Protected Mode, specifically the differences between 80286 and 80386.

Can anyone point me to a good Web site or book (or explain it right here)?

(For extra credit, i.e. an upvote, how does it work in Long Mode?)

Andrew J. Brehm

Posted 2011-02-07T13:42:27.077

Reputation: 4 411

Answers

3

http://www.ddj.com/184409207 Dr Dobbs ran a few articles back in 93 & 94 on this and there is not too many differences between the way the 286 and 386 handles the memory. The basics is you can't do the manipulation on the segment:offset registers because the base memory location and length is now part of the selector which you refer to like a handle.

You set up the selector N with a base address X with a length of M. When that selector is activated (remember the CS: assembly syntax?) that range of memory is used (paged in, etc). Selector N (the 16bit handle) refers to that data structure.

Flat memory model protected mode set the code, data and stack to the same memory addresses (and length of 4gb). That link covers the basics pretty well.

jsymolon

Posted 2011-02-07T13:42:27.077

Reputation: 256

The linked article is really good. – Andrew J. Brehm – 2011-02-08T10:43:02.030

1

For real mode, there is no memory managememt, its just multiply the segment register by 16 and adding the offset then puts this the 21bit result(yes 21bit because 0xFFFF*0x10+0xFFFF=0xFFFF0*0xFFFF=0x1FFFEF or 1_1111_1111_1111_1110_1111b, a 21bit value) on the address buss.

For long mode, segmentation exists, but the descriptors have base 0 and limit 0xFFFFFFFFFFFFFFFF(16EB) thus its flat mode, paging is around and its like PAE paging but the Page Directory Pointer Table is extended from 4 entries to 512 entries and a Page Level 4 Table with 512 entries that each point to a different Page Directory Pointer Table.

And here are some sites that explain it in more detail: http://en.wikipedia.org/wiki/Real_mode for real mode and http://en.wikipedia.org/wiki/Long_mode for ling mode

Tudor

Posted 2011-02-07T13:42:27.077

Reputation: 11