13 #include "../asm/arch/8051/8051_disas.c"
25 { .
name =
"8051-generic",
27 .map_idata = 0x10000000,
28 .map_sfr = 0x10000180,
29 .map_xdata = 0x20000000,
30 .map_pdata = 0x00000000 },
31 { .name =
"8051-shared-code-xdata",
33 .map_idata = 0x10000000,
34 .map_sfr = 0x10000180,
35 .map_xdata = 0x00000000,
36 .map_pdata = 0x00000000 },
102 rz_list_foreach (
maps,
iter, current_map) {
115 ut32 addr_idata, addr_sfr, addr_xdata;
117 if (!analysis->
reg) {
121 const char *
cpu = analysis->
cpu;
166 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
167 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
168 0x80, 0x88, 0x90, 0x98, 0xA0, 0xA8, 0xB0, 0xB8,
169 0xC0, 0xC8, 0xD0, 0xD8, 0xE0, 0xE8, 0xF0, 0xF8
183 static RI8051Reg registers[] = {
185 {
"a", 0xE0, 0x00, 1, 0},
186 {
"b", 0xF0, 0x00, 1, 0},
187 {
"dph", 0x83, 0x00, 1, 0},
188 {
"dpl", 0x82, 0x00, 1, 0},
189 {
"dptr", 0x82, 0x00, 2, 0, 1},
190 {
"ie", 0xA8, 0x00, 1, 0},
191 {
"ip", 0xB8, 0x00, 1, 0},
192 {
"p0", 0x80, 0xFF, 1, 0},
193 {
"p1", 0x90, 0xFF, 1, 0},
194 {
"p2", 0xA0, 0xFF, 1, 0},
195 {
"p3", 0xB0, 0xFF, 1, 0},
196 {
"pcon", 0x87, 0x00, 1, 0},
197 {
"psw", 0xD0, 0x00, 1, 0},
198 {
"r0", 0x00, 0x00, 1, 1},
199 {
"r1", 0x01, 0x00, 1, 1},
200 {
"r2", 0x02, 0x00, 1, 1},
201 {
"r3", 0x03, 0x00, 1, 1},
202 {
"r4", 0x04, 0x00, 1, 1},
203 {
"r5", 0x05, 0x00, 1, 1},
204 {
"r6", 0x06, 0x00, 1, 1},
205 {
"r7", 0x07, 0x00, 1, 1},
206 {
"sbuf", 0x99, 0x00, 1, 0},
207 {
"scon", 0x98, 0x00, 1, 0},
208 {
"sp", 0x81, 0x07, 1, 0},
209 {
"tcon", 0x88, 0x00, 1, 0},
210 {
"th0", 0x8C, 0x00, 1, 0},
211 {
"th1", 0x8D, 0x00, 1, 0},
212 {
"tl0", 0x8A, 0x00, 1, 0},
213 {
"tl1", 0x8B, 0x00, 1, 0},
214 {
"tmod", 0x89, 0x00, 1, 0}
218 #define e(frag) rz_strbuf_append(&op->esil, frag)
219 #define ef(frag, ...) rz_strbuf_appendf(&op->esil, frag, __VA_ARGS__)
221 #define flag_c "7,$c,c,:=,"
222 #define flag_b "8,$b,c,:=,"
223 #define flag_ac "3,$c,ac,:=,"
224 #define flag_ab "3,$b,ac,:=,"
225 #define flag_ov "6,$c,ov,:=,"
226 #define flag_ob "7,$b,6,$b,^,ov,:=,"
227 #define flag_p "0xff,a,&=,$p,!,p,:=,"
230 #define ev_bit bitindex[buf[1] >> 3]
232 #define ev_dir1 buf[1]
233 #define ev_dir2 buf[2]
236 #define ev_imm1 buf[1]
237 #define ev_imm2 buf[2]
238 #define ev_imm16 op->val
239 #define ev_ri (1 & buf[0])
240 #define ev_rix (1 & buf[0])
241 #define ev_rn (7 & buf[0])
251 ef(
"_idata,%d,+,[1],",
addr);
253 ef(
"_sfr,%d,+,[1],",
addr);
262 e(
"_xdata,dptr,+,[1],");
278 ef(
"_idata,r%d,+,[1],",
reg);
282 ef(
"8,0xff,_pdata,&,<<,_xdata,+,r%d,+,[1],",
reg);
290 e(
"_idata,sp,+,[1],");
296 e(
"_idata,sp,+,[2],");
310 ef(
"_idata,%d,+,=[1],",
addr);
312 ef(
"_sfr,%d,+,=[1],",
addr);
329 e(
"_xdata,dptr,+,=[1],");
333 ef(
"_idata,r%d,+,=[1],",
reg);
337 ef(
"8,0xff,_pdata,&,<<,_xdata,+,r%d,+,=[1],",
reg);
346 e(
"_idata,sp,+,=[1],");
351 e(
"_idata,sp,+,=[2],");
356 ef(
"a,%s=,", operation);
360 ef(
"c,%s=,", operation);
364 ef(
"dptr,%s=,", operation);
369 ef(
"_idata,%d,+,%s=[1],",
addr, operation);
371 ef(
"_sfr,%d,+,%s=[1],",
addr, operation);
380 ef(
"_idata,r%d,+,%s=[1],",
reg, operation);
384 ef(
"r%d,%s=,",
reg, operation);
387 #define xr(subject) exr_##subject(op, ev_##subject)
388 #define xw(subject) exw_##subject(op, ev_##subject)
389 #define xi(subject, operation) exi_##subject(op, ev_##subject, operation)
391 #define bit_set ef("%d,1,<<,", buf[1] & 7)
396 ef("%d,", buf[1] & 7); \
399 #define bit_c ef("%d,c,<<,", buf[1] & 7);
401 #define jmp ef("%" PFMT64d ",pc,=", op->jump)
407 ef("%" PFMT64d ",", op->fail); \
411 #define alu_op(val, aluop, flags) \
413 e("a," aluop "=," flags)
414 #define alu_op_c(val, aluop, flags) \
417 e("+,a," aluop "=," flags)
418 #define alu_op_d(val, aluop) \
422 #define template_alu4_c(base, aluop, flags) \
424 alu_op_c(imm1, aluop, flags); \
427 alu_op_c(dir1, aluop, flags); \
431 alu_op_c(ri, aluop, flags); \
441 alu_op_c(rn, aluop, flags); \
444 #define template_alu2(base, aluop) \
446 alu_op_d(a, aluop); \
449 alu_op_d(imm2, aluop); \
452 #define template_alu4(base, aluop, flags) \
454 alu_op(imm1, aluop, flags); \
457 alu_op(dir1, aluop, flags); \
461 alu_op(ri, aluop, flags); \
471 alu_op(rn, aluop, flags); \
549 e(
"1,a,0x101,*,>>,a,=," flag_p);
573 e(
"7,c,<<,1,a,&,c,=,0x7f,1,a,>>,&,+,a,=," flag_p);
598 e(
"7,a,0x101,*,>>,a,=," flag_p);
602 e(
"c,1,&,a,a,+=,7,$c,c,:=,a,+=," flag_p);
648 e(
"a,pc,--,+,[1],a,=," flag_p);
652 e(
"b,0,==,$z,ov,:=,b,a,%,b,a,/=,b,=,0,c,=," flag_p);
702 e(
"8,a,b,*,DUP,a,=,>>,DUP,b,=,0,==,$z,!,ov,:=,0,c,=," flag_p);
781 e(
"0xff,4,a,0x101,*,>>,&,a,=," flag_p);
832 e(
"a,0x0f,&,9,==,4,$b,ac,|,?{,6,a,+=,7,$c,c,|,c,:=,},a,0xf0,&,0x90,==,8,$b,c,|,?{,0x60,a,+=,7,$c,c,|,c,:=,}," flag_p);
949 static int i8051_reg_compare(
const void *
name,
const void *
reg) {
950 return strcmp ((
const char*)
name, ((RI8051Reg*)
reg)->
name);
953 static RI8051Reg *i8051_reg_find(
const char *
name) {
954 return (RI8051Reg *) bsearch (
956 sizeof (registers) /
sizeof (registers[0]),
957 sizeof (registers[0]),
961 static int i8051_reg_get_offset(
RzAnalysisEsil *esil, RI8051Reg *ri) {
965 i8051_hook_reg_read (esil,
"psw", &psw,
NULL);
982 if ((ri = i8051_reg_find (
name))) {
983 ut8 offset = i8051_reg_get_offset(esil, ri);
1002 if ((ri = i8051_reg_find (
name))) {
1003 ut8 offset = i8051_reg_get_offset(esil, ri);
1058 "gpr dptr .16 10 0\n"
1064 "gpr ac .1 .102 0\n"
1088 "gpr _code .32 20 0\n"
1089 "gpr _idata .32 24 0\n"
1090 "gpr _sfr .32 28 0\n"
1091 "gpr _xdata .32 32 0\n"
1092 "gpr _pdata .32 36 0\n";
1185 if (arg1 ==
A_RI || arg1 ==
A_RN) {
1250 if (
op->ptr != -1 &&
op->refptr == 0) {
1255 ut8 copy[3] = { 0, 0, 0 };
1293 .desc =
"8051 CPU code analysis plugin",
1303 #ifndef RZ_PLUGIN_INCORE
static char * rz_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen)
static ut64 arg_offset(ut64 bank, ut16 pc, ut8 offset)
static ut64 arg_addr11(ut64 bank, ut16 pc, const ut8 *buf)
static ut64 apply_bank(ut64 ref, ut16 addr)
Construct an address with the higher bits from ref (determining the bank) and the lower from addr (of...
static _8051_op_t _8051_ops[]
static ut8 arg_bit(ut8 bit_addr)
static void exw_sp2(RzAnalysisOp *op, ut8 dummy)
static bool i8051_reg_write(RzReg *reg, const char *regname, ut32 num)
static void exi_a(RzAnalysisOp *op, ut8 dummy, const char *operation)
static void exr_rn(RzAnalysisOp *op, ut8 reg)
static void exi_dir1(RzAnalysisOp *op, ut8 addr, const char *operation)
static char * get_reg_profile(RzAnalysis *analysis)
static void exr_ri(RzAnalysisOp *op, ut8 reg)
static void exi_rn(RzAnalysisOp *op, ut8 reg, const char *operation)
static const int I8051_SFR
static void set_cpu_model(RzAnalysis *analysis, bool force)
static int esil_i8051_fini(RzAnalysisEsil *esil)
static void exw_bit(RzAnalysisOp *op, ut8 addr)
static void exw_a(RzAnalysisOp *op, ut8 dummy)
#define xi(subject, operation)
static void exi_c(RzAnalysisOp *op, ut8 dummy, const char *operation)
RzAnalysisPlugin rz_analysis_plugin_8051
static void exr_dir1(RzAnalysisOp *op, ut8 addr)
static ut32 map_direct_addr(RzAnalysis *analysis, ut8 addr)
static void exi_ri(RzAnalysisOp *op, ut8 reg, const char *operation)
static void exr_imm2(RzAnalysisOp *op, ut8 val)
static void exr_rix(RzAnalysisOp *op, ut8 reg)
RZ_API RzLibStruct rizin_plugin
static int i8051_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
#define template_alu4_c(base, aluop, flags)
static const ut8 bitindex[]
static const i8051_map_entry init_mem_map[3]
static void exw_dpx(RzAnalysisOp *op, ut8 dummy)
static const int I8051_IDATA
static const int I8051_XDATA
static void exr_sp1(RzAnalysisOp *op, ut8 dummy)
static void exw_ri(RzAnalysisOp *op, ut8 reg)
static void map_cpu_memory(RzAnalysis *analysis, int entry, ut32 addr, ut32 size, bool force)
static void exi_bit(RzAnalysisOp *op, ut8 addr, const char *operation)
#define template_alu2(base, aluop)
static void analop_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf)
static const i8051_cpu_model cpu_models[]
#define template_alu4(base, aluop, flags)
static void exw_rix(RzAnalysisOp *op, ut8 reg)
static void exw_rn(RzAnalysisOp *op, ut8 reg)
static void exw_dp(RzAnalysisOp *op, ut8 dummy)
static void exr_imm16(RzAnalysisOp *op, ut16 val)
static void exw_dir1(RzAnalysisOp *op, ut8 addr)
static bool i8051_init(void **user)
static int esil_i8051_init(RzAnalysisEsil *esil)
static void exr_a(RzAnalysisOp *op, ut8 dummy)
static void exr_sp2(RzAnalysisOp *op, ut8 dummy)
static ut32 i8051_reg_read(RzReg *reg, const char *regname)
static void exr_dpx(RzAnalysisOp *op, ut8 dummy)
static void exw_c(RzAnalysisOp *op, ut8 dummy)
static void exi_dp(RzAnalysisOp *op, ut8 dummy, const char *operation)
static void exw_sp1(RzAnalysisOp *op, ut8 dummy)
static void exw_dir2(RzAnalysisOp *op, ut8 addr)
static bool i8051_fini(void *user)
static void exr_bit(RzAnalysisOp *op, ut8 addr)
static void exr_imm1(RzAnalysisOp *op, ut8 val)
static RzList * maps(RzBinFile *bf)
RZ_API int rz_analysis_esil_mem_write(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len)
RZ_API int rz_analysis_esil_mem_read(RzAnalysisEsil *esil, ut64 addr, ut8 *buf, int len)
static RzAnalysisEsilCallbacks ocbs
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
@ RZ_ANALYSIS_OP_FAMILY_CPU
@ RZ_ANALYSIS_OP_MASK_ESIL
@ RZ_ANALYSIS_OP_MASK_HINT
RZ_API int rz_str_casecmp(const char *dst, const char *orig)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
RZ_API void rz_strbuf_init(RzStrBuf *sb)
@ RZ_TYPE_COND_LO
Carry clear Less than.
@ RZ_TYPE_COND_HS
Carry set >, ==, or unordered.
@ RZ_TYPE_COND_NE
Not equal.
@ RZ_TYPE_COND_AL
Always executed (no condition)
const i8051_cpu_model * cpu_curr_model
int(* reg_read)(ANALYSIS_ESIL *esil, const char *name, ut64 *res, int *size)
int(* hook_reg_read)(ANALYSIS_ESIL *esil, const char *name, ut64 *res, int *size)
RzAnalysisEsilHookRegWriteCB hook_reg_write
RzAnalysisEsilCallbacks cb
RzIOFdGetName fd_get_name
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static char * regname(int reg)