Search
lxdream.org :: lxdream/src/test/testsh4xir.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testsh4xir.c
changeset 1006:3a169c224c12
next1011:fdd58619b760
author nkeynes
date Tue Apr 07 10:55:03 2009 +0000 (14 years ago)
branchxlat-refactor
permissions -rw-r--r--
last change Commit current work-in-progress to xlat-refactor branch
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/testsh4xir.c Tue Apr 07 10:55:03 2009 +0000
1.3 @@ -0,0 +1,150 @@
1.4 +/**
1.5 + * $Id: testsh4x86.c 988 2009-01-15 11:23:20Z nkeynes $
1.6 + *
1.7 + * Test cases for the SH4 => XIR decoder. Takes as
1.8 + * input a binary SH4 object (and VMA), generates the
1.9 + * corresponding IR, and dumps it to stdout.
1.10 + *
1.11 + * Copyright (c) 2009 Nathan Keynes.
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify
1.14 + * it under the terms of the GNU General Public License as published by
1.15 + * the Free Software Foundation; either version 2 of the License, or
1.16 + * (at your option) any later version.
1.17 + *
1.18 + * This program is distributed in the hope that it will be useful,
1.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.21 + * GNU General Public License for more details.
1.22 + */
1.23 +#include <getopt.h>
1.24 +#include <stdlib.h>
1.25 +#include <sys/stat.h>
1.26 +#include <string.h>
1.27 +
1.28 +#include "lxdream.h"
1.29 +#include "sh4/sh4core.h"
1.30 +#include "sh4/sh4mmio.h"
1.31 +#include "sh4/sh4xir.h"
1.32 +
1.33 +
1.34 +struct mmio_region mmio_region_MMU;
1.35 +struct mmio_region mmio_region_PMM;
1.36 +struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
1.37 +struct sh4_registers sh4r;
1.38 +int sh4_breakpoint_count = 0;
1.39 +uint32_t sh4_cpu_period = 5;
1.40 +struct sh4_icache_struct sh4_icache;
1.41 +
1.42 +void MMU_ldtlb() { }
1.43 +void FASTCALL sh4_sleep() { }
1.44 +void FASTCALL sh4_write_fpscr( uint32_t val ) { }
1.45 +void sh4_switch_fr_banks() { }
1.46 +void FASTCALL sh4_write_sr( uint32_t val ) { }
1.47 +uint32_t FASTCALL sh4_read_sr( void ) { return 0; }
1.48 +void FASTCALL sh4_raise_trap( int exc ) { }
1.49 +void FASTCALL sh4_raise_exception( int exc ) { }
1.50 +void log_message( void *ptr, int level, const gchar *source, const char *msg, ... ) { }
1.51 +gboolean sh4_execute_instruction( ) { return TRUE; }
1.52 +void **sh4_address_space;
1.53 +void **sh4_user_address_space;
1.54 +unsigned char *xlat_output;
1.55 +
1.56 +#define MAX_INS_SIZE 32
1.57 +#define MAX_XIR_OPS 16384
1.58 +
1.59 +char *option_list = "s:o:d:h";
1.60 +struct option longopts[1] = { { NULL, 0, 0, 0 } };
1.61 +
1.62 +struct xir_symbol_entry debug_symbols[] = {
1.63 + { "sh4_cpu_period", &sh4_cpu_period },
1.64 + { "sh4_write_fpscr", sh4_write_fpscr },
1.65 + { "sh4_write_sr", sh4_write_sr },
1.66 + { "sh4_read_sr", sh4_read_sr },
1.67 + { "sh4_sleep", sh4_sleep },
1.68 + { "sh4_switch_fr_banks", sh4_switch_fr_banks },
1.69 + { "sh4_raise_exception", sh4_raise_exception },
1.70 + { "sh4_raise_trap", sh4_raise_trap },
1.71 + { "sh4_execute_instruction", sh4_execute_instruction },
1.72 +};
1.73 +
1.74 +extern struct xlat_source_machine sh4_source_machine;
1.75 +extern struct xlat_target_machine x86_target_machine;
1.76 +void usage()
1.77 +{
1.78 + fprintf( stderr, "Usage: testsh4xir [options] <input bin file>\n");
1.79 + fprintf( stderr, "Options:\n");
1.80 + fprintf( stderr, " -d <filename> Diff results against contents of file\n" );
1.81 + fprintf( stderr, " -h Display this help message\n" );
1.82 + fprintf( stderr, " -o <filename> Output disassembly to file [stdout]\n" );
1.83 + fprintf( stderr, " -s <addr> Specify start address of binary [8C010000]\n" );
1.84 +}
1.85 +
1.86 +int main( int argc, char *argv[] )
1.87 +{
1.88 + char *input_file;
1.89 + char *output_file;
1.90 + char *diff_file;
1.91 + char *inbuf;
1.92 + uint32_t start_addr = 0x8c010000;
1.93 + struct stat st;
1.94 + int opt;
1.95 + struct xir_op xir[MAX_XIR_OPS];
1.96 + xir_op_t xir_ptr = &xir[0];
1.97 +
1.98 + while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
1.99 + switch( opt ) {
1.100 + case 'd':
1.101 + diff_file = optarg;
1.102 + break;
1.103 + case 'o':
1.104 + output_file = optarg;
1.105 + break;
1.106 + case 's':
1.107 + start_addr = strtoul(optarg, NULL, 0);
1.108 + break;
1.109 + case 'h':
1.110 + usage();
1.111 + exit(0);
1.112 + }
1.113 + }
1.114 + if( optind < argc ) {
1.115 + input_file = argv[optind++];
1.116 + } else {
1.117 + usage();
1.118 + exit(1);
1.119 + }
1.120 +
1.121 + mmio_region_MMU.mem = malloc(4096);
1.122 + memset( mmio_region_MMU.mem, 0, 4096 );
1.123 +
1.124 + ((uint32_t *)mmio_region_MMU.mem)[4] = 1;
1.125 +
1.126 + FILE *in = fopen( input_file, "ro" );
1.127 + if( in == NULL ) {
1.128 + perror( "Unable to open input file" );
1.129 + exit(2);
1.130 + }
1.131 + fstat( fileno(in), &st );
1.132 + inbuf = malloc( st.st_size );
1.133 + fread( inbuf, st.st_size, 1, in );
1.134 + sh4_icache.mask = 0xFFFFF000;
1.135 + sh4_icache.page_vma = start_addr & 0xFFFFF000;
1.136 + sh4_icache.page = (unsigned char *)(inbuf - (start_addr&0xFFF));
1.137 + sh4_icache.page_ppa = start_addr & 0xFFFFF000;
1.138 +
1.139 + struct xir_basic_block xbb;
1.140 + xbb.source = &sh4_source_machine;
1.141 + xbb.ir_alloc_begin = &xir[0];
1.142 + xbb.ir_alloc_end = &xir[MAX_XIR_OPS];
1.143 + xbb.ir_begin = xbb.ir_ptr = xbb.ir_end = xbb.ir_alloc_begin;
1.144 + xbb.pc_begin = start_addr;
1.145 + xbb.pc_end = start_addr+4096;
1.146 + xbb.source->decode_basic_block( &xbb );
1.147 +
1.148 + x86_target_machine.lower( &xbb, xbb.ir_begin, xbb.ir_end );
1.149 + xir_set_register_names( sh4_source_machine.reg_names, x86_target_machine.reg_names );
1.150 + xir_set_symbol_table( debug_symbols );
1.151 + xir_dump_block( &xir[0], NULL );
1.152 + return 0;
1.153 +}
.