Coverage Report

Created: 2025-08-26 06:30

/src/capstonenext/arch/Mips/MipsMapping.c
Line
Count
Source (jump to first uncovered line)
1
/* Capstone Disassembly Engine */
2
/* By Giovanni Dante Grazioli, deroad <wargio@libero.it>, 2024 */
3
4
#ifdef CAPSTONE_HAS_MIPS
5
6
#include <stdio.h>
7
#include <string.h>
8
9
#include <capstone/capstone.h>
10
#include <capstone/mips.h>
11
12
#include "../../Mapping.h"
13
#include "../../MCDisassembler.h"
14
#include "../../cs_priv.h"
15
#include "../../cs_simple_types.h"
16
17
#include "MipsMapping.h"
18
#include "MipsLinkage.h"
19
#include "MipsDisassembler.h"
20
21
#define GET_REGINFO_ENUM
22
#define GET_REGINFO_MC_DESC
23
#include "MipsGenRegisterInfo.inc"
24
25
#define GET_INSTRINFO_ENUM
26
#include "MipsGenInstrInfo.inc"
27
28
void Mips_init_mri(MCRegisterInfo *MRI)
29
3.73k
{
30
3.73k
  MCRegisterInfo_InitMCRegisterInfo(MRI, MipsRegDesc, sizeof(MipsRegDesc),
31
3.73k
            0, 0, MipsMCRegisterClasses,
32
3.73k
            ARR_SIZE(MipsMCRegisterClasses), 0, 0,
33
3.73k
            MipsRegDiffLists, 0,
34
3.73k
            MipsSubRegIdxLists,
35
3.73k
            ARR_SIZE(MipsSubRegIdxLists), 0);
36
3.73k
}
37
38
const char *Mips_reg_name(csh handle, unsigned int reg)
39
25.4k
{
40
25.4k
  int syntax_opt = ((cs_struct *)(uintptr_t)handle)->syntax;
41
25.4k
  return Mips_LLVM_getRegisterName(reg,
42
25.4k
           syntax_opt & CS_OPT_SYNTAX_NOREGNAME);
43
25.4k
}
44
45
void Mips_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
46
106k
{
47
  // Not used by Mips. Information is set after disassembly.
48
106k
}
49
50
static const char *const insn_name_maps[] = {
51
#include "MipsGenCSMappingInsnName.inc"
52
};
53
54
#ifndef CAPSTONE_DIET
55
static const name_map insn_alias_mnem_map[] = {
56
#include "MipsGenCSAliasMnemMap.inc"
57
  // The followings aliases are not generated by LLVM table gen.
58
  { MIPS_INS_ALIAS_B, "b" }, // beq
59
  { MIPS_INS_ALIAS_BEQZ, "beqz" }, // beq
60
  { MIPS_INS_ALIAS_BNEZ, "bnez" }, // bne
61
  { MIPS_INS_ALIAS_LI, "li" }, // addiu
62
  { MIPS_INS_ALIAS_END, NULL },
63
};
64
#endif
65
const char *Mips_insn_name(csh handle, unsigned int id)
66
106k
{
67
106k
#ifndef CAPSTONE_DIET
68
106k
  if (id < MIPS_INS_ALIAS_END && id > MIPS_INS_ALIAS_BEGIN) {
69
0
    if (id - MIPS_INS_ALIAS_BEGIN >= ARR_SIZE(insn_alias_mnem_map))
70
0
      return NULL;
71
72
0
    return insn_alias_mnem_map[id - MIPS_INS_ALIAS_BEGIN - 1].name;
73
0
  }
74
106k
  if (id >= MIPS_INS_ENDING)
75
0
    return NULL;
76
77
106k
  if (id < ARR_SIZE(insn_name_maps))
78
106k
    return insn_name_maps[id];
79
  // not found
80
0
  return NULL;
81
#else
82
  return NULL;
83
#endif
84
106k
}
85
86
#ifndef CAPSTONE_DIET
87
static const name_map group_name_maps[] = {
88
  { MIPS_GRP_INVALID, NULL },
89
90
  { MIPS_GRP_JUMP, "jump" },
91
  { MIPS_GRP_CALL, "call" },
92
  { MIPS_GRP_RET, "return" },
93
  { MIPS_GRP_INT, "int" },
94
  { MIPS_GRP_IRET, "iret" },
95
  { MIPS_GRP_PRIVILEGE, "privilege" },
96
  { MIPS_GRP_BRANCH_RELATIVE, "branch_relative" },
97
98
// architecture-specific groups
99
#include "MipsGenCSFeatureName.inc"
100
};
101
#endif
102
103
const char *Mips_group_name(csh handle, unsigned int id)
104
523k
{
105
523k
#ifndef CAPSTONE_DIET
106
523k
  return id2name(group_name_maps, ARR_SIZE(group_name_maps), id);
107
#else
108
  return NULL;
109
#endif
110
523k
}
111
112
const insn_map mips_insns[] = {
113
#include "MipsGenCSMappingInsn.inc"
114
};
115
116
void Mips_reg_access(const cs_insn *insn, cs_regs regs_read,
117
         uint8_t *regs_read_count, cs_regs regs_write,
118
         uint8_t *regs_write_count)
