Skip to content

Instantly share code, notes, and snippets.

@jpallister
Created December 17, 2013 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpallister/8004422 to your computer and use it in GitHub Desktop.
Save jpallister/8004422 to your computer and use it in GitHub Desktop.
Patch file to apply to msp430 gdb-7.2a, as in http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=Install:fromsource This fixes a crash when a .data segment is not in the file, changes the reset vectors to load from the last word of .vectors and adds simplistic instruction tracing.
diff -u -w -r gdb-7.2/sim/msp430/interp.c gdb-7.2_fixed/sim/msp430/interp.c
--- gdb-7.2/sim/msp430/interp.c 2013-12-17 12:32:59.982840965 +0000
+++ gdb-7.2_fixed/sim/msp430/interp.c 2013-12-17 12:32:35.114841379 +0000
@@ -844,6 +844,8 @@
}
}
+static int tracing = 0;
+
#undef AND
#define MOV 0x4
@@ -919,6 +921,12 @@
#define MASK_SR(x) \
do { if (x.d_reg != 2) alu.regs[2] &= SR_MASK; } while(0)
+#define TRACE(...) do { \
+ if(tracing) \
+ { \
+ printf(__VA_ARGS__); \
+ } \
+ } while(0)
void
flow ()
@@ -964,6 +972,8 @@
alu.insns += 1;
+ TRACE("0x%04X, 0x%04X, ", pc, insn);
+
switch (opcode)
{
default:
@@ -971,6 +981,7 @@
/* single operands */
case RRC:
+ TRACE("rrc");
tmp = (C << (srp.byte ? 8 : 16)) | (READ_SRC (srp));
tmp >>= 1;
WRITE_BACK (srp, tmp);
@@ -981,11 +992,13 @@
msp430_set_status (tmp, srp.byte, "xx-0");
break;
case SWPB:
+ TRACE("swpb");
tmp = ((srp.src << 8) & 0xff00) | ((srp.src >> 8) & 0x00ff);
WRITE_BACK (srp, tmp);
MASK_SR (srp);
break;
case RRA:
+ TRACE("rra");
tmp = READ_SRC (srp);
tmp =
(tmp & (srp.byte ? 0x80 : 0x8000)) | ((tmp >> 1) &
@@ -998,6 +1011,7 @@
msp430_set_status (tmp, srp.byte, "xx-0");
break;
case SXT:
+ TRACE("sxt");
tmp = srp.src & 0xff;
if (tmp & 0x80)
tmp |= 0xff00;
@@ -1006,12 +1020,14 @@
msp430_set_status (tmp, srp.byte, "xx-0");
break;
case PUSH:
+ TRACE("push");
sp -= 2;
srp = msp430_single_operands (insn);
tmp = READ_SRC (srp);
msp430_write_integer (sp, tmp, 2);
break;
case CALL:
+ TRACE("call");
sp -= 2;
srp = msp430_single_operands (insn);
tmp = READ_SRC (srp);
@@ -1019,6 +1035,7 @@
pc = tmp;
break;
case RETI:
+ TRACE("reti");
sr = msp430_fetch_integer (sp);
sp += 2;
msp430_set_status (0, 0, "----");
@@ -1029,6 +1046,7 @@
/* double operand */
case DADD:
+ TRACE("dadd");
{
unsigned int imc = C;
unsigned int ss = drp.src;
@@ -1063,6 +1081,7 @@
}
break;
case MOV:
+ TRACE("mov");
tmp = READ_SRC (drp);
WRITE_BACK (drp, tmp);
MASK_SR (drp);
@@ -1070,6 +1089,7 @@
break;
case ADD:
case ADDC:
+ TRACE("add");
tmp =
(READ_SRC (drp)) + READ_DST (drp) + ((opcode == ADDC) ? C : 0);
WRITE_BACK (drp, tmp);
@@ -1091,6 +1111,7 @@
break;
case SUB:
case SUBC:
+ TRACE("sub");
tmp =
(~READ_SRC (drp)) + READ_DST (drp) + ((opcode == SUBC) ? C : 1);
WRITE_BACK (drp, tmp);
@@ -1111,6 +1132,7 @@
msp430_set_status (tmp, drp.byte, "xxx-");
break;
case CMP:
+ TRACE("cmp");
tmp = (~READ_SRC (drp)) + READ_DST (drp) + 1;
MASK_SR (drp);
{
@@ -1129,6 +1151,7 @@
msp430_set_status (tmp, drp.byte, "xxx-");
break;
case BIT:
+ TRACE("bit");
tmp = (READ_SRC (drp)) & READ_DST (drp);
MASK_SR (drp);
msp430_set_status (tmp, drp.byte, "xx-0");
@@ -1138,18 +1161,21 @@
CLR_C;
break;
case BIC:
+ TRACE("bic");
tmp = (~READ_SRC (drp)) & READ_DST (drp);
WRITE_BACK (drp, tmp);
MASK_SR (drp);
msp430_set_status (tmp, drp.byte, "----");
break;
case BIS:
+ TRACE("bis");
tmp = (READ_SRC (drp)) | READ_DST (drp);
WRITE_BACK (drp, tmp);
MASK_SR (drp);
msp430_set_status (tmp, drp.byte, "----");
break;
case XOR:
+ TRACE("xor");
tmp = (READ_SRC (drp)) ^ READ_DST (drp);
WRITE_BACK (drp, tmp);
MASK_SR (drp);
@@ -1169,6 +1195,7 @@
}
break;
case AND:
+ TRACE("and");
tmp = (READ_SRC (drp)) & READ_DST (drp);
WRITE_BACK (drp, tmp);
MASK_SR (drp);
@@ -1182,38 +1209,47 @@
/* jumps */
case JNZ:
+ TRACE("jnz");
tmp = msp430_offset (insn);
pc += 2 + ((!Z) ? tmp : 0);
break;
case JZ:
+ TRACE("jz");
tmp = msp430_offset (insn);
pc += 2 + ((Z) ? tmp : 0);
break;
case JC:
+ TRACE("jc");
tmp = msp430_offset (insn);
pc += 2 + ((C) ? tmp : 0);
break;
case JNC:
+ TRACE("jnc");
tmp = msp430_offset (insn);
pc += 2 + ((!C) ? tmp : 0);
break;
case JN:
+ TRACE("jn");
tmp = msp430_offset (insn);
pc += 2 + ((N) ? tmp : 0);
break;
case JGE:
+ TRACE("jge");
tmp = msp430_offset (insn);
pc += 2 + ((!(N ^ V)) ? tmp : 0);
break;
case JL:
+ TRACE("jl");
tmp = msp430_offset (insn);
pc += 2 + ((N ^ V) ? tmp : 0);
break;
case JMP:
+ TRACE("jmp");
pc += msp430_offset (insn) + 2;
break;
} /* case */
+ TRACE("\n");
}
while (alu.signal == 0);
}
@@ -1347,8 +1383,6 @@
to some extent. That's the price of emulation. */
-static int tracing = 0;
-
void
sim_resume (sd, step, siggnal)
SIM_DESC sd;
@@ -1657,18 +1691,20 @@
asection *s_vectors;
asection *s_data;
+ bfd_size_type size_vec;
s_vectors = bfd_get_section_by_name (prog_bfd, ".vectors");
- bfd_get_section_contents (prog_bfd, s_vectors, &tmp, 30, 1);
+ size_vec = bfd_get_section_size (s_vectors);
+ bfd_get_section_contents (prog_bfd, s_vectors, &tmp, size_vec-2, 1);
ivec = tmp;
- bfd_get_section_contents (prog_bfd, s_vectors, &tmp, 31, 1);
+ bfd_get_section_contents (prog_bfd, s_vectors, &tmp, size_vec-1, 1);
ivec |= (unsigned short) tmp << 8;
/* we need to do this cause gdb somehow
puts ".data" into .bss */
s_data = bfd_get_section_by_name (prog_bfd, ".data");
- if (s_data->flags & SEC_LOAD)
+ if (s_data && s_data->flags & SEC_LOAD)
{
char *buffer;
#if 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment