Search
lxdream.org :: lxdream/src/test/testxlt.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testxlt.c
changeset 561:533f6b478071
prev515:5e5bb1dd369e
next922:8a8361264b1e
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
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
extern xlat_cache_block_t xlat_temp_cache;
nkeynes@363
    26
extern xlat_cache_block_t xlat_temp_cache_ptr;
nkeynes@363
    27
nkeynes@363
    28
/**
nkeynes@363
    29
 * Test initial allocations from the new cache
nkeynes@363
    30
 */
nkeynes@363
    31
void test_initial()
nkeynes@363
    32
{
nkeynes@363
    33
    int i;
nkeynes@363
    34
    xlat_cache_block_t block = xlat_start_block( 0x0C008000 );
nkeynes@363
    35
    assert( block->active == 1 );
nkeynes@363
    36
    assert( block->size == XLAT_NEW_CACHE_SIZE - (2*sizeof(struct xlat_cache_block)) );
nkeynes@363
    37
    memset( block->code, 0xB5, 8192 );
nkeynes@515
    38
    xlat_commit_block( 8192, 100 );
nkeynes@363
    39
    assert( block->active == 1 );
nkeynes@363
    40
    assert( block->size == 8192 );
nkeynes@363
    41
    
nkeynes@363
    42
    int size = XLAT_NEW_CACHE_SIZE - (4*sizeof(struct xlat_cache_block)) - 8192 - 4096;
nkeynes@363
    43
    xlat_cache_block_t block2 = xlat_start_block( 0x0C009000 );
nkeynes@363
    44
    assert( block2->active == 1 );
nkeynes@363
    45
    assert( block2->size == XLAT_NEW_CACHE_SIZE - (3*sizeof(struct xlat_cache_block)) - 8192 );
nkeynes@363
    46
    memset( block2->code, 0x6D, size );
nkeynes@515
    47
    xlat_commit_block( size, 200 );
nkeynes@363
    48
    assert( block2->active == 1 );
nkeynes@363
    49
    assert( block2->size == size );
nkeynes@363
    50
    
nkeynes@363
    51
    void *addr = xlat_get_code( 0x0C008000 );
nkeynes@363
    52
    assert( addr == &block->code );
nkeynes@363
    53
    addr = xlat_get_code( 0x0C009000 );
nkeynes@363
    54
    assert( addr == &block2->code );
nkeynes@363
    55
    addr = xlat_get_code( 0x0C008002 );
nkeynes@363
    56
    assert( addr == NULL );
nkeynes@363
    57
    
nkeynes@363
    58
    xlat_cache_block_t block3 = xlat_start_block( 0x0D009800 );
nkeynes@363
    59
    assert( block3->active == 1 );
nkeynes@363
    60
    assert( block3->size == 4096 );
nkeynes@363
    61
    memset( block3->code, 0x9C, 4096 );
nkeynes@515
    62
    xlat_cache_block_t block3a = xlat_extend_block(8192);
nkeynes@363
    63
    assert( block3a != block3 );
nkeynes@363
    64
    assert( block3a == block );
nkeynes@363
    65
    assert( block3a->active == 1 );
nkeynes@363
    66
    assert( block3a->size = 8192 );
nkeynes@363
    67
    assert( block3->active == 0 );
nkeynes@363
    68
    assert( block3->size == 4096 );
nkeynes@363
    69
    for( i=0; i<4096; i++ ) {
nkeynes@363
    70
	assert( block3a->code[i] == 0x9C );
nkeynes@363
    71
    }
nkeynes@363
    72
    for( i=4096; i<8192; i++ ) {
nkeynes@363
    73
	assert( block3a->code[i] == 0xB5 );
nkeynes@363
    74
    }
nkeynes@515
    75
    xlat_commit_block(6142, 432);
nkeynes@363
    76
    addr = xlat_get_code( 0x0D009800 );
nkeynes@363
    77
    assert( addr == &block3a->code );
nkeynes@363
    78
    /* check promoted block in temp cache */
nkeynes@363
    79
    addr = xlat_get_code( 0x0C008000 );
nkeynes@363
    80
    assert( addr == &xlat_temp_cache->code );
nkeynes@363
    81
    assert( xlat_temp_cache->active == 1 );
nkeynes@363
    82
    assert( xlat_temp_cache->size == 8192 );
nkeynes@363
    83
    for( i=0; i<8192; i++ ) {
nkeynes@363
    84
	assert( xlat_temp_cache->code[i] == 0xB5 );
nkeynes@363
    85
    }
nkeynes@363
    86
}
nkeynes@363
    87
nkeynes@363
    88
int main()
nkeynes@363
    89
{
nkeynes@363
    90
    xlat_cache_init();
nkeynes@363
    91
    xlat_check_integrity();
nkeynes@363
    92
    
nkeynes@363
    93
    test_initial();
nkeynes@363
    94
    return 0;
nkeynes@363
    95
}
.