5

For example, when we write:
int a;
and doing &a gives us some address in hex form 0x12345678 which we call as virtual address.
Now when we try to do
int *temp = 0xfe000000;
does this address acts like a virtual address or a physical address? As far as I know virtual addresses are given by OS which are further converted to physical addresses by MMU.

As far as I know paging mechanism takes place in between which maps the virtual address to available physical address. What happens when we give an address to a pointer? Does that address acts like virtual address which is then handled by MMU to point to a particular physical address or it acts like a physical address in itself?

int temp;
printf("%x \n", &temp);
int *temp2 = 0xfe000000; //This is just an example address. It could be any address


Does this address (0xfe000000) acts like a real physical address or a virtual address?

macfij
  • 3,093
  • 1
  • 19
  • 24
Navneet
  • 71
  • 8
  • 7
    It depends on the platform. On modern operating systems all addresses are virtual and you cannot address physical addresses from a normal user mode program, only from drivers but that's a different story. On the other hand on simple microcontrollers you only can access physical addresses because there is no virtual memory. – Jabberwocky Jan 23 '19 at 09:55
  • 1
    **A short answer: virtual.** – Tony Tannous Jan 23 '19 at 10:23

2 Answers2

0

In case you are using an operating system, then it is not possible because the OS is using virtual address and whatever you use will be mapped to the physical address via virtual address.

But if you are programming a microcontroller then there is no virtual address and you can access the physical memory location using pointers in C.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Sabster
  • 89
  • 1
  • 12
0

The address we get normally, say for example,a pointer in C programming in a PC is virtual address. The virtual to physical mapping and the other way round, is handled by the operating system internally. Usually, the user(root or otherwise) will have no say in the address mapping.

On the other hand, simple micro controllers usually have no TLB mapping, so the address you access is the actual physical address of the device, as said in other answer.

Also, if you are planning to use a micro processor from ground-up, you can always have your own physical to virtual address mapping, where you can even set properties to the address blocks.