Skip to content

Commit

Permalink
xtensa: fix all
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Nov 3, 2024
1 parent 493cdf4 commit c143bc1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 66 deletions.
61 changes: 29 additions & 32 deletions arch/Xtensa/XtensaDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,8 @@ static DecodeStatus readInstruction16(MCInst *MI, const uint8_t *Bytes,
return MCDisassembler_Fail;
}

if (!IsLittleEndian) {
CS_ASSERT(0 && "Big-endian mode currently is not supported!");
} else {
*Insn = readBytes16(MI, Bytes);
*Size = 2;
}
*Insn = readBytes16(MI, Bytes);
*Size = 2;

return MCDisassembler_Success;
}
Expand All @@ -935,14 +931,10 @@ static DecodeStatus readInstruction24(MCInst *MI, const uint8_t *Bytes,
return MCDisassembler_Fail;
}

if (!IsLittleEndian) {
CS_ASSERT("Big-endian mode currently is not supported!");
} else {
if (CheckTIE && (Bytes[0] & 0x8) != 0)
return MCDisassembler_Fail;
*Insn = readBytes24(MI, Bytes);
*Size = 3;
}
if (CheckTIE && (Bytes[0] & 0x8) != 0)
return MCDisassembler_Fail;
*Insn = readBytes24(MI, Bytes);
*Size = 3;

return MCDisassembler_Success;
}
Expand All @@ -959,14 +951,10 @@ static DecodeStatus readInstruction32(MCInst *MI, const uint8_t *Bytes,
return MCDisassembler_Fail;
}

if (!IsLittleEndian) {
CS_ASSERT("Big-endian mode currently is not supported!");
} else {
if ((Bytes[0] & 0x8) == 0)
return MCDisassembler_Fail;
*Insn = readBytes32(MI, Bytes);
*Size = 4;
}
if ((Bytes[0] & 0x8) == 0)
return MCDisassembler_Fail;
*Insn = readBytes32(MI, Bytes);
*Size = 4;

return MCDisassembler_Success;
}
Expand All @@ -983,13 +971,9 @@ static DecodeStatus readInstructionN(const uint8_t *Bytes, size_t BytesLen,
return MCDisassembler_Fail;
}

if (!IsLittleEndian) {
CS_ASSERT("Big-endian mode currently is not supported!");
} else {
*Insn = 0;
for (unsigned i = 0; i < InstSize; i++)
*Insn |= (Bytes[i] << 8 * i);
}
*Insn = 0;
for (unsigned i = 0; i < InstSize; i++)
*Insn |= (Bytes[i] << 8 * i);

*Size = InstSize;
return MCDisassembler_Success;
Expand Down Expand Up @@ -1020,13 +1004,14 @@ static bool hasESP32S3Ops()
{
return true;
}

static bool hasHIFI3()
{
return true;
}
DecodeStatus getInstruction(MCInst *MI, uint64_t *Size, const uint8_t *Bytes,
size_t BytesLen, uint64_t Address, SStream *CS)

static DecodeStatus getInstruction(MCInst *MI, uint64_t *Size,
const uint8_t *Bytes, size_t BytesLen,
uint64_t Address)
{
uint64_t Insn;
DecodeStatus Result;
Expand Down Expand Up @@ -1104,3 +1089,15 @@ DecodeStatus getInstruction(MCInst *MI, uint64_t *Size, const uint8_t *Bytes,
}
return Result;
}

