diff --git a/src/arch/sparc.c b/src/arch/sparc.c index 059dd81..762213d 100644 --- a/src/arch/sparc.c +++ b/src/arch/sparc.c @@ -65,6 +65,8 @@ ArchPlugin arch_plugin = /* sparc_write */ static int _write_loadstore(ArchPlugin * plugin, ArchInstruction * instruction, ArchInstructionCall * call, uint32_t * opcode); +static int _write_sethi(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call, uint32_t * opcode); static int _sparc_write(ArchPlugin * plugin, ArchInstruction * instruction, ArchInstructionCall * call) @@ -74,6 +76,9 @@ static int _sparc_write(ArchPlugin * plugin, ArchInstruction * instruction, if((opcode & 0xc0000000) == 0xc0000000 && _write_loadstore(plugin, instruction, call, &opcode) != 0) return -1; + else if((opcode & 0x01000000) == 0x01000000 && _write_sethi(plugin, + instruction, call, &opcode) != 0) + return -1; /* FIXME implement the rest */ opcode = _htob32(opcode); if(fwrite(&opcode, sizeof(opcode), 1, plugin->helper->fp) != 1) @@ -166,3 +171,28 @@ static int _write_loadstore(ArchPlugin * plugin, ArchInstruction * instruction, *opcode |= (rd | rs1 | rs2); return 0; } + +static int _write_sethi(ArchPlugin * plugin, ArchInstruction * instruction, + ArchInstructionCall * call, uint32_t * opcode) +{ + ArchPluginHelper * helper = plugin->helper; + uint32_t rd; + uint32_t value; + char const * name; + ArchRegister * ar; + + /* value */ + if(AO_GET_TYPE(instruction->op1) != AOT_IMMEDIATE) + return -1; + value = (call->operands[0].value.immediate.value >> 10); + /* rd */ + if(AO_GET_TYPE(instruction->op2) != AOT_REGISTER) + return -1; + name = call->operands[1].value._register.name; + if((ar = helper->get_register_by_name_size(helper->arch, + name, 32)) == NULL) + return -1; + rd = (ar->id << 25); + *opcode |= (rd | value); + return 0; +} diff --git a/test/sparc.S b/test/sparc.S index 0a562d5..c657abc 100644 --- a/test/sparc.S +++ b/test/sparc.S @@ -48,7 +48,7 @@ sdiv %r29, -$23, %r19 sdivcc %r16, %r26, %r27 sdivcc %r29, -$23, %r19 - sethi $0x87654321, %r2 + sethi $0x87654321, %r2 /* 0x0521d950 */ smul %r16, %r26, %r27 smul %r29, -$23, %r19 smulcc %r16, %r26, %r27