Coverage Report

Created: 2026-07-16 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/Mips/MipsMapping.c
Line
Count
Source
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.53k
{
30
3.53k
  MCRegisterInfo_InitMCRegisterInfo(MRI, MipsRegDesc, sizeof(MipsRegDesc),
31
3.53k
            0, 0, MipsMCRegisterClasses,
32
3.53k
            ARR_SIZE(MipsMCRegisterClasses), 0, 0,
33
3.53k
            MipsRegDiffLists, 0,
34
3.53k
            MipsSubRegIdxLists,
35
3.53k
            ARR_SIZE(MipsSubRegIdxLists), 0);
36
3.53k
}
37
38
const char *Mips_reg_name(csh handle, unsigned int reg)
39
39.2k
{
40
39.2k
  int syntax_opt = ((cs_struct *)(uintptr_t)handle)->syntax;
41
39.2k
  return Mips_LLVM_getRegisterName(reg,
42
39.2k
           syntax_opt & CS_OPT_SYNTAX_NOREGNAME);
43
39.2k
}
44
45
void Mips_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
46
148k
{
47
  // Not used by Mips. Information is set after disassembly.
48
148k
}
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
148k
{
67
148k
#ifndef CAPSTONE_DIET
68
148k
  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
148k
  if (id >= MIPS_INS_ENDING)
75
0
    return NULL;
76
77
148k
  if (id < ARR_SIZE(insn_name_maps))
78
148k
    return insn_name_maps[id];
79
  // not found
80
0
  return NULL;
81
#else
82
  return NULL;
83
#endif
84
148k
}
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
459k
{
105
459k
#ifndef CAPSTONE_DIET
106
459k
  return id2name(group_name_maps, ARR_SIZE(group_name_maps), id);
107
#else
108
  return NULL;
109
#endif
110
459k
}
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
148k
{
174
  // Fixes for missing groups.
175
148k
  if (MCInst_getOpcode(MI) == Mips_JR) {
176
465
    unsigned Reg = MCInst_getOpVal(MI, 0);
177
465
    switch (Reg) {
178
267
    case MIPS_REG_RA:
179
267
    case MIPS_REG_RA_64:
180
267
      add_group(MI, MIPS_GRP_RET);
181
267
      break;
182
465
    }
183
465
  }
184
185
148k
  map_cs_id(MI, mips_insns, ARR_SIZE(mips_insns));
186
148k
  map_implicit_reads(MI, mips_insns);
187
148k
  map_implicit_writes(MI, mips_insns);
188
148k
  map_groups(MI, mips_insns);
189
148k
}
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
151k
{
195
151k
  uint64_t size64;
196
151k
  Mips_init_cs_detail(instr);
197
151k
  instr->MRI = (MCRegisterInfo *)info;
198
151k
  map_set_fill_detail_ops(instr, true);
199
200
151k
  DecodeStatus Result = Mips_LLVM_getInstruction(instr, &size64, code,
201
151k
                   code_len, address, info);
202
151k
  *size = size64;
203
151k
  if (Result != MCDisassembler_Fail) {
204
148k
    Mips_set_instr_map_data(instr);
205
148k
  }
206
151k
  if (Result == MCDisassembler_SoftFail) {
207
0
    MCInst_setSoftFail(instr);
208
0
  }
209
151k
  return Result != MCDisassembler_Fail;
210
151k
}
211
212
void Mips_printer(MCInst *MI, SStream *O, void * /* MCRegisterInfo* */ info)
213
148k
{
214
148k
  MCRegisterInfo *MRI = (MCRegisterInfo *)info;
215
148k
  MI->MRI = MRI;
216
217
148k
  Mips_LLVM_printInst(MI, MI->address, O);
218
148k
#ifndef CAPSTONE_DIET
219
148k
  map_set_alias_id(MI, O, insn_alias_mnem_map,
220
148k
       ARR_SIZE(insn_alias_mnem_map));
221
148k
#endif
222
148k
}
223
224
static void Mips_setup_op(cs_mips_op *op)
225
2.42M
{
226
2.42M
  memset(op, 0, sizeof(cs_mips_op));
227
2.42M
  op->type = MIPS_OP_INVALID;
228
2.42M
}
229
230
void Mips_init_cs_detail(MCInst *MI)
231
151k
{
232
151k
  if (detail_is_set(MI)) {
233
151k
    unsigned int i;
234
235
151k
    memset(get_detail(MI), 0,
236
151k
           offsetof(cs_detail, mips) + sizeof(cs_mips));
237
238
2.57M
    for (i = 0; i < ARR_SIZE(Mips_get_detail(MI)->operands); i++)
239
2.42M
      Mips_setup_op(&Mips_get_detail(MI)->operands[i]);
240
151k
  }
241
151k
}
242
243
static const map_insn_ops insn_operands[] = {
244
#include "MipsGenCSMappingInsnOp.inc"
245
};
246
247
static void Mips_set_detail_op_mem_reg(MCInst *MI, unsigned OpNum, mips_reg Reg)
248
38.4k
{
249
38.4k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
250
38.4k
  Mips_get_detail_op(MI, 0)->mem.base = Reg;
251
38.4k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
252
38.4k
}
253
254
static void Mips_set_detail_op_mem_disp(MCInst *MI, unsigned OpNum, int64_t Imm)
255
38.9k
{
256
38.9k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
257
38.9k
  Mips_get_detail_op(MI, 0)->mem.disp = Imm;
258
38.9k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
259
38.9k
}
260
261
static void Mips_set_detail_op_imm(MCInst *MI, unsigned OpNum, int64_t Imm)
262
61.3k
{
263
61.3k
  if (!detail_is_set(MI))
264
0
    return;
265
266
61.3k
  if (doing_mem(MI)) {
267
38.9k
    Mips_set_detail_op_mem_disp(MI, OpNum, Imm);
268
38.9k
    return;
269
38.9k
  }
270
271
22.3k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_IMM;
272
22.3k
  Mips_get_detail_op(MI, 0)->imm = Imm;
273
22.3k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
274
22.3k
  Mips_inc_op_count(MI);
275
22.3k
}
276
277
static void Mips_set_detail_op_uimm(MCInst *MI, unsigned OpNum, uint64_t Imm)
278
53.7k
{
279
53.7k
  if (!detail_is_set(MI))
280
0
    return;
281
282
53.7k
  if (doing_mem(MI)) {
283
0
    Mips_set_detail_op_mem_disp(MI, OpNum, Imm);
284
0
    return;
285
0
  }
286
287
53.7k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_IMM;
288
53.7k
  Mips_get_detail_op(MI, 0)->uimm = Imm;
289
53.7k
  Mips_get_detail_op(MI, 0)->is_unsigned = true;
290
53.7k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
291
53.7k
  Mips_inc_op_count(MI);
292
53.7k
}
293
294
static void Mips_set_detail_op_reg(MCInst *MI, unsigned OpNum, mips_reg Reg,
295
           bool is_reglist)
