Support 32 bit and 64 bit decoding with one binary
It is possible to configure the build process such that decoding of 32 bit and 64 bit instructions can be chosen at runtime using an additional parameter of the decode function. The header file is now entirely architecture-independent and no longer required any previous defines. Decoding x86-64 still requires a 64-bit pointer size.
This commit is contained in:
@@ -24,24 +24,40 @@ parse_nibble(const char nibble)
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2 && argc != 3)
|
||||
if (argc != 3 && argc != 4)
|
||||
{
|
||||
printf("usage: %s [instruction bytes] ([repetitions])\n", argv[0]);
|
||||
printf("usage: %s [mode] [instruction bytes] ([repetitions])\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
DecodeMode mode;
|
||||
size_t mode_input = strtoul(argv[1], NULL, 0);
|
||||
if (mode_input == 32)
|
||||
{
|
||||
mode = DECODE_32;
|
||||
}
|
||||
else if (mode_input == 64)
|
||||
{
|
||||
mode = DECODE_64;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown decode mode\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Avoid allocation by transforming hex to binary in-place.
|
||||
uint8_t* code = (uint8_t*) argv[1];
|
||||
uint8_t* code = (uint8_t*) argv[2];
|
||||
uint8_t* code_end = code;
|
||||
char* hex = argv[1];
|
||||
char* hex = argv[2];
|
||||
for (; *hex; hex += 2, code_end++)
|
||||
*code_end = (parse_nibble(hex[0]) << 4) | parse_nibble(hex[1]);
|
||||
|
||||
size_t length = (size_t) (code_end - code);
|
||||
|
||||
size_t repetitions = 1;
|
||||
if (argc >= 3)
|
||||
repetitions = strtoul(argv[2], NULL, 0);
|
||||
if (argc >= 4)
|
||||
repetitions = strtoul(argv[3], NULL, 0);
|
||||
|
||||
struct timespec time_start;
|
||||
struct timespec time_end;
|
||||
@@ -56,7 +72,7 @@ main(int argc, char** argv)
|
||||
while (current_off != length)
|
||||
{
|
||||
size_t remaining = length - current_off;
|
||||
int retval = decode(code + current_off, remaining, &instr);
|
||||
int retval = decode(code + current_off, remaining, mode, &instr);
|
||||
if (retval < 0)
|
||||
goto fail;
|
||||
current_off += retval;
|
||||
|
||||
Reference in New Issue
Block a user