Search
lxdream.org :: lxdream/src/mem.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/mem.c
changeset 929:fd8cb0c82f5f
prev825:2ac7ceccd775
next930:07e5b11419db
author nkeynes
date Sat Dec 20 03:01:40 2008 +0000 (12 years ago)
branchlxdream-mem
permissions -rw-r--r--
last change First pass experiment using cached decoding.
file annotate diff log raw
nkeynes@10
     1
/**
nkeynes@586
     2
 * $Id$
nkeynes@10
     3
 * mem.c is responsible for creating and maintaining the overall system memory
nkeynes@10
     4
 * map, as visible from the SH4 processor. 
nkeynes@10
     5
 *
nkeynes@10
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@10
     7
 *
nkeynes@10
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@10
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@10
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@10
    11
 * (at your option) any later version.
nkeynes@10
    12
 *
nkeynes@10
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@10
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@10
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@10
    16
 * GNU General Public License for more details.
nkeynes@10
    17
 */
nkeynes@35
    18
#define MODULE mem_module
nkeynes@10
    19
nkeynes@488
    20
#include <sys/types.h>
nkeynes@10
    21
#include <sys/mman.h>
nkeynes@19
    22
#include <sys/stat.h>
nkeynes@586
    23
#include <glib/gstrfuncs.h>
nkeynes@10
    24
#include <assert.h>
nkeynes@10
    25
#include <stdint.h>
nkeynes@10
    26
#include <stdlib.h>
nkeynes@10
    27
#include <stdio.h>
nkeynes@10
    28
#include <unistd.h>
nkeynes@10
    29
#include <fcntl.h>
nkeynes@10
    30
#include <errno.h>
nkeynes@10
    31
#include <string.h>
nkeynes@10
    32
#include <zlib.h>
nkeynes@10
    33
#include "dream.h"
nkeynes@10
    34
#include "mem.h"
nkeynes@10
    35
#include "mmio.h"
nkeynes@10
    36
#include "dreamcast.h"
nkeynes@10
    37
nkeynes@502
    38
sh4ptr_t *page_map = NULL;
nkeynes@10
    39
nkeynes@17
    40
int mem_load(FILE *f);
nkeynes@17
    41
void mem_save(FILE *f);
nkeynes@15
    42
struct dreamcast_module mem_module =
nkeynes@736
    43
{ "MEM", mem_init, mem_reset, NULL, NULL, NULL, mem_save, mem_load };
nkeynes@15
    44
nkeynes@10
    45
struct mem_region mem_rgn[MAX_MEM_REGIONS];
nkeynes@10
    46
struct mmio_region *io_rgn[MAX_IO_REGIONS];
nkeynes@10
    47
struct mmio_region *P4_io[4096];
nkeynes@10
    48
nkeynes@674
    49
uint32_t num_io_rgns = 0, num_mem_rgns = 0;
nkeynes@10
    50
nkeynes@10
    51
void *mem_alloc_pages( int n )
nkeynes@10
    52
{
nkeynes@10
    53
    void *mem = mmap( NULL, n * 4096,
nkeynes@736
    54
            PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0 );
nkeynes@10
    55
    if( mem == MAP_FAILED ) {
nkeynes@10
    56
        ERROR( "Memory allocation failure! (%s)", strerror(errno) );
nkeynes@10
    57
        return NULL;
nkeynes@10
    58
    }
nkeynes@10
    59
    return mem;
nkeynes@10
    60
}
nkeynes@10
    61
nkeynes@10
    62
nkeynes@10
    63
void mem_init( void )
nkeynes@10
    64
{
nkeynes@796
    65
    page_map = mmap( NULL, sizeof(sh4ptr_t) * LXDREAM_PAGE_TABLE_ENTRIES,
nkeynes@736
    66
            PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0 );
nkeynes@10
    67
    if( page_map == MAP_FAILED ) {
nkeynes@10
    68
        ERROR( "Unable to allocate page map! (%s)", strerror(errno) );
nkeynes@10
    69
        page_map = NULL;
nkeynes@10
    70
        return;
nkeynes@10
    71
    }
nkeynes@10
    72
nkeynes@796
    73
    memset( page_map, 0, sizeof(sh4ptr_t) * LXDREAM_PAGE_TABLE_ENTRIES );
nkeynes@10
    74
}
nkeynes@10
    75
nkeynes@10
    76
