to be done at the bytecode and expression level.
svn path=/trunk/yasm/; revision=283
printf("\n***Symbol Table***\n");
symrec_foreach((int (*) (symrec *))symrec_print);
+ sections_parser_finalize(sections);
+
+ printf("Post-parser-finalization:\n");
+ sections_print(sections);
+
if (in_filename)
free(in_filename);
return EXIT_SUCCESS;
unsigned char opcode[3]; /* opcode */
unsigned char opcode_len;
- unsigned char addrsize; /* 0 indicates no override */
+ unsigned char addrsize; /* 0 or =mode_bits => no override */
unsigned char opersize; /* 0 indicates no override */
unsigned char lockrep_pre; /* 0 indicates no prefix */
/* The *FORCED forms are specified in the source as such */
jmprel_opcode_sel op_sel;
- unsigned char addrsize; /* 0 indicates no override */
+ unsigned char addrsize; /* 0 or =mode_bits => no override */
unsigned char opersize; /* 0 indicates no override */
unsigned char lockrep_pre; /* 0 indicates no prefix */
} jmprel;
}
void
-bytecode_print(bytecode *bc)
+bytecode_print(const bytecode *bc)
{
switch (bc->type) {
case BC_EMPTY:
printf("Immediate Value:\n");
printf(" Val=");
if (!bc->data.insn.imm)
- printf("(nil)");
+ printf("(nil)\n");
else {
expr_print(bc->data.insn.imm->val);
printf("\n");
printf("Offset=%lx BITS=%u\n", bc->offset, bc->mode_bits);
}
+static void
+bytecode_parser_finalize_insn(bytecode *bc)
+{
+ effaddr *ea = bc->data.insn.ea;
+
+ if (ea) {
+ if ((ea->disp) && ((!ea->valid_sib && ea->need_sib) ||
+ (!ea->valid_modrm && ea->need_modrm))) {
+ /* First simplify expression to minimize check cost */
+ expr_simplify(ea->disp);
+
+ /* Check validity of effective address and calc R/M bits of
+ * Mod/RM byte and SIB byte. We won't know the Mod field
+ * of the Mod/RM byte until we know more about the
+ * displacement.
+ */
+ if (!expr_checkea(&ea->disp, &bc->data.insn.addrsize,
+ bc->mode_bits, &ea->len, &ea->modrm,
+ &ea->valid_modrm, &ea->need_modrm, &ea->sib,
+ &ea->valid_sib, &ea->need_sib))
+ return; /* failed, don't bother checking rest of insn */
+ }
+ }
+}
+
+void
+bytecode_parser_finalize(bytecode *bc)
+{
+ switch (bc->type) {
+ case BC_EMPTY:
+ /* FIXME: delete it (probably in bytecodes_ level, not here */
+ InternalError(__LINE__, __FILE__,
+ _("got empty bytecode in parser_finalize"));
+ break;
+ case BC_INSN:
+ bytecode_parser_finalize_insn(bc);
+ break;
+ default:
+ break;
+ }
+}
+
bytecode *
bytecodes_append(bytecodehead *headp, bytecode *bc)
{
}
}
+void
+bytecodes_parser_finalize(bytecodehead *headp)
+{
+ bytecode *cur;
+
+ STAILQ_FOREACH(cur, headp, link)
+ bytecode_parser_finalize(cur);
+}
+
dataval *
dataval_new_expr(expr *expn)
{
}
void
-dataval_print(datavalhead *head)
+dataval_print(const datavalhead *head)
{
dataval *cur;
*/
int bytecode_get_offset(section *sect, bytecode *bc, unsigned long *ret_val);
-void bytecode_print(bytecode *bc);
+void bytecode_print(const bytecode *bc);
+
+void bytecode_parser_finalize(bytecode *bc);
/* void bytecodes_initialize(bytecodehead *headp); */
#define bytecodes_initialize(headp) STAILQ_INIT(headp)
void bytecodes_print(const bytecodehead *headp);
+void bytecodes_parser_finalize(bytecodehead *headp);
+
dataval *dataval_new_expr(expr *expn);
dataval *dataval_new_float(floatnum *flt);
dataval *dataval_new_string(char *str_val);
*/
dataval *datavals_append(datavalhead *headp, dataval *dv);
-void dataval_print(datavalhead *head);
+void dataval_print(const datavalhead *head);
#endif
}
void
-sections_print(sectionhead *headp)
+sections_print(const sectionhead *headp)
{
section *cur;
section_print(cur);
}
+void
+sections_parser_finalize(sectionhead *headp)
+{
+ section *cur;
+
+ STAILQ_FOREACH(cur, headp, link)
+ bytecodes_parser_finalize(&cur->bc);
+}
+
bytecodehead *
section_get_bytecodes(section *sect)
{
section *sections_switch(sectionhead *headp, struct objfmt_s *of,
const char *name);
-void sections_print(sectionhead *headp);
+void sections_print(const sectionhead *headp);
+
+void sections_parser_finalize(sectionhead *headp);
bytecodehead *section_get_bytecodes(section *sect);
unsigned char opcode[3]; /* opcode */
unsigned char opcode_len;
- unsigned char addrsize; /* 0 indicates no override */
+ unsigned char addrsize; /* 0 or =mode_bits => no override */
unsigned char opersize; /* 0 indicates no override */
unsigned char lockrep_pre; /* 0 indicates no prefix */
/* The *FORCED forms are specified in the source as such */
jmprel_opcode_sel op_sel;
- unsigned char addrsize; /* 0 indicates no override */
+ unsigned char addrsize; /* 0 or =mode_bits => no override */
unsigned char opersize; /* 0 indicates no override */
unsigned char lockrep_pre; /* 0 indicates no prefix */
} jmprel;
}
void
-bytecode_print(bytecode *bc)
+bytecode_print(const bytecode *bc)
{
switch (bc->type) {
case BC_EMPTY:
printf("Immediate Value:\n");
printf(" Val=");
if (!bc->data.insn.imm)
- printf("(nil)");
+ printf("(nil)\n");
else {
expr_print(bc->data.insn.imm->val);
printf("\n");
printf("Offset=%lx BITS=%u\n", bc->offset, bc->mode_bits);
}
+static void
+bytecode_parser_finalize_insn(bytecode *bc)
+{
+ effaddr *ea = bc->data.insn.ea;
+
+ if (ea) {
+ if ((ea->disp) && ((!ea->valid_sib && ea->need_sib) ||
+ (!ea->valid_modrm && ea->need_modrm))) {
+ /* First simplify expression to minimize check cost */
+ expr_simplify(ea->disp);
+
+ /* Check validity of effective address and calc R/M bits of
+ * Mod/RM byte and SIB byte. We won't know the Mod field
+ * of the Mod/RM byte until we know more about the
+ * displacement.
+ */
+ if (!expr_checkea(&ea->disp, &bc->data.insn.addrsize,
+ bc->mode_bits, &ea->len, &ea->modrm,
+ &ea->valid_modrm, &ea->need_modrm, &ea->sib,
+ &ea->valid_sib, &ea->need_sib))
+ return; /* failed, don't bother checking rest of insn */
+ }
+ }
+}
+
+void
+bytecode_parser_finalize(bytecode *bc)
+{
+ switch (bc->type) {
+ case BC_EMPTY:
+ /* FIXME: delete it (probably in bytecodes_ level, not here */
+ InternalError(__LINE__, __FILE__,
+ _("got empty bytecode in parser_finalize"));
+ break;
+ case BC_INSN:
+ bytecode_parser_finalize_insn(bc);
+ break;
+ default:
+ break;
+ }
+}
+
bytecode *
bytecodes_append(bytecodehead *headp, bytecode *bc)
{
}
}
+void
+bytecodes_parser_finalize(bytecodehead *headp)
+{
+ bytecode *cur;
+
+ STAILQ_FOREACH(cur, headp, link)
+ bytecode_parser_finalize(cur);
+}
+
dataval *
dataval_new_expr(expr *expn)
{
}
void
-dataval_print(datavalhead *head)
+dataval_print(const datavalhead *head)
{
dataval *cur;
*/
int bytecode_get_offset(section *sect, bytecode *bc, unsigned long *ret_val);
-void bytecode_print(bytecode *bc);
+void bytecode_print(const bytecode *bc);
+
+void bytecode_parser_finalize(bytecode *bc);
/* void bytecodes_initialize(bytecodehead *headp); */
#define bytecodes_initialize(headp) STAILQ_INIT(headp)
void bytecodes_print(const bytecodehead *headp);
+void bytecodes_parser_finalize(bytecodehead *headp);
+
dataval *dataval_new_expr(expr *expn);
dataval *dataval_new_float(floatnum *flt);
dataval *dataval_new_string(char *str_val);
*/
dataval *datavals_append(datavalhead *headp, dataval *dv);
-void dataval_print(datavalhead *head);
+void dataval_print(const datavalhead *head);
#endif
printf("\n***Symbol Table***\n");
symrec_foreach((int (*) (symrec *))symrec_print);
+ sections_parser_finalize(sections);
+
+ printf("Post-parser-finalization:\n");
+ sections_print(sections);
+
if (in_filename)
free(in_filename);
return EXIT_SUCCESS;
}
void
-sections_print(sectionhead *headp)
+sections_print(const sectionhead *headp)
{
section *cur;
section_print(cur);
}
+void
+sections_parser_finalize(sectionhead *headp)
+{
+ section *cur;
+
+ STAILQ_FOREACH(cur, headp, link)
+ bytecodes_parser_finalize(&cur->bc);
+}
+
bytecodehead *
section_get_bytecodes(section *sect)
{
section *sections_switch(sectionhead *headp, struct objfmt_s *of,
const char *name);
-void sections_print(sectionhead *headp);
+void sections_print(const sectionhead *headp);
+
+void sections_parser_finalize(sectionhead *headp);
bytecodehead *section_get_bytecodes(section *sect);