Line 26... |
Line 26... |
|
|
#include <ctype.h>
|
#include <ctype.h>
|
#include <string.h>
|
#include <string.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
|
|
CONST unsigned int num_opcodes = (((sizeof or32_opcodes) / (sizeof or32_opcodes[0])) - 1);
|
|
|
|
#define EXTEND29(x) ((x) & 0x10000000 ? ((x) | 0xf0000000) : ((x)))
|
#define EXTEND29(x) ((x) & 0x10000000 ? ((x) | 0xf0000000) : ((x)))
|
|
|
/* Calculates instruction length in bytes. Either 2 or 4 for OR16
|
|
and always 4 for OR32. */
|
|
int insn_len (char *insn)
|
|
{
|
|
CONST struct or32_opcode *pinsn;
|
|
char *enc;
|
|
int len = 0;
|
|
|
|
for(pinsn = or32_opcodes; strlen(pinsn->name); pinsn++) {
|
|
if (strcmp(pinsn->name, insn) == 0) {
|
|
for (enc = pinsn->encoding; *enc != '\0'; enc++)
|
|
if ((*enc == '0') && (*(enc+1) == 'x')) {
|
|
len += 4;
|
|
enc += 2;
|
|
}
|
|
else if (!isspace(*enc))
|
|
len++;
|
|
return len / 8;
|
|
}
|
|
}
|
|
printf("insn_len(%s): Unknown instruction.\n", insn);
|
|
exit(1);
|
|
}
|
|
|
|
/* Now find the four bytes of INSN_CH and put them in *INSN. */
|
/* Now find the four bytes of INSN_CH and put them in *INSN. */
|
static void
|
static void
|
find_bytes_big (insn_ch, insn)
|
find_bytes_big (insn_ch, insn)
|
unsigned char *insn_ch;
|
unsigned char *insn_ch;
|
unsigned long *insn;
|
unsigned long *insn;
|
Line 69... |
Line 43... |
#if DEBUG
|
#if DEBUG
|
printf("find_bytes_big3: %x\n", *insn);
|
printf("find_bytes_big3: %x\n", *insn);
|
#endif
|
#endif
|
}
|
}
|
|
|
/* Is individual insn's operand signed or unsigned? */
|
|
int letter_signed(char l)
|
|
{
|
|
struct or32_letter *pletter;
|
|
|
|
for(pletter = or32_letters; pletter->letter != '\0'; pletter++)
|
|
if (pletter->letter == l)
|
|
return pletter->sign;
|
|
|
|
printf("letter_signed(%c): Unknown letter.\n", l);
|
|
return 0;
|
|
}
|
|
|
|
/* Number of letters in the individual lettered operand. */
|
|
int letter_range(char l)
|
|
{
|
|
CONST struct or32_opcode *pinsn;
|
|
char *enc;
|
|
int range = 0;
|
|
|
|
for(pinsn = or32_opcodes; strlen(pinsn->name); pinsn++) {
|
|
if (strchr(pinsn->encoding,l)) {
|
|
for (enc = pinsn->encoding; *enc != '\0'; enc++)
|
|
if ((*enc == '0') && (*(enc+1) == 'x')) {
|
|
enc += 2;
|
|
}
|
|
else if (*enc == l)
|
|
range++;
|
|
return range;
|
|
}
|
|
}
|
|
printf("\nABORT: letter_range(%c): Never used letter.\n", l);
|
|
exit(1);
|
|
}
|
|
|
|
static void
|
static void
|
find_bytes_little (insn_ch, insn)
|
find_bytes_little (insn_ch, insn)
|
unsigned char *insn_ch;
|
unsigned char *insn_ch;
|
unsigned long *insn;
|
unsigned long *insn;
|
{
|
{
|
Line 144... |
Line 83... |
#if DEBUG
|
#if DEBUG
|
printf("or32_extract: %c %x ", param_ch, param_pos);
|
printf("or32_extract: %c %x ", param_ch, param_pos);
|
#endif
|
#endif
|
opc_pos = 32;
|
opc_pos = 32;
|
for (enc = enc_initial; *enc != '\0'; )
|
for (enc = enc_initial; *enc != '\0'; )
|
if ((*enc == '0') && (*(enc+1) == 'x')) {
|
if ((*enc == '0') && (*(enc+1) == 'x'))
|
|
{
|
opc_pos -= 4;
|
opc_pos -= 4;
|
if ((param_ch == '0') || (param_ch == '1')) {
|
if ((param_ch == '0') || (param_ch == '1'))
|
|
{
|
unsigned long tmp = strtol(enc, NULL, 16);
|
unsigned long tmp = strtol(enc, NULL, 16);
|
#if DEBUG
|
#if DEBUG
|
printf(" enc=%s, tmp=%x ", enc, tmp);
|
printf(" enc=%s, tmp=%x ", enc, tmp);
|
#endif
|
#endif
|
if (param_ch == '0')
|
if (param_ch == '0')
|
tmp = 15 - tmp;
|
tmp = 15 - tmp;
|
ret |= tmp << opc_pos;
|
ret |= tmp << opc_pos;
|
}
|
}
|
enc += 3;
|
enc += 3;
|
}
|
}
|
else if ((*enc == '0') || (*enc == '1')) {
|
else if ((*enc == '0') || (*enc == '1'))
|
|
{
|
opc_pos--;
|
opc_pos--;
|
if (param_ch == *enc)
|
if (param_ch == *enc)
|
ret |= 1 << opc_pos;
|
ret |= 1 << opc_pos;
|
enc++;
|
enc++;
|
}
|
}
|
else if (*enc == param_ch) {
|
else if (*enc == param_ch)
|
|
{
|
opc_pos--;
|
opc_pos--;
|
param_pos--;
|
param_pos--;
|
#if DEBUG
|
#if DEBUG
|
printf("\n ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
|
printf("\n ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
|
#endif
|
#endif
|
ret += ((insn >> opc_pos) & 0x1) << param_pos;
|
ret += ((insn >> opc_pos) & 0x1) << param_pos;
|
if (!param_pos && letter_signed(param_ch) && ret >> (letter_range(param_ch) - 1)) {
|
if (!param_pos && letter_signed(param_ch) && ret >> (letter_range(param_ch) - 1))
|
|
{
|
#if DEBUG
|
#if DEBUG
|
printf("\n ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
|
printf("\n ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
|
#endif
|
#endif
|
ret |= 0xffffffff << letter_range(param_ch);
|
ret |= 0xffffffff << letter_range(param_ch);
|
#if DEBUG
|
#if DEBUG
|
printf("\n after conversion to signed: ret=%x\n", ret);
|
printf("\n after conversion to signed: ret=%x\n", ret);
|
#endif
|
#endif
|
}
|
}
|
enc++;
|
enc++;
|
}
|
}
|
else if (isalpha(*enc)) {
|
else if (isalpha(*enc))
|
|
{
|
opc_pos--;
|
opc_pos--;
|
enc++;
|
enc++;
|
}
|
}
|
else if (*enc == '-') {
|
else if (*enc == '-')
|
|
{
|
opc_pos--;
|
opc_pos--;
|
enc++;
|
enc++;
|
}
|
}
|
else
|
else
|
enc++;
|
enc++;
|