void mem_reset( void )
nkeynes@10
    77
{
nkeynes@10
    78
    /* Restore all mmio registers to their initial settings */
nkeynes@10
    79
    int i, j;
nkeynes@10
    80
    for( i=1; i<num_io_rgns; i++ ) {
nkeynes@10
    81
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@10
    82
            if( io_rgn[i]->ports[j].def_val != UNDEFINED &&
nkeynes@736
    83
                    io_rgn[i]->ports[j].def_val != *io_rgn[i]->ports[j].val ) {
nkeynes@929
    84
                io_rgn[i]->fn.write_long( io_rgn[i]->ports[j].offset,
nkeynes@736
    85
                        io_rgn[i]->ports[j].def_val );
nkeynes@10
    86
            }
nkeynes@10
    87
        }
nkeynes@10
    88
    }
nkeynes@10
    89
}
nkeynes@10
    90
nkeynes@17
    91
void mem_save( FILE *f ) 
nkeynes@17
    92
{
nkeynes@17
    93
    int i;
nkeynes@17
    94
    uint32_t len;
nkeynes@736
    95
nkeynes@17
    96
    /* All memory regions */
nkeynes@17
    97
    fwrite( &num_mem_rgns, sizeof(num_mem_rgns), 1, f );
nkeynes@17
    98
    for( i=0; i<num_mem_rgns; i++ ) {
nkeynes@736
    99
        fwrite_string( mem_rgn[i].name, f );
nkeynes@736
   100
        fwrite( &mem_rgn[i].base, sizeof(uint32_t), 1, f );
nkeynes@736
   101
        fwrite( &mem_rgn[i].flags, sizeof(uint32_t), 1, f );
nkeynes@736
   102
        fwrite( &mem_rgn[i].size, sizeof(uint32_t), 1, f );
nkeynes@736
   103
        if( mem_rgn[i].flags != MEM_FLAG_ROM )
nkeynes@736
   104
            fwrite_gzip( mem_rgn[i].mem, mem_rgn[i].size, 1, f );
nkeynes@17
   105
    }
nkeynes@17
   106
nkeynes@17
   107
    /* All MMIO regions */
nkeynes@17
   108
    fwrite( &num_io_rgns, sizeof(num_io_rgns), 1, f );
nkeynes@17
   109
    for( i=0; i<num_io_rgns; i++ ) {
nkeynes@736
   110
        fwrite_string( io_rgn[i]->id, f );
nkeynes@736
   111
        fwrite( &io_rgn[i]->base, sizeof( uint32_t ), 1, f );
nkeynes@736
   112
        len = 4096;
nkeynes@736
   113
        fwrite( &len, sizeof(len), 1, f );
nkeynes@736
   114
        fwrite_gzip( io_rgn[i]->mem, len, 1, f );
nkeynes@17
   115
    }
nkeynes@17
   116
}
nkeynes@17
   117
nkeynes@17
   118
int mem_load( FILE *f )
nkeynes@17
   119
{
nkeynes@17
   120
    char tmp[64];
nkeynes@17
   121
    uint32_t len;
nkeynes@18
   122
    uint32_t base, size;
nkeynes@510
   123
    uint32_t flags;
nkeynes@17
   124
    int i;
nkeynes@17
   125
nkeynes@17
   126
    /* All memory regions */
nkeynes@18
   127
    fread( &len, sizeof(len), 1, f );
nkeynes@18
   128
    if( len != num_mem_rgns )
nkeynes@736
   129
        return -1;
nkeynes@18
   130
    for( i=0; i<len; i++ ) {
nkeynes@736
   131
        fread_string( tmp, sizeof(tmp), f );
nkeynes@736
   132
        fread( &base, sizeof(base), 1, f );
nkeynes@736
   133
        fread( &flags, sizeof(flags), 1, f );
nkeynes@736
   134
        fread( &size, sizeof(size), 1, f );
nkeynes@736
   135
        if( strcmp( mem_rgn[i].name, tmp ) != 0 ||
nkeynes@736
   136
                base != mem_rgn[i].base ||
nkeynes@736
   137
                flags != mem_rgn[i].flags ||
nkeynes@736
   138
                size != mem_rgn[i].size ) {
nkeynes@736
   139
            ERROR( "Bad memory region %d %s", i, tmp );
nkeynes@736
   140
            return -1;
nkeynes@736
   141
        }
nkeynes@736
   142
        if( flags != MEM_FLAG_ROM )
nkeynes@736
   143
            fread_gzip( mem_rgn[i].mem, size, 1, f );
nkeynes@18
   144
    }
nkeynes@18
   145
nkeynes@18
   146
    /* All MMIO regions */
nkeynes@18
   147
    fread( &len, sizeof(len), 1, f );
nkeynes@18
   148
    if( len != num_io_rgns ) 
nkeynes@736
   149
        return -1;
nkeynes@18
   150
    for( i=0; i<len; i++ ) {
nkeynes@736
   151
        fread_string( tmp, sizeof(tmp), f );
nkeynes@736
   152
        fread( &base, sizeof(base), 1, f );
nkeynes@736
   153
        fread( &size, sizeof(size), 1, f );
nkeynes@736
   154
        if( strcmp( io_rgn[i]->id, tmp ) != 0 ||
nkeynes@736
   155
                base != io_rgn[i]->base ||
nkeynes@736
   156
                size != 4096 ) {
nkeynes@736
   157
            ERROR( "Bad MMIO region %d %s", i, tmp );
nkeynes@736
   158
            return -1;
nkeynes@736
   159
        }
nkeynes@736
   160
        fread_gzip( io_rgn[i]->mem, size, 1, f );
nkeynes@18
   161
    }
nkeynes@18
   162
    return 0;
nkeynes@17
   163
}
nkeynes@17
   164