DecodeStatus Xtensa_LLVM_getInstruction(MCInst *MI, uint16_t *size16,
const uint8_t *Bytes,
unsigned BytesSize, uint64_t Address)
{
uint64_t size64;
DecodeStatus status =
getInstruction(MI, &size64, Bytes, BytesSize, Address);
CS_ASSERT_RET_VAL(size64 < 0xffff, MCDisassembler_Fail);
*size16 = size64;
return status;
}
28 changes: 14 additions & 14 deletions arch/Xtensa/XtensaGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7901,8 +7901,8 @@ static void printInstruction(MCInst *MI, uint64_t Address, SStream *O) {
break;
case 11:
// AE_MOVI
printImmOperand_-16_47_1(MI, 1, O);
return;
printImmOperand_minus16_47_1(MI, 1, O);
return;
break;
case 12:
// AE_MULA16X4, AE_MULAF16X4SS, AE_MULAFD24X2_FIR_H, AE_MULAFD24X2_FIR_L,...
Expand Down Expand Up @@ -8119,32 +8119,32 @@ static void printInstruction(MCInst *MI, uint64_t Address, SStream *O) {
break;
case 14:
// AE_L16M_I, AE_L16_I, AE_S16M_L_I, AE_S16_0_I
printImmOperand_-16_14_2(MI, 2, O);
return;
printImmOperand_minus16_14_2(MI, 2, O);
return;
break;
case 15:
// AE_L16M_IU, AE_L16_IP, AE_S16M_L_IU, AE_S16_0_IP
printImmOperand_-16_14_2(MI, 3, O);
return;
printImmOperand_minus16_14_2(MI, 3, O);
return;
break;
case 16:
// AE_L16M_XC, AE_L16M_XU, AE_L16X2M_XC, AE_L16X2M_XU, AE_L16X4_XC, AE_L1...
printOperand(MI, 3, O);
break;
case 17:
// AE_L16X2M_I, AE_L32F24_I, AE_L32M_I, AE_L32_I, AE_S16X2M_I, AE_S24RA64...
printImmOperand_-32_28_4(MI, 2, O);
return;
printImmOperand_minus32_28_4(MI, 2, O);
return;
break;
case 18:
// AE_L16X2M_IU, AE_L32F24_IP, AE_L32M_IU, AE_L32_IP, AE_S16X2M_IU, AE_S2...
printImmOperand_-32_28_4(MI, 3, O);
return;
printImmOperand_minus32_28_4(MI, 3, O);
return;
break;
case 19:
// AE_L16X4_I, AE_L32X2F24_I, AE_L32X2_I, AE_L64_I, AE_LALIGN64_I, AE_S16...
printImmOperand_-64_56_8(MI, 2, O);
return;
printImmOperand_minus64_56_8(MI, 2, O);
return;
break;
case 20:
// AE_L16X4_IP, AE_L32X2F24_IP, AE_L32X2_IP, AE_S16X4_IP, AE_S32X2F24_IP,...
Expand All @@ -8153,8 +8153,8 @@ static void printInstruction(MCInst *MI, uint64_t Address, SStream *O) {
break;
case 21:
// AE_L64_IP, AE_S64_IP
printImmOperand_-64_56_8(MI, 3, O);
return;
printImmOperand_minus64_56_8(MI, 3, O);
return;
break;
case 22:
// AE_LA16X4_IC, AE_LA16X4_IP, AE_LA16X4_RIC, AE_LA16X4_RIP, AE_LA24X2_IC...
Expand Down
8 changes: 4 additions & 4 deletions arch/Xtensa/XtensaGenCSOpGroup.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
Xtensa_OP_GROUP_Imm1n_15_AsmOperand = 15,
Xtensa_OP_GROUP_Imm8_sh8_AsmOperand = 16,
Xtensa_OP_GROUP_Imm1_16_AsmOperand = 17,
Xtensa_OP_GROUP_ImmOperand_-16_14_2 = 18,
Xtensa_OP_GROUP_ImmOperand_-32_28_4 = 19,
Xtensa_OP_GROUP_ImmOperand_-64_56_8 = 20,
Xtensa_OP_GROUP_ImmOperand_minus16_14_2 = 18,
Xtensa_OP_GROUP_ImmOperand_minus32_28_4 = 19,
Xtensa_OP_GROUP_ImmOperand_minus64_56_8 = 20,
Xtensa_OP_GROUP_ImmOperand_0_56_8 = 21,
Xtensa_OP_GROUP_ImmOperand_-16_47_1 = 22,
Xtensa_OP_GROUP_ImmOperand_minus16_47_1 = 22,
Xtensa_OP_GROUP_ImmOperand_0_3_1 = 23,
Xtensa_OP_GROUP_Uimm4_AsmOperand = 24,
Xtensa_OP_GROUP_Imm7_22_AsmOperand = 25,
Expand Down
31 changes: 30 additions & 1 deletion arch/Xtensa/XtensaInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static void printOperand(MCInst *MI, const int op_num, SStream *O)
else
CS_ASSERT("Invalid operand");
}

static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS)
{
Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum);
Expand Down Expand Up @@ -681,6 +680,31 @@ static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum,
printOperand(MI, OpNum, O);
}

