Melab
Melab

Reputation: 2872

Where are real mode address contents located in protected mode?

In real mode, an x86 CPU can only see address space that ranges 0x00000 to 0xFFFFF. MBR code is loaded into 0x07C00 by the BIOS. If that MBR code immediately switched into protected mode, where in the protected mode address space would that code and the rest of the contents of the real mode address space then be found?

Upvotes: 0

Views: 125

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 366094

Physical address space is always the same, regardless of real vs. protected vs. long mode.

In real mode, linear addresses are physical. Same in protected mode with paging disabled, but segment registers work differently: writing a segment register sets the segment base to a value from the GDT or LDT entry indexed by it, instead of to regval << 4 in real mode.

In protected mode with paging enabled, physical addresses 0x00000 to 0xFFFFF are still there, but linear addresses are virtual. (A linear address is the result of segment_base + offset.)

To access those bytes of memory, you'd need to set up page-table entries that map some virtual pages to those physical addresses. (You need to create page tables before enabling paging, because you need to set CR3 to the physical address of a top-level page directory, and if you didn't have any valid page tables any load or store would fault so you couldn't create more.)

You can choose which part of virtual address-space (if any) you maps to those low physical addresses. You could identity-map it, so physical=virtual for any address in that range, or direct-map it (virtual = physical+offset for some range) by creating the appropriate page-table entry for each page in the range. Or one 4M (or 2M with PAE or long mode) that covers the whole range: a page-directory entry that is a translation for the whole region instead of pointing at a table of PTEs.

Upvotes: 1

Related Questions