nkeynes@50
   165
int mem_save_block( const gchar *file, uint32_t start, uint32_t length )
nkeynes@19
   166
{
nkeynes@502
   167
    sh4ptr_t region;
nkeynes@50
   168
    int len = 4096, total = 0;
nkeynes@50
   169
    uint32_t addr = start;
nkeynes@50
   170
    FILE *f = fopen(file,"w");
nkeynes@19
   171
nkeynes@50
   172
    if( f == NULL )
nkeynes@736
   173
        return errno;
nkeynes@736
   174
nkeynes@50
   175
    while( total < length ) {
nkeynes@736
   176
        region = mem_get_region(addr);
nkeynes@736
   177
        len = 4096 - (addr & 0x0FFF);
nkeynes@736
   178
        if( len > (length-total) ) 
nkeynes@736
   179
            len = (length-total);
nkeynes@736
   180
        if( fwrite( region, len, 1, f ) != 1 ) {
nkeynes@736
   181
            ERROR( "Unexpected error writing blocks: %d (%s)", len, strerror(errno) );
nkeynes@736
   182
            break;
nkeynes@736
   183
        }
nkeynes@736
   184
nkeynes@736
   185
        addr += len;
nkeynes@736
   186
        total += len;
nkeynes@50
   187
    }
nkeynes@50
   188
    fclose( f );
nkeynes@743
   189
    INFO( "Saved %d of %d bytes to %08X", total, length, start );
nkeynes@50
   190
    return 0;
nkeynes@19
   191
}
nkeynes@19
   192
nkeynes@19
   193
int mem_load_block( const gchar *file, uint32_t start, uint32_t length )
nkeynes@19
   194
{
nkeynes@502
   195
    sh4ptr_t region;
nkeynes@19
   196
    int len = 4096, total = 0;
nkeynes@19
   197
    uint32_t addr = start;
nkeynes@19
   198
    struct stat st;
nkeynes@19
   199
    FILE *f = fopen(file,"r");
nkeynes@19
   200
nkeynes@180
   201
    if( f == NULL ) {
nkeynes@736
   202
        WARN( "Unable to load file '%s': %s", file, strerror(errno) );
nkeynes@736
   203
        return -1;
nkeynes@180
   204
    }
nkeynes@19
   205
    fstat( fileno(f), &st );
nkeynes@72
   206
    if( length == 0 || length == -1 || length > st.st_size )
nkeynes@736
   207
        length = st.st_size;
nkeynes@736
   208
nkeynes@19
   209
    while( total < length ) {
nkeynes@736
   210
        region = mem_get_region(addr);
nkeynes@736
   211
        len = 4096 - (addr & 0x0FFF);
nkeynes@736
   212
        if( len > (length-total) ) 
nkeynes@736
   213
            len = (length-total);
nkeynes@736
   214
        if( fread( region, len, 1, f ) != 1 ) {
nkeynes@736
   215
            ERROR( "Unexpected error reading: %d (%s)", len, strerror(errno) );
nkeynes@736
   216
            break;
nkeynes@736
   217
        }
nkeynes@736
   218
nkeynes@736
   219
        addr += len;
nkeynes@736
   220
        total += len;
nkeynes@19
   221
    }
nkeynes@19
   222
    fclose( f );
nkeynes@19
   223
    INFO( "Loaded %d of %d bytes to %08X", total, length, start );
nkeynes@19
   224
    return 0;
nkeynes@19
   225
}
nkeynes@19
   226