119
0
{
120
0
  uint8_t i;
121
0
  uint8_t read_count, write_count;
122
0
  cs_mips *mips = &(insn->detail->mips);
123
124
0
  read_count = insn->detail->regs_read_count;
125
0
  write_count = insn->detail->regs_write_count;
126
127
  // implicit registers
128
0
  memcpy(regs_read, insn->detail->regs_read,
129
0
         read_count * sizeof(insn->detail->regs_read[0]));
130
0
  memcpy(regs_write, insn->detail->regs_write,
131
0
         write_count * sizeof(insn->detail->regs_write[0]));
132
133
  // explicit registers
134
0
  for (i = 0; i < mips->op_count; i++) {
135
0
    cs_mips_op *op = &(mips->operands[i]);
136
0
    switch ((int)op->type) {
137
0
    case MIPS_OP_REG:
138
0
      if ((op->access & CS_AC_READ) &&
139
0
          !arr_exist(regs_read, read_count, op->reg)) {
140
0
        regs_read[read_count] = (uint16_t)op->reg;
141
0
        read_count++;
142
0
      }
143
0
      if ((op->access & CS_AC_WRITE) &&
144
0
          !arr_exist(regs_write, write_count, op->reg)) {
145
0
        regs_write[write_count] = (uint16_t)op->reg;
146
0
        write_count++;
147
0
      }
148
0
      break;
149
0
    case MIPS_OP_MEM:
150
      // registers appeared in memory references always being read
151
0
      if ((op->mem.base != MIPS_REG_INVALID) &&
152
0
          !arr_exist(regs_read, read_count, op->mem.base)) {
153
0
        regs_read[read_count] = (uint16_t)op->mem.base;
154
0
        read_count++;
155
0
      }
156
0
      if ((insn->detail->writeback) &&
157
0
          (op->mem.base != MIPS_REG_INVALID) &&
158
0
          !arr_exist(regs_write, write_count, op->mem.base)) {
159
0
        regs_write[write_count] =
160
0
          (uint16_t)op->mem.base;
161
0
        write_count++;
162
0
      }
163
0
    default:
164
0
      break;
165
0
    }
166
0
  }
167
168
0
  *regs_read_count = read_count;
169
0
  *regs_write_count = write_count;
170
0
}
171
172
void Mips_set_instr_map_data(MCInst *MI)
173
106k
{
174
  // Fixes for missing groups.
175
106k
  if (MCInst_getOpcode(MI) == Mips_JR) {
176
64
    unsigned Reg = MCInst_getOpVal(MI, 0);
177
64
    switch (Reg) {
178
34
    case MIPS_REG_RA:
179
34
    case MIPS_REG_RA_64:
180
34
      add_group(MI, MIPS_GRP_RET);
181
34
      break;
182
64
    }
183
64
  }
184
185
106k
  map_cs_id(MI, mips_insns, ARR_SIZE(mips_insns));
186
106k
  map_implicit_reads(MI, mips_insns);
187
106k
  map_implicit_writes(MI, mips_insns);
188
106k
  map_groups(MI, mips_insns);
189
106k
}
190
191
bool Mips_getInstruction(csh handle, const uint8_t *code, size_t code_len,
192
       MCInst *instr, uint16_t *size, uint64_t address,
193
       void *info)
