tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [Milkymist port] virtual memory management



Hello Eduardo,

Le 30/05/13 22:45, Eduardo Horvath a écrit :
On Wed, 29 May 2013, Yann Sionneau wrote:

Hello NetBSD fellows,

As I mentioned in my previous e-mail, I may need from time to time a little
bit of help since this is my first "full featured OS" port.

I am wondering how I can manage virtual memory (especially how to avoid tlb
miss, or deal with them) in exception handlers.
There are essentially three ways to do this.  Which one you chose depends
on the hardware.

1) Turn off the MMU on exception

2) Keep parts of the address space untranslated

3) Lock important pages into the TLB


Turning off the MMU is pretty straight-forward.  ISTR the PowerPC Book E
processors do this.  Just look up the TLB entry in the table and return
from exception.  You just have to make sure that the kernel manages page
tables using physical addresses.
This seems like the easiest thing to do (because I won't have to think about recursive faults) but then if I put physical addresses in my 1st level page table, how does the kernel manage the page table entries? Since the kernel runs with MMU on, using virtual addresses, it cannot dereference physical pointers then it cannot add/modify/remove PTEs, right? I'm sure there is some kernel internal mechanism that I don't know about which could help me getting the virtual address from the physical one, do you know which mechanism it would be?

Also, is it possible to make sure that everything (in kernel space) is mapped so that virtual_addr = physical_addr - RAM_START_ADDR + virtual_offset In my case RAM_START_ADDR is 0x40000000 and I am trying to use virtual_offset of 0xc0000000 (everything in my kernel ELF binary is mapped at virtual address starting at 0xc0000000) If I can ensure that this formula is always correct I can then use a very simple macro to translate "statically" a physical address to a virtual address.

Then I have another question, who is supposed to build the kernel's page table? pmap_bootstrap()? If so, then how do I allocate pages for that purpose? using pmap_pte_pagealloc() and pmap_segtab_init() ?

FYI I am using those files for my pmap:

uvm/pmap/pmap.c
uvm/pmap/pmap_segtab.c
uvm/pmap/pmap_tlb.c

I am taking inspiration from the PPC Book-E (mpc85xx) code.

Thanks !

Regards,

--
Yann


Home | Main Index | Thread Index | Old Index