Search
lxdream.org :: lxdream/test/sh4/testmmu.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename test/sh4/testmmu.c
changeset 976:e57a25d9eb7d
next1090:71e28626b358
author nkeynes
date Tue Mar 24 11:15:57 2009 +0000 (15 years ago)
permissions -rw-r--r--
last change Add preliminary implementation of the GDB remote debugging server - attaches to
either or both the SH4 and ARM
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/sh4/testmmu.c Tue Mar 24 11:15:57 2009 +0000
1.3 @@ -0,0 +1,117 @@
1.4 +#include "utlb.h"
1.5 +#include "../lib.h"
1.6 +
1.7 +struct utlb_test_case {
1.8 + const char *name;
1.9 + uint32_t vma;
1.10 + uint32_t pma;
1.11 + int read_exc;
1.12 + int write_exc;
1.13 +};
1.14 +
1.15 +#define OK 0
1.16 +
1.17 +#define MAX_BATCH_ENTRIES 4
1.18 +#define MAX_BATCH_TESTS 8
1.19 +
1.20 +uint32_t dummy;
1.21 +
1.22 +#define LOAD(ent,asid,vpn,ppn,mode) load_utlb_entry( ent, vpn, ppn, asid, mode )
1.23 +#define TEST(name,asid,vma,pma,sr,sw,ur,uw) run_utlb_test_case(name,asid,vma,pma,sr,sw,ur,uw)
1.24 +
1.25 +int run_utlb_priv_test( struct utlb_test_case *test );
1.26 +int run_utlb_user_test( struct utlb_test_case *test );
1.27 +
1.28 +int cases_failed;
1.29 +int cases_run;
1.30 +int tests_failed;
1.31 +int tests_run;
1.32 +int tests_skipped;
1.33 +
1.34 +int run_utlb_test_case( const char *name, int asid, unsigned int vma, unsigned int pma,
1.35 + int sr, int sw, int ur, int uw )
1.36 +{
1.37 + char tmp[64];
1.38 + struct utlb_test_case test = { tmp, vma, pma, sr, sw };
1.39 + int fails = 0;
1.40 +
1.41 + cases_run++;
1.42 +
1.43 + set_asid( asid );
1.44 + if( sr == OTLBMULTIHIT || sw == OTLBMULTIHIT ) {
1.45 + fprintf( stderr, "%s: Skipping system test (multihit)\n", name );
1.46 + tests_skipped += 2;
1.47 + } else {
1.48 + snprintf(tmp,sizeof(tmp), "%s (System)", name );
1.49 + tests_run += 2;
1.50 + fails += run_utlb_priv_test( &test );
1.51 + }
1.52 +
1.53 + if( ur == OTLBMULTIHIT || uw == OTLBMULTIHIT ) {
1.54 + fprintf( stderr, "%s: Skipping user test '%s' (multihit)\n", name );
1.55 + tests_skipped += 2;
1.56 + } else {
1.57 + snprintf(tmp,sizeof(tmp), "%s (User)", name );
1.58 + test.read_exc = ur;
1.59 + test.write_exc = uw;
1.60 + tests_run += 2;
1.61 + fails += run_utlb_user_test( &test );
1.62 + }
1.63 + if( fails != 0 ) {
1.64 + cases_failed++;
1.65 + tests_failed += fails;
1.66 + }
1.67 + return fails;
1.68 +}
1.69 +
1.70 +int main()
1.71 +{
1.72 + /* Non-TLB behaviour tests */
1.73 +
1.74 +
1.75 + /* TLB tests */
1.76 + install_utlb_test_handler();
1.77 + invalidate_tlb();
1.78 + /* Permanently map the first and last MB of RAM into userspace - without
1.79 + * this it's a bit hard to actually run any user-mode tests.
1.80 + */
1.81 + LOAD(62, 0, 0x0C000000, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);
1.82 + LOAD(63, 0, 0x0CF00000, 0x0CF00000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);
1.83 + set_tlb_enabled(1);
1.84 +
1.85 + /* Test miss */
1.86 + TEST( "U0", 0, 0x12345008, 0x0c000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
1.87 + TEST( "P1", 0, 0x8c000018, 0x0c000018, OK, OK, RADDERR, WADDERR );
1.88 + TEST( "P1", 0, 0xac000018, 0x0c000018, OK, OK, RADDERR, WADDERR );
1.89 + TEST( "P3", 0, 0xC4345008, 0x0c000018, RTLBMISS, WTLBMISS, RADDERR, WADDERR );
1.90 +
1.91 + /* Test flags with 1K pages */
1.92 + LOAD( 0, 0, 0x12345C00, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
1.93 + LOAD( 1, 1, 0x12345C00, 0x0CFFFC00, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
1.94 + LOAD( 2, 0, 0x12345800, 0x0C000800, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
1.95 + LOAD( 3, 0, 0x12345400, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
1.96 + LOAD( 4, 0, 0x12345000, 0x0C000000, TLB_VALID|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );
1.97 + LOAD( 5, 1, 0x12345800, 0x0CF01800, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );
1.98 + LOAD( 6, 1, 0x12346000, 0x0C000000, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );
1.99 + LOAD( 7, 2, 0x12346800, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_SHARE|TLB_DIRTY );
1.100 + TEST( "1K ASID 0", 0, 0x12345C18, 0x0C000018, OK, OK, OK, OK );
1.101 + TEST( "1K ASID 1", 1, 0x12345C18, 0x0CFFFC18, OK, OK, OK, OK );
1.102 + TEST( "1K ASID 2", 2, 0x12345C18, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
1.103 + TEST( "1K PRIV", 0, 0x12345818, 0x0C000818, OK, OK, READPROT, WRITEPROT );
1.104 + TEST( "1K READONLY", 0, 0x12345418, 0x0C000418, OK, WRITEPROT, OK, WRITEPROT );
1.105 + TEST( "1K PRIVREAD", 0, 0x12345018, 0x0C000018, OK, WRITEPROT, READPROT, WRITEPROT );
1.106 + TEST( "1K FIRSTWR", 1, 0x12345818, 0x0CF01818, OK, FIRSTWRITE, OK, FIRSTWRITE );
1.107 + TEST( "1K PRIVFWR", 1, 0x12346018, 0x0C000018, OK, FIRSTWRITE, READPROT, WRITEPROT );
1.108 + TEST( "1K MISS", 1, 0x12346418, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );
1.109 + TEST( "1K SHARED 0", 0, 0x12346818, 0x0C000418, OK, OK, OK, OK );
1.110 + TEST( "1K SHARED 2", 2, 0x12346818, 0x0C000418, OK, OK, OK, OK );
1.111 +
1.112 +
1.113 + uninstall_utlb_test_handler();
1.114 +
1.115 +
1.116 + printf( "--> %d/%d Test cases passed (%d%%)\n", cases_run-cases_failed, cases_run, ( (cases_run-cases_failed)*100/cases_run) );
1.117 + printf( "--> %d/%d Tests passed (%d%%)\n", tests_run-tests_failed, tests_run, ( (tests_run-tests_failed)*100/tests_run) );
1.118 +
1.119 + return cases_failed == 0 ? 0 : 1;
1.120 +}
.