194
109k
{
195
109k
  uint64_t size64;
196
109k
  Mips_init_cs_detail(instr);
197
109k
  instr->MRI = (MCRegisterInfo *)info;
198
109k
  map_set_fill_detail_ops(instr, true);
199
200
109k
  DecodeStatus Result = Mips_LLVM_getInstruction(instr, &size64, code, code_len,
201
109k
                 address,
202
109k
                 info);
203
109k
  *size = size64;
204
109k
  if (Result != MCDisassembler_Fail) {
205
106k
    Mips_set_instr_map_data(instr);
206
106k
  }
207
109k
  if (Result == MCDisassembler_SoftFail) {
208
0
    MCInst_setSoftFail(instr);
209
0
  }
210
109k
  return Result != MCDisassembler_Fail;
211
109k
}
212
213
void Mips_printer(MCInst *MI, SStream *O, void * /* MCRegisterInfo* */ info)
214
106k
{
215
106k
  MCRegisterInfo *MRI = (MCRegisterInfo *)info;
216
106k
  MI->MRI = MRI;
217
218
106k
  Mips_LLVM_printInst(MI, MI->address, O);
219
106k
#ifndef CAPSTONE_DIET
220
106k
  map_set_alias_id(MI, O, insn_alias_mnem_map,
221
106k
       ARR_SIZE(insn_alias_mnem_map));
222
106k
#endif
223
106k
}
224
225
static void Mips_setup_op(cs_mips_op *op)
226
1.74M
{
227
1.74M
  memset(op, 0, sizeof(cs_mips_op));
228
1.74M
  op->type = MIPS_OP_INVALID;
229
1.74M
}
230
231
void Mips_init_cs_detail(MCInst *MI)
232
109k
{
233
109k
  if (detail_is_set(MI)) {
234
109k
    unsigned int i;
235
236
109k
    memset(get_detail(MI), 0,
237
109k
           offsetof(cs_detail, mips) + sizeof(cs_mips));
238
239
1.85M
    for (i = 0; i < ARR_SIZE(Mips_get_detail(MI)->operands); i++)
240
1.74M
      Mips_setup_op(&Mips_get_detail(MI)->operands[i]);
241
109k
  }
242
109k
}
243
244
static const map_insn_ops insn_operands[] = {
245
#include "MipsGenCSMappingInsnOp.inc"
246
};
247
248
static void Mips_set_detail_op_mem_reg(MCInst *MI, unsigned OpNum, mips_reg Reg)
249
29.6k
{
250
29.6k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
251
29.6k
  Mips_get_detail_op(MI, 0)->mem.base = Reg;
252
29.6k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
253
29.6k
}
254
255
static void Mips_set_detail_op_mem_disp(MCInst *MI, unsigned OpNum, int64_t Imm)
256
29.9k
{
257
29.9k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
258
29.9k
  Mips_get_detail_op(MI, 0)->mem.disp = Imm;
259
29.9k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
260
29.9k
}
261
262
static void Mips_set_detail_op_imm(MCInst *MI, unsigned OpNum, int64_t Imm)
263
45.6k
{
264
45.6k
  if (!detail_is_set(MI))
265
0
    return;
266
267
45.6k
  if (doing_mem(MI)) {
268
29.9k
    Mips_set_detail_op_mem_disp(MI, OpNum, Imm);
269
29.9k
    return;
270
29.9k
  }
271
272
15.6k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_IMM;
273
15.6k
  Mips_get_detail_op(MI, 0)->imm = Imm;
274
15.6k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
275
15.6k
  Mips_inc_op_count(MI);
276
15.6k
}
277
278
static void Mips_set_detail_op_uimm(MCInst *MI, unsigned OpNum, uint64_t Imm)
279
38.3k
{
280
38.3k
  if (!detail_is_set(MI))
281
0
    return;
282
283
38.3k
  if (doing_mem(MI)) {
284
0
    Mips_set_detail_op_mem_disp(MI, OpNum, Imm);
285
0
    return;
286
0
  }
287
288
38.3k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_IMM;
289
38.3k
  Mips_get_detail_op(MI, 0)->uimm = Imm;
290
38.3k
  Mips_get_detail_op(MI, 0)->is_unsigned = true;
291
38.3k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
292
38.3k
  Mips_inc_op_count(MI);
293
38.3k
}
294
295
static void Mips_set_detail_op_reg(MCInst *MI, unsigned OpNum, mips_reg Reg,
296
           bool is_reglist)
