Memory mapping

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Memory mapping

Post by Neo »

Thanks a lot Pype btw those were physical addresses.
I want to know one more thing though,I have passed the virtual address to be mapped as an immediate value(unsigned long) not pointer(unsigned long*) so which inline asm statement is correct

Code: Select all

__asm__ __volatile__ ("invlpg %0"::"m"(*(char*)(virt)); 
or

Code: Select all

__asm__ __volatile__ ("invlpg %0"::"m"(virt)); 
Thanks.
Only Human
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Memory mapping

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:27 pm, edited 1 time in total.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Memory mapping

Post by Candy »

Perica wrote: According to the Intel manuals, using a register as an operand is not valid. But they don't say anything about using something like invlpg [eax]. Do you think think something like this would work ?;
Yes, that's exactly what I said. Register as operand means using the register itself, memory reference is using the register as pointer. Encoding 0 is using eax as memory reference ([eax]) and encoding C0 is using eax as register (eax). So, use it as memory reference.
The Intel manuals also state: The INVLPG instruction is implementation dependent, and its function may be implemented differently on future IA-32 processors. If this is the case, I might aswell not use the instruction (as it might break compatibility with future processors ?). Everytime i change a page directory or page table entry, I'll just reaload the cr3 register, like this;

Code: Select all

mov eax, cr3
mov cr3, eax
You miss the point of the entire sentence. Its function may be implemented differently, so its function stays the same. Using it will stay the same, but it might send some sort of invalidate to all processors, be just uniprocessor, something like that, send other processors an exclusive request instead, things like that.

invlpg will still work, if only because it's useful.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Memory mapping

Post by Neo »

I want to know one more thing though,I have passed the virtual address to be mapped as an immediate value(unsigned long) not pointer(unsigned long*) so which inline asm statement is correct

Code: Select all

__asm__ __volatile__ ("invlpg %0"::"m"(*(char*)(virt));  
or

Code: Select all

__asm__ __volatile__ ("invlpg %0"::"m"(virt)); 

Err... could you answer my question above

I also have another related question which i hadn't thought of before. When do i need a new PageTable.? For e.g I'm using Tim's idea of separting the Kernel space into 4 regions (3-3.25GB, 3.25-3.5GB, 3.5-3.75GB and 3.75-4GB) can i statically allocate PageTables for these entries in the PageDirectory? if not then when should i obtain pages for these? also can these PageTables be located anywhere or should they be fixed?
Only Human
guest

Re:Memory mapping

Post by guest »

how can i use a single C function for mapping in a new PageTableEntry and a new PageDirEntry. Right now i use 2 separate ones for this. Do i have to send an extra argument to distinguish this or is there a better way?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Memory mapping

Post by Pype.Clicker »

guest wrote: how can i use a single C function for mapping in a new PageTableEntry and a new PageDirEntry. Right now i use 2 separate ones for this. Do i have to send an extra argument to distinguish this or is there a better way?
well, basically

Code: Select all

pgMap(vaddr_t va, phys_addr_t pa, pg_flags f) 
{
    unsigned dir_idx=PG_DIR_IDX(va); // extracts bits 22..31
    unsigned tbl_idx=PG_TBL_IDX(va); //extracts bits 12..21

    if (!directory[dir_idx].present) {
       create_and_initialize_table(dir_idx,f);
    } 
    
    // now ready to map the entry in the new/existing table
}
should do the trick ... i'm currently rewriting my page mapper to allow one-command mapping, so you can have a look and see if you find something helpful in it ...
Post Reply