Line 39... |
Line 39... |
unsigned long insn_mask;
|
unsigned long insn_mask;
|
int in_pass;
|
int in_pass;
|
} *ti;
|
} *ti;
|
|
|
static char *in_file;
|
static char *in_file;
|
|
unsigned long op[MAX_OPERANDS];
|
|
int num_op;
|
|
|
inline void debug(int level, const char *format, ...)
|
inline void debug(int level, const char *format, ...)
|
{
|
{
|
char *p;
|
char *p;
|
va_list ap;
|
va_list ap;
|
Line 57... |
Line 59... |
fflush(stdout);
|
fflush(stdout);
|
free(p);
|
free(p);
|
#endif
|
#endif
|
}
|
}
|
|
|
|
static int olevel;
|
|
|
|
char *replace_operands (FILE *fo, char *str) {
|
|
int replace = 0;
|
|
if (*str == '}') {olevel--;}
|
|
else if (*str == '{') {olevel++;}
|
|
else if (strncmp ("eval_operand", str, 12) == 0) {
|
|
replace = 1; str += 12;
|
|
} else if (strncmp ("set_operand", str, 11) == 0) {
|
|
replace = 2; str += 11;
|
|
}
|
|
if (replace) {
|
|
int width, oper;
|
|
sscanf (str, "%i(%i", &width, &oper);
|
|
while (*str && *str != '(') str++;
|
|
while (*str && *str != ',') str++;
|
|
str++;
|
|
if (replace == 1) {
|
|
if (op[oper] & OPTYPE_DIS) {
|
|
fprintf (fo, "eval_mem%i (%c", width, 'a' + oper);
|
|
} else {
|
|
if (op[oper] & OPTYPE_REG) {
|
|
fprintf (fo, "eval_reg%i (%c", width, 'a' + oper);
|
|
} else {
|
|
fprintf (fo, "(%c", 'a' + oper);
|
|
}
|
|
}
|
|
} else {
|
|
op[oper] |= OPTYPE_DST;
|
|
if (op[oper] & OPTYPE_DIS) {
|
|
fprintf (fo, "set_mem%i(%c,", width, 'a' + oper);
|
|
} else if (op[oper] & OPTYPE_REG) {
|
|
fprintf (fo, "set_reg%i(%c,",width, 'a' + oper);
|
|
} else {
|
|
fprintf (stderr, "Invalid operand type.\n");
|
|
exit (1);
|
|
}
|
|
while (*str != ',') str = replace_operands (fo, str) + 1;
|
|
}
|
|
while (*str && *str != ')') str++;
|
|
if (op[oper] & OPTYPE_DIS) fprintf (fo, ", &breakpoint)");
|
|
else fprintf (fo, ")");
|
|
} else {
|
|
fputc (*str, fo);
|
|
}
|
|
return str;
|
|
}
|
|
|
int output_function (FILE *fo, const char *func_name, int level)
|
int output_function (FILE *fo, const char *func_name, int level)
|
{
|
{
|
FILE *fi;
|
FILE *fi;
|
if ((fi = fopen (in_file, "rt")) == NULL) return 1;
|
if ((fi = fopen (in_file, "rt")) == NULL) return 1;
|
while (!feof (fi)) {
|
while (!feof (fi)) {
|
Line 75... |
Line 125... |
while (*s && *s != ')') s++;
|
while (*s && *s != ')') s++;
|
*s = 0;
|
*s = 0;
|
while (isspace(*(s - 1))) s--;
|
while (isspace(*(s - 1))) s--;
|
*s = 0;
|
*s = 0;
|
if (strcmp (str, func_name) == 0) {
|
if (strcmp (str, func_name) == 0) {
|
char c;
|
olevel = 1;
|
int olevel = 1;
|
|
str += strlen (str) + 1;
|
str += strlen (str) + 1;
|
while (isspace (*str)) str++;
|
while (isspace (*str)) str++;
|
s = str;
|
s = str;
|
while (*s && *s != '\n' && *s != '\r') s++;
|
while (*s && *s != '\n' && *s != '\r') s++;
|
*s = 0;
|
*s = 0;
|
Line 88... |
Line 137... |
*s = 0;
|
*s = 0;
|
fprintf (fo, "%s", str);
|
fprintf (fo, "%s", str);
|
fprintf (fo, " /* \"%s\" */\n", func_name);
|
fprintf (fo, " /* \"%s\" */\n", func_name);
|
SHIFT;
|
SHIFT;
|
do {
|
do {
|
c = fgetc (fi);
|
fgets (line, sizeof (line), fi);
|
if (c == '}') {olevel--;}
|
line[sizeof(line) - 1] = 0;
|
else if (c == '{') {olevel++;}
|
for (str = line; *str; str++) {
|
fputc (c, fo);
|
str = replace_operands (fo, str);
|
if (c == '\n') SHIFT;
|
}
|
|
SHIFT;
|
} while (olevel);
|
} while (olevel);
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
}
|
}
|
Line 144... |
Line 194... |
firstd = 0;
|
firstd = 0;
|
dis = 1;
|
dis = 1;
|
} else
|
} else
|
{
|
{
|
if (dis && (opd->type & OPTYPE_REG)) {
|
if (dis && (opd->type & OPTYPE_REG)) {
|
SHIFT; fprintf (fo, "op[%i] = data + eval_reg32 (tmp);\n", no);
|
SHIFT; fprintf (fo, "op[%i] = %c = data + eval_reg32 (tmp);\n", no, 'a' + no);
|
} else {
|
} else {
|
SHIFT; fprintf (fo, "op[%i] = tmp;\n", no);
|
SHIFT; fprintf (fo, "op[%i] = %c = tmp;\n", no, 'a' + no);
|
}
|
}
|
SHIFT; fprintf (fo, "op[%i + MAX_OPERANDS] = 0x%08x;\n", no, opd->type | (dis ? OPTYPE_DIS : 0));
|
SHIFT; fprintf (fo, "op[%i + MAX_OPERANDS] = 0x%08x;\n", no, opd->type | (dis ? OPTYPE_DIS : 0));
|
|
op[no] = opd->type | (dis ? OPTYPE_DIS : 0);
|
no++;
|
no++;
|
firstd = 1;
|
firstd = 1;
|
dis = 0;
|
dis = 0;
|
}
|
}
|
if(opd->type & OPTYPE_LAST) {
|
if(opd->type & OPTYPE_LAST) {
|
SHIFT; fprintf (fo, "num_op = %i;\n", no);
|
SHIFT; fprintf (fo, "num_op = %i;\n", no);
|
|
num_op = no;
|
return;
|
return;
|
}
|
}
|
opd++;
|
opd++;
|
}
|
}
|
SHIFT; fprintf (fo, "num_op = %i;\n", no);
|
SHIFT; fprintf (fo, "num_op = %i;\n", no);
|
}
|
}
|
|
|
int output_call (FILE *fo, int index, int level)
|
int output_call (FILE *fo, int index, int level)
|
{
|
{
|
|
int i;
|
|
printf ("%i:%s\n", index, insn_name (index));
|
fprintf (fo, "{\n");
|
fprintf (fo, "{\n");
|
level++;
|
level++;
|
if (index >= 0) {
|
if (index >= 0) {
|
SHIFT; fprintf (fo, "unsigned long data = 0, tmp = 0, nbits = 0;\n");
|
SHIFT; fprintf (fo, "unsigned long data, tmp;\n");
|
|
SHIFT; fprintf (fo, "unsigned long a, b, c; /* operands */\n");
|
}
|
}
|
SHIFT; fprintf (fo, "insn_index = %i; /* \"%s\" */\n", index, insn_name (index));
|
|
if (index >= 0) {
|
if (index >= 0) {
|
SHIFT; fprintf (fo, "op = &cur->op[0];\n");
|
SHIFT; fprintf (fo, "insn_index = %i; /* \"%s\" */\n", index, insn_name (index));
|
//SHIFT; fprintf (fo, "eval_operands (insn, insn_index, &breakpoint);\n");
|
|
gen_eval_operands (fo, index, level);
|
gen_eval_operands (fo, index, level);
|
|
} else {
|
|
SHIFT; fprintf (fo, "/* insn_index = -1 by default */\n");
|
}
|
}
|
SHIFT;
|
SHIFT;
|
if (index < 0) output_function (fo, "l_invalid", level);
|
if (index < 0) output_function (fo, "l_invalid", level);
|
else output_function (fo, or32_opcodes[index].function_name, level);
|
else output_function (fo, or32_opcodes[index].function_name, level);
|
fprintf (fo, "\n");
|
printf ("\n");
|
|
for (i = 0; i < num_op; i++)
|
|
if (op[i] & OPTYPE_DST) {
|
|
SHIFT; fprintf (fo, "IFF (config.cpu.dependstats) op[%i + MAX_OPERANDS] |= OPTYPE_DST;\n", i);
|
|
}
|
level--;
|
level--;
|
SHIFT; fprintf (fo, "}");
|
SHIFT; fprintf (fo, "}");
|
return 0;
|
return 0;
|
}
|
}
|
|
|
static int generate_header (FILE *fo)
|
static int generate_header (FILE *fo)
|
{
|
{
|
fprintf (fo, "/* This file was automatically generated by generate (see cpu/or32/generate.c) */\n\n");
|
fprintf (fo, "/* This file was automatically generated by generate (see cpu/or32/generate.c) */\n\n");
|
fprintf (fo, "static inline void decode_execute (struct iqueue_entry *current, int *breapoint)\n{\n");
|
fprintf (fo, "static inline void decode_execute (struct iqueue_entry *current)\n{\n");
|
fprintf (fo, " unsigned long insn = current->insn;\n");
|
fprintf (fo, " unsigned long insn = current->insn;\n");
|
fprintf (fo, " int insn_index = -1;\n");
|
fprintf (fo, " int insn_index = -1;\n");
|
|
fprintf (fo, " op = &cur->op[0];\n");
|
return 0;
|
return 0;
|
}
|
}
|
|
|
int generate_footer (FILE *fo)
|
int generate_footer (FILE *fo)
|
{
|
{
|
Line 237... |
Line 297... |
if (prev_invalid) {
|
if (prev_invalid) {
|
if (output_call (fo, -1, level)) return 1;
|
if (output_call (fo, -1, level)) return 1;
|
fprintf (fo, " break;\n");
|
fprintf (fo, " break;\n");
|
}
|
}
|
level--;
|
level--;
|
SHIFT;
|
|
if (level > 1)
|
if (level > 1)
|
fprintf (fo, "} break;\n");
|
fprintf (fo, "} break;\n");
|
else
|
else
|
fprintf (fo, "}\n");
|
fprintf (fo, "}\n");
|
} else {
|
} else {
|