Search
lxdream.org :: lxdream/test/sh4/testmmu.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testmmu.c
changeset 1090:71e28626b358
prev976:e57a25d9eb7d
author nkeynes
date Mon Dec 07 17:44:27 2009 +1000 (12 years ago)
permissions -rw-r--r--
last change Prevent writes to the mmu page tables when the TLB is disabled.
view annotate diff log raw
     1 #include "utlb.h"
     2 #include "../lib.h"
     4 struct utlb_test_case {
     5     const char *name;
     6     uint32_t vma;
     7     uint32_t pma;
     8     int read_exc;
     9     int write_exc;
    10 };
    12 #define OK 0
    14 #define MAX_BATCH_ENTRIES 4
    15 #define MAX_BATCH_TESTS 8
    17 uint32_t dummy;
    19 #define LOAD(ent,asid,vpn,ppn,mode) load_utlb_entry( ent, vpn, ppn, asid, mode )
    20 #define TEST(name,asid,vma,pma,sr,sw,ur,uw) run_utlb_test_case(name,asid,vma,pma,sr,sw,ur,uw) 
    22 int run_utlb_priv_test( struct utlb_test_case *test );
    23 int run_utlb_user_test( struct utlb_test_case *test );
    25 int cases_failed;
    26 int cases_run;
    27 int tests_failed;
    28 int tests_run;
    29 int tests_skipped;
    31 int run_utlb_test_case( const char *name, int asid, unsigned int vma, unsigned int pma,
    32                           int sr, int sw, int ur, int uw )
    33 {
    34     char tmp[64];
    35     struct utlb_test_case test = { tmp, vma, pma, sr, sw };
    36     int fails = 0;
    38     cases_run++;
    40     set_asid( asid );
    41     if( sr == OTLBMULTIHIT || sw == OTLBMULTIHIT ) {
    42         fprintf( stderr, "%s: Skipping system test (multihit)\n", name );
    43         tests_skipped += 2;
    44     } else {
    45         snprintf(tmp,sizeof(tmp), "%s (System)", name );
    46         tests_run += 2;
    47         fails += run_utlb_priv_test( &test );
    48     }
    50     if( ur == OTLBMULTIHIT || uw == OTLBMULTIHIT ) {
    51         fprintf( stderr, "%s: Skipping user test '%s' (multihit)\n", name );
    52         tests_skipped += 2;
    53     } else {
    54         snprintf(tmp,sizeof(tmp), "%s (User)", name ); 
    55         test.read_exc = ur;
    56         test.write_exc = uw;
    57         tests_run += 2;
    58         fails += run_utlb_user_test( &test );
    59     }
    60     if( fails != 0 ) {
    61         cases_failed++;
    62         tests_failed += fails;
    63     }
    64     return fails;
    65 }
    67 int main()
    68 {
    69     /* Non-TLB behaviour tests */
    71     install_utlb_test_handler();
    73     /* TLB off tests (make sure the MMU _stays_ off) */
    74     LOAD( 62, 0, 0x0C000000, 0x0CFFFC00, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    75     TEST( "TLB OFF", 0, 0x0C000018, 0x0C000018, OK, OK, OK, OK );
    76     TEST( "TLB OFF", 1, 0x0C000018, 0x0C000018, OK, OK, OK, OK );
    78     /* TLB tests */
    79     invalidate_tlb();
    80     /* Permanently map the first and last MB of RAM into userspace - without 
    81      * this it's a bit hard to actually run any user-mode tests.
    82      */
    83     LOAD(62, 0, 0x0C000000, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);
    84     LOAD(63, 0, 0x0CF00000, 0x0CF00000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);
    85     set_tlb_enabled(1);
    87     /* Test miss */
    88     TEST( "U0", 0, 0x12345008, 0x0c000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
    89     TEST( "P1", 0, 0x8c000018, 0x0c000018, OK, OK, RADDERR, WADDERR );
    90     TEST( "P1", 0, 0xac000018, 0x0c000018, OK, OK, RADDERR, WADDERR );
    91     TEST( "P3", 0, 0xC4345008, 0x0c000018, RTLBMISS, WTLBMISS, RADDERR, WADDERR );
    93     /* Test flags with 1K pages */
    94     LOAD( 0, 0, 0x12345C00, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    95     LOAD( 1, 1, 0x12345C00, 0x0CFFFC00, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    96     LOAD( 2, 0, 0x12345800, 0x0C000800, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    97     LOAD( 3, 0, 0x12345400, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    98     LOAD( 4, 0, 0x12345000, 0x0C000000, TLB_VALID|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    99     LOAD( 5, 1, 0x12345800, 0x0CF01800, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );
   100     LOAD( 6, 1, 0x12346000, 0x0C000000, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );
   101     LOAD( 7, 2, 0x12346800, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_SHARE|TLB_DIRTY );
   102     TEST( "1K ASID 0",   0, 0x12345C18, 0x0C000018, OK, OK, OK, OK );
   103     TEST( "1K ASID 1",   1, 0x12345C18, 0x0CFFFC18, OK, OK, OK, OK );
   104     TEST( "1K ASID 2",   2, 0x12345C18, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
   105     TEST( "1K PRIV",     0, 0x12345818, 0x0C000818, OK, OK, READPROT, WRITEPROT );
   106     TEST( "1K READONLY", 0, 0x12345418, 0x0C000418, OK, WRITEPROT, OK, WRITEPROT );
   107     TEST( "1K PRIVREAD", 0, 0x12345018, 0x0C000018, OK, WRITEPROT, READPROT, WRITEPROT );
   108     TEST( "1K FIRSTWR",  1, 0x12345818, 0x0CF01818, OK, FIRSTWRITE, OK, FIRSTWRITE ); 
   109     TEST( "1K PRIVFWR",  1, 0x12346018, 0x0C000018, OK, FIRSTWRITE, READPROT, WRITEPROT );
   110     TEST( "1K MISS",     1, 0x12346418, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
   111     TEST( "1K SHARED 0", 0, 0x12346818, 0x0C000418, OK, OK, OK, OK );
   112     TEST( "1K SHARED 2", 2, 0x12346818, 0x0C000418, OK, OK, OK, OK );
   115     uninstall_utlb_test_handler();
   118     printf( "--> %d/%d Test cases passed (%d%%)\n", cases_run-cases_failed, cases_run, ( (cases_run-cases_failed)*100/cases_run) );
   119     printf( "--> %d/%d Tests passed (%d%%)\n", tests_run-tests_failed, tests_run, ( (tests_run-tests_failed)*100/tests_run) );
   121     return cases_failed == 0 ? 0 : 1;
   122 }
.