296
272k
{
297
272k
  if (!detail_is_set(MI))
298
0
    return;
299
300
272k
  if (doing_mem(MI)) {
301
38.4k
    Mips_set_detail_op_mem_reg(MI, OpNum, Reg);
302
38.4k
    return;
303
38.4k
  }
304
305
233k
  CS_ASSERT(is_reglist ||
306
233k
      (map_get_op_type(MI, OpNum) & ~CS_OP_MEM) == CS_OP_REG);
307
233k
  Mips_get_detail_op(MI, 0)->type = MIPS_OP_REG;
308
233k
  Mips_get_detail_op(MI, 0)->reg = Reg;
309
233k
  Mips_get_detail_op(MI, 0)->is_reglist = is_reglist;
310
233k
  Mips_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
311
233k
  Mips_inc_op_count(MI);
312
233k
}
313
314
static void Mips_set_detail_op_operand(MCInst *MI, unsigned OpNum)
315
329k
{
316
329k
  cs_op_type op_type = map_get_op_type(MI, OpNum) & ~CS_OP_MEM;
317
329k
  int64_t value = MCInst_getOpVal(MI, OpNum);
318
329k
  if (op_type == CS_OP_IMM) {
319
61.3k
    Mips_set_detail_op_imm(MI, OpNum, value);
320
267k
  } else if (op_type == CS_OP_REG) {
321
265k
    Mips_set_detail_op_reg(MI, OpNum, value, false);
322
265k
  } 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.13k
    if (MCOperand_isImm(MCInst_getOperand(MI, OpNum))) {
327
1.30k
      Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
328
1.30k
      Mips_get_detail_op(MI, 0)->mem.disp = value;
329
1.30k
    } else if (MCOperand_isReg(MCInst_getOperand(MI, OpNum))) {
330
827
      Mips_get_detail_op(MI, 0)->mem.base = value;
331
827
    } else {
332
0
      printf("Operand type %d not handled!\n", op_type);
333
0
    }
334
2.13k
  }
