4 * Translation cache test functions
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include "sh4/xltcache.h"
21 #include "dreamcast.h"
23 extern xlat_cache_block_t xlat_new_cache;
24 extern xlat_cache_block_t xlat_new_cache_ptr;
25 extern xlat_cache_block_t xlat_temp_cache;
26 extern xlat_cache_block_t xlat_temp_cache_ptr;
29 * Test initial allocations from the new cache
34 xlat_cache_block_t block = xlat_start_block( 0x0C008000 );
35 assert( block->active == 1 );
36 assert( block->size == XLAT_NEW_CACHE_SIZE - (2*sizeof(struct xlat_cache_block)) );
37 memset( block->code, 0xB5, 8192 );
38 xlat_commit_block( 8192, 100 );
39 assert( block->active == 1 );
40 assert( block->size == 8192 );
42 int size = XLAT_NEW_CACHE_SIZE - (4*sizeof(struct xlat_cache_block)) - 8192 - 4096;
43 xlat_cache_block_t block2 = xlat_start_block( 0x0C009000 );
44 assert( block2->active == 1 );
45 assert( block2->size == XLAT_NEW_CACHE_SIZE - (3*sizeof(struct xlat_cache_block)) - 8192 );
46 memset( block2->code, 0x6D, size );
47 xlat_commit_block( size, 200 );
48 assert( block2->active == 1 );
49 assert( block2->size == size );
51 void *addr = xlat_get_code( 0x0C008000 );
52 assert( addr == &block->code );
53 addr = xlat_get_code( 0x0C009000 );
54 assert( addr == &block2->code );
55 addr = xlat_get_code( 0x0C008002 );
56 assert( addr == NULL );
58 xlat_cache_block_t block3 = xlat_start_block( 0x0D009800 );
59 assert( block3->active == 1 );
60 assert( block3->size == 4096 );
61 memset( block3->code, 0x9C, 4096 );
62 xlat_cache_block_t block3a = xlat_extend_block(8192);
63 assert( block3a != block3 );
64 assert( block3a == block );
65 assert( block3a->active == 1 );
66 assert( block3a->size = 8192 );
67 assert( block3->active == 0 );
68 assert( block3->size == 4096 );
69 for( i=0; i<4096; i++ ) {
70 assert( block3a->code[i] == 0x9C );
72 for( i=4096; i<8192; i++ ) {
73 assert( block3a->code[i] == 0xB5 );
75 xlat_commit_block(6142, 432);
76 addr = xlat_get_code( 0x0D009800 );
77 assert( addr == &block3a->code );
78 /* check promoted block in temp cache */
79 addr = xlat_get_code( 0x0C008000 );
80 assert( addr == &xlat_temp_cache->code );
81 assert( xlat_temp_cache->active == 1 );
82 assert( xlat_temp_cache->size == 8192 );
83 for( i=0; i<8192; i++ ) {
84 assert( xlat_temp_cache->code[i] == 0xB5 );
91 xlat_check_integrity();
.