nkeynes@10
   227
struct mem_region *mem_map_region( void *mem, uint32_t base, uint32_t size,
nkeynes@929
   228
                                   const char *name, mem_region_fn_t fn, int flags, uint32_t repeat_offset,
nkeynes@736
   229
                                   uint32_t repeat_until )
nkeynes@10
   230
{
nkeynes@10
   231
    int i;
nkeynes@10
   232
    mem_rgn[num_mem_rgns].base = base;
nkeynes@10
   233
    mem_rgn[num_mem_rgns].size = size;
nkeynes@10
   234
    mem_rgn[num_mem_rgns].flags = flags;
nkeynes@10
   235
    mem_rgn[num_mem_rgns].name = name;
nkeynes@10
   236
    mem_rgn[num_mem_rgns].mem = mem;
nkeynes@929
   237
    mem_rgn[num_mem_rgns].fn = fn;
nkeynes@10
   238
    num_mem_rgns++;
nkeynes@10
   239
nkeynes@146
   240
    do {
nkeynes@796
   241
        for( i=0; i<size>>LXDREAM_PAGE_BITS; i++ )
nkeynes@796
   242
            page_map[(base>>LXDREAM_PAGE_BITS)+i] = mem + (i<<LXDREAM_PAGE_BITS);
nkeynes@736
   243
        base += repeat_offset;	
nkeynes@146
   244
    } while( base <= repeat_until );
nkeynes@10
   245
nkeynes@10
   246
    return &mem_rgn[num_mem_rgns-1];
nkeynes@10
   247
}
nkeynes@10
   248
nkeynes@929
   249
void *mem_create_ram_region( uint32_t base, uint32_t size, const char *name, mem_region_fn_t fn )
nkeynes@10
   250
{
nkeynes@929
   251
    return mem_create_repeating_ram_region( base, size, name, fn, size, base );
nkeynes@146
   252
}
nkeynes@146
   253
nkeynes@422
   254
void *mem_create_repeating_ram_region( uint32_t base, uint32_t size, const char *name,
nkeynes@929
   255
                                       mem_region_fn_t fn,
nkeynes@736
   256
                                       uint32_t repeat_offset, uint32_t repeat_until )
nkeynes@146
   257
{
nkeynes@10
   258
    char *mem;
nkeynes@736
   259
nkeynes@10
   260
    assert( (base&0xFFFFF000) == base ); /* must be page aligned */
nkeynes@10
   261
    assert( (size&0x00000FFF) == 0 );
nkeynes@10
   262
    assert( num_mem_rgns < MAX_MEM_REGIONS );
nkeynes@10
   263
    assert( page_map != NULL );
nkeynes@10
   264
nkeynes@796
   265
    mem = mem_alloc_pages( size>>LXDREAM_PAGE_BITS );
nkeynes@10
   266
nkeynes@929
   267
    mem_map_region( mem, base, size, name, fn, MEM_FLAG_RAM, repeat_offset, repeat_until );
nkeynes@736
   268
nkeynes@10
   269
    return mem;
nkeynes@10
   270
}
nkeynes@10
   271
nkeynes@543
   272
gboolean mem_load_rom( const gchar *file, uint32_t base, uint32_t size, uint32_t crc,
nkeynes@929
   273
                       const gchar *region_name, mem_region_fn_t fn )
