#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    7
    Rep Power
    0

    HEADBANGING: Pointer Access


    My doubt is concerning CPU and MMU interaction with OSes.

    Code:
    int main()
    {
            int *p;
            printf("%x",(void* )p);
            sleep(10);
    }
    Try executing the code on two different PCs, you'll get a constatnt value for each system.

    Since 386s use MMUs for logical address -> physical address translation, is it possible for the CPU to directly access actual physical addresses?

    Can the OS or software access actual physical addresses bypassing the MMU?

    Kindly help!

    Rohan
  2. #2
  3. Trapped on the forums...help
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2003
    Location
    /Users/edman007
    Posts
    4,617
    Rep Power
    906
    your need to learn a bit more about memory on a computer, generally the kernel manages the physical RAM with the help of the MMU, the kernel tells the MMU what pages are for the user process then it loads the userspace app and the CPU lets the process run for a bit until something like an interrupt or an access to an unknown page occurs (the userspace process just sees the whole 4GB address space and accesses what it wants, if the CPU does not know about it triggers a page fault and tells the kernel)

    what your seeing with your C code is virtual addresses, you probably have a similar architecture and kernel on both systems, that and the compiler used can determine the default value of a pointer (its undefined by C so never expect it to be a constant), the hardware address used is mapped with the help of the MMU to the virtual address the process sees

    for accessing a hardware address directly you generally need to be running in kernel mode, though there are often ways to get the kernel to access the hardware address you want for you

IMN logo majestic logo threadwatch logo seochat tools logo