getting physical addresses...
getting physical addresses...
Hi, I am trying to figure out a good way of getting physical memory of some virtual memory at hand. I mean some processor data structures (like tss descriptor or and gdt) need physical address information . So when you are dynamically creating a tss you need physical address of some virtual address. How can I get it? Checking page tables might be good idea but it will be slow I think?... So any idea is greatly appreciated. thanx...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:getting physical addresses...
do the creation of TSS really require a physical address ? i don't remember it so ...
Anyway, the best approach is probably to request physical memory and have the same function setting the mapping for it and using it in the other object, so that you don't need to look the page tables.
However, even reading the page tables isn't *that* slow if it hasn't to be done too often, especially if you decidce to map the page tables in a pre-defined region of the memory.
For instance, if you decide that the last entry of the page directory points to the directory itself (i.e. the last 4MB of your logical address space will be mapping page tables), then you can quickly resolve the entry for virtual address X:
Anyway, the best approach is probably to request physical memory and have the same function setting the mapping for it and using it in the other object, so that you don't need to look the page tables.
However, even reading the page tables isn't *that* slow if it hasn't to be done too often, especially if you decidce to map the page tables in a pre-defined region of the memory.
For instance, if you decide that the last entry of the page directory points to the directory itself (i.e. the last 4MB of your logical address space will be mapping page tables), then you can quickly resolve the entry for virtual address X:
Code: Select all
pgEntry *pe=((pgEntry*)0xFFC00000)+(x>>12);
Re:getting physical addresses...
I meant tss descriptor, not the tss itself. You know, tss descriptor contains physical address of tss... Allocating physical memory first is a cool idea. Thanx...
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:getting physical addresses...
afaik, the TSS descriptor holds the virtual address of the descriptor (that is, an address that is not related to a segment, but that will go through the paging unit anyway. What you should take care of is that the first 104 bytes of the TSS are in contiguous physical memory, but that's all ...
Re:getting physical addresses...
Hi, this mapping pd onto itself is what Tim Robinson's talking about in his tutorial right? I could just finally understand how it can be used... ;D And also getting physical address in that way is much more wiser way of doing it. I will try to go in that way... Thanx...
Re:getting physical addresses...
Well if that is the case I do not need to worry about physical memory stuff... But anyway I think I will need it while handling page faults... Thanx...
Re:getting physical addresses...
Hey there is problem with this code, (I just realized)
We cannot just (x>>12) but we also have to take care of correctly setting the appropriate offset in selected page frame(which is our page directory now). Page index is set by page directory index and its ok, but take care of page frame offset. If anybody wants to use it, watch out...
Code: Select all
pgEntry *pe=((pgEntry*)0xFFC00000)+(x>>12);
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:getting physical addresses...
err ... i'm not sure what exactly you wanted to warn us about ...
The small code line i provided is not meant to give the physical address, but just the page table entry. (which can be used to have the page frame number), but that page frame is useless as long as you don't map it somewhere else.
The small code line i provided is not meant to give the physical address, but just the page table entry. (which can be used to have the page frame number), but that page frame is useless as long as you don't map it somewhere else.
Re:getting physical addresses...
Two macros I use for accessing PTEs and PDEs:
Code: Select all
#define PG_DIR_START 0xFFFFF000 /* because of */
#define PG_TABLE_START 0xFFC00000 /* the selfmapping trick */
#define ADDR_TO_PDE(virt) (PG_DIR_START + (virt >> 22) * PDE_SIZE)
#define ADDR_TO_PTE(virt) (PG_TABLE_START + (virt >> 12) * PTE_SIZE)
Re:getting physical addresses...
Code: Select all
#define ADDR_TO_PDE(virt) (PG_DIR_START + (virt >> 22) * PDE_SIZE)
#define ADDR_TO_PTE(virt) (PG_TABLE_START + (virt >> 12) * PTE_SIZE)
I think PTE_SIZE is 4, abless, right?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:getting physical addresses...
well, it's probably more clear using *PTE_SIZE.
I was personnaly using the fact that my pointer was a pgEntry pointer (assuming sizeof pgEntry == 4 as required by the Manual), and thus having ptr+index automatically multiplies index by PTE_SIZE
I was personnaly using the fact that my pointer was a pgEntry pointer (assuming sizeof pgEntry == 4 as required by the Manual), and thus having ptr+index automatically multiplies index by PTE_SIZE
Re:getting physical addresses...
Ozguxxx wrote: I think PTE_SIZE is 4, abless, right?
Code: Select all
#define PTE_SIZE 4
#define PDE_SIZE 4