diff options
author | Yuyang Huang <yuyanghuang@google.com> | 2024-04-26 17:58:20 +0900 |
---|---|---|
committer | Yuyang Huang <yuyanghuang@google.com> | 2024-04-26 18:13:16 +0900 |
commit | 6df7e7b215c7573cd2b1160bf6711717e1f8d489 (patch) | |
tree | e41ac5234dc3a2242cb5baea437df5639a1dcf6c | |
parent | 412b010569c0a1f0fcbcc5eca8874784f3e1f484 (diff) | |
download | apf-6df7e7b215c7573cd2b1160bf6711717e1f8d489.tar.gz |
Extend disassembler's JBSMATCH support for multi-byte sequences
Updated the disassembler to enable the JBSMATCH opcode to handle
matching against multiple byte sequences.
Test: TH
Change-Id: Ice21643d9bc144073a75a283262a4721ae5b1196
-rw-r--r-- | disassembler.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/disassembler.c b/disassembler.c index 2de62e2..0929333 100644 --- a/disassembler.c +++ b/disassembler.c @@ -196,13 +196,26 @@ const char* apf_disassemble(const uint8_t* program, uint32_t program_len, uint32 print_opcode("jbseq"); } bprintf("r0, "); - uint32_t cmp_imm = DECODE_IMM(1 << (len_field - 1)); - bprintf("0x%x, ", cmp_imm); - print_jump_target(*ptr2pc + imm + cmp_imm, program_len); + const uint32_t cmp_imm = DECODE_IMM(1 << (len_field - 1)); + const uint32_t cnt = (cmp_imm >> 11) + 1; // 1+, up to 32 fits in u16 + const uint32_t len = cmp_imm & 2047; // 0..2047 + bprintf("0x%x, ", len); + print_jump_target(*ptr2pc + imm + cnt * len, program_len); bprintf(", "); - while (cmp_imm--) { - uint8_t byte = program[(*ptr2pc)++]; - bprintf("%02x", byte); + if (cnt > 1) { + bprintf("{ "); + } + for (uint32_t i = 0; i < cnt; ++i) { + for (uint32_t j = 0; j < len; ++j) { + uint8_t byte = program[(*ptr2pc)++]; + bprintf("%02x", byte); + } + if (i != cnt - 1) { + bprintf(", "); + } + } + if (cnt > 1) { + bprintf(" }"); } break; } |