Skip to content

Commit 472dfad

Browse files
committed
Added further debug logging mechanisms, and the ability to turn logging on and off
1 parent 3a10429 commit 472dfad

20 files changed

+520
-131
lines changed

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ OBJS_RECOMPILER_32 = r4300/x86/assemble.o r4300/x86/gbc.o r4300/x86/gcop0.o r430
55

66
OBJS_RECOMPILER_64 = r4300/x86_64/assemble.o r4300/x86_64/gbc.o r4300/x86_64/gcop0.o r4300/x86_64/gcop1.o r4300/x86_64/gcop1_d.o r4300/x86_64/gcop1_l.o r4300/x86_64/gcop1_s.o r4300/x86_64/gcop1_w.o r4300/x86_64/gr4300.o r4300/x86_64/gregimm.o r4300/x86_64/gspecial.o r4300/x86_64/gtlb.o r4300/x86_64/regcache.o r4300/x86_64/rjump.o
77

8-
OBJS = ai/ai_controller.o api/callbacks.o main/main.o main/rom.o main/savestates.o main/util.o memory/memory.o pi/cart_rom.o pi/pi_controller.o r4300/cached_interp.o r4300/cp0.o r4300/cp1.o r4300/exception.o r4300/interupt.o r4300/mi_controller.o r4300/pure_interp.o r4300/r4300.o r4300/r4300_core.o r4300/recomp.o r4300/reset.o r4300/tlb.o rdp/rdp_core.o ri/rdram.o ri/rdram_detection_hack.o ri/ri_controller.o rsp/rsp_core.o rsp_hle/alist.o rsp_hle/alist_audio.o rsp_hle/alist_naudio.o rsp_hle/alist_nead.o rsp_hle/audio.o rsp_hle/cicx105.o rsp_hle/hle.o rsp_hle/jpeg.o rsp_hle/memory.o rsp_hle/mp3.o rsp_hle/musyx.o rsp_hle/plugin.o rsp_lle/rsp.o si/cic.o si/game_controller.o si/n64_cic_nus_6105.o si/pif.o si/si_controller.o usf/usf.o usf/barray.o usf/resampler.o vi/vi_controller.o $(OBJS_RECOMPILER_64)
8+
OBJS = ai/ai_controller.o api/callbacks.o debugger/dbg_decoder.o main/main.o main/rom.o main/savestates.o main/util.o memory/memory.o pi/cart_rom.o pi/pi_controller.o r4300/cached_interp.o r4300/cp0.o r4300/cp1.o r4300/exception.o r4300/interupt.o r4300/mi_controller.o r4300/pure_interp.o r4300/r4300.o r4300/r4300_core.o r4300/recomp.o r4300/reset.o r4300/tlb.o rdp/rdp_core.o ri/rdram.o ri/rdram_detection_hack.o ri/ri_controller.o rsp/rsp_core.o rsp_hle/alist.o rsp_hle/alist_audio.o rsp_hle/alist_naudio.o rsp_hle/alist_nead.o rsp_hle/audio.o rsp_hle/cicx105.o rsp_hle/hle.o rsp_hle/jpeg.o rsp_hle/memory.o rsp_hle/mp3.o rsp_hle/musyx.o rsp_hle/plugin.o rsp_lle/rsp.o si/cic.o si/game_controller.o si/n64_cic_nus_6105.o si/pif.o si/si_controller.o usf/usf.o usf/barray.o usf/resampler.o vi/vi_controller.o $(OBJS_RECOMPILER_64)
99

1010
OPTS = -O3 -DDYNAREC -I.
1111
ROPTS = -O3 -DARCH_MIN_SSE2 -I.
@@ -35,4 +35,3 @@ test/dumpresampled.o: test/dumpresampled.c
3535

3636
clean:
3737
rm -f $(OBJS) liblazyusf.a test/bench.o bench test/dumpresampled.o dumpresampled > /dev/null
38-

ai/ai_controller.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ static unsigned int get_dma_duration(struct ai_controller* ai)
7373
static void do_dma(struct ai_controller* ai, const struct ai_dma* dma)
7474
{
7575
#ifdef DEBUG_INFO
76-
fprintf(ai->r4300->state->debug_log, "Audio DMA push: %d %d\n", dma->address, dma->length);
76+
if (ai->r4300->state->debug_log)
77+
fprintf(ai->r4300->state->debug_log, "Audio DMA push: %d %d\n", dma->address, dma->length);
7778
#endif
7879

7980
/* lazy initialization of sample format */
@@ -118,7 +119,7 @@ static void fifo_push(struct ai_controller* ai)
118119
ai->fifo[1].address = ai->regs[AI_DRAM_ADDR_REG];
119120
ai->fifo[1].length = ai->regs[AI_LEN_REG];
120121
ai->fifo[1].duration = duration;
121-
122+
122123
if (ai->r4300->state->enableFIFOfull)
123124
ai->regs[AI_STATUS_REG] |= AI_STATUS_FULL;
124125
else
@@ -237,4 +238,3 @@ void ai_end_of_dma_event(struct ai_controller* ai)
237238
ai->r4300->mi.AudioIntrReg |= MI_INTR_AI;
238239
raise_rcp_interrupt(ai->r4300, MI_INTR_AI);
239240
}
240-