297
194k
{
298
194k
  if (!detail_is_set(MI))
299
0
    return;
300
301
194k
  if (doing_mem(MI)) {
302
29.6k
    Mips_set_detail_op_mem_reg(MI, OpNum, Reg);
303
29.6k
    return;
304
29.6k
  }
305
306
164k
  CS_ASSERT(is_reglist || (map_get_op_type(MI, OpNum) & ~CS_OP_MEM) == CS_OP_REG);
307
164k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_REG;
308
164k
  Mips_get_detail_op(MI, 0)->reg = Reg;
309
164k
  Mips_get_detail_op(MI, 0)->is_reglist = is_reglist;
310
164k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
311
164k
  Mips_inc_op_count(MI);
312
164k
}
313
314
static void Mips_set_detail_op_operand(MCInst *MI, unsigned OpNum)
315
234k
{
316
234k
  cs_op_type op_type = map_get_op_type(MI, OpNum) & ~CS_OP_MEM;
317
234k
  int64_t value = MCInst_getOpVal(MI, OpNum);
318
234k
  if (op_type == CS_OP_IMM) {
319
45.6k
    Mips_set_detail_op_imm(MI, OpNum, value);
320
189k
  } else if (op_type == CS_OP_REG) {
321
186k
    Mips_set_detail_op_reg(MI, OpNum, value, false);
322
186k
  } else {
323
    // Register list which ends with a memory operand
324
    // Gives very large MCInst operand numbers but don't
325
    // have the respective Capstone type in the mapping table.
326
2.40k
    if (MCOperand_isImm(MCInst_getOperand(MI, OpNum))) {
327
1.32k
      Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
328
1.32k
      Mips_get_detail_op(MI, 0)->mem.disp = value;
329
1.32k
    } else if (MCOperand_isReg(MCInst_getOperand(MI, OpNum))) {
330
1.08k
      Mips_get_detail_op(MI, 0)->mem.base = value;
331
1.08k
    } else {
332
0
      printf("Operand type %d not handled!\n", op_type);
333
0
    }
334
2.40k
  }
335
234k
}
336
337
static void Mips_set_detail_op_jump(MCInst *MI, unsigned OpNum)
338
2.51k
{
339
2.51k
  cs_op_type op_type = map_get_op_type(MI, OpNum) & ~CS_OP_MEM;
340
2.51k
  if (op_type == CS_OP_IMM) {
341
2.51k
    uint64_t Base = MI->address & ~0x0fffffffull;
342
2.51k
    uint64_t Target = Base | (uint64_t)MCInst_getOpVal(MI, OpNum);
343
2.51k
    Mips_set_detail_op_uimm(MI, OpNum, Target);
344
2.51k
  } else if (op_type == CS_OP_REG) {
345
0
    Mips_set_detail_op_reg(MI, OpNum, MCInst_getOpVal(MI, OpNum),
346
0
               false);
347
0
  } else
348
0
    printf("Operand type %d not handled!\n", op_type);
349
2.51k
}
350
351
static void Mips_set_detail_op_branch(MCInst *MI, unsigned OpNum)
352
21.6k
{
353
21.6k
  cs_op_type op_type = map_get_op_type(MI, OpNum) & ~CS_OP_MEM;
354
21.6k
  if (op_type == CS_OP_IMM) {
355
20.9k
    uint64_t Target = MI->address + MCInst_getOpVal(MI, OpNum);
356
20.9k
    Mips_set_detail_op_uimm(MI, OpNum, Target);
357
20.9k
  } else if (op_type == CS_OP_REG) {
358
649
    Mips_set_detail_op_reg(MI, OpNum, MCInst_getOpVal(MI, OpNum),
359
649
               false);
360
649
  } else
361
0
    printf("Operand type %d not handled!\n", op_type);
362
21.6k
}
363
364
static void Mips_set_detail_op_unsigned(MCInst *MI, unsigned OpNum)
365
0
{
366
0
  Mips_set_detail_op_uimm(MI, OpNum, MCInst_getOpVal(MI, OpNum));
367
0
}
368
369
static void Mips_set_detail_op_unsigned_offset(MCInst *MI, unsigned OpNum,
370
                 unsigned Bits, uint64_t Offset)
