Search
lxdream.org :: lxdream/src/test/testsh4x86.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testsh4x86.c
changeset 963:1c3a0f67c603
prev953:f4a156508ad1
next968:6fb1481859a4
author nkeynes
date Thu Jan 15 04:15:11 2009 +0000 (15 years ago)
permissions -rw-r--r--
last change Add support for the Intel ICC compiler (C only, icc doesn't support Obj-C)
- Rename Obj-C source to .m
- Separate paths.c into paths_unix.c and paths_osx.m
- Add configuration detection of ICC, along with specific opt flags
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Test cases for the SH4 => x86 translator core. Takes as
     5  * input a binary SH4 object (and VMA), generates the
     6  * corresponding x86 code, and outputs the disassembly.
     7  *
     8  * Copyright (c) 2005 Nathan Keynes.
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; either version 2 of the License, or
    13  * (at your option) any later version.
    14  *
    15  * This program is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  */
    21 #include <stdio.h>
    22 #include <stdarg.h>
    23 #include <getopt.h>
    24 #include <sys/stat.h>
    25 #include "x86dasm/x86dasm.h"
    26 #include "sh4/sh4trans.h"
    27 #include "sh4/sh4core.h"
    28 #include "sh4/sh4mmio.h"
    29 #include "sh4/mmu.h"
    31 struct dreamcast_module sh4_module;
    32 struct mmio_region mmio_region_MMU;
    33 struct mmio_region mmio_region_PMM;
    34 struct breakpoint_struct sh4_breakpoints[MAX_BREAKPOINTS];
    35 int sh4_breakpoint_count = 0;
    37 #define MAX_INS_SIZE 32
    40 struct mem_region_fn **sh4_address_space = (void *)0x12345432;
    41 struct mem_region_fn **sh4_user_address_space = (void *)0x12345678;
    42 char *option_list = "s:o:d:h";
    43 struct option longopts[1] = { { NULL, 0, 0, 0 } };
    45 char *input_file = NULL;
    46 char *diff_file = NULL;
    47 char *output_file = NULL;
    48 gboolean sh4_starting;
    49 uint32_t start_addr = 0x8C010000;
    50 uint32_t sh4_cpu_period = 5;
    51 unsigned char dc_main_ram[4096];
    52 unsigned char dc_boot_rom[4096];
    53 FILE *in;
    55 char *inbuf;
    57 struct x86_symbol local_symbols[] = {
    58     { "sh4r+128", ((char *)&sh4r)+128 },
    59     { "sh4_cpu_period", &sh4_cpu_period },
    60     { "sh4_address_space", (void *)0x12345432 },
    61     { "sh4_user_address_space", (void *)0x12345678 },
    62     { "sh4_write_fpscr", sh4_write_fpscr },
    63     { "sh4_write_sr", sh4_write_sr },
    64     { "sh4_read_sr", sh4_read_sr },
    65     { "sh4_sleep", sh4_sleep },
    66     { "sh4_fsca", sh4_fsca },
    67     { "sh4_ftrv", sh4_ftrv },
    68     { "sh4_switch_fr_banks", sh4_switch_fr_banks },
    69     { "sh4_execute_instruction", sh4_execute_instruction },
    70     { "signsat48", signsat48 },
    71     { "xlat_get_code_by_vma", xlat_get_code_by_vma },
    72     { "xlat_get_code", xlat_get_code }
    73 };
    75 // Stubs
    76 gboolean sh4_execute_instruction( ) { return TRUE; }
    77 void sh4_accept_interrupt() {}
    78 void sh4_set_breakpoint( uint32_t pc, breakpoint_type_t type ) { }
    79 gboolean sh4_clear_breakpoint( uint32_t pc, breakpoint_type_t type ) { return TRUE; }
    80 gboolean dreamcast_is_running() { return FALSE; }
    81 int sh4_get_breakpoint( uint32_t pc ) { return 0; }
    82 void sh4_finalize_instruction() { }
    83 void sh4_core_exit( int exit_code ){}
    84 void event_execute() {}
    85 void TMU_run_slice( uint32_t nanos ) {}
    86 void CCN_set_cache_control( uint32_t val ) { }
    87 void PMM_write_control( int ctr, uint32_t val ) { }
    88 void SCIF_run_slice( uint32_t nanos ) {}
    89 void FASTCALL sh4_write_fpscr( uint32_t val ) { }
    90 void FASTCALL sh4_write_sr( uint32_t val ) { }
    91 uint32_t FASTCALL sh4_read_sr( void ) { return 0; }
    92 void FASTCALL sh4_sleep() { }
    93 void FASTCALL sh4_fsca( uint32_t angle, float *fr ) { }
    94 void FASTCALL sh4_ftrv( float *fv ) { }
    95 void FASTCALL signsat48(void) { }
    96 void sh4_switch_fr_banks() { }
    97 void mem_copy_to_sh4( sh4addr_t addr, sh4ptr_t src, size_t size ) { }
    98 gboolean sh4_has_page( sh4vma_t vma ) { return TRUE; }
    99 void syscall_invoke( uint32_t val ) { }
   100 void dreamcast_stop() {} 
   101 void dreamcast_reset() {}
   102 void FASTCALL sh4_raise_reset( int exc ) { }
   103 void FASTCALL sh4_raise_exception( int exc ) { }
   104 void FASTCALL sh4_raise_tlb_exception( int exc, sh4vma_t vma ) { }
   105 void FASTCALL sh4_raise_tlb_multihit( sh4vma_t vma) { }
   106 void FASTCALL sh4_raise_trap( int exc ) { }
   107 void FASTCALL sh4_flush_store_queue( sh4addr_t addr ) { }
   108 void FASTCALL sh4_flush_store_queue_mmu( sh4addr_t addr, void *exc ) { }
   109 uint32_t sh4_sleep_run_slice(uint32_t nanosecs) { return nanosecs; }
   110 gboolean gui_error_dialog( const char *fmt, ... ) { return TRUE; }
   111 gboolean FASTCALL mmu_update_icache( sh4vma_t addr ) { return TRUE; }
   112 void MMU_ldtlb() { }
   113 struct sh4_icache_struct sh4_icache;
   114 struct mem_region_fn mem_region_unmapped;
   116 void usage()
   117 {
   118     fprintf( stderr, "Usage: testsh4x86 [options] <input bin file>\n");
   119     fprintf( stderr, "Options:\n");
   120     fprintf( stderr, "  -d <filename>  Diff results against contents of file\n" );
   121     fprintf( stderr, "  -h             Display this help message\n" );
   122     fprintf( stderr, "  -o <filename>  Output disassembly to file [stdout]\n" );
   123     fprintf( stderr, "  -s <addr>      Specify start address of binary [8C010000]\n" );
   124 }
   126 void emit( void *ptr, int level, const gchar *source, const char *msg, ... )
   127 {
   128     va_list ap;
   129     va_start( ap, msg );
   130     vfprintf( stderr, msg, ap );
   131     fprintf( stderr, "\n" );
   132     va_end(ap);
   133 }
   136 struct sh4_registers sh4r;
   139 int main( int argc, char *argv[] )
   140 {
   141     struct stat st;
   142     int opt;
   143     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
   144 	switch( opt ) {
   145 	case 'd':
   146 	    diff_file = optarg;
   147 	    break;
   148 	case 'o':
   149 	    output_file = optarg;
   150 	    break;
   151 	case 's':
   152 	    start_addr = strtoul(optarg, NULL, 0);
   153 	    break;
   154 	case 'h':
   155 	    usage();
   156 	    exit(0);
   157 	}
   158     }
   159     if( optind < argc ) {
   160 	input_file = argv[optind++];
   161     } else {
   162 	usage();
   163 	exit(1);
   164     }
   166     mmio_region_MMU.mem = malloc(4096);
   167     memset( mmio_region_MMU.mem, 0, 4096 );
   169     ((uint32_t *)mmio_region_MMU.mem)[4] = 1;
   171     in = fopen( input_file, "ro" );
   172     if( in == NULL ) {
   173 	perror( "Unable to open input file" );
   174 	exit(2);
   175     }
   176     fstat( fileno(in), &st );
   177     inbuf = malloc( st.st_size );
   178     fread( inbuf, st.st_size, 1, in );
   179     sh4_icache.mask = 0xFFFFF000;
   180     sh4_icache.page_vma = start_addr & 0xFFFFF000;
   181     sh4_icache.page = (unsigned char *)(inbuf - (sh4_icache.page_vma&0xFFF));
   182     sh4_icache.page_ppa = start_addr & 0xFFFFF000;
   184     xlat_cache_init();
   185     uintptr_t pc;
   186     uint8_t *buf = sh4_translate_basic_block( start_addr );
   187     uint32_t buflen = xlat_get_code_size(buf);
   188     x86_disasm_init( (uintptr_t)buf, (uintptr_t)buf, buflen );
   189     x86_set_symtab( local_symbols, sizeof(local_symbols)/sizeof(struct x86_symbol) );
   190     for( pc = buf; pc < buf + buflen;  ) {
   191 	char buf[256];
   192 	char op[256];
   193 	uintptr_t pc2 = x86_disasm_instruction( pc, buf, sizeof(buf), op );
   194 	fprintf( stdout, "%08x: %s\n", pc, buf );
   195 	pc = pc2;
   196     }
   197     return 0;
   198 }
.