Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/mm/as_pt.c

    rada559c rd99c1d2  
    3333/**
    3434 * @file
    35  * @brief Address space functions for 4-level hierarchical pagetables.
     35 * @brief       Address space functions for 4-level hierarchical pagetables.
    3636 */
    3737
     
    4747#include <arch.h>
    4848
    49 static pte_t *ptl0_create(unsigned int);
    50 static void ptl0_destroy(pte_t *);
     49static pte_t *ptl0_create(int flags);
     50static void ptl0_destroy(pte_t *page_table);
    5151
    52 static void pt_lock(as_t *, bool);
    53 static void pt_unlock(as_t *, bool);
    54 static bool pt_locked(as_t *);
     52static void pt_lock(as_t *as, bool lock);
     53static void pt_unlock(as_t *as, bool unlock);
    5554
    5655as_operations_t as_pt_operations = {
     
    5857        .page_table_destroy = ptl0_destroy,
    5958        .page_table_lock = pt_lock,
    60         .page_table_unlock = pt_unlock,
    61         .page_table_locked = pt_locked,
     59        .page_table_unlock = pt_unlock
    6260};
    6361
     
    6967 *
    7068 * @return New PTL0.
    71  *
    7269 */
    73 pte_t *ptl0_create(unsigned int flags)
     70pte_t *ptl0_create(int flags)
    7471{
    75         pte_t *dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE, FRAME_KA);
    76         size_t table_size = FRAME_SIZE << PTL0_SIZE;
     72        pte_t *src_ptl0, *dst_ptl0;
     73        ipl_t ipl;
     74        int table_size;
     75
     76        dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE, FRAME_KA);
     77        table_size = FRAME_SIZE << PTL0_SIZE;
     78
     79        if (flags & FLAG_AS_KERNEL) {
     80                memsetb(dst_ptl0, table_size, 0);
     81        } else {
     82                uintptr_t src, dst;
    7783       
    78         if (flags & FLAG_AS_KERNEL)
    79                 memsetb(dst_ptl0, table_size, 0);
    80         else {
    8184                /*
    8285                 * Copy the kernel address space portion to new PTL0.
    83                  *
    8486                 */
    85                
    86                 ipl_t ipl = interrupts_disable();
    87                 mutex_lock(&AS_KERNEL->lock);
    88                
    89                 pte_t *src_ptl0 =
    90                     (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
    91                
    92                 uintptr_t src =
    93                     (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
    94                 uintptr_t dst =
    95                     (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
    96                
     87                 
     88                ipl = interrupts_disable();
     89                mutex_lock(&AS_KERNEL->lock);           
     90                src_ptl0 = (pte_t *) PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
     91
     92                src = (uintptr_t) &src_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
     93                dst = (uintptr_t) &dst_ptl0[PTL0_INDEX(KERNEL_ADDRESS_SPACE_START)];
     94
    9795                memsetb(dst_ptl0, table_size, 0);
    98                 memcpy((void *) dst, (void *) src,
    99                     table_size - (src - (uintptr_t) src_ptl0));
    100                
     96                memcpy((void *) dst, (void *) src, table_size - (src - (uintptr_t) src_ptl0));
    10197                mutex_unlock(&AS_KERNEL->lock);
    10298                interrupts_restore(ipl);
    10399        }
    104        
     100
    105101        return (pte_t *) KA2PA((uintptr_t) dst_ptl0);
    106102}
     
    111107 *
    112108 * @param page_table Physical address of PTL0.
    113  *
    114109 */
    115110void ptl0_destroy(pte_t *page_table)
    116111{
    117         frame_free((uintptr_t) page_table);
     112        frame_free((uintptr_t)page_table);
    118113}
    119114
     
    123118 * Interrupts must be disabled.
    124119 *
    125  * @param as   Address space.
     120 * @param as Address space.
    126121 * @param lock If false, do not attempt to lock the address space.
    127  *
    128122 */
    129123void pt_lock(as_t *as, bool lock)
     
    138132 * Interrupts must be disabled.
    139133 *
    140  * @param as     Address space.
     134 * @param as Address space.
    141135 * @param unlock If false, do not attempt to unlock the address space.
    142  *
    143136 */
    144137void pt_unlock(as_t *as, bool unlock)
     
    148141}
    149142
    150 /** Test whether page tables are locked.
    151  *
    152  * @param as            Address space where the page tables belong.
    153  *
    154  * @return              True if the page tables belonging to the address soace
    155  *                      are locked, otherwise false.
    156  */
    157 bool pt_locked(as_t *as)
    158 {
    159         return mutex_locked(&as->lock);
    160 }
    161 
    162143/** @}
    163144 */
Note: See TracChangeset for help on using the changeset viewer.