correctly parse add instruction

This commit is contained in:
nganhkhoa 2024-08-29 15:22:56 +07:00
parent 88b79bccb9
commit 083556f914

View File

@ -43,6 +43,7 @@ struct add {
uint32_t op : 1;
uint32_t s : 1;
uint32_t sig : 5;
uint32_t shift : 2;
uint32_t imm : 12;
uint32_t rn : 5;
uint32_t rd : 5;
@ -54,6 +55,7 @@ struct add to_add(uint32_t inst) {
parsed.op = is_bit_set(inst, 30);
parsed.s = is_bit_set(inst, 29);
parsed.sig = get_bits(inst, 24, 28);
parsed.shift = get_bits(inst, 22, 23);
parsed.imm = get_bits(inst, 10, 21);
parsed.rn = get_bits(inst, 5, 9);
parsed.rd = get_bits(inst, 0, 4);
@ -66,6 +68,7 @@ void from_add(struct add parsed, uint32_t *inst) {
*inst |= parsed.op << 30;
*inst |= parsed.s << 29;
*inst |= parsed.sig << 24;
*inst |= parsed.shift << 22;
*inst |= parsed.imm << 10;
*inst |= parsed.rn << 5;
*inst |= parsed.rd;
@ -83,6 +86,10 @@ int add_imm_set(uint32_t *inst, uint32_t offset) {
uint32_t add_imm_get(uint32_t inst) {
struct add parsed = to_add(inst);
if (parsed.shift != 0) {
printf("add instruction shift != 0 is not supported\n");
*(char*)0 = 0;
}
return parsed.imm;
}