Re: about the address of the variable

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

 



Please correct me if i'm wrong, this is from my understanding.

Under x86, we have both segmentation and paging. Here's a rough flow:

Logical Address (<Segment>:<Offset>) ---> (segmentation)---> Linear
address ---> (paging)---> Physical Address.

In protected mode, the processor takes the value of whatever is in the
segment register, uses it to index into the descriptor table, and from
the descriptor it gets the base address of the segment, and adds that
to the offset to get the linear address. So obviously, if the base
address is 0, the linear address will be equal to the logical address.

Now as for the other question, i modified the program a bit:

int main()
{
  int a;
  unsigned int b = &a;
  printf("%08x", b);
  return 0;
}

The assembly the second line produces is:

lea -0xc(%ebp), %eax

>From the Intel processor manual, what lea does is:

The offset part of the effective address is calculated by lea and
stored in the specified register.

So, what you're seeing as the printf output is the <offset> part of
the logical address.

If anyone feels i'm wrong, please do correct me.

On Mon, Jun 23, 2008 at 3:17 AM, karunakar rao
<karunakar.santhu@xxxxxxxxx> wrote:
> I took the following lines from understanding linux kernel book.
>
> All Linux processes running in User Mode use the same pair of segments to
> address instructions and data. These segments are called user code segment
> and user data segment , respectively. Similarly, all Linux processes running
> in Kernel Mode use the same pair of segments to address instructions and
> data: they are called kernel code segment and kernel data segment ,
> respectively.
>
> linear addresses associated with such segments all start at 0 and reach the
> addressing limit of 232 -1. This means that all processes, either in User
> Mode or in Kernel Mode, may use the same logical addresses.
>
> Another important consequence of having all segments start at 0x00000000 is
> that in Linux, logical addresses coincide with linear addresses; that is,
> the value of the Offset field of a logical address always coincides with the
> value of the corresponding linear address.
>
> On Mon, Jun 23, 2008 at 8:49 AM, Steven Zhou <lullaby2005@xxxxxxxxx> wrote:
>>
>> Thanks for pay attenion to my question.
>>
>> I know virtual address includes logical address and linear address, which
>> one does the "0xbfcce590" belongs to?
>>
>> On Mon, Jun 23, 2008 at 11:12 AM, Mark Brown <markb@xxxxxxxxxxxxxxxxxxxxx>
>> wrote:
>>>
>>> Hi Steven,
>>>
>>>  The address 0xbfcce590 is a virtual address (in the stack) which is
>>> assigned to you by the loader.
>>>
>>> -- Mark
>>>
>>> On Jun 22, 2008, at 10:43 PM, Steven Zhou wrote:
>>>
>>>> Hi guys,
>>>>
>>>> I'm troubling with a problem about the logical address, linear address
>>>> and the physical address in programs.
>>>> For example, there's a program below:
>>>>
>>>> #include <stdio.h>
>>>>
>>>> int main ()
>>>> {
>>>>    int a;
>>>>    printf("%x\n", &a);
>>>>    return 0;
>>>> }
>>>>
>>>> the result is :
>>>> bfcce590
>>>>
>>>> I konw the address "bfcce590" is in the user mode stack space of the
>>>> process, but I'm not sure that the address is logical address, linear
>>>> address, or physical address?
>>>> (I konw the logical is identiy with linear address in x86 platform, but
>>>> I want to known deeply)
>>>>
>>>> Can you kindly help me unserstand the detail of this problem?
>>>> thx:)
>>>>
>>>> --
>>>> Best Regards.
>>>
>>
>>
>>
>> --
>> Best Regards.
>



-- 
KTHXBYE

-Mayank

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[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