api/callbacks.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ void DebugMessage(usf_state_t * state, int level, const char *message, ...)
4747
level > 1 )
4848
{
4949
#ifdef DEBUG_INFO
50-
char buffer[1024];
51-
va_start(args, message);
52-
vsprintf(buffer, message, args);
53-
va_end(args);
54-
fprintf(state->debug_log, "%s\n", buffer);
50+
if (state->debug_log)
51+
{
52+
char buffer[1024];
53+
va_start(args, message);
54+
vsprintf(buffer, message, args);
55+
va_end(args);
56+
fprintf(state->debug_log, "%s\n", buffer);
57+
}
5558
if ( level > 1 )
5659
#endif
5760
return;
@@ -69,9 +72,7 @@ void DebugMessage(usf_state_t * state, int level, const char *message, ...)
6972
vsprintf(state->error_message + len, message, args);
7073
#endif
7174
va_end(args);
72-
75+
7376
state->last_error = state->error_message;
7477
state->stop = 1;
7578
}
76-
77-

debugger/dbg_print.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
#include "dbg_decoder.h"
6+
7+
int main(int argc, char ** argv)
8+
{
9+
if (argc >= 3)
10+
{
11+
char * end;
12+
unsigned int start_address = (unsigned int) strtoul(argv[1], &end, 0);
13+
int i;
14+
15+
for (i = 2; i < argc; ++i)
16+
{
17+
char opcode[64];
18+
char argument[64];
19+
memset(opcode, 0, sizeof(opcode));
20+
memset(argument, 0, sizeof(argument));
21+
22+
unsigned int opcode_val = (unsigned int) strtoul(argv[i], &end, 0);
23+
24+
r4300_decode_op( opcode_val, opcode, argument, start_address );
25+
26+
printf("%08x: %-16s %s\n", start_address, opcode, argument);
27+
start_address += 4;
28+
}
29+
}
30+
31+
return 0;
32+
}

main/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ m64p_error main_start(usf_state_t * state)
132132

133133
memcpy(&RDRAMSize, state->save_state + 4, 4);
134134
to_little_endian_buffer(&RDRAMSize, 4, 1);
135-
135+
136136
/* take the r4300 emulator mode from the config file at this point and cache it in a global variable */
137137
#ifdef DEBUG_INFO
138138
state->r4300emu = 0;
@@ -169,14 +169,14 @@ m64p_error main_start(usf_state_t * state)
169169

170170
if (!savestates_load(state, state->save_state, state->save_state_size, 0))
171171
return M64ERR_INVALID_STATE;
172-
172+
173173
if (state->enableFIFOfull)
174174
{
175175
state->g_delay_ai = 1;
176176
ai_fifo_queue_int(&state->g_ai);
177177
state->g_ai.regs[AI_STATUS_REG] |= 0x40000000;
178178
}
179-
179+
180180
// We want to leave in all the necessary code so that these can one day be enabled for the trimmed sets
181181
if (state->enable_trimming_mode)
182182
{
@@ -186,7 +186,7 @@ m64p_error main_start(usf_state_t * state)
186186
state->g_delay_dp = 1;
187187
state->enable_hle_audio = 0;
188188
}
189-
189+
190190
return M64ERR_SUCCESS;
191191
}
192192

pi/pi_controller.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ static void dma_pi_write(usf_state_t * state, struct pi_controller* pi)
6363
{
6464
unsigned int longueur;
6565
int i;
66-
66+
6767
#ifdef DEBUG_INFO
68-
fprintf(state->debug_log, "PI DMA WRITE: %08x to %08x for %08x bytes\n", pi->regs[PI_CART_ADDR_REG], pi->regs[PI_DRAM_ADDR_REG], pi->regs[PI_WR_LEN_REG] + 1);
68+
if (state->debug_log)
69+
fprintf(state->debug_log, "PI DMA WRITE: %08x to %08x for %08x bytes\n", pi->regs[PI_CART_ADDR_REG], pi->regs[PI_DRAM_ADDR_REG], pi->regs[PI_WR_LEN_REG] + 1);
6970
#endif
7071

7172
if (pi->regs[PI_CART_ADDR_REG] < 0x10000000)
@@ -131,7 +132,7 @@ static void dma_pi_write(usf_state_t * state, struct pi_controller* pi)
131132
bit_array_set(state->barray_ram_written_first, ram_address / 4);
132133
}
133134
}
134-
135+
135136
((unsigned char*)pi->ri->rdram.dram)[ram_address^S8]=
136137
pi->cart_rom.rom[rom_address^S8];
137138

r4300/interupt.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ void add_interupt_event_count(usf_state_t * state, int type, unsigned int count)
170170
int special;
171171

