Search
lxdream.org :: lxdream :: r9:2784c7660165
lxdream 0.9.1
released Jun 29
Download Now
changeset9:2784c7660165
parent8:6730608cdaf0
child10:c898b37506e0
authornkeynes
dateThu Dec 08 13:38:00 2005 +0000 (13 years ago)
Generalise the core debug window to allow multiple instances.
Add cpu description structure to define different cpus for use by the
debug window, in preparation for ARM implementation
src/Makefile.am
src/cpu.h
src/dream.h
src/gui/callbacks.c
src/gui/debug_win.c
src/gui/gui.c
src/gui/gui.h
src/loader.c
src/main.c
src/sh4/sh4core.c
src/sh4/sh4dasm.c
src/sh4/sh4dasm.h
1.1 --- a/src/Makefile.am Sun Dec 12 07:44:49 2004 +0000
1.2 +++ b/src/Makefile.am Thu Dec 08 13:38:00 2005 +0000
1.3 @@ -21,6 +21,7 @@
1.4 sh4/sh4core.c sh4/sh4core.h sh4/sh4dasm.c sh4/sh4dasm.h \
1.5 sh4/sh4mmio.c sh4/sh4mmio.h sh4/watch.c \
1.6 fileio.c ipbin.c
1.7 +## aica/armcore.c aica/armcore.h aica/armdasm.c \
1.8
1.9 dream_LDADD = @PACKAGE_LIBS@ $(INTLLIBS)
1.10
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/cpu.h Thu Dec 08 13:38:00 2005 +0000
2.3 @@ -0,0 +1,50 @@
2.4 +
2.5 +#ifndef dream_disasm_H
2.6 +#define dream_disasm_H 1
2.7 +
2.8 +#include <stdlib.h>
2.9 +
2.10 +#ifdef __cplusplus
2.11 +extern "C" {
2.12 +#endif
2.13 +
2.14 +/**
2.15 + * Disassembly function pointer typedef.
2.16 + *
2.17 + * @param pc Address to disassemble
2.18 + * @param buffer String buffer to write disassembly into
2.19 + * @param buflen Maximum length of buffer
2.20 + * @return next address to disassemble
2.21 + */
2.22 +typedef int (*disasm_func_t)(uint32_t pc, char *buffer, int buflen );
2.23 +
2.24 +#define REG_INT 0
2.25 +#define REG_FLT 1
2.26 +#define REG_SPECIAL 2
2.27 +
2.28 +/**
2.29 + * Structure that defines a single register in a CPU for display purposes.
2.30 + */
2.31 +typedef struct reg_desc_struct {
2.32 + char *name;
2.33 + int type;
2.34 + void *value;
2.35 +} reg_desc_t;
2.36 +
2.37 +typedef struct cpu_desc_struct {
2.38 + char *name; /* CPU Name */
2.39 + disasm_func_t disasm_func; /* Disassembly function */
2.40 + size_t instr_size; /* Size of instruction */
2.41 + char *regs; /* Pointer to start of registers */
2.42 + size_t regs_size; /* Size of register structure in bytes */
2.43 + struct reg_desc_struct *regs_info; /* Description of all registers */
2.44 + uint32_t *pc; /* Pointer to PC register */
2.45 + uint32_t *icount; /* Pointer to instruction counter */
2.46 + /* Memory map? */
2.47 +} *cpu_desc_t;
2.48 +
2.49 +#ifdef __cplusplus
2.50 +}
2.51 +#endif
2.52 +
2.53 +#endif /* !dream_disasm_H */
3.1 --- a/src/dream.h Sun Dec 12 07:44:49 2004 +0000
3.2 +++ b/src/dream.h Thu Dec 08 13:38:00 2005 +0000
3.3 @@ -4,7 +4,9 @@
3.4 #ifndef dream_H
3.5 #define dream_H 1
3.6
3.7 +#include <stdlib.h>
3.8 #include <stdint.h>
3.9 +#include <string.h>
3.10
3.11 #ifdef __cplusplus
3.12 extern "C" {
3.13 @@ -24,14 +26,14 @@
3.14 #define MODULE_ID 0
3.15 #endif
3.16
3.17 -void emit( int level, int source, char *msg, ... );
3.18 +void emit( void *, int level, int source, char *msg, ... );
3.19
3.20 -#define FATAL( ... ) emit( EMIT_FATAL, MODULE_ID, __VA_ARGS__ )
3.21 -#define ERROR( ... ) emit( EMIT_ERR, MODULE_ID, __VA_ARGS__ )
3.22 -#define WARN( ... ) emit( EMIT_WARN, MODULE_ID, __VA_ARGS__ )
3.23 -#define INFO( ... ) emit( EMIT_INFO, MODULE_ID, __VA_ARGS__ )
3.24 -#define DEBUG( ... ) emit( EMIT_DEBUG, MODULE_ID, __VA_ARGS__ )
3.25 -#define TRACE( ... ) emit( EMIT_TRACE, MODULE_ID, __VA_ARGS__ )
3.26 +#define FATAL( ... ) emit( NULL, EMIT_FATAL, MODULE_ID, __VA_ARGS__ )
3.27 +#define ERROR( ... ) emit( NULL, EMIT_ERR, MODULE_ID, __VA_ARGS__ )
3.28 +#define WARN( ... ) emit( NULL, EMIT_WARN, MODULE_ID, __VA_ARGS__ )
3.29 +#define INFO( ... ) emit( NULL, EMIT_INFO, MODULE_ID, __VA_ARGS__ )
3.30 +#define DEBUG( ... ) emit( NULL, EMIT_DEBUG, MODULE_ID, __VA_ARGS__ )
3.31 +#define TRACE( ... ) emit( NULL, EMIT_TRACE, MODULE_ID, __VA_ARGS__ )
3.32
3.33 #define BIOS_PATH "../bios"
3.34
4.1 --- a/src/gui/callbacks.c Sun Dec 12 07:44:49 2004 +0000
4.2 +++ b/src/gui/callbacks.c Thu Dec 08 13:38:00 2005 +0000
4.3 @@ -10,7 +10,6 @@
4.4 #include "sh4core.h"
4.5 #include "asic.h"
4.6
4.7 -extern int disasm_from;
4.8 int selected_pc = -1;
4.9
4.10 void
4.11 @@ -107,14 +106,14 @@
4.12 }
4.13
4.14
4.15 -void run( uint32_t target ) {
4.16 +void run( debug_info_t data, uint32_t target ) {
4.17 if( ! sh4_isrunning() ) {
4.18 do {
4.19 if( target == -1 )
4.20 sh4_runfor(1000000);
4.21 else
4.22 sh4_runto(target, 1000000);
4.23 - update_icount();
4.24 + update_icount(data);
4.25 run_timers(1000000);
4.26 while( gtk_events_pending() )
4.27 gtk_main_iteration();
4.28 @@ -127,7 +126,8 @@
4.29 on_run_btn_clicked (GtkButton *button,
4.30 gpointer user_data)
4.31 {
4.32 - run(-1);
4.33 + debug_info_t data = get_debug_info(GTK_WIDGET(button));
4.34 + run(data,-1);
4.35 }
4.36
4.37
4.38 @@ -135,11 +135,12 @@
4.39 on_runto_btn_clicked (GtkButton *button,
4.40 gpointer user_data)
4.41 {
4.42 + debug_info_t data = get_debug_info(GTK_WIDGET(button));
4.43 if( selected_pc == -1 )
4.44 WARN( "No address selected, so can't run to it", NULL );
4.45 else {
4.46 INFO( "Running until %08X...", selected_pc );
4.47 - run( selected_pc );
4.48 + run( data, selected_pc );
4.49 }
4.50 }
4.51
4.52 @@ -169,7 +170,8 @@
4.53 GdkEvent *event,
4.54 gpointer user_data)
4.55 {
4.56 - selected_pc = disasm_from + (row<<1);
4.57 + debug_info_t data = get_debug_info(GTK_WIDGET(clist));
4.58 + selected_pc = row_to_address(data, row);
4.59 }
4.60
4.61
4.62 @@ -180,7 +182,8 @@
4.63 GdkEvent *event,
4.64 gpointer user_data)
4.65 {
4.66 - int pc = disasm_from + (row<<1);
4.67 + debug_info_t data = get_debug_info(GTK_WIDGET(clist));
4.68 + int pc = row_to_address(data,row);
4.69 if( selected_pc == pc ) selected_pc = -1;
4.70 }
4.71
4.72 @@ -233,15 +236,16 @@
4.73 gpointer user_data)
4.74 {
4.75 if( event->keyval == GDK_Return || event->keyval == GDK_Linefeed ) {
4.76 + debug_info_t data = get_debug_info(widget);
4.77 gchar *text = gtk_entry_get_text( GTK_ENTRY(widget) );
4.78 gchar *endptr;
4.79 unsigned int val = strtoul( text, &endptr, 16 );
4.80 if( text == endptr ) { /* invalid input */
4.81 char buf[10];
4.82 - sprintf( buf, "%08X", disasm_from );
4.83 + sprintf( buf, "%08X", row_to_address(data,0) );
4.84 gtk_entry_set_text( GTK_ENTRY(widget), buf );
4.85 } else {
4.86 - set_disassembly_region(val);
4.87 + set_disassembly_region(data, val);
4.88 }
4.89 }
4.90 return FALSE;
4.91 @@ -260,7 +264,8 @@
4.92 gtk_clist_get_text( clist, row, 1, &val );
4.93 if( val[0] != '\0' ) {
4.94 int addr = strtoul( val, NULL, 16 );
4.95 - jump_to_disassembly( addr, TRUE );
4.96 + debug_info_t data = get_debug_info( GTK_WIDGET(clist) );
4.97 + jump_to_disassembly( data, addr, TRUE );
4.98 }
4.99 }
4.100 }
4.101 @@ -270,7 +275,8 @@
4.102 on_jump_pc_btn_clicked (GtkButton *button,
4.103 gpointer user_data)
4.104 {
4.105 - jump_to_disassembly( sh4r.pc, TRUE );
4.106 + debug_info_t data = get_debug_info( GTK_WIDGET(button) );
4.107 + jump_to_pc( data, TRUE );
4.108 }
4.109
4.110
5.1 --- a/src/gui/debug_win.c Sun Dec 12 07:44:49 2004 +0000
5.2 +++ b/src/gui/debug_win.c Thu Dec 08 13:38:00 2005 +0000
5.3 @@ -5,121 +5,105 @@
5.4 #include <math.h>
5.5 #include "gui.h"
5.6 #include "mem.h"
5.7 -#include "sh4dasm.h"
5.8 -#include "sh4core.h"
5.9 +#include "disasm.h"
5.10
5.11 GdkColor *msg_colors[] = { &clrError, &clrError, &clrWarn, &clrNormal,
5.12 &clrDebug, &clrTrace };
5.13
5.14 -#define REG_INT 0
5.15 -#define REG_FLT 1
5.16 -#define REG_SPECIAL 2
5.17 -
5.18 -struct reg_map_struct {
5.19 - char *name;
5.20 - int type;
5.21 - void *value;
5.22 +struct debug_info_struct {
5.23 + int disasm_from;
5.24 + int disasm_to;
5.25 + int disasm_pc;
5.26 + struct cpu_desc_struct *cpu;
5.27 + GtkCList *msgs_list;
5.28 + GtkCList *regs_list;
5.29 + GtkCList *disasm_list;
5.30 + GtkEntry *page_field;
5.31 + GtkProgressBar *icounter;
5.32 + char icounter_text[16];
5.33 + char saved_regs[0];
5.34 };
5.35
5.36 -struct reg_map_struct sh4_reg_map[] =
5.37 - { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},
5.38 - {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},
5.39 - {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},
5.40 - {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},
5.41 - {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},
5.42 - {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},
5.43 - {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},
5.44 - {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},
5.45 - {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},
5.46 - {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},
5.47 - {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},
5.48 - {"VBR",REG_INT, &sh4r.vbr},
5.49 - {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},
5.50 - {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},
5.51 - {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},
5.52 - {NULL, 0, NULL} };
5.53 -
5.54 -GtkCList *msgs, *regs, *disasm;
5.55 -GtkEntry *page_field;
5.56 -GtkProgressBar *icounter;
5.57 -char icounter_text[16];
5.58 -
5.59 -struct sh4_registers sh4r_s;
5.60 -int disasm_from = -1, disasm_to = -1;
5.61 -int disasm_pc = -1;
5.62 -
5.63 -
5.64 -void init_debug_win(GtkWidget *win)
5.65 +debug_info_t init_debug_win(GtkWidget *win, struct cpu_desc_struct *cpu )
5.66 {
5.67 int i;
5.68 char buf[20];
5.69 char *arr[2];
5.70 GnomeAppBar *appbar;
5.71 +
5.72 + debug_info_t data = g_malloc0( sizeof(struct debug_info_struct) + cpu->regs_size );
5.73 + data->disasm_from = -1;
5.74 + data->disasm_to = -1;
5.75 + data->disasm_pc = -1;
5.76 + data->cpu = cpu;
5.77 +
5.78 + data->regs_list= gtk_object_get_data(GTK_OBJECT(win), "reg_list");
5.79 + arr[1] = buf;
5.80 + for( i=0; data->cpu->regs_info[i].name != NULL; i++ ) {
5.81 + arr[0] = data->cpu->regs_info[i].name;
5.82 + if( data->cpu->regs_info->type == REG_INT )
5.83 + sprintf( buf, "%08X", *((uint32_t *)data->cpu->regs_info->value) );
5.84 + else
5.85 + sprintf( buf, "%f", *((float *)data->cpu->regs_info->value) );
5.86 + gtk_clist_append( data->regs_list, arr );
5.87 + }
5.88 + gtk_widget_modify_font( GTK_WIDGET(data->regs_list), fixed_list_font );
5.89
5.90 - regs = gtk_object_get_data(GTK_OBJECT(win), "reg_list");
5.91 - arr[1] = buf;
5.92 - for( i=0; sh4_reg_map[i].name != NULL; i++ ) {
5.93 - arr[0] = sh4_reg_map[i].name;
5.94 - if( sh4_reg_map[i].type == REG_INT )
5.95 - sprintf( buf, "%08X", *((uint32_t *)sh4_reg_map[i].value) );
5.96 - else
5.97 - sprintf( buf, "%f", *((float *)sh4_reg_map[i].value) );
5.98 - gtk_clist_append( regs, arr );
5.99 - }
5.100 - gtk_widget_modify_font( GTK_WIDGET(regs), fixed_list_font );
5.101 -
5.102 - msgs = gtk_object_get_data(GTK_OBJECT(win), "output_list");
5.103 - disasm = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");
5.104 - gtk_clist_set_column_width( disasm, 1, 16 );
5.105 - page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");
5.106 + data->msgs_list = gtk_object_get_data(GTK_OBJECT(win), "output_list");
5.107 + data->disasm_list = gtk_object_get_data(GTK_OBJECT(win), "disasm_list");
5.108 + gtk_clist_set_column_width( data->disasm_list, 1, 16 );
5.109 + data->page_field = gtk_object_get_data(GTK_OBJECT(win), "page_field");
5.110
5.111 appbar = gtk_object_get_data(GTK_OBJECT(win), "debug_appbar");
5.112 - icounter = gnome_appbar_get_progress( appbar );
5.113 - gtk_progress_bar_set_text(icounter, "1");
5.114 + data->icounter = gnome_appbar_get_progress( appbar );
5.115 + gtk_progress_bar_set_text(data->icounter, "1");
5.116 +
5.117 + gtk_object_set_data( GTK_OBJECT(win), "debug_data", data );
5.118 + return data;
5.119 }
5.120
5.121 /*
5.122 * Check for changed registers and update the display
5.123 */
5.124 -void update_registers( void )
5.125 +void update_registers( debug_info_t data )
5.126 {
5.127 int i;
5.128 - for( i=0; sh4_reg_map[i].name != NULL; i++ ) {
5.129 - if( sh4_reg_map[i].type == REG_INT ) {
5.130 + for( i=0; data->cpu->regs_info[i].name != NULL; i++ ) {
5.131 + if( data->cpu->regs_info[i].type == REG_INT ) {
5.132 /* Yes this _is_ probably fairly evil */
5.133 - if( *((uint32_t *)sh4_reg_map[i].value) !=
5.134 - *((uint32_t *)((char *)&sh4r_s + ((char *)sh4_reg_map[i].value - (char *)&sh4r))) ) {
5.135 + if( *((uint32_t *)data->cpu->regs_info[i].value) !=
5.136 + *((uint32_t *)((char *)data->saved_regs + ((char *)data->cpu->regs_info[i].value - (char *)data->cpu->regs))) ) {
5.137 char buf[20];
5.138 - sprintf( buf, "%08X", *((uint32_t *)sh4_reg_map[i].value) );
5.139 - gtk_clist_set_text( regs, i, 1, buf );
5.140 - gtk_clist_set_foreground( regs, i, &clrChanged );
5.141 + sprintf( buf, "%08X", *((uint32_t *)data->cpu->regs_info[i].value) );
5.142 + gtk_clist_set_text( data->regs_list, i, 1, buf );
5.143 + gtk_clist_set_foreground( data->regs_list, i, &clrChanged );
5.144 } else {
5.145 - gtk_clist_set_foreground( regs, i, &clrNormal );
5.146 + gtk_clist_set_foreground( data->regs_list, i, &clrNormal );
5.147 }
5.148 } else {
5.149 - if( *((float *)sh4_reg_map[i].value) !=
5.150 - *((float *)((char *)&sh4r_s + ((char *)sh4_reg_map[i].value - (char *)&sh4r))) ) {
5.151 + if( *((float *)data->cpu->regs_info[i].value) !=
5.152 + *((float *)((char *)data->saved_regs + ((char *)data->cpu->regs_info[i].value - (char *)data->cpu->regs))) ) {
5.153 char buf[20];
5.154 - sprintf( buf, "%f", *((float *)sh4_reg_map[i].value) );
5.155 - gtk_clist_set_text( regs, i, 1, buf );
5.156 - gtk_clist_set_foreground( regs, i, &clrChanged );
5.157 + sprintf( buf, "%f", *((float *)data->cpu->regs_info[i].value) );
5.158 + gtk_clist_set_text( data->regs_list, i, 1, buf );
5.159 + gtk_clist_set_foreground( data->regs_list, i, &clrChanged );
5.160 } else {
5.161 - gtk_clist_set_foreground( regs, i, &clrNormal );
5.162 + gtk_clist_set_foreground( data->regs_list, i, &clrNormal );
5.163 }
5.164 }
5.165 }
5.166 - if( sh4r.pc != sh4r_s.pc )
5.167 - set_disassembly_pc( sh4r.pc, FALSE );
5.168 - memcpy( &sh4r_s, &sh4r, sizeof(sh4r) );
5.169 +
5.170 + set_disassembly_pc( data, *data->cpu->pc, FALSE );
5.171 + memcpy( data->saved_regs, data->cpu->regs, data->cpu->regs_size );
5.172 }
5.173
5.174 -void update_icount( void )
5.175 +void update_icount( debug_info_t data )
5.176 {
5.177 - sprintf( icounter_text, "%d", sh4r.icount );
5.178 - gtk_progress_bar_set_text( icounter, icounter_text );
5.179 + sprintf( data->icounter_text, "%d", *data->cpu->icount );
5.180 + gtk_progress_bar_set_text( data->icounter, data->icounter_text );
5.181 }
5.182
5.183 -void set_disassembly_region( unsigned int page )
5.184 +void set_disassembly_region( debug_info_t data, unsigned int page )
5.185 {
5.186 uint32_t i, posn;
5.187 uint16_t op;
5.188 @@ -130,87 +114,107 @@
5.189 unsigned int from = page & 0xFFFFF000;
5.190 unsigned int to = from + 4096;
5.191
5.192 - gtk_clist_clear(disasm);
5.193 + gtk_clist_clear(data->disasm_list);
5.194
5.195 sprintf( addr, "%08X", from );
5.196 - gtk_entry_set_text( page_field, addr );
5.197 + gtk_entry_set_text( data->page_field, addr );
5.198
5.199 if( !mem_has_page( from ) ) {
5.200 arr[3] = "This page is currently unmapped";
5.201 - gtk_clist_append( disasm, arr );
5.202 - gtk_clist_set_foreground( disasm, 0, &clrError );
5.203 + gtk_clist_append( data->disasm_list, arr );
5.204 + gtk_clist_set_foreground( data->disasm_list, 0, &clrError );
5.205 } else {
5.206 - for( i=from; i<to; i+=2 ) {
5.207 - sh4_disasm_instruction( i, buf, sizeof(buf) );
5.208 + for( i=from; i<to; ) {
5.209 + i = data->cpu->disasm_func( i, buf, sizeof(buf) );
5.210 sprintf( addr, "%08X", i );
5.211 op = mem_read_phys_word(i);
5.212 sprintf( opcode, "%02X %02X", op&0xFF, op>>8 );
5.213 - posn = gtk_clist_append( disasm, arr );
5.214 + posn = gtk_clist_append( data->disasm_list, arr );
5.215 if( buf[0] == '?' )
5.216 - gtk_clist_set_foreground( disasm, posn, &clrWarn );
5.217 + gtk_clist_set_foreground( data->disasm_list, posn, &clrWarn );
5.218 }
5.219 - if( disasm_pc != -1 && disasm_pc >= from && disasm_pc < to )
5.220 - gtk_clist_set_foreground( disasm, (disasm_pc - from)>>1,
5.221 + if( data->disasm_pc != -1 && data->disasm_pc >= from && data->disasm_pc < to )
5.222 + gtk_clist_set_foreground( data->disasm_list, address_to_row(data, data->disasm_pc),
5.223 &clrPC );
5.224 }
5.225
5.226 if( page != from ) { /* not a page boundary */
5.227 - gtk_clist_moveto( disasm, (page-from)>>1, 0, 0.5, 0.0 );
5.228 + gtk_clist_moveto( data->disasm_list, (page-from)>>1, 0, 0.5, 0.0 );
5.229 }
5.230 - disasm_from = from;
5.231 - disasm_to = to;
5.232 + data->disasm_from = from;
5.233 + data->disasm_to = to;
5.234 }
5.235
5.236 -void jump_to_disassembly( unsigned int addr, gboolean select )
5.237 +void jump_to_disassembly( debug_info_t data, unsigned int addr, gboolean select )
5.238 {
5.239 int row;
5.240
5.241 - if( addr < disasm_from || addr >= disasm_to )
5.242 - set_disassembly_region(addr);
5.243 + if( addr < data->disasm_from || addr >= data->disasm_to )
5.244 + set_disassembly_region(data,addr);
5.245
5.246 - row = (addr-disasm_from)>>1;
5.247 + row = address_to_row( data, addr );
5.248 if(select) {
5.249 - gtk_clist_select_row( disasm, row, 0 );
5.250 + gtk_clist_select_row( data->disasm_list, row, 0 );
5.251 }
5.252 - if( gtk_clist_row_is_visible( disasm, row ) != GTK_VISIBILITY_FULL ){
5.253 - gtk_clist_moveto( disasm, row, 0, 0.5, 0.0 );
5.254 + if( gtk_clist_row_is_visible( data->disasm_list, row ) != GTK_VISIBILITY_FULL ){
5.255 + gtk_clist_moveto( data->disasm_list, row, 0, 0.5, 0.0 );
5.256 }
5.257 }
5.258
5.259 -void set_disassembly_pc( unsigned int pc, gboolean select )
5.260 +void jump_to_pc( debug_info_t data, gboolean select )
5.261 +{
5.262 + jump_to_disassembly( data, *data->cpu->pc, select );
5.263 +}
5.264 +
5.265 +void set_disassembly_pc( debug_info_t data, unsigned int pc, gboolean select )
5.266 {
5.267 int row;
5.268
5.269 - jump_to_disassembly( pc, select );
5.270 - if( disasm_pc != -1 && disasm_pc >= disasm_from && disasm_pc < disasm_to )
5.271 - gtk_clist_set_foreground( disasm, (disasm_pc - disasm_from)>>1,
5.272 + jump_to_disassembly( data, pc, select );
5.273 + if( data->disasm_pc != -1 && data->disasm_pc >= data->disasm_from &&
5.274 + data->disasm_pc < data->disasm_to )
5.275 + gtk_clist_set_foreground( data->disasm_list,
5.276 + (data->disasm_pc - data->disasm_from) / data->cpu->instr_size,
5.277 &clrNormal );
5.278 - row = (pc - disasm_from)>>1;
5.279 - gtk_clist_set_foreground( disasm, row, &clrPC );
5.280 - disasm_pc = pc;
5.281 + row = address_to_row( data, pc );
5.282 + gtk_clist_set_foreground( data->disasm_list, row, &clrPC );
5.283 + data->disasm_pc = pc;
5.284 }
5.285
5.286 +uint32_t row_to_address( debug_info_t data, int row ) {
5.287 + return data->cpu->instr_size * row + data->disasm_from;
5.288 +}
5.289
5.290 -void emit( int level, int source, char *msg, ... )
5.291 +int address_to_row( debug_info_t data, uint32_t address ) {
5.292 + if( data->disasm_from > address || data->disasm_to <= address )
5.293 + return -1;
5.294 + return (address - data->disasm_from) / data->cpu->instr_size;
5.295 +}
5.296 +
5.297 +void emit( void *ptr, int level, int source, char *msg, ... )
5.298 {
5.299 char buf[20], addr[10] = "", *p;
5.300 char *arr[3] = {buf, addr};
5.301 int posn;
5.302 time_t tm = time(NULL);
5.303 va_list ap;
5.304 + debug_info_t data;
5.305 + if( ptr == NULL )
5.306 + data = main_debug;
5.307 + else data = (debug_info_t)ptr;
5.308
5.309 va_start(ap, msg);
5.310 p = g_strdup_vprintf( msg, ap );
5.311 strftime( buf, sizeof(buf), "%H:%M:%S", localtime(&tm) );
5.312 if( source != -1 )
5.313 - sprintf( addr, "%08X", sh4r.pc );
5.314 + sprintf( addr, "%08X", *data->cpu->pc );
5.315 arr[2] = p;
5.316 - posn = gtk_clist_append(msgs, arr);
5.317 + posn = gtk_clist_append(data->msgs_list, arr);
5.318 free(p);
5.319 va_end(ap);
5.320
5.321 - gtk_clist_set_foreground( msgs, posn, msg_colors[level] );
5.322 - gtk_clist_moveto( msgs, posn, 0, 1.0, 0.0 );
5.323 + gtk_clist_set_foreground( data->msgs_list, posn, msg_colors[level] );
5.324 + gtk_clist_moveto( data->msgs_list, posn, 0, 1.0, 0.0 );
5.325
5.326 /* emit _really_ slows down the emu, to the point where the gui can be
5.327 * completely unresponsive if I don't include this:
5.328 @@ -218,3 +222,11 @@
5.329 while( gtk_events_pending() )
5.330 gtk_main_iteration();
5.331 }
5.332 +
5.333 +debug_info_t get_debug_info( GtkWidget *widget ) {
5.334 +
5.335 + GtkWidget *win = gtk_widget_get_toplevel(widget);
5.336 + debug_info_t data = (debug_info_t)gtk_object_get_data( GTK_OBJECT(win), "debug_data" );
5.337 + return data;
5.338 +}
5.339 +
6.1 --- a/src/gui/gui.c Sun Dec 12 07:44:49 2004 +0000
6.2 +++ b/src/gui/gui.c Thu Dec 08 13:38:00 2005 +0000
6.3 @@ -45,8 +45,8 @@
6.4 }
6.5
6.6 void update_gui(void) {
6.7 - update_registers();
6.8 - update_icount();
6.9 + update_registers(main_debug);
6.10 + update_icount(main_debug);
6.11 update_mmr_win();
6.12 dump_win_update_all();
6.13 }
7.1 --- a/src/gui/gui.h Sun Dec 12 07:44:49 2004 +0000
7.2 +++ b/src/gui/gui.h Thu Dec 08 13:38:00 2005 +0000
7.3 @@ -6,6 +6,7 @@
7.4
7.5 #include <gnome.h>
7.6 #include "dream.h"
7.7 +#include "disasm.h"
7.8
7.9 #ifdef __cplusplus
7.10 extern "C" {
7.11 @@ -17,16 +18,23 @@
7.12 void init_gui(void);
7.13 void update_gui(void);
7.14
7.15 -void init_debug_win(GtkWidget *);
7.16 +typedef struct debug_info_struct *debug_info_t;
7.17 +extern debug_info_t main_debug;
7.18 +
7.19 +debug_info_t init_debug_win(GtkWidget *, cpu_desc_t cpu );
7.20 +debug_info_t get_debug_info(GtkWidget *widget);
7.21 void open_file_dialog( void );
7.22 void update_mmr_win( void );
7.23 void init_mmr_win( void );
7.24 -void update_registers( void );
7.25 -void update_icount( void );
7.26 -void dump_win_update_all( void );
7.27 -void set_disassembly_region( unsigned int page );
7.28 -void set_disassembly_pc( unsigned int pc, gboolean select );
7.29 -void jump_to_disassembly( unsigned int addr, gboolean select );
7.30 +void update_registers( debug_info_t debug );
7.31 +void update_icount( debug_info_t debug );
7.32 +void dump_win_update_all();
7.33 +void set_disassembly_region( debug_info_t debug, unsigned int page );
7.34 +void set_disassembly_pc( debug_info_t debug, unsigned int pc, gboolean select );
7.35 +void jump_to_disassembly( debug_info_t debug, unsigned int addr, gboolean select );
7.36 +void jump_to_pc( debug_info_t debug, gboolean select );
7.37 +uint32_t row_to_address( debug_info_t debug, int row );
7.38 +int address_to_row( debug_info_t debug, uint32_t address );
7.39
7.40 extern PangoFontDescription *fixed_list_font;
7.41 extern GdkColor clrNormal, clrChanged, clrError, clrWarn,
8.1 --- a/src/loader.c Sun Dec 12 07:44:49 2004 +0000
8.2 +++ b/src/loader.c Thu Dec 08 13:38:00 2005 +0000
8.3 @@ -57,8 +57,8 @@
8.4 parse_ipbin( load );
8.5 sh4_reset();
8.6 sh4_set_pc( BOOTSTRAP_LOAD_ADDR + 0x300 );
8.7 - set_disassembly_region( BOOTSTRAP_LOAD_ADDR );
8.8 - set_disassembly_pc( sh4r.pc, TRUE );
8.9 + set_disassembly_region( main_debug, BOOTSTRAP_LOAD_ADDR );
8.10 + set_disassembly_pc( main_debug, sh4r.pc, TRUE );
8.11 update_gui();
8.12 } else {
8.13 /* look for a valid ISO9660 header */
9.1 --- a/src/main.c Sun Dec 12 07:44:49 2004 +0000
9.2 +++ b/src/main.c Thu Dec 08 13:38:00 2005 +0000
9.3 @@ -12,8 +12,10 @@
9.4 #include "interface.h"
9.5 #include "gui.h"
9.6 #include "sh4core.h"
9.7 +#include "sh4dasm.h"
9.8 #include "mem.h"
9.9
9.10 +debug_info_t main_debug;
9.11
9.12 int
9.13 main (int argc, char *argv[])
9.14 @@ -27,17 +29,17 @@
9.15 gnome_init ("dreamon", VERSION, argc, argv);
9.16 init_gui();
9.17 debug_win = create_debug_win ();
9.18 - init_debug_win(debug_win);
9.19 + main_debug = init_debug_win(debug_win, &sh4_cpu_desc);
9.20 video_open();
9.21 dreamcast_init();
9.22 init_mmr_win(); /* Note: must be done after sh4_init */
9.23 sh4_reset();
9.24 update_gui();
9.25 gtk_widget_show (debug_win);
9.26 - set_disassembly_region( 0xA0000000 );
9.27 + set_disassembly_region( main_debug, 0xA0000000 );
9.28 // mem_new_watch( 0x0C204818, 0x0C204830, WATCH_WRITE );
9.29
9.30 - emit( EMIT_INFO, -1, "DreamOn! ready..." );
9.31 + emit( main_debug, EMIT_INFO, -1, "DreamOn! ready..." );
9.32
9.33 gtk_main ();
9.34 return 0;
10.1 --- a/src/sh4/sh4core.c Sun Dec 12 07:44:49 2004 +0000
10.2 +++ b/src/sh4/sh4core.c Thu Dec 08 13:38:00 2005 +0000
10.3 @@ -820,8 +820,10 @@
10.4 /* SHAD Rm, Rn */
10.5 tmp = RM(ir);
10.6 if( (tmp & 0x80000000) == 0 ) RN(ir) <<= (tmp&0x1f);
10.7 - else if( (tmp & 0x1F) == 0 ) ((int32_t)RN(ir)) >>=31;
10.8 - else ((int32_t)RN(ir)) >>= (((~RM(ir)) & 0x1F)+1);
10.9 + else if( (tmp & 0x1F) == 0 )
10.10 + RN(ir) = ((int32_t)RN(ir)) >> 31;
10.11 + else
10.12 + RN(ir) = ((int32_t)RN(ir)) >> (((~RM(ir)) & 0x1F)+1);
10.13 } else if( (ir&0x000F) == 0x0D ) {
10.14 /* SHLD Rm, Rn */
10.15 tmp = RM(ir);
11.1 --- a/src/sh4/sh4dasm.c Sun Dec 12 07:44:49 2004 +0000
11.2 +++ b/src/sh4/sh4dasm.c Thu Dec 08 13:38:00 2005 +0000
11.3 @@ -4,6 +4,29 @@
11.4
11.5 #define UNIMP(ir) snprintf( buf, len, "??? " )
11.6
11.7 +
11.8 +struct reg_desc_struct sh4_reg_map[] =
11.9 + { {"R0", REG_INT, &sh4r.r[0]}, {"R1", REG_INT, &sh4r.r[1]},
11.10 + {"R2", REG_INT, &sh4r.r[2]}, {"R3", REG_INT, &sh4r.r[3]},
11.11 + {"R4", REG_INT, &sh4r.r[4]}, {"R5", REG_INT, &sh4r.r[5]},
11.12 + {"R6", REG_INT, &sh4r.r[6]}, {"R7", REG_INT, &sh4r.r[7]},
11.13 + {"R8", REG_INT, &sh4r.r[8]}, {"R9", REG_INT, &sh4r.r[9]},
11.14 + {"R10",REG_INT, &sh4r.r[10]}, {"R11",REG_INT, &sh4r.r[11]},
11.15 + {"R12",REG_INT, &sh4r.r[12]}, {"R13",REG_INT, &sh4r.r[13]},
11.16 + {"R14",REG_INT, &sh4r.r[14]}, {"R15",REG_INT, &sh4r.r[15]},
11.17 + {"SR", REG_INT, &sh4r.sr}, {"GBR", REG_INT, &sh4r.gbr},
11.18 + {"SSR",REG_INT, &sh4r.ssr}, {"SPC", REG_INT, &sh4r.spc},
11.19 + {"SGR",REG_INT, &sh4r.sgr}, {"DBR", REG_INT, &sh4r.dbr},
11.20 + {"VBR",REG_INT, &sh4r.vbr},
11.21 + {"PC", REG_INT, &sh4r.pc}, {"PR", REG_INT, &sh4r.pr},
11.22 + {"MACL",REG_INT, &sh4r.mac},{"MACH",REG_INT, ((uint32_t *)&sh4r.mac)+1},
11.23 + {"FPUL", REG_INT, &sh4r.fpul}, {"FPSCR", REG_INT, &sh4r.fpscr},
11.24 + {NULL, 0, NULL} };
11.25 +
11.26 +struct cpu_desc_struct sh4_cpu_desc = { "SH4", sh4_disasm_instruction, 2,
11.27 + &sh4r, sizeof(sh4r), sh4_reg_map,
11.28 + &sh4r.pc, &sh4r.icount };
11.29 +
11.30 int sh4_disasm_instruction( int pc, char *buf, int len )
11.31 {
11.32 uint16_t ir = mem_read_word(pc);
12.1 --- a/src/sh4/sh4dasm.h Sun Dec 12 07:44:49 2004 +0000
12.2 +++ b/src/sh4/sh4dasm.h Thu Dec 08 13:38:00 2005 +0000
12.3 @@ -1,18 +1,19 @@
12.4 #ifndef sh4dasm_H
12.5 #define sh4dasm_H 1
12.6
12.7 +#include "disasm.h"
12.8 +
12.9 #ifdef __cplusplus
12.10 extern "C" {
12.11 -#if 0
12.12 -}
12.13 -#endif
12.14 #endif
12.15
12.16 #include <stdio.h>
12.17
12.18 int sh4_disasm_instruction( int pc, char *buf, int len );
12.19 void sh4_disasm_region( FILE *f, int from, int to, int load_addr );
12.20 -
12.21 +
12.22 +extern struct cpu_desc_struct sh4_cpu_desc;
12.23 +
12.24 #ifdef __cplusplus
12.25 }
12.26 #endif
.