nkeynes@10
   274
{
nkeynes@502
   275
    sh4ptr_t mem;
nkeynes@10
   276
    uint32_t calc_crc;
nkeynes@488
   277
    int status;
nkeynes@461
   278
nkeynes@461
   279
    mem = mem_get_region(base);
nkeynes@461
   280
    if( mem == NULL ) {
nkeynes@736
   281
        mem = mmap( NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_PRIVATE, -1, 0 );
nkeynes@736
   282
        if( mem == MAP_FAILED ) {
nkeynes@736
   283
            ERROR( "Unable to allocate ROM memory: %s (%s)", file, strerror(errno) );
nkeynes@736
   284
            return FALSE;
nkeynes@736
   285
        }
nkeynes@929
   286
        mem_map_region( mem, base, size, region_name, fn, MEM_FLAG_ROM, size, base );
nkeynes@461
   287
    } else {
nkeynes@736
   288
        mprotect( mem, size, PROT_READ|PROT_WRITE );
nkeynes@10
   289
    }
nkeynes@461
   290
nkeynes@825
   291
    if( file != NULL && file[0] != '\0' ) {
nkeynes@825
   292
        status = mem_load_block( file, base, size );
nkeynes@825
   293
        mprotect( mem, size, PROT_READ );
nkeynes@10
   294
nkeynes@825
   295
        if( status == 0 ) {
nkeynes@825
   296
            /* CRC check only if we loaded something */
nkeynes@825
   297
            calc_crc = crc32(0L, (sh4ptr_t)mem, size);
nkeynes@825
   298
            if( calc_crc != crc ) {
nkeynes@825
   299
                WARN( "Bios CRC Mismatch in %s: %08X (expected %08X)",
nkeynes@825
   300
                        file, calc_crc, crc);
nkeynes@825
   301
            }
nkeynes@825
   302
            return TRUE;
nkeynes@736
   303
        }
nkeynes@10
   304
    }
nkeynes@543
   305
    return FALSE;
nkeynes@10
   306
}
nkeynes@10
   307
nkeynes@502
   308
sh4ptr_t mem_get_region_by_name( const char *name )
nkeynes@10
   309
{
nkeynes@10
   310
    int i;
nkeynes@10
   311
    for( i=0; i<num_mem_rgns; i++ ) {
nkeynes@10
   312
        if( strcmp( mem_rgn[i].name, name ) == 0 )
nkeynes@10
   313
            return mem_rgn[i].mem;
nkeynes@10
   314
    }
nkeynes@10
   315
    return NULL;
nkeynes@10
   316
}
nkeynes@10
   317
nkeynes@10
   318
void register_io_region( struct mmio_region *io )
nkeynes@10
   319
{
nkeynes@10
   320
    int i;
nkeynes@736
   321
nkeynes@10
   322
    assert(io);
nkeynes@10
   323
    io->mem = mem_alloc_pages(2);
nkeynes@796
   324
    io->save_mem = io->mem + LXDREAM_PAGE_SIZE;
nkeynes@10
   325
    io->index = (struct mmio_port **)malloc(1024*sizeof(struct mmio_port *));
nkeynes@41
   326
    io->trace_flag = 0;
nkeynes@10
   327
    memset( io->index, 0, 1024*sizeof(struct mmio_port *) );
nkeynes@10
   328
    for( i=0; io->ports[i].id != NULL; i++ ) {
nkeynes@10
   329
        io->ports[i].val = (uint32_t *)(io->mem + io->ports[i].offset);
nkeynes@10
   330
        *io->ports[i].val = io->ports[i].def_val;
nkeynes@10
   331
        io->index[io->ports[i].offset>>2] = &io->ports[i];
nkeynes@10
   332
    }
nkeynes@796
   333
    memcpy( io->save_mem, io->mem, LXDREAM_PAGE_SIZE );
nkeynes@10
   334
    if( (io->base & 0xFF000000) == 0xFF000000 ) {
nkeynes@10
   335
        /* P4 area (on-chip I/O channels */
nkeynes@10
   336
        P4_io[(io->base&0x1FFFFFFF)>>19] = io;
nkeynes@10
   337
    } else {
nkeynes@674
   338
        page_map[io->base>>12] = (sh4ptr_t)(uintptr_t)num_io_rgns;
nkeynes@10
   339
    }
nkeynes@10
   340
    io_rgn[num_io_rgns] = io;
nkeynes@10
   341
    num_io_rgns++;
nkeynes@10
   342
}
nkeynes@10
   343
nkeynes@10
   344
void register_io_regions( struct mmio_region **io )
nkeynes@10
   345
{
nkeynes@10
   346
    while( *io ) register_io_region( *io++ );
nkeynes@10
   347
}
nkeynes@10
   348
nkeynes@10
   349
int mem_has_page( uint32_t addr )
nkeynes@10
   350
{
nkeynes@502
   351
    sh4ptr_t page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   352
    return page != NULL;
nkeynes@10
   353
}
nkeynes@10
   354