371
14.8k
{
372
14.8k
  uint64_t Imm = MCInst_getOpVal(MI, OpNum);
373
14.8k
  Imm -= Offset;
374
14.8k
  Imm &= (((uint64_t)1) << Bits) - 1;
375
14.8k
  Imm += Offset;
376
14.8k
  Mips_set_detail_op_uimm(MI, OpNum, Imm);
377
14.8k
}
378
379
static void Mips_set_detail_op_mem_nanomips(MCInst *MI, unsigned OpNum)
380
0
{
381
0
  CS_ASSERT(doing_mem(MI));
382
383
0
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
384
0
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
385
  // Base is a register, but nanoMips uses the Imm value as register.
386
0
  Mips_get_detail_op(MI, 0)->mem.base = MCOperand_getImm(Op);
387
0
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
388
0
}
389
390
static void Mips_set_detail_op_reglist(MCInst *MI, unsigned OpNum,
391
               bool isNanoMips)
392
1.41k
{
393
1.41k
  if (isNanoMips) {
394
0
    for (unsigned i = OpNum; i < MCInst_getNumOperands(MI); i++) {
395
0
      Mips_set_detail_op_reg(MI, i, MCInst_getOpVal(MI, i),
396
0
                 true);
397
0
    }
398
0
    return;
399
0
  }
400
  // -2 because register List is always first operand of instruction
401
  // and it is always followed by memory operand (base + offset).
402
7.89k
  for (unsigned i = OpNum, e = MCInst_getNumOperands(MI) - 2; i != e;
403
6.48k
       ++i) {
404
6.48k
    Mips_set_detail_op_reg(MI, i, MCInst_getOpVal(MI, i), true);
405
6.48k
  }
406
1.41k
}
407
408
static void Mips_set_detail_op_unsigned_address(MCInst *MI, unsigned OpNum)
409
0
{
410
0
  uint64_t Target = MI->address + (uint64_t)MCInst_getOpVal(MI, OpNum);
411
0
  Mips_set_detail_op_imm(MI, OpNum, Target);
412
0
}
413
414
void Mips_add_cs_detail(MCInst *MI, mips_op_group op_group, va_list args)
415
275k
{
416
275k
  if (!detail_is_set(MI) || !map_fill_detail_ops(MI))
417
0
    return;
418
419
275k
  unsigned OpNum = va_arg(args, unsigned);
420
421
275k
  switch (op_group) {
422
0
  default:
423
0
    printf("Operand group %d not handled!\n", op_group);
424
0
    return;
425
0
  case Mips_OP_GROUP_MemOperand:
426
    // this is only used by nanoMips.
427
0
    return Mips_set_detail_op_mem_nanomips(MI, OpNum);
428
21.6k
  case Mips_OP_GROUP_BranchOperand:
429
21.6k
    return Mips_set_detail_op_branch(MI, OpNum);
430
2.51k
  case Mips_OP_GROUP_JumpOperand:
431
2.51k
    return Mips_set_detail_op_jump(MI, OpNum);
432
234k
  case Mips_OP_GROUP_Operand:
433
234k
    return Mips_set_detail_op_operand(MI, OpNum);
434
479
  case Mips_OP_GROUP_UImm_1_0:
435
479
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 1, 0);
436
758
  case Mips_OP_GROUP_UImm_2_0:
437
758
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 2, 0);
438
1.42k
  case Mips_OP_GROUP_UImm_3_0:
