Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A 16K page directory containing a one-to-one virtual/physical mapping can be created with the following (untested) code:</p> <pre><code>/* Setup types for virtual addresses, physical address, and the page table. */ typedef unsigned long vaddr_t; typedef unsigned long paddr_t; typedef unsigned long pde_t; /* Reserve space for a page directory. Must be 16k aligned. */ pde_t page_directory[1 &lt;&lt; 12] ALIGNED(1 &lt;&lt; 12); /* Create a 1MB mapping in the given page directory from 'virt' to 'phys'. */ void set_large_page_mapping(pde_t *pd, vaddr_t virt, paddr_t phys) { pde_t entry = 0; entry |= phys &amp; 0xfff00000; /* Target of the mapping. */ entry |= 2; /* This is a 1MB section entry. */ entry |= 1 &lt;&lt; 4; /* Enable caches (C). */ entry |= 1 &lt;&lt; 3; /* Enable writeback (B). */ entry |= 3 &lt;&lt; 10; /* Full read/write permission. */ pd[virt &gt;&gt; 20] = entry; /* Install the entry. */ } /* Setup a page directory with one-to-one physical/virtual mappings. */ void setup_one_to_one_mappings(void) { unsigned long i; /* Setup a mapping for each 1MB region in the virtual address space. */ for (i = 0; i &lt; (1 &lt;&lt; 12); i++) { /* Map the virtual address "i &lt;&lt; 20" to phys address "i &lt;&lt; 20". */ set_large_page_mapping(page_directory, i &lt;&lt; 20, i &lt;&lt; 20); } /* TODO: Write function to install this page directory and enable the MMU. */ enable_mmu(page_directory); } </code></pre> <p>The <code>enable_mmu</code> function still needs to be written, which will need to:</p> <ul> <li>Clean data and instruction caches;</li> <li>Invalid existing TLB entries;</li> <li>Flush other caches (prefetch buffer, branch target caches, etc);</li> <li>Setup TTBR0 to contain a pointer to the PD generated above; and finally</li> <li>Enable caches and the MMU.</li> </ul> <p>Each of these instructions tend to be CPU-specific, but examples should (hopefully) be available for your hardware elsewhere (or, failing that, by looking at sources to other operating systems, such as Linux or FreeBSD). Additionally, for testing, you probably need only worry about the last two points to get started.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload