revision 976:e57a25d9eb7d
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 976:e57a25d9eb7d |
parent | 975:007bf7eb944f |
child | 977:8514fb4bc101 |
author | nkeynes |
date | Mon Jan 26 12:32:23 2009 +0000 (15 years ago) |
Add some initial TLB test cases
test/Makefile.in | view | annotate | diff | log | ||
test/lib.h | view | annotate | diff | log | ||
test/lib/crt0.s | view | annotate | diff | log | ||
test/sh4/ldc.s | view | annotate | diff | log | ||
test/sh4/mmummio.c | view | annotate | diff | log | ||
test/sh4/testmmu.c | view | annotate | diff | log | ||
test/sh4/testsh4.c | view | annotate | diff | log | ||
test/sh4/testutlb.s | view | annotate | diff | log | ||
test/sh4/tlb.s | view | annotate | diff | log | ||
test/sh4/utlb.c | view | annotate | diff | log | ||
test/sh4/utlb.h | view | annotate | diff | log |
1.1 --- a/test/Makefile.in Mon Jan 26 07:26:24 2009 +00001.2 +++ b/test/Makefile.in Mon Jan 26 12:32:23 2009 +00001.3 @@ -75,7 +75,7 @@1.4 # $(RUNTEST) testide -d ../disc/test.nrg1.7 -build-tests: testsh4 testmath testide testta testregs testrend testdisp testspu testmmu1.8 +build-tests: testsh4 testmmu testmath testide testta testregs testrend testdisp testspu testmmu1.10 lib/crt0.so: lib/crt0.s1.11 $(mkdir_p) lib1.12 @@ -97,14 +97,15 @@1.13 $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)1.14 $(SH4OBJCOPY) testsh4 testsh4.bin1.16 +testmmu: lib/crt0.so sh4/testmmu.so sh4/utlb.so sh4/testutlb.so sh4/mmummio.so1.17 + $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)1.18 + $(SH4OBJCOPY) testmmu testmmu.bin1.19 +1.20 +1.21 testide: lib/crt0.so $(SHARED_OBJECTS) testide.so ide.so1.22 $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)1.23 $(SH4OBJCOPY) testide testide.bin1.25 -testmmu: lib/crt0.so $(SHARED_OBJECTS) testmmu.so1.26 - $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)1.27 - $(SH4OBJCOPY) testmmu testmmu.bin1.28 -1.29 testmath: lib/crt0.so $(SHARED_OBJECTS) testmath.so math.so1.30 $(SH4CC) $(SH4LDFLAGS) $^ -o $@ $(SH4LIBS)
2.1 --- a/test/lib.h Mon Jan 26 07:26:24 2009 +00002.2 +++ b/test/lib.h Mon Jan 26 12:32:23 2009 +00002.3 @@ -61,4 +61,23 @@2.4 #define CHECK_IEQUALS( a, b ) if( a != b ) { fprintf(stderr, "Assertion failed at %s:%d: expected %08X, but was %08X\n", __FILE__, __LINE__, a, b ); return -1; }2.5 #define DMA_ALIGN(x) ((void *)((((unsigned int)(x))+0x1F)&0xFFFFFFE0))2.7 +2.8 +/* SH4 Exceptions */2.9 +#define POWERON 0x000 /* reset vector */2.10 +#define MANRESET 0x020 /* reset vector */2.11 +#define OTLBMULTIHIT 0x140 /* reset vector */2.12 +#define RTLBMISS 0x040 /* TLB vector */2.13 +#define WTLBMISS 0x060 /* TLB vector */2.14 +#define FIRSTWRITE 0x0802.15 +#define READPROT 0x0A02.16 +#define WRITEPROT 0x0C02.17 +#define RADDERR 0x0E02.18 +#define WADDERR 0x1002.19 +#define FPUEXC 0x1202.20 +#define ILLSLOT 0x1A02.21 +#define RESINST 0x1802.22 +#define TRAP 0x1602.23 +#define FPUDIS 0x8002.24 +#define SLOTFPUDIS 0x8202.25 +2.26 #endif
3.1 --- a/test/lib/crt0.s Mon Jan 26 07:26:24 2009 +00003.2 +++ b/test/lib/crt0.s Mon Jan 26 12:32:23 2009 +00003.3 @@ -47,6 +47,9 @@3.4 lds r3,fpscr3.5 #endif /* defined (__SH3E__) || defined(__SH4_SINGLE__) || defined(__SH4__) || defined(__SH4_SINGLE_ONLY__) */3.7 + mov.l sr_data, r13.8 + ldc r1, sr3.9 +3.10 ! call the mainline3.11 mov.l main_k,r03.12 jsr @r03.13 @@ -103,6 +106,8 @@3.14 .long start_23.15 p2_mask:3.16 .long 0xa00000003.17 +sr_data:3.18 + .long 0x400000f03.19 ccr_addr:3.20 .long 0xff00001c3.21 ccr_data:
4.1 --- a/test/sh4/ldc.s Mon Jan 26 07:26:24 2009 +00004.2 +++ b/test/sh4/ldc.s Mon Jan 26 12:32:23 2009 +00004.3 @@ -4,17 +4,19 @@4.4 .global _test_ldc4.5 _test_ldc:4.6 start_test4.7 + mov.l r8, @-r154.8 + mov.l r9, @-r154.10 test_ldcsr_1:4.11 add #1, r124.13 - stc sr, r04.14 + stc sr, r84.15 mov #-1, r14.16 ldc r1, sr4.17 - stc sr, r24.18 - ldc r0, sr4.19 + stc sr, r94.20 + ldc r8, sr4.21 mov.l sr_mask, r34.22 - cmp/eq r2, r34.23 + cmp/eq r9, r34.24 bt test_ldsfpscr_14.25 fail test_ldc_str_k4.27 @@ -31,6 +33,8 @@4.28 fail test_ldc_str_k4.30 test_ldc_end:4.31 + mov.l @r15+, r94.32 + mov.l @r15+, r84.33 end_test test_ldc_str_k4.35 test_ldc_str:
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00005.2 +++ b/test/sh4/mmummio.c Mon Jan 26 12:32:23 2009 +00005.3 @@ -0,0 +1,61 @@5.4 +#include <assert.h>5.5 +#include <stdio.h>5.6 +#include "../lib.h"5.7 +5.8 +#define PTEH 0xFF0000005.9 +#define PTEL 0xFF0000045.10 +#define TTB 0xFF0000085.11 +#define TEA 0xFF00000C5.12 +#define MMUCR 0xFF0000105.13 +#define PTEA 0xFF0000345.14 +5.15 +#define ITLB_ADDR(entry) (0xF2000000 + (entry<<8))5.16 +#define ITLB_DATA(entry) (0xF3000000 + (entry<<8))5.17 +#define UTLB_ADDR(entry) (0xF6000000 + (entry<<8))5.18 +#define UTLB_DATA1(entry) (0xF7000000 + (entry<<8))5.19 +#define UTLB_DATA2(entry) (0xF7800000 + (entry<<8))5.20 +5.21 +/* Bang on the mmio side of the TLBs to make sure the bits5.22 + * respond appropriately (with AT disabled so we don't risk5.23 + * doing a hard crash) */5.24 +void test_tlb_mmio()5.25 +{5.26 + int entry;5.27 + for( entry=0; entry<64; entry++ ) {5.28 + long_write( UTLB_DATA1(entry), 0 );5.29 + long_write( UTLB_ADDR(entry), 0xFFFFFFFF );5.30 + assert( long_read( UTLB_ADDR(entry) ) == 0xFFFFFFFF );5.31 + assert( long_read( UTLB_DATA1(entry) ) == 0x00000104 );5.32 + long_write( UTLB_ADDR(entry), 0x00000000 );5.33 + assert( long_read( UTLB_ADDR(entry) ) == 0x00000000 );5.34 + assert( long_read( UTLB_DATA1(entry) ) == 0x00000000 );5.35 + long_write( UTLB_DATA1(entry), 0xFFFFFFFF );5.36 + assert( long_read( UTLB_DATA1(entry) ) == 0x1FFFFDFF );5.37 + assert( long_read( UTLB_ADDR(entry) ) == 0x00000300 );5.38 + long_write( UTLB_DATA1(entry), 0x00000000 );5.39 + assert( long_read( UTLB_DATA1(entry) ) == 0x00000000 );5.40 + assert( long_read( UTLB_ADDR(entry) ) == 0x00000000 );5.41 + long_write( UTLB_DATA2(entry), 0xFFFFFFFF );5.42 + assert( long_read( UTLB_DATA2(entry) ) == 0x0000000F );5.43 + long_write( UTLB_DATA2(entry), 0x00000000 );5.44 + assert( long_read( UTLB_DATA2(entry) ) == 0x00000000 );5.45 + }5.46 +5.47 + for( entry=0; entry<4; entry++ ) {5.48 + long_write( ITLB_DATA(entry), 0 );5.49 + long_write( ITLB_ADDR(entry), 0xFFFFFFFF );5.50 + assert( long_read( ITLB_ADDR(entry) ) == 0xFFFFFDFF );5.51 + assert( long_read( ITLB_DATA(entry) ) == 0x00000100 );5.52 + long_write( ITLB_ADDR(entry), 0x00000000 );5.53 + assert( long_read( ITLB_ADDR(entry) ) == 0x00000000 );5.54 + assert( long_read( ITLB_DATA(entry) ) == 0x00000000 );5.55 + long_write( ITLB_DATA(entry), 0xFFFFFFFF );5.56 + assert( long_read( ITLB_DATA(entry) ) == 0x1FFFFDDA );5.57 + assert( long_read( ITLB_ADDR(entry) ) == 0x00000100 );5.58 + long_write( ITLB_DATA(entry), 0x00000000 );5.59 + assert( long_read( ITLB_DATA(entry) ) == 0x00000000 );5.60 + assert( long_read( ITLB_ADDR(entry) ) == 0x00000000 );5.61 +5.62 + }5.63 +}5.64 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00006.2 +++ b/test/sh4/testmmu.c Mon Jan 26 12:32:23 2009 +00006.3 @@ -0,0 +1,117 @@6.4 +#include "utlb.h"6.5 +#include "../lib.h"6.6 +6.7 +struct utlb_test_case {6.8 + const char *name;6.9 + uint32_t vma;6.10 + uint32_t pma;6.11 + int read_exc;6.12 + int write_exc;6.13 +};6.14 +6.15 +#define OK 06.16 +6.17 +#define MAX_BATCH_ENTRIES 46.18 +#define MAX_BATCH_TESTS 86.19 +6.20 +uint32_t dummy;6.21 +6.22 +#define LOAD(ent,asid,vpn,ppn,mode) load_utlb_entry( ent, vpn, ppn, asid, mode )6.23 +#define TEST(name,asid,vma,pma,sr,sw,ur,uw) run_utlb_test_case(name,asid,vma,pma,sr,sw,ur,uw)6.24 +6.25 +int run_utlb_priv_test( struct utlb_test_case *test );6.26 +int run_utlb_user_test( struct utlb_test_case *test );6.27 +6.28 +int cases_failed;6.29 +int cases_run;6.30 +int tests_failed;6.31 +int tests_run;6.32 +int tests_skipped;6.33 +6.34 +int run_utlb_test_case( const char *name, int asid, unsigned int vma, unsigned int pma,6.35 + int sr, int sw, int ur, int uw )6.36 +{6.37 + char tmp[64];6.38 + struct utlb_test_case test = { tmp, vma, pma, sr, sw };6.39 + int fails = 0;6.40 +6.41 + cases_run++;6.42 +6.43 + set_asid( asid );6.44 + if( sr == OTLBMULTIHIT || sw == OTLBMULTIHIT ) {6.45 + fprintf( stderr, "%s: Skipping system test (multihit)\n", name );6.46 + tests_skipped += 2;6.47 + } else {6.48 + snprintf(tmp,sizeof(tmp), "%s (System)", name );6.49 + tests_run += 2;6.50 + fails += run_utlb_priv_test( &test );6.51 + }6.52 +6.53 + if( ur == OTLBMULTIHIT || uw == OTLBMULTIHIT ) {6.54 + fprintf( stderr, "%s: Skipping user test '%s' (multihit)\n", name );6.55 + tests_skipped += 2;6.56 + } else {6.57 + snprintf(tmp,sizeof(tmp), "%s (User)", name );6.58 + test.read_exc = ur;6.59 + test.write_exc = uw;6.60 + tests_run += 2;6.61 + fails += run_utlb_user_test( &test );6.62 + }6.63 + if( fails != 0 ) {6.64 + cases_failed++;6.65 + tests_failed += fails;6.66 + }6.67 + return fails;6.68 +}6.69 +6.70 +int main()6.71 +{6.72 + /* Non-TLB behaviour tests */6.73 +6.74 +6.75 + /* TLB tests */6.76 + install_utlb_test_handler();6.77 + invalidate_tlb();6.78 + /* Permanently map the first and last MB of RAM into userspace - without6.79 + * this it's a bit hard to actually run any user-mode tests.6.80 + */6.81 + LOAD(62, 0, 0x0C000000, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);6.82 + LOAD(63, 0, 0x0CF00000, 0x0CF00000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1M|TLB_CACHEABLE|TLB_DIRTY|TLB_SHARE);6.83 + set_tlb_enabled(1);6.84 +6.85 + /* Test miss */6.86 + TEST( "U0", 0, 0x12345008, 0x0c000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );6.87 + TEST( "P1", 0, 0x8c000018, 0x0c000018, OK, OK, RADDERR, WADDERR );6.88 + TEST( "P1", 0, 0xac000018, 0x0c000018, OK, OK, RADDERR, WADDERR );6.89 + TEST( "P3", 0, 0xC4345008, 0x0c000018, RTLBMISS, WTLBMISS, RADDERR, WADDERR );6.90 +6.91 + /* Test flags with 1K pages */6.92 + LOAD( 0, 0, 0x12345C00, 0x0C000000, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );6.93 + LOAD( 1, 1, 0x12345C00, 0x0CFFFC00, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );6.94 + LOAD( 2, 0, 0x12345800, 0x0C000800, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );6.95 + LOAD( 3, 0, 0x12345400, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );6.96 + LOAD( 4, 0, 0x12345000, 0x0C000000, TLB_VALID|TLB_SIZE_1K|TLB_CACHEABLE|TLB_DIRTY );6.97 + LOAD( 5, 1, 0x12345800, 0x0CF01800, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );6.98 + LOAD( 6, 1, 0x12346000, 0x0C000000, TLB_VALID|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE );6.99 + LOAD( 7, 2, 0x12346800, 0x0C000400, TLB_VALID|TLB_USERMODE|TLB_WRITABLE|TLB_SIZE_1K|TLB_CACHEABLE|TLB_SHARE|TLB_DIRTY );6.100 + TEST( "1K ASID 0", 0, 0x12345C18, 0x0C000018, OK, OK, OK, OK );6.101 + TEST( "1K ASID 1", 1, 0x12345C18, 0x0CFFFC18, OK, OK, OK, OK );6.102 + TEST( "1K ASID 2", 2, 0x12345C18, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );6.103 + TEST( "1K PRIV", 0, 0x12345818, 0x0C000818, OK, OK, READPROT, WRITEPROT );6.104 + TEST( "1K READONLY", 0, 0x12345418, 0x0C000418, OK, WRITEPROT, OK, WRITEPROT );6.105 + TEST( "1K PRIVREAD", 0, 0x12345018, 0x0C000018, OK, WRITEPROT, READPROT, WRITEPROT );6.106 + TEST( "1K FIRSTWR", 1, 0x12345818, 0x0CF01818, OK, FIRSTWRITE, OK, FIRSTWRITE );6.107 + TEST( "1K PRIVFWR", 1, 0x12346018, 0x0C000018, OK, FIRSTWRITE, READPROT, WRITEPROT );6.108 + TEST( "1K MISS", 1, 0x12346418, 0x0C000018, RTLBMISS, WTLBMISS, RTLBMISS, WTLBMISS );6.109 + TEST( "1K SHARED 0", 0, 0x12346818, 0x0C000418, OK, OK, OK, OK );6.110 + TEST( "1K SHARED 2", 2, 0x12346818, 0x0C000418, OK, OK, OK, OK );6.111 +6.112 +6.113 + uninstall_utlb_test_handler();6.114 +6.115 +6.116 + printf( "--> %d/%d Test cases passed (%d%%)\n", cases_run-cases_failed, cases_run, ( (cases_run-cases_failed)*100/cases_run) );6.117 + printf( "--> %d/%d Tests passed (%d%%)\n", tests_run-tests_failed, tests_run, ( (tests_run-tests_failed)*100/tests_run) );6.118 +6.119 + return cases_failed == 0 ? 0 : 1;6.120 +}
7.1 --- a/test/sh4/testsh4.c Mon Jan 26 07:26:24 2009 +00007.2 +++ b/test/sh4/testsh4.c Mon Jan 26 12:32:23 2009 +00007.3 @@ -14,6 +14,9 @@7.5 void test_print_failure( char *testname, int number, char *message )7.6 {7.7 + fprintf( stderr, "Fail" );7.8 + fprintf( stderr, testname );7.9 +7.10 if( message == NULL ) {7.11 fprintf( stderr, "%s: Test %d failed!\n", testname, number );7.12 } else {
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00008.2 +++ b/test/sh4/testutlb.s Mon Jan 26 12:32:23 2009 +00008.3 @@ -0,0 +1,720 @@8.4 +8.5 +8.6 +.global _install_utlb_test_handler8.7 +_install_utlb_test_handler:8.8 + mov.l utlb_old_vbr_k, r08.9 + stc vbr, r18.10 + mov.l r1, @r08.11 +8.12 + mov.l utlb_vbr_k, r08.13 + ldc r0, vbr8.14 + rts8.15 + nop8.16 +8.17 +.global _uninstall_utlb_test_handler8.18 +_uninstall_utlb_test_handler:8.19 + mov.l utlb_old_vbr_k, r08.20 + mov.l @r0, r08.21 + ldc r0, vbr8.22 + rts8.23 + nop8.24 +8.25 +utlb_exc_handler:8.26 + mov.l utlb_exc_stack_k, r158.27 + mov.l r0, @-r158.28 + mov.l r1, @-r158.29 + mov.l r2, @-r158.30 + sts pr, r08.31 + mov.l r0, @-r158.32 +8.33 + mov.l mmu_expevt_k, r28.34 + mov.l @r2, r28.35 + mov r2, r08.36 + shlr2 r08.37 + cmp/eq #0x58, r08.38 + bt utlb_trap8.39 +8.40 + mov.l utlb_exc_k_1, r08.41 + mov.l @(16,r0), r18.42 + tst r1, r18.43 + bt utlb_exc_unexpected8.44 +8.45 + mov.l @r0, r18.46 + tst r1, r18.47 + bf utlb_exc_set8.48 + mov.l r2, @r08.49 + stc spc, r28.50 + mov.l r2, @(8,r0)8.51 +8.52 +utlb_exc_set:8.53 + mov.l @(4,r0), r28.54 + add #1, r28.55 + mov.l r2, @(4,r0)8.56 +8.57 + mov.l @(12,r0), r28.58 + stc spc, r18.59 + add r2, r18.60 + ldc r1, spc8.61 +8.62 +utlb_exc_done:8.63 + mov.l @r15+, r08.64 + lds r0, pr8.65 + mov.l @r15+, r28.66 + mov.l @r15+, r18.67 + mov.l @r15+, r08.68 + rte8.69 + stc sgr, r158.70 +8.71 +utlb_trap:8.72 + mov.l mmu_tra_k, r28.73 + mov.l @r2, r08.74 + shlr2 r08.75 + cmp/eq #42, r08.76 + bt utlb_trap_priv8.77 + cmp/eq #41, r08.78 + bt utlb_trap_printf8.79 + bra utlb_exc_done8.80 + nop8.81 +utlb_trap_priv:8.82 + stc ssr, r08.83 + mov.l mmu_sr_md, r18.84 + or r1, r08.85 + ldc r0, ssr8.86 + bra utlb_exc_done8.87 + nop8.88 +utlb_trap_printf:8.89 + stc sr, r08.90 + mov.l mmu_sr_rb_mask, r18.91 + and r1, r08.92 + ldc r0, sr8.93 + mov.l utlb_printf_k, r08.94 + jsr @r08.95 + nop8.96 + bra utlb_exc_done8.97 + nop8.98 +utlb_exc_unexpected: /* Report an unexpected exception. Save everything in case printf clobbers it */8.99 + mov.l r3, @-r158.100 + mov.l r4, @-r158.101 + mov.l r5, @-r158.102 + mov.l r6, @-r158.103 + mov.l r7, @-r158.104 + mov.l r8, @-r158.105 + mov.l r9, @-r158.106 + mov.l r10, @-r158.107 + mov.l r11, @-r158.108 + mov.l r12, @-r158.109 + mov.l r13, @-r158.110 + mov.l r14, @-r158.111 + sts fpscr, r08.112 + mov.l r0, @-r158.113 +8.114 + stc spc, r68.115 + mov r2, r58.116 + mov.l utlb_unexpected_msg_k, r48.117 + mov.l utlb_printf_k, r38.118 + jsr @r38.119 + nop8.120 +8.121 + mov.l @r15+, r08.122 + lds r0, fpscr8.123 + mov.l @r15+, r148.124 + mov.l @r15+, r138.125 + mov.l @r15+, r128.126 + mov.l @r15+, r118.127 + mov.l @r15+, r108.128 + mov.l @r15+, r98.129 + mov.l @r15+, r88.130 + mov.l @r15+, r78.131 + mov.l @r15+, r68.132 + mov.l @r15+, r58.133 + mov.l @r15+, r48.134 + mov.l @r15+, r38.135 + mov.l utlb_exc_k_1, r08.136 + bra utlb_exc_set8.137 + nop8.138 +8.139 +8.140 +.align 48.141 +utlb_vbr_k:8.142 + .long utlb_vbr8.143 +utlb_old_vbr_k:8.144 + .long utlb_old_vbr8.145 +utlb_exc_k_1:8.146 + .long utlb_exc8.147 +mmu_expevt_k:8.148 + .long 0xFF0000248.149 +mmu_tra_k:8.150 + .long 0xFF0000208.151 +mmu_sr_md:8.152 + .long 0x400000008.153 +mmu_sr_rb_mask:8.154 + .long 0x500000008.155 +utlb_exc_stack_k:8.156 + .long utlb_exc_stack8.157 +utlb_printf_k:8.158 + .long _printf8.159 +utlb_unexpected_msg_k:8.160 + .long utlb_unexpected_msg8.161 +8.162 + .skip 0x1F00 /* 8K stack */8.163 +utlb_vbr:8.164 + .skip 0x1008.165 +utlb_exc_stack:8.166 + mov.l utlb_exc_handler_k1, r158.167 + jmp @r158.168 + nop8.169 + nop8.170 +utlb_exc_handler_k1:8.171 + .long utlb_exc_handler8.172 +8.173 + .skip 0x2F48.174 + mov.l utlb_exc_handler_k2, r158.175 + jmp @r158.176 + nop8.177 + nop8.178 +utlb_exc_handler_k2:8.179 + .long utlb_exc_handler8.180 + .skip 0x1F48.181 + rte8.182 + stc sgr, r158.183 +8.184 +8.185 +utlb_expect_exc:8.186 + mova utlb_exc, r08.187 + xor r1, r18.188 + mov.l r1, @r08.189 + mov.l r1, @(4,r0)8.190 + mov.l r1, @(8,r0)8.191 + mov #1, r18.192 + mov.l r1, @(16,r0)8.193 + mov #2, r18.194 + mov.l r1, @(12,r0)8.195 + rts8.196 + nop8.197 +8.198 +utlb_noexpect_exc:8.199 + mova utlb_exc, r08.200 + xor r1, r18.201 + mov.l r1, @r08.202 + mov.l r1, @(4,r0)8.203 + mov.l r1, @(8,r0)8.204 + mov.l r1, @(16,r0)8.205 + mov #2, r18.206 + mov.l r1, @(12,r0)8.207 + rts8.208 + nop8.209 +8.210 +/* Check the result of a read test. Call with:8.211 + * r0 = expected spc8.212 + * r1 = value read (if any)8.213 + * r9 = (char *) testname8.214 + * r10 = test VMA8.215 + * r11 = test PMA8.216 + * r12 = expected exc8.217 + *8.218 + * Trashes r0..r78.219 + */8.220 +utlb_check_read_exc:8.221 + mov.l utlb_exc_k, r38.222 + mov.l addr_mask, r28.223 + and r2, r38.224 +8.225 + mov.l @r3, r28.226 + cmp/eq r2, r128.227 + bf test_read_exc_bad8.228 + tst r12, r128.229 + bt test_read_ok /* Expected no exception, and got none */8.230 + mov.l @(4,r3), r28.231 + dt r28.232 + bf test_read_count_bad8.233 + mov.l @(8,r3), r28.234 + cmp/eq r0, r28.235 + bt test_read_ok8.236 +test_read_pc_bad:8.237 + add #1, r148.238 + mov r0, r68.239 + mov.l err_read_pc_msg_k, r48.240 + mov r2, r78.241 + mov r9, r58.242 + trapa #418.243 + bra test_read_ok8.244 + nop8.245 +test_read_count_bad:8.246 + add #1, r148.247 + add #2, r28.248 + mov.l err_read_count_msg_k, r48.249 + mov r2, r68.250 + mov r9, r58.251 + trapa #418.252 + bra test_read_ok8.253 + nop8.254 +test_read_exc_bad:8.255 + add #1, r148.256 + mov.l err_read_exc_msg_k, r48.257 + mov r12, r68.258 + mov r2, r78.259 + mov r9, r58.260 + trapa #418.261 + bra test_read_ok8.262 + nop8.263 +test_read_ok:8.264 + bra utlb_expect_exc8.265 + nop8.266 +8.267 +/* Check the result of a write test (and clears the exception). Call with:8.268 + * r0 = expected spc8.269 + * r1 = written value8.270 + * r9 = (char *) testname8.271 + * r10 = test VMA8.272 + * r11 = test PMA8.273 + * r13 = expected exc8.274 + * r14 = fail count (updated)8.275 + *8.276 + * Trashes r0..r78.277 + */8.278 +utlb_check_write_exc:8.279 + mov.l utlb_exc_k, r38.280 + mov.l addr_mask, r28.281 + and r2, r38.282 +8.283 + mov.l @r3, r28.284 + cmp/eq r2, r138.285 + bf test_write_exc_bad8.286 + tst r13, r138.287 + bt test_write_ok /* Expected no exception, and got none */8.288 + mov.l @(4,r3), r28.289 + dt r28.290 + bf test_write_count_bad8.291 + mov.l @(8,r3), r28.292 + cmp/eq r0, r28.293 + bt test_write_ok8.294 +test_write_pc_bad:8.295 + add #1, r148.296 + mov r0, r68.297 + mov.l err_write_pc_msg_k, r48.298 + mov r2, r78.299 + mov r9, r58.300 + trapa #418.301 + bra test_write_ok8.302 + nop8.303 +test_write_count_bad:8.304 + add #1, r148.305 + add #1, r28.306 + mov.l err_write_count_msg_k, r48.307 + mov r2, r68.308 + mov r9, r58.309 + trapa #418.310 + bra test_write_ok8.311 + nop8.312 +test_write_exc_bad:8.313 + add #1, r148.314 + mov.l err_write_exc_msg_k, r48.315 + mov r13, r68.316 + mov r2, r78.317 + mov r9, r58.318 + trapa #418.319 + bra test_write_ok8.320 + nop8.321 +test_write_ok:8.322 + bra utlb_expect_exc8.323 + nop8.324 +.align 48.325 +utlb_exc_k:8.326 + .long utlb_exc8.327 +err_read_exc_msg_k:8.328 + .long err_read_exc_msg8.329 +err_read_count_msg_k:8.330 + .long err_read_count_msg8.331 +err_read_pc_msg_k:8.332 + .long err_read_pc_msg8.333 +err_write_exc_msg_k:8.334 + .long err_write_exc_msg8.335 +err_write_count_msg_k:8.336 + .long err_write_count_msg8.337 +err_write_pc_msg_k:8.338 + .long err_write_pc_msg8.339 +8.340 +.align 48.341 +utlb_old_vbr:8.342 + .long 08.343 +utlb_exc:8.344 + .long 08.345 +utlb_exc_count:8.346 + .long 08.347 +utlb_exc_spc:8.348 + .long 08.349 +utlb_rte_offset:8.350 + .long 28.351 +utlb_expected:8.352 + .long 08.353 +8.354 +.global _run_utlb_priv_test8.355 +_run_utlb_priv_test:8.356 + mov.l r14, @-r158.357 + sts pr, r08.358 + mov.l r0, @-r158.359 + mov.l r13, @-r158.360 + mov.l r12, @-r158.361 + mov.l r11, @-r158.362 + mov.l r10, @-r158.363 + mov.l r9, @-r158.364 + mov.l r8, @-r158.365 +8.366 + mov.l @(0,r4), r9 /* Test name */8.367 + mov.l @(4,r4), r10 /* Test VMA */8.368 + mov.l @(8,r4), r11 /* Test PMA */8.369 + mov.l @(12,r4), r12 /* Read exception */8.370 + mov.l @(16,r4), r13 /* Write exception */8.371 + xor r14, r14 /* Fail count */8.372 +8.373 + mov.l @r11, r0 /* Save original memory value */8.374 + ocbp @r118.375 + mov.l r0, @-r158.376 +8.377 + tst r12, r128.378 + bt utlb_read_test_noexc8.379 +8.380 +/* Exception test cases - all should fail with the same exception */8.381 +utlb_read_test_exc:8.382 + mov r10, r88.383 + bsr utlb_expect_exc8.384 + nop8.385 +8.386 +/* Test mov.l Rm, Rn */8.387 + mova test_readl_1, r08.388 +.align 48.389 +test_readl_1:8.390 + mov.l @r10, r18.391 + bsr utlb_check_read_exc8.392 + nop8.393 +8.394 +/* Test mov.l @Rm+, Rn */8.395 + mova test_readl_2, r08.396 +.align 48.397 +test_readl_2:8.398 + mov.l @r8+, r18.399 + bsr utlb_check_read_exc8.400 + nop8.401 + cmp/eq r8,r108.402 + bt test_readl_2_ok8.403 +8.404 + add #1, r148.405 + mov.l err_readlp_bad_msg_k, r48.406 + mov r9, r58.407 + trapa #418.408 +8.409 +test_readl_2_ok:8.410 +/* Test mov.w @Rm, Rn */8.411 + mova test_readw_1, r08.412 +.align 48.413 +test_readw_1:8.414 + mov.w @r10, r18.415 + bsr utlb_check_read_exc8.416 + nop8.417 +8.418 +/* Test mov.w @Rm+, Rn */8.419 + mova test_readw_2, r08.420 +.align 48.421 +test_readw_2:8.422 + mov.w @r8+, r18.423 + bsr utlb_check_read_exc8.424 + nop8.425 + cmp/eq r8, r108.426 + bt test_readw_2_ok8.427 +8.428 + add #1, r148.429 + mov.l err_readwp_bad_msg_k, r48.430 + mov r9, r58.431 + trapa #418.432 +8.433 +test_readw_2_ok:8.434 +8.435 +/* Test mov.b @Rm, Rn */8.436 + mova test_readb_1, r08.437 +.align 48.438 +test_readb_1:8.439 + mov.b @r10, r18.440 + bsr utlb_check_read_exc8.441 + nop8.442 +8.443 +/* Test mov.b @Rm+, Rn */8.444 + mova test_readb_2, r08.445 +.align 48.446 +test_readb_2:8.447 + mov.b @r8+, r18.448 + bsr utlb_check_read_exc8.449 + nop8.450 + cmp/eq r8, r108.451 + bt test_readb_2_ok8.452 +8.453 + add #1, r148.454 + mov.l err_readbp_bad_msg_k, r48.455 + mov r9, r58.456 + trapa #418.457 +8.458 +test_readb_2_ok:8.459 +8.460 + bra utlb_read_test_done8.461 + nop8.462 +8.463 +/* Non-exception read tests */8.464 +utlb_read_test_noexc:8.465 + mov.l utlb_exc_k_2, r88.466 + mov.l addr_mask, r08.467 + and r0, r88.468 + bsr utlb_noexpect_exc8.469 + nop8.470 +8.471 + mov.l @r10, r18.472 + not r1, r28.473 + mov.l r2, @r118.474 + ocbp @r118.475 + ocbi @r108.476 + mov.l @r10, r18.477 + ocbi @r108.478 + cmp/eq r1, r28.479 + bt noexc_readl_ok8.480 +8.481 +8.482 + add #1, r148.483 + mov.l err_read_mismatch_msg_k, r48.484 + mov r9, r58.485 + trapa #418.486 +8.487 +noexc_readl_ok:8.488 +8.489 + mov.l @(4,r8), r08.490 + add r0, r148.491 +utlb_read_test_done:8.492 +8.493 +/*********************** Begin write tests *****************************/8.494 + tst r13, r138.495 + bt utlb_write_test_noexc8.496 +8.497 +/* Exception write tests */8.498 +utlb_write_test_exc:8.499 + bsr utlb_expect_exc8.500 + nop8.501 +8.502 + mova test_writel_pc, r08.503 +.align 48.504 +test_writel_pc:8.505 + mov.l r1, @r108.506 + bsr utlb_check_write_exc8.507 + nop8.508 +8.509 + mova test_writelp_pc, r08.510 + mov r10, r88.511 +.align 48.512 +test_writelp_pc:8.513 + mov.l r1, @-r88.514 + bsr utlb_check_write_exc8.515 + nop8.516 + cmp/eq r8, r108.517 + bt test_writelp_ok8.518 + add #1, r148.519 + mov.l err_writelp_bad_msg_k, r48.520 + mov r9, r58.521 + trapa #418.522 +test_writelp_ok:8.523 +8.524 + mova test_writew_pc, r08.525 +.align 48.526 +test_writew_pc:8.527 + mov.w r1, @r108.528 + bsr utlb_check_write_exc8.529 + nop8.530 +8.531 + mova test_writewp_pc, r08.532 + mov r10, r88.533 +.align 48.534 +test_writewp_pc:8.535 + mov.w r1, @-r88.536 + bsr utlb_check_write_exc8.537 + nop8.538 + cmp/eq r8, r108.539 + bt test_writewp_ok8.540 + add #1, r148.541 + mov.l err_writewp_bad_msg_k, r48.542 + mov r9, r58.543 + trapa #418.544 +test_writewp_ok:8.545 +8.546 + mova test_writeb_pc, r08.547 +.align 48.548 +test_writeb_pc:8.549 + mov.b r1, @r108.550 + bsr utlb_check_write_exc8.551 + nop8.552 +8.553 + mova test_writebp_pc, r08.554 + mov r10, r88.555 +.align 48.556 +test_writebp_pc:8.557 + mov.b r1, @-r88.558 + bsr utlb_check_write_exc8.559 + nop8.560 + cmp/eq r8, r108.561 + bt test_writebp_ok8.562 + add #1, r148.563 + mov.l err_writelp_bad_msg_k, r48.564 + mov r9, r58.565 + trapa #418.566 +test_writebp_ok:8.567 +8.568 + bra utlb_write_test_done8.569 + nop8.570 +8.571 +/* Non-exception write tests */8.572 +utlb_write_test_noexc:8.573 + mov.l utlb_exc_k_2, r88.574 + mov.l addr_mask, r08.575 + and r0, r88.576 + bsr utlb_noexpect_exc8.577 + nop8.578 +8.579 + mov.l @r11, r78.580 + ocbp @r118.581 + not r7, r18.582 +8.583 + mov.l r1, @r108.584 + ocbp @r108.585 + mov.l @r11, r68.586 + cmp/eq r6, r18.587 + bt test_writel_1_ok8.588 +8.589 + add #1, r148.590 + mov.l err_write_ignored_msg_k, r48.591 + mov r9, r58.592 + trapa #418.593 +8.594 +test_writel_1_ok:8.595 +8.596 + mov.l @(4,r8), r08.597 + add r0, r148.598 +utlb_write_test_done:8.599 +8.600 + xor r0, r08.601 + mov.l r0, @(16,r8)8.602 +8.603 + mov.l @r15+, r08.604 + mov.l r0, @r118.605 + mov.l @r15+, r88.606 + mov.l @r15+, r98.607 + mov.l @r15+, r108.608 + mov.l @r15+, r118.609 + mov.l @r15+, r128.610 + mov.l @r15+, r138.611 + mov.l @r15+, r18.612 + lds r1, pr8.613 + mov r14, r08.614 + mov.l @r15+, r148.615 + rts8.616 + nop8.617 +8.618 +.align 48.619 +err_read_mismatch_msg_k:8.620 + .long err_read_mismatch_msg8.621 +err_write_ignored_msg_k:8.622 + .long err_write_ignored_msg8.623 +err_readlp_bad_msg_k:8.624 + .long err_readlp_bad_msg8.625 +err_readwp_bad_msg_k:8.626 + .long err_readwp_bad_msg8.627 +err_readbp_bad_msg_k:8.628 + .long err_readbp_bad_msg8.629 +err_writelp_bad_msg_k:8.630 + .long err_readlp_bad_msg8.631 +err_writewp_bad_msg_k:8.632 + .long err_readwp_bad_msg8.633 +err_writebp_bad_msg_k:8.634 + .long err_readbp_bad_msg8.635 +8.636 +8.637 +8.638 +.global _run_utlb_user_test8.639 +_run_utlb_user_test:8.640 + sts pr, r08.641 + mov.l r0, @-r158.642 + stc sr, r28.643 + mov.l sr_mask, r18.644 + and r1, r28.645 +8.646 + mova user_entry_point, r08.647 + mov.l addr_mask, r18.648 + and r1, r08.649 +8.650 + mov.l r15, @-r158.651 +8.652 + jmp @r08.653 + nop8.654 +8.655 +user_entry_point:8.656 + nop8.657 + ldc r2, sr8.658 +8.659 + /* In user mode */8.660 +8.661 + mov.l main_test_k, r08.662 + and r1, r08.663 + and r1, r48.664 + and r1, r158.665 + jsr @r08.666 + nop8.667 +8.668 + /* Done, return to priv mode */8.669 + trapa #428.670 + mov.l user_retaddr, r18.671 + jmp @r18.672 + nop8.673 +8.674 +user_exit_point:8.675 + /* Back to priv mode */8.676 + mov.l @r15+, r158.677 + mov.l @r15+, r18.678 + lds r1, pr8.679 + rts8.680 + nop8.681 +.align 48.682 +8.683 +utlb_exc_k_2:8.684 + .long utlb_exc8.685 +main_test_k:8.686 + .long _run_utlb_priv_test8.687 +addr_mask:8.688 + .long 0x1FFFFFFF8.689 +sr_mask:8.690 + .long 0x3FFFFFFF8.691 +user_retaddr:8.692 + .long user_exit_point8.693 +8.694 +err_read_exc_msg:8.695 + .string "%s: Read failed: Expected Exc %04X but got %04X\n"8.696 +err_read_count_msg:8.697 + .string "%s: Read bad exception: Exception 1 exception, but got %d\n"8.698 +err_read_pc_msg:8.699 + .string "%s: Read bad exception: Expected PC=%08X but was %08X\n"8.700 +err_read_mismatch_msg:8.701 + .string "%s: Read failed: Data mismatch!\n"8.702 +err_readlp_bad_msg:8.703 + .string "%s: Mov.l @Rm+, Rn failed: Rm changed!\n"8.704 +err_readwp_bad_msg:8.705 + .string "%s: Mov.w @Rm+, Rn failed: Rm changed!\n"8.706 +err_readbp_bad_msg:8.707 + .string "%s: Mov.b @Rm+, Rn failed: Rm changed!\n"8.708 +err_writelp_bad_msg:8.709 + .string "%s: Mov.l Rm, @-Rn failed: Rm changed!\n"8.710 +err_writewp_bad_msg:8.711 + .string "%s: Mov.w Rm, @-Rn failed: Rm changed!\n"8.712 +err_writebp_bad_msg:8.713 + .string "%s: Mov.b Rm, @-Rn failed: Rm changed!\n"8.714 +err_write_exc_msg:8.715 + .string "%s: Write failed: Expected Exc %04X but got %04X\n"8.716 +err_write_count_msg:8.717 + .string "%s: Write bad exception: Expected 1 exception, but got %d\n"8.718 +err_write_pc_msg:8.719 + .string "%s: Write bad exception: Expected PC=%08X but was %08X\n"8.720 +err_write_ignored_msg:8.721 + .string "%s: Write failed: write didn't happen!\n"8.722 +utlb_unexpected_msg:8.723 + .string "*** Unexpected exception %04X at %08X!\n"
9.1 --- a/test/sh4/tlb.s Mon Jan 26 07:26:24 2009 +00009.2 +++ b/test/sh4/tlb.s Mon Jan 26 12:32:23 2009 +00009.3 @@ -104,6 +104,8 @@9.4 bt test_tlb_69.5 test_tlb5_fail:9.6 fail test_tlb_str_k9.7 + bra test_tlb_69.8 + nop9.10 test_tlb5_addr:9.11 .long 0xF6000000
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +000010.2 +++ b/test/sh4/utlb.c Mon Jan 26 12:32:23 2009 +000010.3 @@ -0,0 +1,99 @@10.4 +/**10.5 + * $Id: utlb.c 831 2008-08-13 10:32:00Z nkeynes $10.6 + *10.7 + * UTLB unit test support10.8 + *10.9 + * Copyright (c) 2006 Nathan Keynes.10.10 + *10.11 + * This program is free software; you can redistribute it and/or modify10.12 + * it under the terms of the GNU General Public License as published by10.13 + * the Free Software Foundation; either version 2 of the License, or10.14 + * (at your option) any later version.10.15 + *10.16 + * This program is distributed in the hope that it will be useful,10.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of10.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10.19 + * GNU General Public License for more details.10.20 + */10.21 +10.22 +#include <assert.h>10.23 +#include "utlb.h"10.24 +#include "../lib.h"10.25 +10.26 +#define TLB_VALID 0x0000010010.27 +#define TLB_USERMODE 0x0000004010.28 +#define TLB_WRITABLE 0x0000002010.29 +#define TLB_SIZE_1K 0x0000000010.30 +#define TLB_SIZE_4K 0x0000001010.31 +#define TLB_SIZE_64K 0x0000008010.32 +#define TLB_SIZE_1M 0x0000009010.33 +#define TLB_CACHEABLE 0x0000000810.34 +#define TLB_DIRTY 0x0000000410.35 +#define TLB_SHARE 0x0000000210.36 +#define TLB_WRITETHRU 0x0000000110.37 +10.38 +#define PTEH 0xFF00000010.39 +#define PTEL 0xFF00000410.40 +#define TEA 0xFF00000C10.41 +#define MMUCR 0xFF00001010.42 +10.43 +void set_tlb_enabled( int flag )10.44 +{10.45 + uint32_t val = long_read( MMUCR );10.46 + if( flag ) {10.47 + val |= 1;10.48 + } else {10.49 + val &= ~1;10.50 + }10.51 + long_write( MMUCR, val );10.52 +}10.53 +10.54 +void invalidate_tlb()10.55 +{10.56 + uint32_t val = long_read( MMUCR );10.57 + long_write( MMUCR, val | 4 );10.58 +}10.59 +10.60 +void set_sv_enabled( int flag )10.61 +{10.62 + uint32_t val = long_read( MMUCR );10.63 + if( flag ) {10.64 + val |= 0x100;10.65 + } else {10.66 + val &= ~0x100;10.67 + }10.68 + long_write( MMUCR, val );10.69 +}10.70 +10.71 +void set_storequeue_protected( int flag )10.72 +{10.73 + uint32_t val = long_read( MMUCR );10.74 + if( flag ) {10.75 + val |= 0x200;10.76 + } else {10.77 + val &= ~0x200;10.78 + }10.79 + long_write( MMUCR, val );10.80 +}10.81 +10.82 +10.83 +void set_asid( int asid )10.84 +{10.85 + uint32_t val = long_read( PTEH ) & 0xFFFFFF00;10.86 + long_write( PTEH, val | asid );10.87 +}10.88 +10.89 +10.90 +void load_utlb_entry( int entryNo, uint32_t vpn, uint32_t ppn, int asid, uint32_t mode )10.91 +{10.92 + long_write( (0xF6000000 | (entryNo<<8)), vpn | asid );10.93 + long_write( (0xF7000000 | (entryNo<<8)), ppn | mode );10.94 +}10.95 +10.96 +10.97 +void check_utlb_access( uint32_t addr, uint32_t direct_addr, int mode )10.98 +{10.99 +10.100 +10.101 +}10.102 +
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +000011.2 +++ b/test/sh4/utlb.h Mon Jan 26 12:32:23 2009 +000011.3 @@ -0,0 +1,51 @@11.4 +/**11.5 + * $Id: utlb.c 831 2008-08-13 10:32:00Z nkeynes $11.6 + *11.7 + * UTLB unit test support11.8 + *11.9 + * Copyright (c) 2006 Nathan Keynes.11.10 + *11.11 + * This program is free software; you can redistribute it and/or modify11.12 + * it under the terms of the GNU General Public License as published by11.13 + * the Free Software Foundation; either version 2 of the License, or11.14 + * (at your option) any later version.11.15 + *11.16 + * This program is distributed in the hope that it will be useful,11.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of11.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11.19 + * GNU General Public License for more details.11.20 + */11.21 +11.22 +#include <../lib.h>11.23 +11.24 +#ifndef TEST_UTLB11.25 +#define TEST_UTLB 111.26 +11.27 +#define TLB_VALID 0x0000010011.28 +#define TLB_USERMODE 0x0000004011.29 +#define TLB_WRITABLE 0x0000002011.30 +#define TLB_USERWRITABLE (TLB_WRITABLE|TLB_USERMODE)11.31 +#define TLB_SIZE_MASK 0x0000009011.32 +#define TLB_SIZE_1K 0x0000000011.33 +#define TLB_SIZE_4K 0x0000001011.34 +#define TLB_SIZE_64K 0x0000008011.35 +#define TLB_SIZE_1M 0x0000009011.36 +#define TLB_CACHEABLE 0x0000000811.37 +#define TLB_DIRTY 0x0000000411.38 +#define TLB_SHARE 0x0000000211.39 +#define TLB_WRITETHRU 0x0000000111.40 +11.41 +void set_tlb_enabled( int flag );11.42 +void invalidate_tlb();11.43 +void set_sv_enabled( int flag );11.44 +void set_storequeue_protected( int flag );11.45 +void set_asid( int asid );11.46 +void load_utlb_entry( int entryNo, uint32_t vpn, uint32_t ppn, int asid, uint32_t mode );11.47 +11.48 +#define ACCESS_OK 011.49 +#define ACCESS_READONLY 111.50 +#define ACCESS_PRIVONLY 211.51 +#define ACCESS_USERMISS 411.52 +void check_utlb_access( uint32_t addr, uint32_t direct_addr, int mode );11.53 +11.54 +#endif /* !TEST_UTLB */
.