335
329k
}
336
337
static void Mips_set_detail_op_jump(MCInst *MI, unsigned OpNum)
338
4.70k
{
339
4.70k
  cs_op_type op_type = map_get_op_type(MI, OpNum) & ~CS_OP_MEM;
340
4.70k
  if (op_type == CS_OP_IMM) {
341
4.70k
    uint64_t Base = MI->address & ~0x0fffffffull;
342
4.70k
    uint64_t Target = Base | (uint64_t)MCInst_getOpVal(MI, OpNum);
343
4.70k
    Mips_set_detail_op_uimm(MI, OpNum, Target);
344
4.70k
  } 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
4.70k
}
350
351
static void Mips_set_detail_op_branch(MCInst *MI, unsigned OpNum)
352
30.4k
{
353
30.4k
  cs_op_type op_type = map_get_op_type(MI, OpNum) & ~CS_OP_MEM;
354
30.4k
  if (op_type == CS_OP_IMM) {
355
29.9k
    uint64_t Target = MI->address + MCInst_getOpVal(MI, OpNum);
356
29.9k
    Mips_set_detail_op_uimm(MI, OpNum, Target);
357
29.9k
  } else if (op_type == CS_OP_REG) {
358
537
    Mips_set_detail_op_reg(MI, OpNum, MCInst_getOpVal(MI, OpNum),
359
537
               false);
360
537
  } else
361
0
    printf("Operand type %d not handled!\n", op_type);
362
30.4k
}
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
19.1k
{
372
19.1k
  uint64_t Imm = MCInst_getOpVal(MI, OpNum);
373
19.1k
  Imm -= Offset;
374
19.1k
  Imm &= (((uint64_t)1) << Bits) - 1;
375
19.1k
  Imm += Offset;
376
19.1k
  Mips_set_detail_op_uimm(MI, OpNum, Imm);
377
19.1k
}
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.43k
  for (unsigned i = OpNum, e = MCInst_getNumOperands(MI) - 2; i != e;
403
6.02k
       ++i) {
404
6.02k
    Mips_set_detail_op_reg(MI, i, MCInst_getOpVal(MI, i), true);
405
6.02k
  }
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_0(MCInst *MI, mips_op_group op_group, size_t OpNum)
415
385k
{
416
385k
  if (!detail_is_set(MI) || !map_fill_detail_ops(MI))
417
0
    return;
418
419
385k
  switch (op_group) {
420
0
  default:
421
0
    printf("Operand group %d not handled!\n", op_group);
422
0
    return;
423
0
  case Mips_OP_GROUP_MemOperand:
424
    // this is only used by nanoMips.
425
0
    return Mips_set_detail_op_mem_nanomips(MI, OpNum);
426
30.4k
  case Mips_OP_GROUP_BranchOperand:
427
30.4k
    return Mips_set_detail_op_branch(MI, OpNum);
428
4.70k
  case Mips_OP_GROUP_JumpOperand:
429
4.70k
    return Mips_set_detail_op_jump(MI, OpNum);
430
329k
  case Mips_OP_GROUP_Operand:
431
329k
    return Mips_set_detail_op_operand(MI, OpNum);
432
615
  case Mips_OP_GROUP_UImm_1_0:
433
615
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 1, 0);
434
958
  case Mips_OP_GROUP_UImm_2_0:
435
958
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 2, 0);
436
1.89k
  case Mips_OP_GROUP_UImm_3_0:
