Changeset 64f6ef04 in mainline for kernel/arch/amd64/src/mm/page.c


Ignore:
Timestamp:
2010-06-27T23:54:45Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
05e3cb8
Parents:
a1f60f3
Message:

amd64: create identity mapping of the first 8 GB of physical memory (instead of just 4 GB) during the bootstrap process
remove the crude on-demand identity mapping creation which could lead to livelocks (unmapping the page pointing to 0 MB physical while trying to map the page pointing to 4096 MB physical)

(currently the implementation is in no way closer to the ideal solution of ticket #3, but at least it allows to debug non-trivial cases of physical memory sizes > 4 GB during the approach to solving #3)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/mm/page.c

    ra1f60f3 r64f6ef04  
    3939#include <mm/frame.h>
    4040#include <mm/as.h>
    41 #include <arch/interrupt.h>
    4241#include <arch/asm.h>
    4342#include <config.h>
     
    4746#include <panic.h>
    4847#include <align.h>
    49 
    50 /* Definitions for identity page mapper */
    51 pte_t helper_ptl1[512] __attribute__((aligned (PAGE_SIZE)));
    52 pte_t helper_ptl2[512] __attribute__((aligned (PAGE_SIZE)));
    53 pte_t helper_ptl3[512] __attribute__((aligned (PAGE_SIZE)));
    54 
    55 static uintptr_t oldpage = 0;
    56 
    57 extern pte_t ptl_0;  /* From boot.S */
    58 
    59 #define PTL1_PRESENT(ptl0, page) \
    60         (!(GET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))
    61 
    62 #define PTL2_PRESENT(ptl1, page) \
    63         (!(GET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))
    64 
    65 #define PTL3_PRESENT(ptl2, page) \
    66         (!(GET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))
    67 
    68 #define PTL1_ADDR(ptl0, page) \
    69         ((pte_t *) PA2KA(GET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page))))
    70 
    71 #define PTL2_ADDR(ptl1, page) \
    72         ((pte_t *) PA2KA(GET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page))))
    73 
    74 #define PTL3_ADDR(ptl2, page) \
    75         ((pte_t *) PA2KA(GET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page))))
    76 
    77 #define SETUP_PTL1(ptl0, page, tgt) \
    78         { \
    79                 SET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    80                 SET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    81         }
    82 
    83 #define SETUP_PTL2(ptl1, page, tgt) \
    84         { \
    85                 SET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    86                 SET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    87         }
    88 
    89 #define SETUP_PTL3(ptl2, page, tgt) \
    90         { \
    91                 SET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    92                 SET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    93         }
    94 
    95 #define SETUP_FRAME(ptl3, page, tgt) \
    96         { \
    97                 SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    98                 SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    99         }
    10048
    10149void page_arch_init(void)
     
    12270        } else
    12371                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    124 }
    125 
    126 /** Identity page mapper
    127  *
    128  * We need to map whole physical memory identically before the page subsystem
    129  * is initializaed. This thing clears page table and fills in the specific
    130  * items.
    131  *
    132  */
    133 void ident_page_fault(unsigned int n, istate_t *istate)
    134 {
    135         pte_t *aptl_1;
    136         pte_t *aptl_2;
    137         pte_t *aptl_3;
    138        
    139         uintptr_t page = read_cr2();
    140        
    141         /* Unmap old address */
    142         if (oldpage) {
    143                 pte_t *aptl_1 = PTL1_ADDR(&ptl_0, oldpage);
    144                 pte_t *aptl_2 = PTL2_ADDR(aptl_1, oldpage);
    145                 pte_t *aptl_3 = PTL3_ADDR(aptl_2, oldpage);
    146                
    147                 SET_FRAME_FLAGS_ARCH(aptl_3, PTL3_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    148                
    149                 if (KA2PA(aptl_3) == KA2PA(helper_ptl3))
    150                         SET_PTL3_FLAGS_ARCH(aptl_2, PTL2_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    151                
    152                 if (KA2PA(aptl_2) == KA2PA(helper_ptl2))
    153                         SET_PTL2_FLAGS_ARCH(aptl_1, PTL1_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    154                
    155                 if (KA2PA(aptl_1) == KA2PA(helper_ptl1))
    156                         SET_PTL1_FLAGS_ARCH(&ptl_0, PTL0_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    157         }
    158        
    159         if (PTL1_PRESENT(&ptl_0, page))
    160                 aptl_1 = PTL1_ADDR(&ptl_0, page);
    161         else {
    162                 SETUP_PTL1(&ptl_0, page, helper_ptl1);
    163                 aptl_1 = helper_ptl1;
    164         }
    165        
    166         if (PTL2_PRESENT(aptl_1, page))
    167                 aptl_2 = PTL2_ADDR(aptl_1, page);
    168         else {
    169                 SETUP_PTL2(aptl_1, page, helper_ptl2);
    170                 aptl_2 = helper_ptl2;
    171         }
    172        
    173         if (PTL3_PRESENT(aptl_2, page))
    174                 aptl_3 = PTL3_ADDR(aptl_2, page);
    175         else {
    176                 SETUP_PTL3(aptl_2, page, helper_ptl3);
    177                 aptl_3 = helper_ptl3;
    178         }
    179        
    180         SETUP_FRAME(aptl_3, page, page);
    181        
    182         oldpage = page;
    18372}
    18473
Note: See TracChangeset for help on using the changeset viewer.