172172
special = (type == SPECIAL_INT);
173-
173+
174174
if(state->g_cp0_regs[CP0_COUNT_REG] > 0x80000000) state->SPECIAL_done = 0;
175-
175+
176176
if (get_event(state, type)) {
177177
DebugMessage(state, M64MSG_WARNING, "two events of type 0x%x in interrupt queue", type);
178178
/* FIXME: hack-fix for freezing in Perfect Dark
@@ -355,22 +355,23 @@ void check_interupt(usf_state_t * state)
355355

356356
state->g_r4300.mi.regs[MI_INTR_REG] &= ~MI_INTR_AI;
357357
state->g_r4300.mi.regs[MI_INTR_REG] |= state->g_r4300.mi.AudioIntrReg & MI_INTR_AI;
358-
358+
359359
#ifdef DEBUG_INFO
360-
if (state->g_r4300.mi.regs[MI_INTR_REG])
360+
if (state->g_r4300.mi.regs[MI_INTR_REG] && state->debug_log)
361361
fprintf(state->debug_log, "Interrupt %d - ", state->g_r4300.mi.regs[MI_INTR_REG]);
362362
#endif
363363
if (state->g_r4300.mi.regs[MI_INTR_REG] & state->g_r4300.mi.regs[MI_INTR_MASK_REG])
364364
{
365365
#ifdef DEBUG_INFO
366-
fprintf(state->debug_log, "triggered\n");
366+
if (state->debug_log)
367+
fprintf(state->debug_log, "triggered\n");
367368
#endif
368369
state->g_cp0_regs[CP0_CAUSE_REG] = (state->g_cp0_regs[CP0_CAUSE_REG] | 0x400) & 0xFFFFFF83;
369370
}
370371
else
371372
{
372373
#ifdef DEBUG_INFO
373-
if (state->g_r4300.mi.regs[MI_INTR_REG])
374+
if (state->g_r4300.mi.regs[MI_INTR_REG] && state->debug_log)
374375
fprintf(state->debug_log, "masked\n");
375376
#endif
376377
state->g_cp0_regs[CP0_CAUSE_REG] &= ~0x400;
@@ -518,7 +519,7 @@ void osal_fastcall gen_interupt(usf_state_t * state)
518519
return;
519520
}
520521
}
521-
522+
522523
if (state->skip_jump)
523524
{
524525
unsigned int dest = state->skip_jump;
@@ -532,7 +533,7 @@ void osal_fastcall gen_interupt(usf_state_t * state)
532533
state->last_addr = dest;
533534
generic_jump_to(state, dest);
534535
return;
535-
}
536+
}
536537

537538
switch(state->q.first->data.type)
538539
{
@@ -544,26 +545,26 @@ void osal_fastcall gen_interupt(usf_state_t * state)
544545
remove_interupt_event(state);
545546
vi_vertical_interrupt_event(&state->g_vi);
546547
break;
547-
548+
548549
case COMPARE_INT:
549550
compare_int_handler(state);
550551
break;
551-
552+
552553
case CHECK_INT:
553554
remove_interupt_event(state);
554555
wrapped_exception_general(state);
555556
break;
556-
557+
557558
case SI_INT:
558559
remove_interupt_event(state);
559560
si_end_of_dma_event(&state->g_si);
560561
break;
561-
562+
562563
case PI_INT:
563564
remove_interupt_event(state);
564565
pi_end_of_dma_event(&state->g_pi);
565566
break;
566-
567+
567568
case AI_INT:
568569
remove_interupt_event(state);
569570
ai_end_of_dma_event(&state->g_ai);
@@ -573,7 +574,7 @@ void osal_fastcall gen_interupt(usf_state_t * state)
573574
remove_interupt_event(state);
574575
rsp_interrupt_event(&state->g_sp);
575576
break;
576-
577+
577578
case DP_INT:
578579
remove_interupt_event(state);
579580
rdp_interrupt_event(&state->g_dp);
@@ -594,4 +595,3 @@ void osal_fastcall gen_interupt(usf_state_t * state)
594595
break;
595596
}
596597
}
597-

r4300/pure_interp.c

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void InterpretOpcode(usf_state_t * state)
179179
{
180180
uint32_t op = *fast_mem_access(state, state->PC->addr);
181181
#ifdef DEBUG_INFO
182+
if (state->debug_log)
182183
{
183184
char instr[256];
184185
char arguments[256];

r4300/tlb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ unsigned int virtual_to_physical_address(usf_state_t * state, unsigned int addre
101101
//printf("tlb exception !!! @ %x, %x, add:%x\n", addresse, w, PC->addr);
102102
//getchar();
103103
#ifdef DEBUG_INFO
104-
fprintf(state->debug_log, "TLB exception @ %x, %x, add:%x\n", addresse, w, state->PC->addr);
105-
fflush(state->debug_log);
104+
if (state->debug_log)
105+
fprintf(state->debug_log, "TLB exception @ %x, %x, add:%x\n", addresse, w, state->PC->addr);
106106
#endif
107107
TLB_refill_exception(state,addresse,w);
108108
//return 0x80000000;

0 commit comments

Comments
 (0)