Reputation: 23
We see virtual address corresponding to any instruction,so my question is where does these virtual address exist ? If we see disassembly in gdb we saw virtual address where does these address reside ? Please don't say it is only virtual address it have to mapped to a physical address by page table, I know it but where these virtual address that we saw in gdb exist ? In RAM or in Hard disk ?
Upvotes: 2
Views: 860
Reputation: 47573
An overall simplification to answer your question relative to the x86 might be this:
If the Instruction Pointer(IP) is found to be associated with a virtual memory address in a page that is marked not present it will cause a page fault. The page fault handler will load a free page frame with the code, map it to virtual memory, mark the virtual page present and then return back to the virtual memory location with the newly loaded instruction. An attempt to execute the instruction will be made.
If the instruction accesses a memory operand(s) that reference a virtual memory address that is not present then they too will cause additional page fault(s). A page fault will occur, the page handler loads the needed data into a free page frame, maps it to a virtual memory, marks the virtual page as present, and then returns back to the instruction that caused the fault. At that point the instruction is again retried.
The exact mechanism that an OS uses to maintain page frames; maintain the page tables and directories; decides where/how to load the data/code from are implementation details that will vary. The key thing is that page faults are the primary mechanism to load data/code into virtual memory pages that may have been marked as not present by the OS.
Upvotes: 1
Reputation: 62058
An address (or any other numeric value for that matter) can exist in CPU registers, memory and any other storage, including disk. But that probably isn't surprising to you nor is what you're asking about.
If we're talking about 32-bit x86 page translation, then page tables don't contain virtual addresses that undergo translation to physical addresses. Page tables contain only physical addresses, but not virtual. It is not needed to store virtual addresses inside page tables.
Let's simplify things and suppose that the system has only one page table and this page table contains 1024 physical addresses of code/data pages. Where are virtual addresses in here? They are pretty much indices into the page table. If pages are 4KB in size and all addresses are 22-bit, then the 12 low bits of a virtual address specify the location inside a code/data page (0 to 4095) and the 10 top bits of a virtual address select one of the 1024 pages through the page table. When the CPU uses a virtual address to access memory, it breaks the virtual address into an index into the page table and into an offset within the selected page. Then it gets the physical address of the page (from the page table), adds the offset within the page to it and then uses the resultant physical address read or write memory at.
Upvotes: 2
Reputation: 93014
A virtual address does not exist in the same way a street address does not exist. Only the house referenced by a street address can exist and in the same way, the storage referenced by a virtual address can (but doesn't have to) exist. What kind of storage that is depends on the system. Typically it's RAM but it can also be ROM, a memory mapped peripheral, open bus (i.e. nothing) or something else.
Upvotes: 2