Skip to content

Commit

Permalink
Merge pull request ctm#1 from autc04/debugging-support
Browse files Browse the repository at this point in the history
Debugging support
  • Loading branch information
autc04 authored Feb 17, 2019
2 parents 9b3a95c + 67c7efa commit 217ef47
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
tab_width = 8
indent_width = 2
charset = utf-8
7 changes: 7 additions & 0 deletions include/syn68k_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ extern uint16 callback_dummy_address_space[];
#define MAGIC_EXIT_EMULATOR_ADDRESS (MAGIC_ADDRESS_BASE + 0)
#define MAGIC_RTE_ADDRESS (MAGIC_ADDRESS_BASE + 2)

typedef struct {
uint32_t (*debugger)(uint32_t addr);
uint32_t (*getNextBreakpoint)(uint32_t addr);
} DebuggerCallbacks;

extern DebuggerCallbacks syn68k_debugger_callbacks;

/* Address bits that have meaning, for the CLEAN() macro, below. */
#define LEGAL_ADDRESS_BITS 0xFFFFFFFFUL

Expand Down
30 changes: 27 additions & 3 deletions runtime/blockinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ compute_block_info (Block *b, const uint16 *code, TempBlockInfo *temp)
int clobbered = 0, may_set = 0, may_not_set = ALL_CCS, needed = 0;
int next_array_size;
const OpcodeMappingInfo *map = NULL;
uint32_t break_addr = 0xFFFFFFFF;
bool breakpoint = false;

/* Initialize the next offset array. This lets us step through this
* code forwards when we actually get around to compiling it.
*/
temp->num_68k_instrs = 0;
next_array_size = 16;
temp->next_instr_offset = (int8 *) xmalloc (next_array_size * sizeof (int8));
temp->break_at_end = false;

if(syn68k_debugger_callbacks.getNextBreakpoint)
{
uint32_t addr = US_TO_SYN68K(code);
break_addr = syn68k_debugger_callbacks.getNextBreakpoint(addr);
}

/* Loop over all instructions in the block and determine information
* about how this block deals with CC bits.
Expand All @@ -40,8 +49,15 @@ compute_block_info (Block *b, const uint16 *code, TempBlockInfo *temp)
{
int insn_size;
unsigned m68k_op;
uint32_t addr = US_TO_SYN68K (code);

m68k_op = READUW (US_TO_SYN68K (code));
if (addr >= break_addr)
{
breakpoint = true;
break;
}

m68k_op = READUW (addr);
map = &opcode_map_info[opcode_map_index[m68k_op]];

#if 0
Expand Down Expand Up @@ -89,8 +105,16 @@ compute_block_info (Block *b, const uint16 *code, TempBlockInfo *temp)
/* Terminate the array with a 0 offset. */
temp->next_instr_offset[temp->num_68k_instrs] = 0;

/* Figure out where this block goes (if possible). */
determine_next_block_addresses (old_code, temp, map);
if (breakpoint)
{
temp->num_child_blocks = 0;
temp->break_at_end = true;
}
else
{
/* Figure out where this block goes (if possible). */
determine_next_block_addresses (old_code, temp, map);
}

/* Record the block information we've computed. */
b->cc_clobbered = clobbered;
Expand Down
2 changes: 2 additions & 0 deletions runtime/include/blockinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#define _blockinfo_h_

#include "block.h"
#include <stdbool.h>

typedef struct {
uint32 child[2]; /* m68k addresses of m68k code following this blk. */
int16 num_child_blocks; /* # of child addrs we can know at translate time. */
uint16 num_68k_instrs;
int8 *next_instr_offset; /* word offset to next instr; 0 iff last instr. */
bool break_at_end;
} TempBlockInfo;

extern void compute_block_info (Block *b, const uint16 *code,
Expand Down
1 change: 1 addition & 0 deletions runtime/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ uint32 ROMlib_offset;
uint64 ROMlib_offsets[OFFSET_TABLE_SIZE];
uint64 ROMlib_sizes[OFFSET_TABLE_SIZE] = {0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF, 0x3FFFFFFF};
#endif
DebuggerCallbacks syn68k_debugger_callbacks = {0,0};

/* This function initializes syn68k. Call it exactly once, before any
* other syn68k calls. DOS_INT_FLAG_ADDR is the conventional memory
Expand Down
20 changes: 16 additions & 4 deletions runtime/syn68k_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,23 @@ interpret_code1 (const uint16 *code, CPUState *cpu_state_ptr, const void ***out_
CASE_POSTAMBLE (ROUND_UP (PTR_WORDS + 1));
#endif /* !GENERATE_NATIVE_CODE */

/* Reserved - two word NOP. */
/* Debugger breakpoint or single-step. */
CASE (0x0002)
/* Historical cruft. */
CASE_PREAMBLE ("Reserved: 2 word NOP", "", "", "", "")
CASE_POSTAMBLE (ROUND_UP (PTR_WORDS + 1));
CASE_PREAMBLE ("Debugger breakpoint or single-step", "", "", "", "")
if(syn68k_debugger_callbacks.debugger)
{
SAVE_CPU_STATE ();
code = code_lookup( syn68k_debugger_callbacks.debugger(*(uint32_t*)code) );
LOAD_CPU_STATE ();
}
else
{
// We should never get here, (callbacks.getNextBreakpoint set
// but callbacks.debugger cleared). But if we do, it's not a prolbem.
code = code_lookup(*(uint32_t*)code);
}

CASE_POSTAMBLE (ROUND_UP (PTR_WORDS));

/* Reserved - skip stub NOP. */
CASE (0x0003)
Expand Down
11 changes: 11 additions & 0 deletions runtime/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ typedef struct
static void compute_maps_and_ccs (Block *b, MapAndCC *m,
const TempBlockInfo *tbi);

static inline uint16 * output_opcode (uint16 *code, uint32 opcode);


/* Compiles a block at a specified address and returns a mask indicating
* which cc bits must be valid on entry to this block. The block is placed
Expand Down Expand Up @@ -317,6 +319,7 @@ generate_code (Block *b, TempBlockInfo *tbi, BOOL try_native_p)

/* Loop over all instructions, in forwards order, and compile them. */
m68k_code = SYN68K_TO_US (b->m68k_start_address);

#ifdef GENERATE_NATIVE_CODE
prev_native_p = TRUE; /* So n->s stub will be generated if necessary. */
#endif /* GENERATE_NATIVE_CODE */
Expand Down Expand Up @@ -517,6 +520,14 @@ generate_code (Block *b, TempBlockInfo *tbi, BOOL try_native_p)
prev_native_p = native_p;
#endif /* GENERATE_NATIVE_CODE */
}

if (tbi->break_at_end)
{
uint8_t *p = (uint8_t*)output_opcode((uint16*)(code + num_code_bytes), 0x0002);
*(uint32_t*)p = US_TO_SYN68K(m68k_code);
p += 4;
num_code_bytes = p - code;
}

/* Copy the code we just created over to the block. We allocate a little
* extra space because we prepend all compiled code with the big-endian
Expand Down

0 comments on commit 217ef47

Please sign in to comment.