Memory mapping
Memory mapping
what parameters should i pass to the function that maps the virtual memory to the physical memory.
any help appreciated.
any help appreciated.
Re:Memory mapping
Whatever it needs. Typically your virtual-to-physical mapping function might look like this:
If your design lets you access any page directory from anywhere, you might want to add a page directory address parameter there too.
PS: I use addr_t for physical addresses and void* for virtual ones. The reason for this is that physical addresses can be longer than virtual addresses; for instance, 36 bits with PAE enabled.
Code: Select all
void map_virtual_to_physical(const void *virtual, addr_t physical, uint16_t flags);
PS: I use addr_t for physical addresses and void* for virtual ones. The reason for this is that physical addresses can be longer than virtual addresses; for instance, 36 bits with PAE enabled.
Re:Memory mapping
Tim Could you please specify the steps to be followed by a mapping function?
Only Human
Re:Memory mapping
what is wrong with this function which maps any given virtual address to video memory
I use a PD mapped to itself. And call the function like this
after this i expect to get 'A' displayed on the top left but nothing happens not even a page fault :-X. What is wrong with my function?
Code: Select all
void map2v(DWORD virt)
{
unsigned long a=0,*PD=0xFFFFF000,*PT=0xFFC00000; // self-mapped
a=((0xB8000>>12)>>2);
PD[((virt>>22)>>2)] = PT[a]|3;
PT[a]= 0xB8000|3;
}
Code: Select all
unsigned long *temp=0xE03FF001;
map2v(*temp); // map2v(0xE03FF001) also does'nt work
*temp='A';
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Memory mapping
after having modified the page tables, you (almost) always need to do a pginvld instruction to commit the change to the MMU...
Re:Memory mapping
i'm not very proficient in inline GCC assembly so can someone tell me if this is correct
where 'virt' is the virtual address passed to the function as argument. (This still does not work but i dont know if it is due to wrong GCC asm or something else).Please help.
Code: Select all
__asm__ __volatile__("invlpg %0"::"m"(virt));
Only Human
Re:Memory mapping
No -- I made the same mistake originally. "m" should be an l-value, such as a dereferenced pointer. The code you have there invalidates the page that contains the 'virt' variable, which probably isn't what you want.
Instead, do this:
Instead, do this:
Code: Select all
__asm__ __volatile__("invlpg %0" : : "m" (*(char*) virt))
Re:Memory mapping
i tried your code out but to no avail. Maybe something is wrong elsewhere? ??? btw is the function doing what i think its doing?
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Memory mapping
no. afaik, invlpg requires a memory argument and will use the effective address of its argument as the virtual address to be discarded.
For instance
invalidates the page that maps DS.base+0x1000 ...
For instance
Code: Select all
invlpg [0x1000]
Re:Memory mapping
I just reload the CR3 register with the address of the page directory after making any changes to it. ;D
Re:Memory mapping
I'm having a tough time with my memory mapping function so could one of you *please* tell me if this is right.
I want to map address 0xD0CF_F001(binary 1101-0000-1100-1111-1111-0000-0000-0001) to video mem(0xB8000).
If i have a PageDir(PD) at 0xC000 and a PageTable(PT) at 0xE000, is the following correct
The physical address 0xC340(0xC000+(0xD0*4)) should have the value 0xE000|3 (i.e. start of PT) and the physical address 0xE0FF(0xE000+(0x3F*4)) should have the value 0xB8000|3 (i.e. video mem address).
Is this correct? if not what is wrong?
(I hope i'm clear)
WISHING EVERYONE HERE A MERRY CHRISTMAS. Take a well deserved break for a day.
I want to map address 0xD0CF_F001(binary 1101-0000-1100-1111-1111-0000-0000-0001) to video mem(0xB8000).
If i have a PageDir(PD) at 0xC000 and a PageTable(PT) at 0xE000, is the following correct
The physical address 0xC340(0xC000+(0xD0*4)) should have the value 0xE000|3 (i.e. start of PT) and the physical address 0xE0FF(0xE000+(0x3F*4)) should have the value 0xB8000|3 (i.e. video mem address).
Is this correct? if not what is wrong?
(I hope i'm clear)
WISHING EVERYONE HERE A MERRY CHRISTMAS. Take a well deserved break for a day.
Only Human
Re:Memory mapping
Code: Select all
_invlpg:
push ebp
mov ebp, esp
mov eax, DWORD [ebp + 8]
invlpg eax
leave
ret
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Memory mapping
You'll be unable to do that. 0xD0CF_F001 may be mapped to 0xB8001, but not to 0xB8000.Neo wrote: I'm having a tough time with my memory mapping function so could one of you *please* tell me if this is right.
I want to map address 0xD0CF_F001 (binary 1101-0000-11 00-1111-1111 -0000-0000-0001) to video mem(0xB8000).
Are these logical or physical addresses ?If i have a PageDir(PD) at 0xC000 and a PageTable(PT) at 0xE000,
From your target address, you should be in entry 0x343 (xx11-0100-0011) of your page directory and in entry 0x0FF (xx00-1111-1111) of your page table.
so phys [0xC000 + 0xD0C] should be 0xE003
and phys [0xE000 + 0x3FC] should be 0xB8003