nkeynes@502
   355
sh4ptr_t mem_get_page( uint32_t addr )
nkeynes@10
   356
{
nkeynes@502
   357
    sh4ptr_t page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@10
   358
    return page;
nkeynes@10
   359
}
nkeynes@10
   360
nkeynes@502
   361
sh4ptr_t mem_get_region( uint32_t addr )
nkeynes@10
   362
{
nkeynes@502
   363
    sh4ptr_t page = page_map[ (addr & 0x1FFFFFFF) >> 12 ];
nkeynes@490
   364
    if( ((uintptr_t)page) < MAX_IO_REGIONS ) { /* IO Region */
nkeynes@10
   365
        return NULL;
nkeynes@10
   366
    } else {
nkeynes@10
   367
        return page+(addr&0xFFF);
nkeynes@10
   368
    }
nkeynes@10
   369
}
nkeynes@11
   370
nkeynes@669
   371
void mem_write_long( sh4addr_t addr, uint32_t value )
nkeynes@669
   372
{
nkeynes@669
   373
    sh4ptr_t ptr = mem_get_region(addr);
nkeynes@669
   374
    assert(ptr != NULL);
nkeynes@669
   375
    *((uint32_t *)ptr) = value;
nkeynes@669
   376
}
nkeynes@669
   377
nkeynes@156
   378
struct mmio_region *mem_get_io_region( uint32_t addr )
nkeynes@156
   379
{
nkeynes@156
   380
    if( addr > 0xFF000000 ) {
nkeynes@736
   381
        return P4_io[(addr&0x00FFFFFF)>>12];
nkeynes@156
   382
    }
nkeynes@502
   383
    sh4ptr_t page = page_map[(addr&0x1FFFFFFF)>>12];
nkeynes@490
   384
    if( ((uintptr_t)page) < MAX_IO_REGIONS ) {
nkeynes@736
   385
        return io_rgn[(uintptr_t)page];
nkeynes@156
   386
    } else {
nkeynes@736
   387
        return NULL;
nkeynes@156
   388
    }
nkeynes@156
   389
}
nkeynes@156
   390
nkeynes@586
   391
struct mmio_region *mem_get_io_region_by_name( const gchar *name )
nkeynes@156
   392
{
nkeynes@586
   393
    int i;
nkeynes@586
   394
    for( i=0; i<num_io_rgns; i++ ) {
nkeynes@736
   395
        if( strcasecmp(io_rgn[i]->id, name) == 0 ) {
nkeynes@736
   396
            return io_rgn[i];
nkeynes@736
   397
        }
nkeynes@586
   398
    }
nkeynes@586
   399
    return NULL;
nkeynes@156
   400
}
nkeynes@156
   401
nkeynes@586
   402
void mem_set_trace( const gchar *tracelist, gboolean flag )
nkeynes@586
   403
{
nkeynes@586
   404
    if( tracelist != NULL ) {
nkeynes@736
   405
        gchar ** tracev = g_strsplit_set( tracelist, ",:; \t\r\n", 0 );
nkeynes@736
   406
        int i;
nkeynes@736
   407
        for( i=0; tracev[i] != NULL; i++ ) {
nkeynes@736
   408
            // Special case "all" - trace everything
nkeynes@736
   409
            if( strcasecmp(tracev[i], "all") == 0 ) {
nkeynes@736
   410
                int j;
nkeynes@736
   411
                for( j=0; j<num_io_rgns; j++ ) {
nkeynes@736
   412
                    io_rgn[j]->trace_flag = flag ? 1 : 0;
nkeynes@736
   413
                }
nkeynes@736
   414
                break;
nkeynes@736
   415
            }
nkeynes@736
   416
            struct mmio_region *region = mem_get_io_region_by_name( tracev[i] );
nkeynes@736
   417
            if( region == NULL ) {
nkeynes@736
   418
                WARN( "Unknown IO region '%s'", tracev[i] );
nkeynes@736
   419
            } else {
nkeynes@736
   420
                region->trace_flag = flag ? 1 : 0;
nkeynes@736
   421
            }
nkeynes@736
   422
        }
nkeynes@736
   423
        g_strfreev( tracev );
nkeynes@586
   424
    }
nkeynes@586
   425
}
nkeynes@586
   426
.