437
1.89k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 3, 0);
438
0
  case Mips_OP_GROUP_UImm_32_0:
439
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 32, 0);
440
4.45k
  case Mips_OP_GROUP_UImm_16_0:
441
4.45k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 16, 0);
442
1.45k
  case Mips_OP_GROUP_UImm_8_0:
443
1.45k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 8, 0);
444
5.06k
  case Mips_OP_GROUP_UImm_5_0:
445
5.06k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 0);
446
1.11k
  case Mips_OP_GROUP_UImm_6_0:
447
1.11k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 6, 0);
448
1.36k
  case Mips_OP_GROUP_UImm_4_0:
449
1.36k
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 4, 0);
450
76
  case Mips_OP_GROUP_UImm_7_0:
451
76
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 7, 0);
452
858
  case Mips_OP_GROUP_UImm_10_0:
453
858
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 10, 0);
454
0
  case Mips_OP_GROUP_UImm_6_1:
455
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 6, 1);
456
453
  case Mips_OP_GROUP_UImm_5_1:
457
453
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 1);
458
0
  case Mips_OP_GROUP_UImm_5_33:
459
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 33);
460
0
  case Mips_OP_GROUP_UImm_5_32:
461
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 5, 32);
462
0
  case Mips_OP_GROUP_UImm_6_2:
463
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 6, 2);
464
304
  case Mips_OP_GROUP_UImm_2_1:
465
304
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 2, 1);
466
212
  case Mips_OP_GROUP_UImm_0_0:
467
212
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 0, 0);
468
0
  case Mips_OP_GROUP_UImm_26_0:
469
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 26, 0);
470
0
  case Mips_OP_GROUP_UImm_12_0:
471
0
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 12, 0);
472
302
  case Mips_OP_GROUP_UImm_20_0:
473
302
    return Mips_set_detail_op_unsigned_offset(MI, OpNum, 20, 0);
474
1.41k
  case Mips_OP_GROUP_RegisterList:
475
1.41k
    return Mips_set_detail_op_reglist(MI, OpNum, false);
476
0
  case Mips_OP_GROUP_NanoMipsRegisterList:
477
0
    return Mips_set_detail_op_reglist(MI, OpNum, true);
478
0
  case Mips_OP_GROUP_PCRel:
479
    /* fall-thru */
480
0
  case Mips_OP_GROUP_Hi20PCRel:
481
0
    return Mips_set_detail_op_unsigned_address(MI, OpNum);
482
0
  case Mips_OP_GROUP_Hi20:
483
0
    return Mips_set_detail_op_unsigned(MI, OpNum);
484
385k
  }
485
385k
}
486
487
void Mips_set_mem_access(MCInst *MI, bool status)
488
79.5k
{
489
79.5k
  if (!detail_is_set(MI))
490
0
    return;
491
79.5k
  set_doing_mem(MI, status);
492
79.5k
  if (status) {
493
39.7k
    if (Mips_get_detail(MI)->op_count > 0 &&
494
39.2k
        Mips_get_detail_op(MI, -1)->type == MIPS_OP_MEM &&
495
0
        Mips_get_detail_op(MI, -1)->mem.disp == 0) {
496
      // Previous memory operand not done yet. Select it.
497
0
      Mips_dec_op_count(MI);
498
0
      return;
499
0
    }
500
501
    // Init a new one.
502
39.7k
    Mips_get_detail_op(MI, 0)->type = MIPS_OP_MEM;
503
39.7k
    Mips_get_detail_op(MI, 0)->mem.base = MIPS_REG_INVALID;
504
39.7k
    Mips_get_detail_op(MI, 0)->mem.disp = 0;
505
506
39.7k
#ifndef CAPSTONE_DIET
507
39.7k
    uint8_t access =
508
39.7k
      map_get_op_access(MI, Mips_get_detail(MI)->op_count);
509
39.7k
    Mips_get_detail_op(MI, 0)->access = access;
510
39.7k
#endif
511
39.7k
  } else {
512
    // done, select the next operand slot
513
39.7k
    Mips_inc_op_count(MI);
514
39.7k
  }
515
79.5k
}
516
517
#endif