#define IMPL_printImmOperand(N, L, H, S) \
static void printImmOperand_##N(MCInst *MI, int OpNum, SStream *O) \
{ \
Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \
OpNum); \
MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \
if (MCOperand_isImm(MC)) { \
int64_t Value = MCOperand_getImm(MC); \
CS_ASSERT((Value >= L && Value <= H && \
((Value % S) == 0)) && \
"Invalid argument"); \
printInt64(O, Value); \
} else { \
printOperand(MI, OpNum, O); \
} \
}

IMPL_printImmOperand(minus64_56_8, -64, 56, 8);
IMPL_printImmOperand(minus32_28_4, -32, 28, 4);
IMPL_printImmOperand(minus16_47_1, -16, 47, 1);
IMPL_printImmOperand(minus16_14_2, -16, 14, 2);
IMPL_printImmOperand(0_56_8, 0, 56, 8);
IMPL_printImmOperand(0_3_1, 0, 3, 1);
IMPL_printImmOperand(0_63_1, 0, 63, 1);

#include "XtensaGenAsmWriter.inc"

static void printInst(MCInst *MI, uint64_t Address, const char *Annot,
Expand Down Expand Up @@ -714,3 +738,8 @@ void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O)
{
printInst(MI, Address, NULL, O);
}

const char *Xtensa_LLVM_getRegisterName(unsigned RegNo)
{
return getRegisterName(RegNo);
}
4 changes: 4 additions & 0 deletions arch/Xtensa/XtensaMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ void Xtensa_reg_access(const cs_insn *insn, cs_regs regs_read,

void Xtensa_add_cs_detail_0(MCInst *MI, xtensa_op_group op_group, int op_num)
{
if (!detail_is_set(MI)) {
return;
}

cs_xtensa_op *xop = Xtensa_get_detail_op(MI, 0);
switch (op_group) {
case Xtensa_OP_GROUP_Operand: {
Expand Down
36 changes: 21 additions & 15 deletions suite/auto-sync/src/autosync/cpptranslator/saved_patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -3433,14 +3433,14 @@
"edit": ""
},
"printBranchTarget": {
"apply_type": "NEW",
"old_hash": "e632d7f4e5e1ab69af65ca0254bb924564ef5a01c2356ad92404fd7c4c3b7590",
"apply_type": "OLD",
"old_hash": "b44eac3a548beca2fc0dbab7136888a138bb82956939ee2d6775715e825d3ed8",
"new_hash": "30a5c55b095e3d7d128f6764a44b3721c391120c1eebda142e8c48581a015c35",
"edit": ""
},
"printCallOperand": {
"apply_type": "NEW",
"old_hash": "d81f1332c969bc840a2cc023df8355a80a07b6383b8d02c9476a993b5e30c114",
"apply_type": "OLD",
"old_hash": "74c10cbd33480583bf9cb16cfeb0255f39f007cc2086d2d366198a6195a48193",
"new_hash": "e6f5a1baa3ab336e904439496e9ab427495257c30b5b4bf30c2e656d491912cc",
"edit": ""
},
Expand Down Expand Up @@ -3518,25 +3518,25 @@
},
"printInst": {
"apply_type": "OLD",
"old_hash": "2a3a80825d189b9d9448677b0a3eb8cc821fbd15eebb623ddde7ba0d49c770af",
"old_hash": "847b1638dc95faa0a1ec26726d737939555436b002a4e1c9a976402e190d901b",
"new_hash": "7f31dabd32046112fe19e125b98a28aef3ddd55fb89387414a3902dec7450cdb",
"edit": ""
},
"printJumpTarget": {
"apply_type": "NEW",
"old_hash": "41ee67cb3706ab05eadf7a65f39e8865017af6ee70474e4973b382824de53359",
"apply_type": "OLD",
"old_hash": "6f6b415c66f99c315ad194dd5baf40f43ad7cae2326ecc4e3bfb38c824f2aff2",
"new_hash": "54fadd3e08a0846250448d4c5002689cc964b13737d9b9c282faeb3124338330",
"edit": ""
},
"printL32RTarget": {
"apply_type": "NEW",
"old_hash": "c264dfe627342dd8336a76c0b502043e9372709ab5494e36f969915e269f4fcb",
"apply_type": "OLD",
"old_hash": "60e841bb8af9939f55f126e972ed9ba8f251fe2d817aa8adde94765fb58cd77b",
"new_hash": "8a5e44a06861b439015f20cfac19090017738f307211042e63838e6d91099315",
"edit": ""
},
"printLoopTarget": {
"apply_type": "NEW",
"old_hash": "e2008f8d4bcce64c331c3495ee7babe5924cb06c09d07c7c2d8f54d5bc93de4a",
"apply_type": "OLD",
"old_hash": "f3c1287796da8ce8515d78be3d6d817bf08a93a14b6bec7363b5823d34d5312c",
"new_hash": "e0cfc237a3f7589e29a888b9b87e7b337eb4084f865c4064266339979739a40a",
"edit": ""
},
Expand All @@ -3548,13 +3548,13 @@
},
"printOffset4m32_AsmOperand": {
"apply_type": "NEW",
"old_hash": "9a1ed8ae267ad1678e7cbce08a6d0a62a9c9afc5fef75cbca906b758866bf961",
"old_hash": "",
"new_hash": "305876681b43dde9508a2727be55953d3faa4d61277604daaccd62ff025ba282",
"edit": ""
},
"printOffset8m16_AsmOperand": {
"apply_type": "NEW",
"old_hash": "156368b8f3d4e3df40fbb8e061b591025490e89cb73eb12ad8415e971a044a37",
"old_hash": "",
"new_hash": "7d1dc598131cde86738fba8a48b108d9ef47f8c1d7c0dfd4bd6c14630b937eea",
"edit": ""
},
Expand All @@ -3566,7 +3566,7 @@
},
"printOffset8m8_AsmOperand": {
"apply_type": "NEW",
"old_hash": "a687c720cc5cdf504e5b8a015c3d356830eb5e3d8d77e0399ce73aa6b5cfadb5",
"old_hash": "",
"new_hash": "ba9e749a819a45c761157999d8da64d0ce36d349e615ea0ee8557895514a7490",
"edit": ""
},
Expand Down Expand Up @@ -3614,7 +3614,7 @@
},
"printOperand": {
"apply_type": "OLD",
"old_hash": "7ecfe056397bacaab5a6ae4d6f70d66d43f795c04167c8aea0bde0f8b999221f",
"old_hash": "73ffe28b1e49daebc32ee4bc16161eb26dbd5eba12b5e0d9d4277244eaa6ae83",
"new_hash": "",
"edit": ""
},
Expand Down Expand Up @@ -3677,6 +3677,12 @@
"old_hash": "a030d6b8a00d4a7823586eda567a8b5033fcaa42d49ac4905755a86ac1e3cb63",
"new_hash": "70af971b7faf90e7127d09f60b897cae8eb097ffd8d1ed3e8c1bb53bd63410c5",
"edit": ""
},
"Xtensa_LLVM_printInstruction": {
"apply_type": "OLD",
"old_hash": "6ca58c91fb8b87d0eb7763591edd07ccc9a8b369cfdf4bb806507ff766ab0fb5",
"new_hash": "",
"edit": ""
}
}
}

0 comments on commit c143bc1

Please sign in to comment.