Search
lxdream.org :: lxdream/test/sh4/testmmu.c
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testmmu.c
changeset 976:e57a25d9eb7d
next1090:71e28626b358
author nkeynes
date Wed Dec 02 10:36:49 2009 +1000 (14 years ago)
permissions -rw-r--r--
last change Add missing SUBV instruction to the emulation core (translation core is ok),
along with test cases. Thanks to D. Jeff Dionne for pointing this out.
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 */
    72     /* TLB tests */
    73     install_utlb_test_handler();
    74     invalidate_tlb();
    75     /* Permanently map the first and last MB of RAM into userspace - without 
    76      * this it's a bit hard to actually run any user-mode tests.
    77      */
    78     LOAD(62, 0, 0x0C000000, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);
    79     LOAD(63, 0, 0x0CF00000, 0x0CF00000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);
    80     set_tlb_enabled(1);
    82     /* Test miss */
    83     TEST( "U0", 0, 0x12345008, 0x0c000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
    84     TEST( "P1", 0, 0x8c000018, 0x0c000018, OK, OK, RADDERR, WADDERR );
    85     TEST( "P1", 0, 0xac000018, 0x0c000018, OK, OK, RADDERR, WADDERR );
    86     TEST( "P3", 0, 0xC4345008, 0x0c000018, RTLBMISS, WTLBMISS, RADDERR, WADDERR );
    88     /* Test flags with 1K pages */
    89     LOAD( 0, 0, 0x12345C00, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    90     LOAD( 1, 1, 0x12345C00, 0x0CFFFC00, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    91     LOAD( 2, 0, 0x12345800, 0x0C000800, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    92     LOAD( 3, 0, 0x12345400, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    93     LOAD( 4, 0, 0x12345000, 0x0C000000, TLB_VALID|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
    94     LOAD( 5, 1, 0x12345800, 0x0CF01800, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );
    95     LOAD( 6, 1, 0x12346000, 0x0C000000, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );
    96     LOAD( 7, 2, 0x12346800, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_SHARE|TLB_DIRTY );
    97     TEST( "1K ASID 0",   0, 0x12345C18, 0x0C000018, OK, OK, OK, OK );
    98     TEST( "1K ASID 1",   1, 0x12345C18, 0x0CFFFC18, OK, OK, OK, OK );
    99     TEST( "1K ASID 2",   2, 0x12345C18, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
   100     TEST( "1K PRIV",     0, 0x12345818, 0x0C000818, OK, OK, READPROT, WRITEPROT );
   101     TEST( "1K READONLY", 0, 0x12345418, 0x0C000418, OK, WRITEPROT, OK, WRITEPROT );
   102     TEST( "1K PRIVREAD", 0, 0x12345018, 0x0C000018, OK, WRITEPROT, READPROT, WRITEPROT );
   103     TEST( "1K FIRSTWR",  1, 0x12345818, 0x0CF01818, OK, FIRSTWRITE, OK, FIRSTWRITE ); 
   104     TEST( "1K PRIVFWR",  1, 0x12346018, 0x0C000018, OK, FIRSTWRITE, READPROT, WRITEPROT );
   105     TEST( "1K MISS",     1, 0x12346418, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
   106     TEST( "1K SHARED 0", 0, 0x12346818, 0x0C000418, OK, OK, OK, OK );
   107     TEST( "1K SHARED 2", 2, 0x12346818, 0x0C000418, OK, OK, OK, OK );
   110     uninstall_utlb_test_handler();
   113     printf( "--> %d/%d Test cases passed (%d%%)\n", cases_run-cases_failed, cases_run, ( (cases_run-cases_failed)*100/cases_run) );
   114     printf( "--> %d/%d Tests passed (%d%%)\n", tests_run-tests_failed, tests_run, ( (tests_run-tests_failed)*100/tests_run) );
   116     return cases_failed == 0 ? 0 : 1;
   117 }
.