Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/test/mm/mapping1.c

    r20de14d rf66b565  
    3131#include <mm/page.h>
    3232#include <mm/frame.h>
     33#include <mm/as.h>
    3334#include <arch/mm/page.h>
    34 #include <mm/km.h>
    3535#include <typedefs.h>
    3636#include <debug.h>
    3737#include <arch.h>
    3838
    39 #define TEST_MAGIC  UINT32_C(0x01234567)
     39#define PAGE0  0x10000000
     40#define PAGE1  (PAGE0 + PAGE_SIZE)
     41
     42#define VALUE0  UINT32_C(0x01234567)
     43#define VALUE1  UINT32_C(0x89abcdef)
    4044
    4145const char *test_mapping1(void)
    4246{
    43         uintptr_t page0, page1;
    44         uintptr_t frame;
    45         uint32_t v;
    46         int i;
     47        uintptr_t frame0, frame1;
     48        uint32_t v0, v1;
    4749       
    48         frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE);
     50        frame0 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
     51        frame1 = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_KA);
     52       
     53        TPRINTF("Writing %#" PRIx32 " to physical address %p.\n",
     54            (uint32_t) VALUE0, (void *) KA2PA(frame0));
     55        *((uint32_t *) frame0) = VALUE0;
     56       
     57        TPRINTF("Writing %#" PRIx32 " to physical address %p.\n",
     58            (uint32_t) VALUE1, (void *) KA2PA(frame1));
     59        *((uint32_t *) frame1) = VALUE1;
     60       
     61        page_table_lock(AS, true);
    4962
    50         page0 = km_map(frame, FRAME_SIZE,
    51             PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
    52         TPRINTF("Virtual address %p mapped to physical address %p.\n",
    53             (void *) page0, (void *) frame);
    54         page1 = km_map(frame, FRAME_SIZE,
    55             PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
    56         TPRINTF("Virtual address %p mapped to physical address %p.\n",
    57             (void *) page1, (void *) frame);
     63        TPRINTF("Mapping virtual address %p to physical address %p.\n",
     64            (void *) PAGE0, (void *) KA2PA(frame0));
     65        page_mapping_insert(AS_KERNEL, PAGE0, KA2PA(frame0), PAGE_PRESENT | PAGE_WRITE);
    5866       
    59         for (i = 0; i < 2; i++) {
    60                 TPRINTF("Writing magic using the first virtual address.\n");
     67        TPRINTF("Mapping virtual address %p to physical address %p.\n",
     68            (void *) PAGE1, (void *) KA2PA(frame1));
     69        page_mapping_insert(AS_KERNEL, PAGE1, KA2PA(frame1), PAGE_PRESENT | PAGE_WRITE);
    6170
    62                 *((uint32_t *) page0) = TEST_MAGIC;
    63 
    64                 TPRINTF("Reading magic using the second virtual address.\n");
    65 
    66                 v = *((uint32_t *) page1);
     71        page_table_unlock(AS, true);
    6772       
    68                 if (v != TEST_MAGIC)
    69                         return "Criss-cross read does not match the value written.";
    70 
    71                 TPRINTF("Writing zero using the second virtual address.\n");
     73        v0 = *((uint32_t *) PAGE0);
     74        v1 = *((uint32_t *) PAGE1);
     75        TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
     76            (void *) PAGE0, v0);
     77        TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
     78            (void *) PAGE1, v1);
    7279       
    73                 *((uint32_t *) page1) = 0;
    74 
    75                 TPRINTF("Reading zero using the first virtual address.\n");
     80        if (v0 != VALUE0)
     81                return "Value at v0 not equal to VALUE0";
     82        if (v1 != VALUE1)
     83                return "Value at v1 not equal to VALUE1";
    7684       
    77                 v = *((uint32_t *) page0);
     85        TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n",
     86            (uint32_t) 0, (void *) PAGE0);
     87        *((uint32_t *) PAGE0) = 0;
    7888       
    79                 if (v != 0)
    80                         return "Criss-cross read does not match the value written.";
    81         }
    82 
    83         // FIXME: do not leak frame, page0 and page1
     89        TPRINTF("Writing %#" PRIx32 " to virtual address %p.\n",
     90            (uint32_t) 0, (void *) PAGE1);
     91        *((uint32_t *) PAGE1) = 0;
     92       
     93        v0 = *((uint32_t *) PAGE0);
     94        v1 = *((uint32_t *) PAGE1);
     95       
     96        TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
     97            (void *) PAGE0, *((uint32_t *) PAGE0));
     98        TPRINTF("Value at virtual address %p is %#" PRIx32 ".\n",
     99            (void *) PAGE1, *((uint32_t *) PAGE1));
     100       
     101        if (v0 != 0)
     102                return "Value at v0 not equal to 0";
     103        if (v1 != 0)
     104                return "Value at v1 not equal to 0";
    84105       
    85106        return NULL;
Note: See TracChangeset for help on using the changeset viewer.