10 #define MAXPSEUDOOPS 10
19 { 0,
"add",
"# = # + #", { 1, 2, 3 } },
20 { 0,
"addi",
"# = # + #", { 1, 2, 3 } },
21 { 0,
"and",
"# = # & #", { 1, 2, 3 } },
22 { 0,
"andi",
"# = # & #", { 1, 2, 3 } },
23 { 0,
"beq",
"if (# == #) goto #", { 1, 2, 3 } },
24 { 0,
"bleu",
"if (unsigned)# <= # goto #", { 1, 2, 3 } },
25 { 0,
"bltu",
"if (unsigned)# < # goto #", { 1, 2, 3 } },
26 { 0,
"blt",
"if (# < #) goto #", { 1, 2, 3 } },
27 { 0,
"beqz",
"if (# == 0) goto #", { 1, 2 } },
28 { 0,
"bne",
"if (# != #) goto #", { 1, 2, 3 } },
29 { 0,
"bnez",
"if (# != 0) goto #", { 1, 2 } },
30 { 0,
"bgez",
"if (# >= 0) goto #", { 1, 2 } },
31 { 0,
"bgtz",
"if (# > 0) goto #", { 1, 2 } },
32 { 0,
"fld",
"# = #", { 1, 2 } },
33 { 0,
"j",
"jmp #", { 1 } },
34 { 0,
"jr",
"jmp #", { 1 } },
35 { 0,
"jalr",
"jmp #", { 1 } },
36 { 0,
"jal",
"jmp #", { 1 } },
37 { 0,
"ld",
"# = (double)[#]", { 1, 2 } },
38 { 0,
"li",
"# = #", { 1, 2 } },
39 { 0,
"lh",
"# = [#]", { 1, 2 } },
40 { 0,
"lui",
"# = #", { 1, 2 } },
41 { 0,
"lbu",
"# = (unsigned)[#]", { 1, 2 } },
42 { 0,
"lhu",
"# = (unsigned)[#]", { 1, 2 } },
43 { 0,
"lw",
"# = [#]", { 1, 2 } },
44 { 0,
"mv",
"# = #", { 1, 2 } },
45 { 0,
"or",
"# = # | #", { 1, 2, 3 } },
46 { 0,
"sd",
"[#] = (double)#", { 2, 1 } },
47 { 0,
"sw",
"[#] = #", { 2, 1 } },
48 { 0,
"sb",
"[#] = #", { 2, 1 } },
49 { 0,
"sh",
"[#] = #", { 2, 1 } },
50 { 0,
"sub",
"# = # - #", { 1, 2, 3 } },
57 for (
i = 0;
ops[
i].op;
i++) {
59 if (argc - 1 !=
ops[
i].narg) {
68 for (j = 0,
k = 0; ch !=
'\0'; j++,
k++) {
100 for (
i = 0;
i < argc;
i++) {
102 strcat(
newstr, (!
i ||
i == argc - 1) ?
" " :
",");
111 char w0[256],
w1[256],
w2[256],
w3[256];
112 char str[1024] = { 0 };
113 int i,
len = strlen(data),
n;
114 char *
buf, *ptr, *optr, *
num;
116 if (
len >=
sizeof(
w0)) {
126 ptr = strchr(
buf,
' ');
128 ptr = strchr(
buf,
'\t');
132 for (++ptr; *ptr ==
' '; ptr++) {
135 strncpy(
w0,
buf,
sizeof(
w0) - 1);
136 strncpy(
w1, ptr,
sizeof(
w1) - 1);
140 ptr = strchr(ptr + 1,
')');
142 if (ptr && *ptr ==
'[') {
143 ptr = strchr(ptr + 1,
']');
145 if (ptr && *ptr ==
'{') {
146 ptr = strchr(ptr + 1,
'}');
149 eprintf(
"Unbalanced bracket\n");
153 ptr = strchr(ptr,
',');
156 for (++ptr; *ptr ==
' '; ptr++) {
159 strncpy(
w1, optr,
sizeof(
w1) - 1);
160 strncpy(
w2, ptr,
sizeof(
w2) - 1);
162 ptr = strchr(ptr,
',');
165 for (++ptr; *ptr ==
' '; ptr++) {
168 strncpy(
w2, optr,
sizeof(
w2) - 1);
169 strncpy(
w3, ptr,
sizeof(
w3) - 1);
172 ptr = strchr(
buf,
'(');
185 char *rest =
strdup(ptr + 1);
186 size_t dist =
len + 1 - (ptr -
buf);
200 const char *wa[] = {
w0,
w1,
w2,
w3 };
202 for (
i = 0;
i < 4;
i++) {
223 .
name =
"riscv.pseudo",
224 .desc =
"riscv pseudo syntax",
228 #ifndef RZ_PLUGIN_INCORE
static RASN1String * newstr(const char *string)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
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
static static fork const void static count static fd const char const char static newpath char char argv
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")
static bool parse(RzParse *p, const char *data, RzStrBuf *sb)
RZ_API RzLibStruct rizin_plugin
RzParsePlugin rz_parse_plugin_riscv_pseudo
static int replace(int argc, const char *argv[], char *newstr)
RZ_API const char * rz_str_lchr(const char *str, char chr)
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
RZ_API int rz_str_replace_char(char *s, int a, int b)
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)