Move utilities into separate file.
This commit is contained in:
parent
7eec63c431
commit
0f15fd3e21
2
Makefile
2
Makefile
|
@ -25,7 +25,7 @@ clean:
|
||||||
|
|
||||||
.SUFFIXES: .c .o
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o
|
mspdebug: main.o fet.o rf2500.o dis.o uif.o ihex.o elf32.o stab.o util.o
|
||||||
$(CC) $(CFLAGS) -o $@ $^ -lusb
|
$(CC) $(CFLAGS) -o $@ $^ -lusb
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
|
|
3
dis.c
3
dis.c
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "dis.h"
|
#include "dis.h"
|
||||||
#include "stab.h"
|
#include "stab.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Disassembler
|
/* Disassembler
|
||||||
|
@ -429,8 +430,6 @@ int dis_decode(u_int8_t *code, u_int16_t offset, u_int16_t len,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
|
|
||||||
|
|
||||||
/* Return the mnemonic for an operation, if possible.
|
/* Return the mnemonic for an operation, if possible.
|
||||||
*
|
*
|
||||||
* If the argument is not a valid operation, this function returns the
|
* If the argument is not a valid operation, this function returns the
|
||||||
|
|
5
fet.c
5
fet.c
|
@ -26,10 +26,9 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
#define ARRAY_LEN(a) ((sizeof(a)) / sizeof((a)[0]))
|
|
||||||
|
|
||||||
static const struct fet_transport *fet_transport;
|
static const struct fet_transport *fet_transport;
|
||||||
static int fet_is_rf2500;
|
static int fet_is_rf2500;
|
||||||
|
|
||||||
|
@ -551,8 +550,6 @@ static const struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void hexdump(int addr, const u_int8_t *data, int len);
|
|
||||||
|
|
||||||
static int do_identify(void)
|
static int do_identify(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
39
main.c
39
main.c
|
@ -28,41 +28,10 @@
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "binfile.h"
|
#include "binfile.h"
|
||||||
#include "stab.h"
|
#include "stab.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static const struct device *msp430_dev;
|
static const struct device *msp430_dev;
|
||||||
|
|
||||||
void hexdump(int addr, const u_int8_t *data, int len)
|
|
||||||
{
|
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
while (offset < len) {
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
/* Address label */
|
|
||||||
printf(" %04x:", offset + addr);
|
|
||||||
|
|
||||||
/* Hex portion */
|
|
||||||
for (i = 0; i < 16 && offset + i < len; i++)
|
|
||||||
printf(" %02x",
|
|
||||||
((const unsigned char *)data)[offset + i]);
|
|
||||||
for (j = i; j < 16; j++)
|
|
||||||
printf(" ");
|
|
||||||
|
|
||||||
/* Printable characters */
|
|
||||||
printf(" |");
|
|
||||||
for (j = 0; j < i; j++) {
|
|
||||||
int c = ((const unsigned char *)data)[offset + j];
|
|
||||||
|
|
||||||
printf("%c", (c >= 32 && c <= 126) ? c : '.');
|
|
||||||
}
|
|
||||||
for (; j < 16; j++)
|
|
||||||
printf(" ");
|
|
||||||
printf("|\n");
|
|
||||||
|
|
||||||
offset += i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Command-line interface
|
* Command-line interface
|
||||||
*/
|
*/
|
||||||
|
@ -551,13 +520,11 @@ static const struct command all_commands[] = {
|
||||||
" Load symbols from the given file.\n"},
|
" Load symbols from the given file.\n"},
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUM_COMMANDS (sizeof(all_commands) / sizeof(all_commands[0]))
|
|
||||||
|
|
||||||
const struct command *find_command(const char *name)
|
const struct command *find_command(const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_COMMANDS; i++)
|
for (i = 0; i < ARRAY_LEN(all_commands); i++)
|
||||||
if (!strcasecmp(name, all_commands[i].name))
|
if (!strcasecmp(name, all_commands[i].name))
|
||||||
return &all_commands[i];
|
return &all_commands[i];
|
||||||
|
|
||||||
|
@ -581,7 +548,7 @@ static int cmd_help(char **arg)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
printf("Available commands:");
|
printf("Available commands:");
|
||||||
for (i = 0; i < NUM_COMMANDS; i++)
|
for (i = 0; i < ARRAY_LEN(all_commands); i++)
|
||||||
printf(" %s", all_commands[i].name);
|
printf(" %s", all_commands[i].name);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Type \"help <command>\" for more information.\n");
|
printf("Type \"help <command>\" for more information.\n");
|
||||||
|
|
3
rf2500.c
3
rf2500.c
|
@ -21,8 +21,7 @@
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
|
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
#include "util.h"
|
||||||
extern void hexdump(int addr, const u_int8_t *data, int len);
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* USB transport
|
* USB transport
|
||||||
|
|
3
uif.c
3
uif.c
|
@ -27,8 +27,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
#include "util.h"
|
||||||
extern void hexdump(int addr, const u_int8_t *data, int len);
|
|
||||||
|
|
||||||
static int serial_fd = -1;
|
static int serial_fd = -1;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* MSPDebug - debugging tool for the eZ430
|
||||||
|
* Copyright (C) 2009, 2010 Daniel Beer
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
void hexdump(int addr, const u_int8_t *data, int len)
|
||||||
|
{
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
while (offset < len) {
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
/* Address label */
|
||||||
|
printf(" %04x:", offset + addr);
|
||||||
|
|
||||||
|
/* Hex portion */
|
||||||
|
for (i = 0; i < 16 && offset + i < len; i++)
|
||||||
|
printf(" %02x", data[offset + i]);
|
||||||
|
for (j = i; j < 16; j++)
|
||||||
|
printf(" ");
|
||||||
|
|
||||||
|
/* Printable characters */
|
||||||
|
printf(" |");
|
||||||
|
for (j = 0; j < i; j++) {
|
||||||
|
int c = data[offset + j];
|
||||||
|
|
||||||
|
printf("%c", (c >= 32 && c <= 126) ? c : '.');
|
||||||
|
}
|
||||||
|
for (; j < 16; j++)
|
||||||
|
printf(" ");
|
||||||
|
printf("|\n");
|
||||||
|
|
||||||
|
offset += i;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* MSPDebug - debugging tool for the eZ430
|
||||||
|
* Copyright (C) 2009, 2010 Daniel Beer
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UTIL_H_
|
||||||
|
#define UTIL_H_
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
void hexdump(int addr, const u_int8_t *data, int len);
|
||||||
|
|
||||||
|
#define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue