diff --git a/librz/arch/isa/avr/assembler.c b/librz/arch/isa/avr/assembler.c index 9665a6ce69..12dd66af52 100644 --- a/librz/arch/isa/avr/assembler.c +++ b/librz/arch/isa/avr/assembler.c @@ -4,8 +4,8 @@ #include "assembler.h" #include "common.h" -#define MAX_TOKENS 6 -#define IS_INDIRECT_ADDRESS_REGISTER(x) ((x)=='x'||(x)=='y'||(x)=='z') +#define MAX_TOKENS 6 +#define IS_INDIRECT_ADDRESS_REGISTER(x) ((x) == 'x' || (x) == 'y' || (x) == 'z') #define throw_error(msg, ...) \ do { \ @@ -21,15 +21,15 @@ } \ } while (0) -#define expected_const_or_error(a,exp) \ +#define expected_const_or_error(a, exp) \ do { \ - if (RZ_STR_ISEMPTY((a)) || strcmp((a),(exp))) { \ + if (RZ_STR_ISEMPTY((a)) || strcmp((a), (exp))) { \ RZ_LOG_ERROR("[!] avr_assembler: expected '%s' but got '%s'.\n", (exp), (a)); \ return AVR_INVALID_SIZE; \ } \ } while (0) -#define parse_register_or_error_limit(rn,rs,min,max) \ +#define parse_register_or_error_limit(rn, rs, min, max) \ do { \ cchar *tmp = (rs); \ if (*tmp == 'r') { \ @@ -46,7 +46,7 @@ } \ } while (0) -#define parse_register_or_error(rn,rs) \ +#define parse_register_or_error(rn, rs) \ do { \ cchar *tmp = (rs); \ if (*tmp == 'r') { \ @@ -64,7 +64,7 @@ } while (0) /// Parse things like "r25:r24" or just "r24". Result would be 24 in both cases. -#define parse_register_pair_or_error(rn,rs) \ +#define parse_register_pair_or_error(rn, rs) \ do { \ cchar *tmp = (rs); \ if (*tmp == 'r') { \ @@ -92,13 +92,13 @@ } \ if (high != (rn) + 1) { \ RZ_LOG_ERROR("[!] avr_assembler: register pair r%u:r%u invalid: %u != %u + 1.\n", \ - (unsigned int)high, (unsigned int)(rn), (unsigned int)high, (unsigned int)(rn)); \ + (unsigned int)high, (unsigned int)(rn), (unsigned int)high, (unsigned int)(rn)); \ return AVR_INVALID_SIZE; \ } \ } \ } while (0) -#define parse_unsigned_or_error(rn,rs,limit) \ +#define parse_unsigned_or_error(rn, rs, limit) \ do { \ cchar *tmp = (rs); \ ut32 base = 0; \ @@ -117,7 +117,7 @@ } \ } while (0) -#define parse_address_or_error(rn,rs,pc,llow,lhigh) \ +#define parse_address_or_error(rn, rs, pc, llow, lhigh) \ do { \ cchar *tmp = (rs); \ if (RZ_STR_ISEMPTY(tmp)) { \ @@ -131,7 +131,7 @@ (rn) = abs - pc; \ } \ if ((rn) < 0) { \ - (rn) = ~(-((rn) - 1)); \ + (rn) = ~(-((rn)-1)); \ } else { \ (rn) -= 2; \ } \ @@ -142,7 +142,7 @@ } \ } while (0) -#define parse_signed_or_error(rn,rs,min,max) \ +#define parse_signed_or_error(rn, rs, min, max) \ do { \ cchar *tmp = (rs); \ if (RZ_STR_ISEMPTY(tmp)) { \ @@ -160,7 +160,7 @@ } \ } while (0) -#define auto_write16(buf,val,be) \ +#define auto_write16(buf, val, be) \ do { \ if (be) { \ rz_write_be16(buf, val); \ @@ -169,30 +169,27 @@ } \ } while (0) -typedef ut32 (*Encode)(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be); +typedef ut32 (*Encode)(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be); typedef struct avr_decoder_t { - cchar* opcode; /* instruction name */ + cchar *opcode; /* instruction name */ ut16 cbits; /* constant bits */ ut32 mintoks; /* required min token number */ ut32 maxtoks; /* required max token number */ Encode encode; } AvrInstruction; - -static ut32 avr_unique(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_unique(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { auto_write16(data, cbins, be); return 2; } - -static ut32 avr_rdddddrrrr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_rdddddrrrr(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd,Rr | 0 <= d <= 31 | 0 <= r <= 31 */ ut16 Rd, Rr; parse_register_or_error(Rd, tokens[1]); parse_register_or_error(Rr, tokens[2]); - cbins |= (Rr & 0x000F); cbins |= ((Rr << 5) & 0x0200); cbins |= ((Rd << 4) & 0x01F0); @@ -201,8 +198,7 @@ static ut32 avr_rdddddrrrr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } - -static ut32 avr_KKddKKKK(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_KKddKKKK(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, K | d = {24,26,28,30}, 0 <= K <= 63 */ ut16 Rd, K; parse_register_pair_or_error(Rd, tokens[1]); @@ -223,8 +219,7 @@ static ut32 avr_KKddKKKK(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut return 2; } - -static ut32 avr_KKKKddddKKKK(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_KKKKddddKKKK(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, K | 16 <= d <= 31, 0 <= K <= 255 */ ut16 Rd, K; parse_register_or_error_limit(Rd, tokens[1], 16, 31); @@ -240,8 +235,7 @@ static ut32 avr_KKKKddddKKKK(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data return 2; } - -static ut32 avr_cbr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_cbr(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, K | 16 <= d <= 31, 0 <= K <= 255 */ ut16 Rd, K; parse_register_or_error_limit(Rd, tokens[1], 16, 31); @@ -258,8 +252,7 @@ static ut32 avr_cbr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc return 2; } - -static ut32 avr_dddddcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_dddddcccc(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd | 0 <= d <= 31 */ ut16 Rd; parse_register_or_error(Rd, tokens[1]); @@ -269,8 +262,7 @@ static ut32 avr_dddddcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, u return 2; } - -static ut32 avr_dddddcbbb(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_dddddcbbb(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, b | 0 <= d <= 31, 0 <= b <= 7 */ ut16 Rd, b; @@ -284,8 +276,7 @@ static ut32 avr_dddddcbbb(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, u return 2; } - -static ut32 avr_kkkkkkkccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_kkkkkkkccc(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* k | -64 <= k <= 63 */ st16 k; parse_address_or_error(k, tokens[1], pc, -64, 63); @@ -294,8 +285,7 @@ static ut32 avr_kkkkkkkccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } - -static ut32 avr_kkkkkccck(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_kkkkkccck(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { // k | 0 <= k < 0x7ffffe ut32 k; parse_unsigned_or_error(k, tokens[1], 0x7ffffe); @@ -313,14 +303,12 @@ static ut32 avr_kkkkkccck(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, u return 4; } - -static ut32 avr_AAAAAbbb(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_AAAAAbbb(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { // CBI A,b | 0 <= A <= 31 | 0 <= b <= 7 ut16 A, b; parse_unsigned_or_error(A, tokens[1], 31); parse_unsigned_or_error(b, tokens[2], 7); - cbins |= (b & 0x0007); cbins |= ((A << 3) & 0x00F8); @@ -328,8 +316,7 @@ static ut32 avr_AAAAAbbb(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut return 2; } - -static ut32 avr_dddddddddd(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_dddddddddd(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd | 0 <= d <= 31 */ ut16 Rd; parse_register_or_error(Rd, tokens[1]); @@ -342,8 +329,7 @@ static ut32 avr_dddddddddd(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } - -static ut32 avr_KKKKcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_KKKKcccc(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* K | 0 <= K <= 0xF */ ut16 K; parse_unsigned_or_error(K, tokens[1], 0xF); @@ -354,8 +340,7 @@ static ut32 avr_KKKKcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut return 2; } - -static ut32 avr_elpm(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_elpm(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { if (ntokens == 1) { /* elpm */ /* 1001010111011000 */ @@ -387,7 +372,7 @@ static ut32 avr_elpm(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 p return 2; } -static ut32 avr_dddcrrr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_dddcrrr(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd,Rr | 16 <= d <= 23 | 16 <= r <= 23 */ ut16 Rd, Rr; parse_register_or_error_limit(Rd, tokens[1], 16, 23); @@ -403,8 +388,7 @@ static ut32 avr_dddcrrr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut6 return 2; } - -static ut32 avr_AAdddddAAAA(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_AAdddddAAAA(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, A | 0 <= d <= 31, 0 <= A <= 63 */ ut16 Rd, A; parse_register_or_error(Rd, tokens[1]); @@ -418,7 +402,7 @@ static ut32 avr_AAdddddAAAA(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } -static ut32 avr_rrrrrcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_rrrrrcccc(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd | 0 <= d <= 31 */ ut16 Rd; expected_const_or_error(tokens[1], "z"); @@ -429,9 +413,7 @@ static ut32 avr_rrrrrcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, u return 2; } - - -static ut32 avr_ld(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_ld(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* ld Rd, M | 0 <= d <= 31 | M = {X,Y,Z,X+,Y+,Z+,-X,-Y,-Z} */ ut16 Rd; parse_register_or_error(Rd, tokens[1]); @@ -489,8 +471,7 @@ static ut32 avr_ld(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, return 2; } - -static ut32 avr_ldd(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_ldd(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* ldd Rd, M + q | 0 <= d <= 31 | M = {Y,Z} | 0 <= q <= 63*/ ut16 Rd, q; parse_register_or_error(Rd, tokens[1]); @@ -520,8 +501,7 @@ static ut32 avr_ldd(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc return 2; } - -static ut32 avr_lds(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_lds(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { ut16 Rd; ut32 k; parse_register_or_error(Rd, tokens[1]); @@ -554,8 +534,7 @@ static ut32 avr_lds(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc return 4; } - -static ut32 avr_lpm(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_lpm(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { if (ntokens == 1) { /* lpm */ /* 1001010111001000 */ @@ -587,8 +566,7 @@ static ut32 avr_lpm(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc return 2; } - -static ut32 avr_kkkkkkkkkkkk(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_kkkkkkkkkkkk(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* k | -4096 <= k <= 4096 */ st16 k; parse_address_or_error(k, tokens[1], pc, -4096, 4096); @@ -598,8 +576,7 @@ static ut32 avr_kkkkkkkkkkkk(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data return 2; } - -static ut32 avr_ddddrrrr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_ddddrrrr(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, Rr | d = {0,2,...,30} | r = {0,2,...,30} */ ut16 Rd, Rr; parse_register_or_error(Rd, tokens[1]); @@ -620,8 +597,7 @@ static ut32 avr_ddddrrrr(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut return 2; } - -static ut32 avr_ddddrrrr_2x(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_ddddrrrr_2x(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, Rr | 16 <= d <= 31 | 16 <= r <= 31 */ ut16 Rd, Rr; parse_register_or_error_limit(Rd, tokens[1], 16, 31); @@ -636,8 +612,7 @@ static ut32 avr_ddddrrrr_2x(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } - -static ut32 avr_AArrrrrAAAA(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_AArrrrrAAAA(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd, A | 0 <= d <= 31, 0 <= A <= 63 */ ut16 Rd, A; parse_unsigned_or_error(A, tokens[1], 63); @@ -651,8 +626,7 @@ static ut32 avr_AArrrrrAAAA(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } - -static ut32 avr_rrrrrcbbb(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_rrrrrcbbb(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rr, b | 0 <= d <= 31, 0 <= b <= 7 */ ut16 Rr, b; parse_register_or_error(Rr, tokens[1]); @@ -665,7 +639,7 @@ static ut32 avr_rrrrrcbbb(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, u return 2; } -static ut32 avr_ddddcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_ddddcccc(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* Rd | 16 <= d <= 31 */ ut16 Rd; parse_register_or_error_limit(Rd, tokens[1], 16, 31); @@ -677,8 +651,7 @@ static ut32 avr_ddddcccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut return 2; } - -static ut32 avr_spm(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_spm(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { if (ntokens == 1) { /* spm */ /* 1001010111101000 */ @@ -698,8 +671,7 @@ static ut32 avr_spm(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc return 2; } - -static ut32 avr_st(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_st(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* st M, Rr | 0 <= r <= 31 | M = {X,Y,Z,-X,-Y,-Z} */ ut16 Rr; parse_register_or_error(Rr, tokens[2]); @@ -757,8 +729,7 @@ static ut32 avr_st(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, return 2; } - -static ut32 avr_std(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_std(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { if (ntokens == 4) { /* std M, Rr | 0 <= r <= 31 | M = {X+,Y+,Z+} */ ut16 Rr; @@ -815,9 +786,7 @@ static ut32 avr_std(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc throw_error("expected std Rr, M + q | 0 <= d <= 31 | M = {Y,Z} | 0 <= q <= 63\n"); } - - -static ut32 avr_sts(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_sts(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* sts k, Rr | 0 <= r <= 31, 0 <= k <= 0xFFFF */ ut16 Rr; ut32 k; @@ -851,8 +820,7 @@ static ut32 avr_sts(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc return 4; } - -static ut32 avr_ssscccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_ssscccc(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* b | 0 <= b <= 7 */ ut16 b; parse_unsigned_or_error(b, tokens[1], 7); @@ -862,8 +830,7 @@ static ut32 avr_ssscccc(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut6 return 2; } - -static ut32 avr_kkkkkkksss(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { +static ut32 avr_kkkkkkksss(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc, bool be) { /* b, k | -64 <= k <= 63 | 0 <= b <= 7 */ ut16 b; st16 k; @@ -876,7 +843,7 @@ static ut32 avr_kkkkkkksss(ut16 cbins, cchar** tokens, ut32 ntokens, ut8 *data, return 2; } - +// clang-format off static const AvrInstruction instructions[] = { { "adc" /* 000111rdddddrrrr */ , 0x1C00, 3, 3, avr_rdddddrrrr }, { "add" /* 000011rdddddrrrr */ , 0x0C00, 3, 3, avr_rdddddrrrr }, @@ -998,13 +965,14 @@ static const AvrInstruction instructions[] = { { "wdr" /* 1001010110101000 */ , 0x95A8, 1, 1, avr_unique }, { "xch" /* 1001001rrrrr0100 */ , 0x9204, 3, 3, avr_rrrrrcccc } }; +// clang-format on static char *strdup_limit(cchar *begin, cchar *end) { ssize_t size = end - begin; if (size < 1) { return NULL; } - char* str = malloc(size + 1); + char *str = malloc(size + 1); if (!str) { return NULL; } @@ -1023,7 +991,7 @@ static void sanitize_input(char *cinput, st32 input_size) { static char **tokens_new(cchar *input, st32 input_size, ut32 *ntokens) { - char* cinput = strdup(input); + char *cinput = strdup(input); if (!cinput) { rz_warn_if_reached(); return NULL; @@ -1031,7 +999,7 @@ static char **tokens_new(cchar *input, st32 input_size, ut32 *ntokens) { sanitize_input(cinput, input_size); - char **tokens = RZ_NEWS0(char*, MAX_TOKENS); + char **tokens = RZ_NEWS0(char *, MAX_TOKENS); if (!tokens) { free(cinput); rz_warn_if_reached(); @@ -1040,7 +1008,7 @@ static char **tokens_new(cchar *input, st32 input_size, ut32 *ntokens) { ut32 count; cchar *start, *end; - char* copy; + char *copy; start = rz_str_trim_head_ro(cinput); for (count = 0; *start && count < MAX_TOKENS; count++) { @@ -1086,13 +1054,12 @@ ut32 avr_assembler(const char *input, st32 input_size, ut8 *output, st32 output_ ut32 written = AVR_INVALID_SIZE; ut32 ntokens = 0; - char** tokens = tokens_new(input, input_size, &ntokens); + char **tokens = tokens_new(input, input_size, &ntokens); if (!tokens || ntokens < 1) { RZ_LOG_ERROR("[!] avr_assembler: invalid assembly.\n"); goto avr_assembler_end; } - for (ut32 i = 0; i < RZ_ARRAY_SIZE(instructions); ++i) { if (!rz_str_casecmp(tokens[0], instructions[i].opcode)) { ut16 mintoks = instructions[i].mintoks; @@ -1101,7 +1068,7 @@ ut32 avr_assembler(const char *input, st32 input_size, ut8 *output, st32 output_ RZ_LOG_ERROR("[!] avr_assembler: '%s' requires %u <= ntokens <= %u, but %u tokens was provided.\n", tokens[0], mintoks, maxtoks, ntokens); goto avr_assembler_end; } - written = instructions[i].encode(instructions[i].cbits, (cchar**)tokens, ntokens, output, pc, be); + written = instructions[i].encode(instructions[i].cbits, (cchar **)tokens, ntokens, output, pc, be); break; } } diff --git a/librz/arch/isa/avr/disassembler.c b/librz/arch/isa/avr/disassembler.c index e1738cc60e..e6b9847a3f 100644 --- a/librz/arch/isa/avr/disassembler.c +++ b/librz/arch/isa/avr/disassembler.c @@ -20,10 +20,10 @@ * - q = displacement const */ -typedef ut32 (*Decode)(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb); +typedef ut32 (*Decode)(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb); typedef struct avr_decoder_t { - cchar* name; /* instruction name */ + cchar *name; /* instruction name */ AVROpMnem id; /* instruction identifier */ ut32 cycles; /* number of execution cycles */ ut16 cbits; /* constant bits */ @@ -32,13 +32,13 @@ typedef struct avr_decoder_t { Decode decode; } AvrInstruction; -static ut32 avr_unique(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_unique(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { aop->mnemonic = id; rz_strbuf_set(sb, name); return 2; } -static ut32 avr_rdddddrrrr(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rdddddrrrr(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = data[0] & 0x000F; ut16 Rd = ((data[0] & 0x01F0) >> 4); Rr |= ((data[0] & 0x0200) >> 5); @@ -71,8 +71,7 @@ static ut32 avr_rdddddrrrr(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVR return 2; } - -static ut32 avr_KKddKKKK(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_KKddKKKK(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 K = data[0] & 0x000F; ut16 Rd = 24 + ((data[0] & 0x0030) >> 3); K |= ((data[0] & 0x00C0) >> 2); @@ -85,8 +84,7 @@ static ut32 avr_KKddKKKK(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp return 2; } - -static ut32 avr_KKKKddddKKKK(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_KKKKddddKKKK(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 K = data[0] & 0x000F; ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4); K |= ((data[0] & 0x0F00) >> 4); @@ -104,8 +102,7 @@ static ut32 avr_KKKKddddKKKK(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_dddddcccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -114,8 +111,7 @@ static ut32 avr_dddddcccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVRO return 2; } - -static ut32 avr_dddddcbbb(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcbbb(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 b = data[0] & 0x0007; ut16 Rd = ((data[0] & 0x01F0) >> 4); @@ -126,8 +122,7 @@ static ut32 avr_dddddcbbb(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVRO return 2; } - -static ut32 avr_kkkkkkkccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_kkkkkkkccc(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { st16 k = (data[0] & 0x03F8) >> 3; k *= 2; if (k & 0x0080) { @@ -145,8 +140,7 @@ static ut32 avr_kkkkkkkccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVR return 2; } - -static ut32 avr_kkkkkccck(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_kkkkkccck(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { st32 k = data[0] & 0x0001; k |= ((data[0] & 0x01F0) >> 3); k <<= 16; @@ -160,8 +154,7 @@ static ut32 avr_kkkkkccck(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVRO return 4; } - -static ut32 avr_AAAAAbbb(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_AAAAAbbb(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 b = data[0] & 0x0007; ut16 A = ((data[0] & 0x00F8) >> 3); @@ -172,8 +165,7 @@ static ut32 avr_AAAAAbbb(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp return 2; } - -static ut32 avr_KKKKcccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_KKKKcccc(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 K = ((data[0] & 0x00F0) >> 4); aop->mnemonic = id; @@ -182,8 +174,7 @@ static ut32 avr_KKKKcccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp return 2; } - -static ut32 avr_dddddcccc_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_z(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -193,8 +184,7 @@ static ut32 avr_dddddcccc_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_dddddcccc_zp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_zp(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -206,8 +196,7 @@ static ut32 avr_dddddcccc_zp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_dddcrrr(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddcrrr(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = 16 + (data[0] & 0x0007); ut16 Rd = 16 + ((data[0] & 0x0070) >> 4); @@ -218,8 +207,7 @@ static ut32 avr_dddcrrr(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp return 2; } - -static ut32 avr_AAdddddAAAA(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_AAdddddAAAA(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 A = data[0] & 0x000F; ut16 Rd = ((data[0] & 0x01F0) >> 4); A |= ((data[0] & 0x0600) >> 5); @@ -231,8 +219,7 @@ static ut32 avr_AAdddddAAAA(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_dddddcccc_x(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_x(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -242,8 +229,7 @@ static ut32 avr_dddddcccc_x(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_dddddcccc_xp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_xp(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -255,8 +241,7 @@ static ut32 avr_dddddcccc_xp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_dddddcccc_xm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_xm(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -268,8 +253,7 @@ static ut32 avr_dddddcccc_xm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_dddddcccc_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_y(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -279,8 +263,7 @@ static ut32 avr_dddddcccc_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_dddddcccc_yp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_yp(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -292,8 +275,7 @@ static ut32 avr_dddddcccc_yp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_dddddcccc_ym(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_ym(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -305,8 +287,7 @@ static ut32 avr_dddddcccc_ym(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_qcqqcdddddcqqq_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_qcqqcdddddcqqq_y(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 q = data[0] & 0x0007; ut16 Rd = ((data[0] & 0x01F0) >> 4); q |= ((data[0] & 0x0C00) >> 7); @@ -321,8 +302,7 @@ static ut32 avr_qcqqcdddddcqqq_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 p return 2; } - -static ut32 avr_dddddcccc_zm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_zm(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -334,8 +314,7 @@ static ut32 avr_dddddcccc_zm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_qcqqcdddddcqqq_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_qcqqcdddddcqqq_z(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 q = data[0] & 0x0007; ut16 Rd = ((data[0] & 0x01F0) >> 4); q |= ((data[0] & 0x0C00) >> 7); @@ -350,8 +329,7 @@ static ut32 avr_qcqqcdddddcqqq_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 p return 2; } - -static ut32 avr_dddddcccc_load32(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_load32(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; aop->param[0] = Rd; @@ -360,8 +338,7 @@ static ut32 avr_dddddcccc_load32(cchar* name, AVROpMnem id, ut16 data[2], ut64 p return 4; } - -static ut32 avr_kkkddddkkkk_load16(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_kkkddddkkkk_load16(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 k = data[0] & 0x000F; ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4); k |= ((data[0] & 0x0700) >> 4); @@ -372,8 +349,7 @@ static ut32 avr_kkkddddkkkk_load16(cchar* name, AVROpMnem id, ut16 data[2], ut64 return 2; } - -static ut32 avr_ddddrrrr(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_ddddrrrr(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = data[0] & 0x000F; ut16 Rd = ((data[0] & 0x00F0) >> 4); @@ -387,8 +363,7 @@ static ut32 avr_ddddrrrr(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp return 2; } - -static ut32 avr_ddddrrrr_2x(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_ddddrrrr_2x(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = data[0] & 0x000F; ut16 Rd = ((data[0] & 0x00F0) >> 4); Rr += 16; @@ -401,8 +376,7 @@ static ut32 avr_ddddrrrr_2x(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_AArrrrrAAAA(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_AArrrrrAAAA(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 A = data[0] & 0x000F; ut16 Rr = ((data[0] & 0x01F0) >> 4); A |= ((data[0] & 0x0600) >> 5); @@ -414,8 +388,7 @@ static ut32 avr_AArrrrrAAAA(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_kkkkkkkkkkkk(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_kkkkkkkkkkkk(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { st16 k = data[0] & 0x0FFF; k *= 2; if (k & 0x1000) { @@ -434,8 +407,7 @@ static ut32 avr_kkkkkkkkkkkk(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_rrrrrcbbb(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcbbb(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 b = data[0] & 0x0007; ut16 Rr = ((data[0] & 0x01F0) >> 4); @@ -446,8 +418,7 @@ static ut32 avr_rrrrrcbbb(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVRO return 2; } - -static ut32 avr_ddddcccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_ddddcccc(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4); aop->mnemonic = id; @@ -456,8 +427,7 @@ static ut32 avr_ddddcccc(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp return 2; } - -static ut32 avr_spmz(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_spmz(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { aop->mnemonic = id; aop->param[0] = 'Z'; aop->param[1] = '+'; @@ -465,8 +435,7 @@ static ut32 avr_spmz(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *ao return 2; } - -static ut32 avr_rrrrrcccc_x(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_x(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -476,8 +445,7 @@ static ut32 avr_rrrrrcccc_x(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_rrrrrcccc_xp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_xp(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -489,8 +457,7 @@ static ut32 avr_rrrrrcccc_xp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_rrrrrcccc_xm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_xm(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -502,8 +469,7 @@ static ut32 avr_rrrrrcccc_xm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_rrrrrcccc_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_y(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -513,8 +479,7 @@ static ut32 avr_rrrrrcccc_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_rrrrrcccc_yp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_yp(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -526,8 +491,7 @@ static ut32 avr_rrrrrcccc_yp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_rrrrrcccc_ym(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_ym(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -539,8 +503,7 @@ static ut32 avr_rrrrrcccc_ym(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_qcqqcrrrrrcqqq_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_qcqqcrrrrrcqqq_y(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 q = data[0] & 0x0007; ut16 Rr = ((data[0] & 0x01F0) >> 4); q |= ((data[0] & 0x0C00) >> 7); @@ -555,8 +518,7 @@ static ut32 avr_qcqqcrrrrrcqqq_y(cchar* name, AVROpMnem id, ut16 data[2], ut64 p return 2; } - -static ut32 avr_rrrrrcccc_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_z(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -566,8 +528,7 @@ static ut32 avr_rrrrrcccc_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AV return 2; } - -static ut32 avr_rrrrrcccc_zp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_zp(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -579,8 +540,7 @@ static ut32 avr_rrrrrcccc_zp(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_rrrrrcccc_zm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_rrrrrcccc_zm(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rr = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -592,8 +552,7 @@ static ut32 avr_rrrrrcccc_zm(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, A return 2; } - -static ut32 avr_qcqqcrrrrrcqqq_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_qcqqcrrrrrcqqq_z(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 q = data[0] & 0x0007; ut16 Rr = ((data[0] & 0x01F0) >> 4); q |= ((data[0] & 0x0C00) >> 7); @@ -608,8 +567,7 @@ static ut32 avr_qcqqcrrrrrcqqq_z(cchar* name, AVROpMnem id, ut16 data[2], ut64 p return 2; } - -static ut32 avr_dddddcccc_store32(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_dddddcccc_store32(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 Rd = ((data[0] & 0x01F0) >> 4); aop->mnemonic = id; @@ -619,8 +577,7 @@ static ut32 avr_dddddcccc_store32(cchar* name, AVROpMnem id, ut16 data[2], ut64 return 4; } - -static ut32 avr_kkkddddkkkk_store16(cchar* name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { +static ut32 avr_kkkddddkkkk_store16(cchar *name, AVROpMnem id, ut16 data[2], ut64 pc, AVROp *aop, RzStrBuf *sb) { ut16 k = data[0] & 0x000F; ut16 Rd = 16 + ((data[0] & 0x00F0) >> 4); k |= ((data[0] & 0x0700) >> 4); @@ -632,7 +589,7 @@ static ut32 avr_kkkddddkkkk_store16(cchar* name, AVROpMnem id, ut16 data[2], ut6 return 2; } - +// clang-format off static const AvrInstruction instructions[] = { { "adc", AVR_OP_ADC /* 000111rdddddrrrr */, 2, 0x1C00, 0xFC00, 2, avr_rdddddrrrr }, { "add", AVR_OP_ADD /* 000011rdddddrrrr */, 2, 0x0C00, 0xFC00, 2, avr_rdddddrrrr }, @@ -769,6 +726,7 @@ static const AvrInstruction instructions[] = { { "wdr", AVR_OP_WDR /* 1001010110101000 */, 2, 0x95A8, 0xFFFF, 2, avr_unique }, { "xch", AVR_OP_XCH /* 1001001rrrrr0100 */, 2, 0x9204, 0xFE0F, 2, avr_rrrrrcccc_z } }; +// clang-format on ut32 avr_disassembler(const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVROp *aop, RzStrBuf *sb) { rz_return_val_if_fail(buffer && size && aop && sb, false); @@ -777,7 +735,7 @@ ut32 avr_disassembler(const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVRO } ut16 masked; - ut16 data[2] = {0}; + ut16 data[2] = { 0 }; data[0] = rz_read_ble16(buffer, be); diff --git a/librz/arch/isa/avr/disassembler.h b/librz/arch/isa/avr/disassembler.h index 9f14fcae7e..e612198f5c 100644 --- a/librz/arch/isa/avr/disassembler.h +++ b/librz/arch/isa/avr/disassembler.h @@ -133,6 +133,6 @@ typedef struct avr_opcode_t { ut16 size; } AVROp; -ut32 avr_disassembler(const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVROp* aop, RzStrBuf *sb); +ut32 avr_disassembler(const ut8 *buffer, const ut32 size, ut64 pc, bool be, AVROp *aop, RzStrBuf *sb); #endif /* RZ_ASM_AVR_DISASSEMBLER_H */ diff --git a/librz/arch/isa/i8080/i8080dis.h b/librz/arch/isa/i8080/i8080dis.h index 906ce73e24..d8fb215aa8 100644 --- a/librz/arch/isa/i8080/i8080dis.h +++ b/librz/arch/isa/i8080/i8080dis.h @@ -16,7 +16,7 @@ // publish, distribute, sublicense, and/or sell copies of the Software, // and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // @@ -31,7 +31,6 @@ #ifndef I8080DIS_H #define I8080DIS_H -int i8080_disasm(unsigned char const* const code, char* text, int text_sz); +int i8080_disasm(unsigned char const *const code, char *text, int text_sz); #endif - diff --git a/librz/arch/isa/mips/mips_assembler.c b/librz/arch/isa/mips/mips_assembler.c index 37f821aa2a..bf9089ded7 100644 --- a/librz/arch/isa/mips/mips_assembler.c +++ b/librz/arch/isa/mips/mips_assembler.c @@ -2,7 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only #include -#include +#include static const char *const regs[33] = { "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", diff --git a/librz/arch/isa/mips/mips_assembler.h b/librz/arch/isa/mips/mips_assembler.h index f3100135b9..1436983c32 100644 --- a/librz/arch/isa/mips/mips_assembler.h +++ b/librz/arch/isa/mips/mips_assembler.h @@ -8,4 +8,4 @@ RZ_IPI int mips_assemble_opcode(const char *str, ut64 pc, ut8 *out); -#endif /* ASSEMBLE_MIPS_H */ +#endif /* ASSEMBLE_MIPS_H */ diff --git a/sys/clang-format.py b/sys/clang-format.py index 144f27abf1..1ef9f4ee19 100755 --- a/sys/clang-format.py +++ b/sys/clang-format.py @@ -26,13 +26,11 @@ dirlist = [ skiplist = [ "/gnu/", "librz/arch/isa_gnu/", - "librz/asm/arch/i8080/", - "librz/asm/arch/arm/aarch64/", "librz/hash/xxhash/", "librz/bin/mangling/cxx/", "librz/bin/d/jni.h", "librz/util/bdiff.c", - "librz/asm/arch/tms320/c55x/table.h", + "librz/arch/isa/tms320/c55x/table.h", "librz/include/sflib/", ]