Re: logical, linear, physical addresses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 05, 2004 at 22:11:22 +0530, Shakthi Kannan wrote:
> Greetings!
> 
> I need some real-time example (with values) for x86 architecture
> illustrating the relationship between logical, linear and physical
> addresses.
> 
> I did go through Chapter 2 of Understanding the Linux kernel, and
> Operating Systems by Harvey Deitel.
> 
> 1/
> I understand in the process of logical to linear address translation
> that segment selector (in segment registers) points to a segment
> descriptor in LDT/GDT. Within the segment descriptor we choose
> base+limit to get the linear address. But, what does this base address
> contain? How is it assigned? ------ (1)

linear_address = base + logical_address.

The base is always 0 in linux, so linear_address = logical_address.

> Similarily, I understand that linear address is translated into
> physical address through page tables, and the linear address consists
> of page frame number and offset. ---- (2)

The 32 bits of linear address is split into 3 parts. IIRC they are:

31 .. 22 - index of page directory
21 .. 12 - index of page table entry
11 .. 0  - offset in the page

The page table is two-level. The first level (1 page containing 1024
4-byte entries) is indexed by the first 10 bits of the linear address.
There the 20 bit address of the second-level table is obtained. Another
10 bits is than used to index this second-level table to get the actual
(20 bit) address of the page. The page is then indexed with the
remaining 12 bits to get the requested cell. So it is:

pde_index = address >> 22;
pte_index = (address >> 12) & 0x3ff;
offset = address & 0x3ff;
physical_address = pte_addr(page_directory[pde_index])[pte_index] + offset;

> But, I don't see how the output of (1) corresponds to the input of
> (2).

Output of (1) IS THE input of (2). There is nothing mystical about that.

> What am I missing here? Most books explain only these concepts
> rather than give a real-time example. Any pointers in this regard will
> be helpful.
> 
> 2/
> If the base (0x00000000) in the segment descriptor is the same for the
> different kernel segments, (code, data, et. al.)  it will overlap in
> the linear address space. But, how can we access them separately if
> they start from the same address location?

I don't understand your question. What do you mean by "separately"?
The translation depends on descriptor used and on current page directory
pointer. There may be several descriptor with the same values -- and
they will still be considered different descriptors.

In linux, all descriptors use the same base. That way you can completely
forget there is anything like segmentation. For all practical matters,
except in boot code and syscall gateway, logical address and linear
address are indistinct in linux (and called virtual address).

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux