//---------------------------------------------------------------------- static void process_operand(op_t &x, bool isload) { ea_t ea; dref_t dref; if ( is_forced_operand(cmd.ea, x.n) ) return; switch ( x.type ) { case o_reg: case o_phrase: break; case o_imm: if ( !isload ) interr("emu1"); process_immediate_number(x.n); if ( isOff(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, OOFS_IFSIGN|OOFW_IMM); break; case o_mem: ea = calc_mem(x.addr); ua_dodata2(x.offb, ea, x.dtyp); dref = cmd.itype == I960_lda ? dr_O : isload ? dr_R : dr_W; ua_add_dref(x.offb, ea, dref); break; case o_near: { cref_t ftype = fl_JN; ea = calc_mem(x.addr); if ( InstrIsSet(cmd.itype, CF_CALL) ) { flow = func_does_return(ea); ftype = fl_CN; } ua_add_cref(x.offb, ea, ftype); } break; case o_displ: dref = cmd.itype == I960_lda ? dr_O : isload ? dr_R : dr_W; process_immediate_number(x.n); if ( x.reg == IP ) { ea_t ea = cmd.ea + 8 + x.addr; ua_add_dref(x.offb, ea, dref); } else { if ( isOff(uFlag, x.n) ) ua_add_off_drefs2(x, dref, OOFS_IFSIGN|OOF_SIGNED|OOF_ADDR|OOFW_32); } break; default: interr("emu"); } }
//---------------------------------------------------------------------- static void process_operand(op_t &x,int isAlt,int isload) { switch ( x.type ) { case o_reg: break; default: // interr("emu"); break; case o_imm: // if ( !isload ) interr("emu2"); process_immediate_number(x.n); if ( isOff(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, x.amode & amode_signed ? OOF_SIGNED : 0); break; case o_phrase: if ( !isAlt && isOff(uFlag, x.n) ) { ua_add_off_drefs2(x, isload ? dr_R : dr_W, OOF_ADDR); ea_t ea = calc_target(cmd.ea+x.offb, cmd.ea, x.n, x.addr); ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } break; case o_mem: { ea_t ea = calc_mem(x); ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } break; case o_near: add_near_ref(x, calc_mem(x)); break; case o_textphrase: break; case o_local: // local variables if ( may_create_stkvars() ) { func_t *pfn = get_func(cmd.ea); if ( (pfn != NULL) && (pfn->flags & FUNC_FRAME) && ua_stkvar2(x, x.addr, STKVAR_VALID_SIZE) ) op_stkvar(cmd.ea, x.n); } break; } }
//---------------------------------------------------------------------- static uval_t find_ret_purged(const func_t *pfn) { uval_t argsize = 0; ea_t ea = pfn->startEA; while ( ea < pfn->endEA ) { decode_insn(ea); if ( cmd.itype == H8500_rtd || cmd.itype == H8500_prtd ) { argsize = cmd.Op1.value; break; } ea = nextthat(ea, pfn->endEA, f_isCode, NULL); } // could not find any ret instructions // but the function ends with a jump if ( ea >= pfn->endEA && (cmd.itype == H8500_jmp || cmd.itype == H8500_pjmp) ) { ea_t target = calc_mem(cmd.Op1); pfn = get_func(target); if ( pfn != NULL ) argsize = pfn->argsize; } return argsize; }
unsigned long calc_mem(mem_block_ptr mem_block) { if (mem_block->next) return(mem_block->size+calc_mem(mem_block->next)); else return(mem_block->size); }
//---------------------------------------------------------------------- static void process_operand(op_t &x,int isAlt,int isload) { switch ( x.type ) { case o_reg: break; default: // interr("emu"); break; case o_imm: process_immediate_number(x.n); if ( op_adds_xrefs(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, OOFS_IFSIGN); break; case o_phrase: if ( !isAlt && op_adds_xrefs(uFlag, x.n) ) { ea_t ea = ua_add_off_drefs2(x, isload ? dr_R : dr_W, OOF_ADDR); if ( ea != BADADDR ) { ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } } break; case o_mem: { ea_t ea = calc_mem(x); ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); if ( x.amode & amode_l ) { ea = ymem + x.addr; ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); ua_dodata2(x.offb, ea, x.dtyp); } } break; case o_near: add_near_ref(x, calc_mem(x)); break; } }
//---------------------------------------------------------------------- bool idaapi outop(op_t &x) { ea_t ea; if ( x.type == o_imm ) out_symbol('#'); char buf[MAXSTR]; switch ( x.type ) { case o_void: return 0; case o_imm: OutValue(x, OOFS_IFSIGN|OOFW_IMM); break; case o_reg: outreg(x.reg); break; case o_mem: // no break; case o_near: { ea = calc_mem(x); if ( ea == cmd.ea+cmd.size ) out_ip_rel(cmd.size); else if ( !out_name_expr(x, ea, x.addr) ) out_bad_address(x.addr); } break; case o_phrase: { qsnprintf(buf, sizeof(buf), "%%%c%" FMT_EA "x", 'a' + x.reg, x.value); ea = calc_data_mem(x, as + x.reg); if ( ( ea != BADADDR ) && ( ( x.reg != SR3 ) || ( x.value < 6 ) ) ) { out_line(buf, COLOR_AUTOCMT); out_symbol(' '); out_address(ea, x); } else out_line(buf, COLOR_REG); } break; default: interr("out"); break; } return 1; }
//---------------------------------------------------------------------- int is_sane_insn(int /*nocrefs*/) { // disallow jumps to nowhere if ( cmd.Op1.type == o_near && !isEnabled(calc_mem(cmd.Op1)) ) return 0; // disallow many nops in a now int i = 0; for ( ea_t ea=cmd.ea; i < 32; i++,ea++ ) if ( get_byte(ea) != 0 ) break; if ( i == 32 ) return 0; return 1; }
//---------------------------------------------------------------------- static void process_operand(op_t &x,int isAlt,int isload) { switch ( x.type ) { case o_reg: case o_reglist: return; case o_imm: QASSERT(10090, isload); process_immediate_number(x.n); if ( op_adds_xrefs(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, calc_opimm_flags()); break; case o_phrase: case o_displ: process_immediate_number(x.n); if ( isAlt ) break; if ( op_adds_xrefs(uFlag, x.n) ) { ea_t ea = ua_add_off_drefs2(x, isload ? dr_R : dr_W, calc_opdispl_flags()); if ( ea != BADADDR ) { ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } } // create stack variables if required if ( x.type == o_displ && may_create_stkvars() && !isDefArg(uFlag, x.n) ) { func_t *pfn = get_func(cmd.ea); if ( pfn != NULL && (issp(x.phrase) || isbp(x.phrase) && (pfn->flags & FUNC_FRAME) != 0) ) { if ( ua_stkvar2(x, x.addr, STKVAR_VALID_SIZE) ) op_stkvar(cmd.ea, x.n); } } break; case o_near: case o_far: { cref_t ftype = x.type == o_near ? fl_JN : fl_JF; ea_t ea = calc_mem(x); if ( InstrIsSet(cmd.itype, CF_CALL) ) { if ( !func_does_return(ea) ) flow = false; ftype = x.type == o_near ? fl_CN : fl_CF; } ua_add_cref(x.offb, ea, ftype); } break; case o_mem: { ea_t ea = calc_mem(x); ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } break; default: INTERR(10091); } }
//---------------------------------------------------------------------- static void process_operand(op_t &x,int isAlt,int isload) { switch ( x.type ) { case o_reg: case o_phrase: case o_reglist: return; case o_imm: QASSERT(10094, isload); process_immediate_number(x.n); if ( op_adds_xrefs(uFlag, x.n) ) ua_add_off_drefs2(x, dr_O, OOFS_IFSIGN|OOFW_IMM); break; case o_displ: process_immediate_number(x.n); if ( isAlt ) break; if ( op_adds_xrefs(uFlag, x.n) ) { ea_t ea = ua_add_off_drefs2(x, isload ? dr_R : dr_W, get_displ_outf(x)); if ( ea != BADADDR ) { ua_dodata2(x.offb, ea, x.dtyp); if ( !isload ) doVar(ea); } } // create stack variables if required if ( may_create_stkvars() && !isDefArg(uFlag, x.n) ) { func_t *pfn = get_func(cmd.ea); if ( pfn != NULL && (issp(x.phrase) || isbp(x.phrase) && (pfn->flags & FUNC_FRAME) != 0) ) { if ( ua_stkvar2(x, x.addr, STKVAR_VALID_SIZE) ) op_stkvar(cmd.ea, x.n); } } break; case o_near: add_code_xref(x, calc_mem(x.addr)); break; case o_mem: case o_memind: { ea_t ea = calc_mem(x.addr); if ( !isEnabled(ea) && find_sym(ea) ) break; // address not here ua_add_dref(x.offb, ea, isload ? dr_R : dr_W); ua_dodata2(x.offb, ea, x.dtyp); if ( x.type == o_memind ) { ssize_t size = get_dtyp_size(x.dtyp); flags_t F = getFlags(ea); if ( (isWord(F) || isDwrd(F)) && (!isDefArg0(F) || isOff0(F)) ) { ea_t target = calc_mem(size == 2 ? get_word(ea) : (get_long(ea) & 0xFFFFFFL)); if ( isEnabled(target) ) add_code_xref(x, target); if ( !isOff0(F) ) set_offset(ea, 0, calc_mem(0)); } break; } if ( !isload ) doVar(ea); } break; default: INTERR(10095); } }
//---------------------------------------------------------------------- bool outop(op_t &x) { ea_t ea; char buf[MAXSTR]; if ( x.type == o_imm ) out_symbol('#'); switch ( x.type ) { case o_void: return 0; case o_imm: if ( x.amode & amode_signed ) OutValue(x, OOF_SIGNED|OOFW_IMM); else OutValue(x, OOFS_IFSIGN|OOFW_IMM); break; case o_reg: outreg(x.reg); break; case o_mem: // no break; ea = calc_mem(x); if ( ea != BADADDR ) out_address(ea, x); else { out_tagon(COLOR_ERROR); OutValue(x, OOFW_IMM|OOF_ADDR|OOFW_16); out_tagoff(COLOR_ERROR); } break; case o_near: { ea_t ea = calc_mem(x); // xmem ioports if ( x.amode & (amode_x) && out_port_address(x.addr) ) { char nbuf[MAXSTR]; const char *pnam = find_port(x.addr); const char *name = get_true_name(BADADDR, ea, nbuf, sizeof(nbuf)); if ( name == NULL || strcmp(name, pnam) != 0 ) set_name(ea, pnam); break; } if ( ea == cmd.ea+cmd.size ) out_ip_rel(cmd.size); else if ( !out_name_expr(x, ea, x.addr) ) out_bad_address(x.addr); } break; case o_phrase: { if ( x.phtype < 4 ) { qsnprintf(buf, sizeof(buf), formats[x.phtype], x.phrase); out_colored_register_line(buf); } if ( x.phtype == 4 ) { out_symbol('('); outreg(x.reg); out_symbol(')'); } } break; case o_local: { out_colored_register_line(formats2[x.phtype]); OutValue(x, OOF_SIGNED|OOF_ADDR); if ( x.phtype == 0 ) out_symbol(')'); break; } case o_textphrase: { char buf[MAXSTR]; switch ( x.textphtype ) { case text_swap: out_line(swap_formats[x.phrase], COLOR_REG); break; case text_banke: int comma; char r0[10], r1[10], r4[10], cfgi[10]; comma = 0; r0[0]=r1[0]=r4[0]=cfgi[0]='\0'; if ( x.phrase & 0x01 ) //cfgi { qsnprintf(cfgi, sizeof(cfgi), "cfgi"); comma = 1; } if ( x.phrase & 0x02 ) //r4 { qsnprintf(r4, sizeof(r4), "r4%s", (comma?", ":"")); comma = 1; } if ( x.phrase & 0x04 ) //r1 { qsnprintf(r1, sizeof(r1), "r1%s", (comma?", ":"")); comma = 1; } if ( x.phrase & 0x08 ) //r0 qsnprintf(r0, sizeof(r0), "r0%s", (comma?", ":"")); qsnprintf(buf, sizeof(buf), "%s%s%s%s", r0, r1, r4, cfgi ); out_line(buf, COLOR_REG); break; case text_cntx: out_symbol( (x.phrase ? 'r': 's') ); break; case text_dmod: if ( x.phrase ) qsnprintf(buf, sizeof(buf), " no modulo"); else qsnprintf(buf, sizeof(buf), " modulo"); out_line(buf, COLOR_REG); break; case text_eu: qsnprintf(buf, sizeof(buf), " eu"); out_line(buf, COLOR_REG); break; } } break; default: interr("out"); break; } return 1; }
//---------------------------------------------------------------------- bool outop(op_t &x) { switch ( x.type ) { case o_void: return 0; case o_reg: outreg(x.reg); break; case o_imm: out_symbol('#'); OutValue(x, OOFS_IFSIGN|OOFW_IMM); break; case o_displ: // o_displ Short Direct Indexed ld A,($10,X) 00..1FE + 1 // o_displ Long Direct Indexed ld A,($1000,X) 0000..FFFF + 2 out_symbol('('); OutValue(x, OOFS_IFSIGN |OOF_ADDR |((cmd.auxpref & aux_16) ? OOFW_16 : OOFW_8)); out_symbol(','); outreg(x.reg); out_symbol(')'); break; case o_phrase: out_symbol('('); outreg(x.reg); out_symbol(')'); break; case o_mem: // o_mem Short Direct ld A,$10 00..FF + 1 // o_mem Long Direct ld A,$1000 0000..FFFF + 2 // o_mem Short Indirect ld A,[$10] 00..FF 00..FF byte + 2 // o_mem Long Indirect ld A,[$10.w] 0000..FFFF 00..FF word + 2 // o_mem Short Indirect Indexed ld A,([$10],X) 00..1FE 00..FF byte + 2 // o_mem Long Indirect Indexed ld A,([$10.w],X) 0000..FFFF 00..FF word + 2 // o_mem Relative Indirect jrne [$10] PC+/-127 00..FF byte + 2 // o_mem Bit Direct bset $10,#7 00..FF + 1 // o_mem Bit Indirect bset [$10],#7 00..FF 00..FF byte + 2 // o_mem Bit Direct Relative btjt $10,#7,skip 00..FF + 2 // o_mem Bit Indirect Relative btjt [$10],#7,skip 00..FF 00..FF byte + 3 if ( cmd.auxpref & aux_index ) out_symbol('('); if ( cmd.auxpref & aux_indir ) out_symbol('['); outmem(x, calc_mem(x.addr)); if ( cmd.auxpref & aux_long ) out_symbol('.'); if ( cmd.auxpref & aux_long ) out_symbol('w'); if ( cmd.auxpref & aux_indir ) out_symbol(']'); if ( cmd.auxpref & aux_index ) { out_symbol(','); outreg(x.reg); out_symbol(')'); } break; case o_near: outmem(x, calc_mem(x.addr)); break; default: interr("out"); break; } return 1; }
//---------------------------------------------------------------------- bool outop(op_t &x) { switch ( x.type ) { case o_void: return 0; case o_reg: outreg(x.reg); break; case o_reglist: out_symbol('('); out_reglist(x.reg, 8); out_symbol(')'); break; case o_imm: out_symbol('#'); OutValue(x, calc_opimm_flags()); out_sizer(x); break; case o_mem: out_symbol('@'); case o_near: case o_far: { ea_t ea = calc_mem(x); if ( !out_name_expr(x, ea, BADADDR) ) out_bad_address(x.addr); out_sizer(x); } break; case o_phrase: if ( x.phtype == ph_normal ) { bool outdisp = isOff(uFlag,x.n) || isStkvar(uFlag,x.n) || isEnum(uFlag,x.n) || isStroff(uFlag,x.n); if ( outdisp ) goto OUTDISP; } out_symbol('@'); if ( x.phtype == ph_pre ) out_symbol('-'); outreg(x.phrase); if ( x.phtype == ph_post ) out_symbol('+'); break; case o_displ: OUTDISP: out_symbol('@'); out_symbol('('); OutValue(x, calc_opdispl_flags()); out_sizer(x); out_symbol(','); outreg(x.reg); out_symbol(')'); break; default: interr("out"); break; } return 1; }
unsigned long get_free_mem(void) { return(calc_mem(free_list)); }