Search
lxdream.org :: lxdream/src/test/testxlt.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testxlt.c
changeset 922:8a8361264b1e
prev561:533f6b478071
next991:60c7fab9c880
author nkeynes
date Thu Dec 11 23:26:03 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Disable the generational translation cache - I've got no evidence that it
actually helps performance, and it simplifies things to get rid of it (in
particular, translated code doesn't have to worry about being moved now).
file annotate diff log raw
nkeynes@561
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@561
     3
 *
nkeynes@561
     4
 * Translation cache test functions
nkeynes@561
     5
 *
nkeynes@561
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@561
     7
 *
nkeynes@561
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@561
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@561
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@561
    11
 * (at your option) any later version.
nkeynes@561
    12
 *
nkeynes@561
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@561
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@561
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@561
    16
 * GNU General Public License for more details.
nkeynes@561
    17
 */
nkeynes@561
    18
nkeynes@363
    19
#include <assert.h>
nkeynes@363
    20
#include "sh4/xltcache.h"
nkeynes@363
    21
#include "dreamcast.h"
nkeynes@363
    22
nkeynes@363
    23
extern xlat_cache_block_t xlat_new_cache;
nkeynes@363
    24
extern xlat_cache_block_t xlat_new_cache_ptr;
nkeynes@363
    25
nkeynes@363
    26
/**
nkeynes@363
    27
 * Test initial allocations from the new cache
nkeynes@363
    28
 */
nkeynes@363
    29
void test_initial()
nkeynes@363
    30
{
nkeynes@363
    31
    int i;
nkeynes@363
    32
    xlat_cache_block_t block = xlat_start_block( 0x0C008000 );
nkeynes@363
    33
    assert( block->active == 1 );
nkeynes@363
    34
    assert( block->size == XLAT_NEW_CACHE_SIZE - (2*sizeof(struct xlat_cache_block)) );
nkeynes@363
    35
    memset( block->code, 0xB5, 8192 );
nkeynes@515
    36
    xlat_commit_block( 8192, 100 );
nkeynes@363
    37
    assert( block->active == 1 );
nkeynes@363
    38
    assert( block->size == 8192 );
nkeynes@363
    39
    
nkeynes@363
    40
    int size = XLAT_NEW_CACHE_SIZE - (4*sizeof(struct xlat_cache_block)) - 8192 - 4096;
nkeynes@363
    41
    xlat_cache_block_t block2 = xlat_start_block( 0x0C009000 );
nkeynes@363
    42
    assert( block2->active == 1 );
nkeynes@363
    43
    assert( block2->size == XLAT_NEW_CACHE_SIZE - (3*sizeof(struct xlat_cache_block)) - 8192 );
nkeynes@363
    44
    memset( block2->code, 0x6D, size );
nkeynes@515
    45
    xlat_commit_block( size, 200 );
nkeynes@363
    46
    assert( block2->active == 1 );
nkeynes@363
    47
    assert( block2->size == size );
nkeynes@363
    48
    
nkeynes@363
    49
    void *addr = xlat_get_code( 0x0C008000 );
nkeynes@363
    50
    assert( addr == &block->code );
nkeynes@363
    51
    addr = xlat_get_code( 0x0C009000 );
nkeynes@363
    52
    assert( addr == &block2->code );
nkeynes@363
    53
    addr = xlat_get_code( 0x0C008002 );
nkeynes@363
    54
    assert( addr == NULL );
nkeynes@363
    55
    
nkeynes@363
    56
    xlat_cache_block_t block3 = xlat_start_block( 0x0D009800 );
nkeynes@363
    57
    assert( block3->active == 1 );
nkeynes@363
    58
    assert( block3->size == 4096 );
nkeynes@363
    59
    memset( block3->code, 0x9C, 4096 );
nkeynes@515
    60
    xlat_cache_block_t block3a = xlat_extend_block(8192);
nkeynes@363
    61
    assert( block3a != block3 );
nkeynes@363
    62
    assert( block3a == block );
nkeynes@363
    63
    assert( block3a->active == 1 );
nkeynes@363
    64
    assert( block3a->size = 8192 );
nkeynes@363
    65
    assert( block3->active == 0 );
nkeynes@363
    66
    assert( block3->size == 4096 );
nkeynes@363
    67
    for( i=0; i<4096; i++ ) {
nkeynes@363
    68
	assert( block3a->code[i] == 0x9C );
nkeynes@363
    69
    }
nkeynes@363
    70
    for( i=4096; i<8192; i++ ) {
nkeynes@363
    71
	assert( block3a->code[i] == 0xB5 );
nkeynes@363
    72
    }
nkeynes@515
    73
    xlat_commit_block(6142, 432);
nkeynes@363
    74
    addr = xlat_get_code( 0x0D009800 );
nkeynes@363
    75
    assert( addr == &block3a->code );
nkeynes@363
    76
}
nkeynes@363
    77
nkeynes@363
    78
int main()
nkeynes@363
    79
{
nkeynes@363
    80
    xlat_cache_init();
nkeynes@363
    81
    xlat_check_integrity();
nkeynes@363
    82
    
nkeynes@363
    83
    test_initial();
nkeynes@363
    84
    return 0;
nkeynes@363
    85
}
.