Fixed the helper for register definitions and some warnings

This commit is contained in:
Pierre Pronchery 2011-04-17 00:15:24 +00:00
parent ed661daee0
commit 902c56d564
5 changed files with 25 additions and 41 deletions

View File

@ -24,6 +24,8 @@
/* AsmArch */
/* types */
typedef struct _Arch Arch;
typedef enum _ArchEndian
{
ARCH_ENDIAN_BIG = 0,
@ -142,7 +144,7 @@ typedef uint32_t ArchOperandDefinition;
typedef struct _ArchInstruction
{
char * name;
char const * name;
uint32_t opcode;
ArchOperandDefinition flags;
ArchOperandDefinition op1;
@ -152,29 +154,29 @@ typedef struct _ArchInstruction
typedef struct _ArchInstructionCall
{
char * name;
char const * name;
ArchOperand operands[3];
size_t operands_cnt;
} ArchInstructionCall;
typedef struct _ArchRegister
{
char * name;
char const * name;
uint32_t size;
uint32_t id;
} ArchRegister;
typedef struct _ArchPluginHelper
{
void * priv;
Arch * arch;
/* variables */
char const * filename;
FILE * fp;
/* callbacks */
int32_t (*get_register_by_name_size)(void * priv, char const * name,
uint32_t size);
ArchRegister * (*get_register_by_name_size)(Arch * arch,
char const * name, uint32_t size);
} ArchPluginHelper;
typedef struct _ArchPlugin ArchPlugin;

View File

@ -171,7 +171,7 @@ ArchInstruction * arch_get_instruction_by_opcode(Arch * arch, uint8_t size,
/* arch_get_instruction_by_call */
static int _call_operands(Arch * arch, ArchInstruction * ai,
static int _call_operands(Arch * arch, ArchInstruction * instruction,
ArchInstructionCall * call);
static int _call_operands_dregister(Arch * arch,
ArchOperandDefinition definition, ArchOperand * operand);
@ -188,7 +188,7 @@ ArchInstruction * arch_get_instruction_by_call(Arch * arch,
int found = 0;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, name);
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, call->name);
#endif
for(i = 0; i < arch->instructions_cnt; i++)
{
@ -205,7 +205,7 @@ ArchInstruction * arch_get_instruction_by_call(Arch * arch,
return NULL;
}
static int _call_operands(Arch * arch, ArchInstruction * ai,
static int _call_operands(Arch * arch, ArchInstruction * instruction,
ArchInstructionCall * call)
{
size_t i;
@ -214,13 +214,13 @@ static int _call_operands(Arch * arch, ArchInstruction * ai,
for(i = 0; i < call->operands_cnt; i++)
{
definition = (i == 0) ? ai->op1 : ((i == 1) ? ai->op2
: ai->op3);
definition = (i == 0) ? instruction->op1 : ((i == 1)
? instruction->op2 : instruction->op3);
operand = &call->operands[i];
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() operand %lu, type %u, type %u\n",
__func__, i, AO_GET_TYPE(definition),
AO_GET_TYPE(operand->definition));
AO_GET_TYPE(operand->type));
#endif
if(AO_GET_TYPE(definition) != operand->type)
return -1;
@ -252,7 +252,8 @@ static int _call_operands_dregister(Arch * arch,
uint64_t offset;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() %ld\n", __func__, ao->dereference);
fprintf(stderr, "DEBUG: %s() %ld\n", __func__,
operand->value.dregister.offset);
#endif
if(_call_operands_register(arch, definition, operand) != 0)
return -1;
@ -386,7 +387,7 @@ int arch_init(Arch * arch, char const * filename, FILE * fp)
fprintf(stderr, "DEBUG: %s(\"%s\", %p)\n", __func__, filename,
(void *)fp);
#endif
arch->helper.priv = arch;
arch->helper.arch = arch;
arch->helper.filename = filename;
arch->helper.fp = fp;
arch->helper.get_register_by_name_size = arch_get_register_by_name_size;

View File

@ -20,15 +20,11 @@
# include <stdint.h>
# include <stdio.h>
# include "Asm.h"
# include "Asm/arch.h"
/* Arch */
/* public */
/* types */
typedef struct _Arch Arch;
/* functions */
Arch * arch_new(char const * name);
void arch_delete(Arch * arch);

View File

@ -187,17 +187,20 @@ static int _write_register(ArchPlugin * plugin,
ArchOperandDefinition definition, ArchOperand * operand)
{
ArchPluginHelper * helper = plugin->helper;
ArchOperandDefinition idefinition;
ArchOperand ioperand;
char const * name = operand->value._register.name;
size_t size = AO_GET_SIZE(definition);
ArchRegister * ar;
ArchOperandDefinition idefinition;
ArchOperand ioperand;
if(AO_GET_FLAGS(definition) & AOF_IMPLICIT)
return 0;
if((ar = helper->get_register_by_name_size(helper->arch, name, size))
== NULL)
return -1;
idefinition = AO_IMMEDIATE(0, 0, 8);
memset(&ioperand, 0, sizeof(ioperand));
ioperand.type = AOT_IMMEDIATE;
ioperand.value.immediate.value = helper->get_register_by_name_size(
helper->priv, name, size);
ioperand.value.immediate.value = ar->id;
return _write_immediate(plugin, idefinition, &ioperand);
}

View File

@ -178,24 +178,6 @@ int code_function(Code * code, char const * function)
/* code_instruction */
static int _instruction_fixed(Code * code, ArchInstruction * ai,
ArchOperand ** operands, size_t operands_cnt);
static int _instruction_fixed_immediate(ArchOperand operand, ArchOperand * ao,
uint32_t * pu);
static int _instruction_fixed_register(Code * code, ArchOperand operand,
ArchOperand * ao, uint32_t * pu);
static int _instruction_variable(Code * code, ArchInstruction * ai,
ArchOperand ** operands, size_t operands_cnt);
static int _instruction_variable_dregister(Code * code, ArchInstruction * ai,
ArchOperand operand, ArchOperand * ao);
static int _instruction_variable_immediate(Code * code, ArchInstruction * ai,
ArchOperand operand, void * value, int swap);
static int _instruction_variable_opcode(Code * code, ArchInstruction * ai);
static int _instruction_variable_operand(Code * code, ArchInstruction * ai,
ArchOperand operand, ArchOperand * ao);
static int _instruction_variable_register(Code * code, ArchInstruction * ai,
ArchOperand operand, ArchOperand * ao);
int code_instruction(Code * code, ArchInstructionCall * call)
{
ArchInstruction * ai;