Fixed compiler warnings

This commit is contained in:
Bart Trzynadlowski 2016-03-21 04:02:14 +00:00
parent 8f87bb1698
commit 27c20ff5e5

View file

@ -30,6 +30,7 @@
* not sure whether any other kinds of instructions need checking. * not sure whether any other kinds of instructions need checking.
*/ */
#include <cstdint>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#ifdef STANDALONE #ifdef STANDALONE
@ -37,7 +38,7 @@
#endif #endif
#include "Supermodel.h" #include "Supermodel.h"
#define DISASM_VERSION "1.0" #define DISASM_VERSION "1.1"
/****************************************************************************** /******************************************************************************
@ -91,11 +92,11 @@
* These macros generate instruction words with their associated fields filled * These macros generate instruction words with their associated fields filled
* in with the passed value. * in with the passed value.
*/ */
#define D_OP(op) ((op & 0x3f) << 26) #define D_OP(op) ((uint32_t(op) & 0x3f) << 26)
#define D_XO(xo) ((xo & 0x3ff) << 1) #define D_XO(xo) ((uint32_t(xo) & 0x3ff) << 1)
#define D_RT(r) ((r & 0x1f) << (31 - 10)) #define D_RT(r) ((uint32_t(r) & 0x1f) << (31 - 10))
#define D_RA(r) ((r & 0x1f) << (31 - 15)) #define D_RA(r) ((uint32_t(r) & 0x1f) << (31 - 15))
#define D_UIMM(u) (u & 0xffff) #define D_UIMM(u) (uint32_t(u) & 0xffff)
/* /*
* Macros to Get Field Values * Macros to Get Field Values
@ -212,9 +213,9 @@ enum
*/ */
typedef struct typedef struct
{ {
char *mnem; // mnemonic const char *mnem; // mnemonic
UINT32 match; // bit pattern of instruction after it has been masked uint32_t match; // bit pattern of instruction after it has been masked
UINT32 mask; // mask of variable fields (AND with ~mask to compare w/ uint32_t mask; // mask of variable fields (AND with ~mask to compare w/
// bit pattern to determine a match) // bit pattern to determine a match)
int format; // operand format int format; // operand format
unsigned flags; // flags unsigned flags; // flags
@ -435,7 +436,7 @@ static const IDESCR itab[] =
* *
* Use an index of BI&3 into this table to obtain the CR field bit name. * Use an index of BI&3 into this table to obtain the CR field bit name.
*/ */
static char *crbit[] = { "lt", "gt", "eq", "so" }; static const char *crbit[] = { "lt", "gt", "eq", "so" };
/* /*
* SPR(): * SPR():
@ -527,13 +528,13 @@ static void SPR(char *dest, unsigned spr_field)
* Predecodes the SIMM field for us. If do_unsigned, it is printed as an * Predecodes the SIMM field for us. If do_unsigned, it is printed as an
* unsigned 32-bit integer. * unsigned 32-bit integer.
*/ */
static void DecodeSigned16(char *outbuf, UINT32 op, bool do_unsigned) static void DecodeSigned16(char *outbuf, uint32_t op, bool do_unsigned)
{ {
INT16 s; INT16 s;
s = G_SIMM(op); s = G_SIMM(op);
if (do_unsigned) // sign extend to unsigned 32-bits if (do_unsigned) // sign extend to unsigned 32-bits
sprintf(outbuf, "0x%04X", (UINT32) s); sprintf(outbuf, "0x%04X", (uint32_t) s);
else // print as signed 16 bits else // print as signed 16 bits
{ {
if (s < 0) if (s < 0)
@ -548,9 +549,9 @@ static void DecodeSigned16(char *outbuf, UINT32 op, bool do_unsigned)
* *
* Generate a mask from bit MB through ME (PPC-style backwards bit numbering.) * Generate a mask from bit MB through ME (PPC-style backwards bit numbering.)
*/ */
static UINT32 Mask(unsigned mb, unsigned me) static uint32_t Mask(unsigned mb, unsigned me)
{ {
UINT32 i, mask; uint32_t i, mask;
mb &= 31; mb &= 31;
me &= 31; me &= 31;
@ -574,7 +575,7 @@ static UINT32 Mask(unsigned mb, unsigned me)
* Perform checks on the instruction as required by the flags. Returns 1 if * Perform checks on the instruction as required by the flags. Returns 1 if
* the instruction failed. * the instruction failed.
*/ */
static bool Check(UINT32 op, unsigned flags) static bool Check(uint32_t op, unsigned flags)
{ {
unsigned nb, rt, ra; unsigned nb, rt, ra;
@ -635,9 +636,9 @@ static bool Check(UINT32 op, unsigned flags)
* Handles all simplified instruction forms. Returns 1 if one was decoded, * Handles all simplified instruction forms. Returns 1 if one was decoded,
* otherwise 0 to indicate disassembly should carry on as normal. * otherwise 0 to indicate disassembly should carry on as normal.
*/ */
static bool Simplified(UINT32 op, UINT32 vpc, char *signed16, char *mnem, char *oprs) static bool Simplified(uint32_t op, uint32_t vpc, char *signed16, char *mnem, char *oprs)
{ {
UINT32 value, disp; uint32_t value, disp;
value = G_SIMM(op); // value is fully sign-extended SIMM field value = G_SIMM(op); // value is fully sign-extended SIMM field
if (value & 0x8000) if (value & 0x8000)
@ -807,12 +808,11 @@ static bool Simplified(UINT32 op, UINT32 vpc, char *signed16, char *mnem, char *
* Zero if successful, non-zero if the instruction was unrecognized or * Zero if successful, non-zero if the instruction was unrecognized or
* had an invalid form (see note above in function description.) * had an invalid form (see note above in function description.)
*/ */
bool DisassemblePowerPC(UINT32 op, UINT32 vpc, char *mnem, char *oprs, bool DisassemblePowerPC(uint32_t op, uint32_t vpc, char *mnem, char *oprs,
bool simplify) bool simplify)
{ {
char signed16[12]; char signed16[12];
UINT32 disp; uint32_t disp;
int i;
mnem[0] = '\0'; // so we can use strcat() mnem[0] = '\0'; // so we can use strcat()
oprs[0] = '\0'; oprs[0] = '\0';
@ -837,7 +837,7 @@ bool DisassemblePowerPC(UINT32 op, UINT32 vpc, char *mnem, char *oprs,
* Search for the instruction in the list and print it if there's a match * Search for the instruction in the list and print it if there's a match
*/ */
for (i = 0; i < sizeof(itab) / sizeof(IDESCR); i++) for (size_t i = 0; i < sizeof(itab) / sizeof(IDESCR); i++)
{ {
if ((op & ~itab[i].mask) == itab[i].match) // check for match if ((op & ~itab[i].mask) == itab[i].match) // check for match
{ {
@ -974,7 +974,7 @@ bool DisassemblePowerPC(UINT32 op, UINT32 vpc, char *mnem, char *oprs,
if (G_RA(op)) if (G_RA(op))
sprintf(oprs, "r%d,%s(r%d)", G_RT(op), signed16, G_RA(op)); sprintf(oprs, "r%d,%s(r%d)", G_RT(op), signed16, G_RA(op));
else else
sprintf(oprs, "r%d,0x%08X", G_RT(op), (UINT32) ((INT16) G_D(op))); sprintf(oprs, "r%d,0x%08X", G_RT(op), (uint32_t) ((INT16) G_D(op)));
break; break;
case F_RT_D_RA: case F_RT_D_RA:
@ -985,7 +985,7 @@ bool DisassemblePowerPC(UINT32 op, UINT32 vpc, char *mnem, char *oprs,
if (G_RA(op)) if (G_RA(op))
sprintf(oprs, "f%d,%s(r%d)", G_RT(op), signed16, G_RA(op)); sprintf(oprs, "f%d,%s(r%d)", G_RT(op), signed16, G_RA(op));
else else
sprintf(oprs, "f%d,0x%08X", G_RT(op), (UINT32) ((INT16) G_D(op))); sprintf(oprs, "f%d,0x%08X", G_RT(op), (uint32_t) ((INT16) G_D(op)));
break; break;
case F_FRT_D_RA: case F_FRT_D_RA:
@ -1111,7 +1111,7 @@ bool DisassemblePowerPC(UINT32 op, UINT32 vpc, char *mnem, char *oprs,
static void PrintUsage(void) static void PrintUsage(void)
{ {
puts("ppcd Version "DISASM_VERSION" by Bart Trzynadlowski: PowerPC 603e Disassembler"); puts("ppcd Version " DISASM_VERSION " by Bart Trzynadlowski: PowerPC 603e Disassembler");
puts("Usage: ppcd <file> [options]"); puts("Usage: ppcd <file> [options]");
puts("Options: -?,-h Show this help text"); puts("Options: -?,-h Show this help text");
puts(" -s <offset> Start offset (hexadecimal)"); puts(" -s <offset> Start offset (hexadecimal)");
@ -1133,9 +1133,9 @@ int main(int argc, char **argv)
{ {
char mnem[16], oprs[48]; char mnem[16], oprs[48];
FILE *fp; FILE *fp;
UINT8 *buffer; uint8_t *buffer;
unsigned i, fsize, start = 0, len, org, file = 0; unsigned i, fsize, start = 0, len, org, file = 0;
UINT32 op; uint32_t op;
bool len_specified = 0, org_specified = 0, little = 0, simple = 1; bool len_specified = 0, org_specified = 0, little = 0, simple = 1;
char *c; char *c;
@ -1208,13 +1208,13 @@ int main(int argc, char **argv)
fsize = ftell(fp); fsize = ftell(fp);
rewind(fp); rewind(fp);
if ((buffer = (UINT8 *) calloc(fsize, sizeof(UINT8))) == NULL) if ((buffer = (uint8_t *) calloc(fsize, sizeof(uint8_t))) == NULL)
{ {
fprintf(stderr, "ppcd: not enough memory to load input file: %s, %lu bytes\n", argv[file], (unsigned long) fsize); fprintf(stderr, "ppcd: not enough memory to load input file: %s, %lu bytes\n", argv[file], (unsigned long) fsize);
fclose(fp); fclose(fp);
exit(1); exit(1);
} }
fread(buffer, sizeof(UINT8), fsize, fp); fread(buffer, sizeof(uint8_t), fsize, fp);
fclose(fp); fclose(fp);
if (!len_specified) if (!len_specified)