439
1.42k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 3, 0);
440
0
  case Mips_OP_GROUP_UImm_32_0:
441
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 32, 0);
442
4.17k
  case Mips_OP_GROUP_UImm_16_0:
443
4.17k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 16, 0);
444
504
  case Mips_OP_GROUP_UImm_8_0:
445
504
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 8, 0);
446
3.02k
  case Mips_OP_GROUP_UImm_5_0:
447
3.02k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 0);
448
548
  case Mips_OP_GROUP_UImm_6_0:
449
548
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 6, 0);
450
790
  case Mips_OP_GROUP_UImm_4_0:
451
790
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 4, 0);
452
206
  case Mips_OP_GROUP_UImm_7_0:
453
206
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 7, 0);
454
1.48k
  case Mips_OP_GROUP_UImm_10_0:
455
1.48k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 10, 0);
456
0
  case Mips_OP_GROUP_UImm_6_1:
457
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 6, 1);
458
328
  case Mips_OP_GROUP_UImm_5_1:
459
328
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 1);
460
0
  case Mips_OP_GROUP_UImm_5_33:
461
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 33);
462
0
  case Mips_OP_GROUP_UImm_5_32:
463
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 32);
464
0
  case Mips_OP_GROUP_UImm_6_2:
465
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 6, 2);
466
268
  case Mips_OP_GROUP_UImm_2_1:
467
268
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 2, 1);
468
342
  case Mips_OP_GROUP_UImm_0_0:
469
342
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 0, 0);
470
0
  case Mips_OP_GROUP_UImm_26_0:
471
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 26, 0);
472
0
  case Mips_OP_GROUP_UImm_12_0:
473
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 12, 0);
474
491
  case Mips_OP_GROUP_UImm_20_0:
475
491
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 20, 0);
476
1.41k
  case Mips_OP_GROUP_RegisterList:
477
1.41k
    return Mips_set_detail_op_reglist(MI, OpNum, false);
478
0
  case Mips_OP_GROUP_NanoMipsRegisterList:
479
0
    return Mips_set_detail_op_reglist(MI, OpNum, true);
480
0
  case Mips_OP_GROUP_PCRel:
481
    /* fall-thru */
482
0
  case Mips_OP_GROUP_Hi20PCRel:
483
0
    return Mips_set_detail_op_unsigned_address(MI, OpNum);
484
0
  case Mips_OP_GROUP_Hi20:
485
0
    return Mips_set_detail_op_unsigned(MI, OpNum);
486
275k
  }
487
275k
}
488
489
void Mips_set_mem_access(MCInst *MI, bool status)
490
62.0k
{
491
62.0k
  if (!detail_is_set(MI))
492
0
    return;
493
62.0k
  set_doing_mem(MI, status);
494
62.0k
  if (status) {
495
31.0k
    if (Mips_get_detail(MI)->op_count > 0 &&
496
31.0k
        Mips_get_detail_op(MI, -1)->type == MIPS_OP_MEM &&
497
31.0k
        Mips_get_detail_op(MI, -1)->mem.disp == 0) {
498
      // Previous memory operand not done yet. Select it.
499
0
      Mips_dec_op_count(MI);
500
0
      return;
501
0
    }
502
503
    // Init a new one.
504
31.0k
    Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
505
31.0k
    Mips_get_detail_op(MI, 0)->mem.base = MIPS_REG_INVALID;
506
31.0k
    Mips_get_detail_op(MI, 0)->mem.disp = 0;
507
508
31.0k
#ifndef CAPSTONE_DIET
509
31.0k
    uint8_t access =
510
31.0k
      map_get_op_access(MI, Mips_get_detail(MI)->op_count);
511
31.0k
    Mips_get_detail_op(MI, 0)->access = access;
512
31.0k
#endif
513
31.0k
  } else {
514
    // done, select the next operand slot
515
31.0k
    Mips_inc_op_count(MI);
516
31.0k
  }
517
62.0k
}
518
519
#endif