diff options
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/add_A884.d | 2 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/add_A889.d | 2 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/b_A8818.d | 12 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/bl_A8825.d | 4 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/sub_A88221.d | 2 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/sub_A88225.d | 2 | ||||
-rw-r--r-- | tools/d2c/args.c | 92 | ||||
-rw-r--r-- | tools/d2c/args.h | 6 | ||||
-rw-r--r-- | tools/d2c/d2c_gram.y | 4 | ||||
-rw-r--r-- | tools/d2c/d2c_tok.l | 40 |
11 files changed, 127 insertions, 59 deletions
@@ -1,3 +1,23 @@ +15-06-14 Cyrille Bagard <nocbos@gmail.com> + + * src/arch/arm/v7/opdefs/add_A884.d: + * src/arch/arm/v7/opdefs/add_A889.d: + Fix a syntax mistake. + + * src/arch/arm/v7/opdefs/b_A8818.d: + * src/arch/arm/v7/opdefs/bl_A8825.d: + Handle properly the sign extension when extending values. + + * src/arch/arm/v7/opdefs/sub_A88221.d: + * src/arch/arm/v7/opdefs/sub_A88225.d: + Fix a syntax mistake. + + * tools/d2c/args.c: + * tools/d2c/args.h: + * tools/d2c/d2c_gram.y: + * tools/d2c/d2c_tok.l: + Allow to use binary or hex values as arguments. Clean the code. + 15-06-13 Cyrille Bagard <nocbos@gmail.com> * Makefile.am: diff --git a/src/arch/arm/v7/opdefs/add_A884.d b/src/arch/arm/v7/opdefs/add_A884.d index 90e1235..fb79567 100644 --- a/src/arch/arm/v7/opdefs/add_A884.d +++ b/src/arch/arm/v7/opdefs/add_A884.d @@ -101,7 +101,7 @@ Rd = Register(Rd) Rn = Register(Rn) - const = ZeroExtend((i:imm3:imm8, 12, 32) + const = ZeroExtend(i:imm3:imm8, 12, 32) } diff --git a/src/arch/arm/v7/opdefs/add_A889.d b/src/arch/arm/v7/opdefs/add_A889.d index 1f81776..3c9d432 100644 --- a/src/arch/arm/v7/opdefs/add_A889.d +++ b/src/arch/arm/v7/opdefs/add_A889.d @@ -101,7 +101,7 @@ Rd = Register(Rd) SP = Register(13) - const = ZeroExtend((i:imm3:imm8, 12, 32) + const = ZeroExtend(i:imm3:imm8, 12, 32) } diff --git a/src/arch/arm/v7/opdefs/b_A8818.d b/src/arch/arm/v7/opdefs/b_A8818.d index f06367b..ab5971f 100644 --- a/src/arch/arm/v7/opdefs/b_A8818.d +++ b/src/arch/arm/v7/opdefs/b_A8818.d @@ -25,14 +25,14 @@ @encoding(t1) { - @half 1 1 0 1 cond(4) top(1) imm8(7) + @half 1 1 0 1 cond(4) imm8(8) @syntax {c} <label> @conv { c = Condition(cond) - label = SignExtend(top:imm8:'0', top, 32) + label = SignExtend(imm8:'0', imm8 & 0x80, 32) } @@ -56,13 +56,13 @@ @encoding(t2) { - @half 1 1 1 0 0 top(1) imm11(10) + @half 1 1 1 0 0 imm11(11) @syntax <label> @conv { - label = SignExtend(top:imm11:'0', top, 32) + label = SignExtend(imm11:'0', imm11 & 0x400, 32) } @@ -147,14 +147,14 @@ @encoding(A1) { - @word cond(4) 1 0 1 0 top(1) imm24(23) + @word cond(4) 1 0 1 0 imm24(24) @syntax {c} <label> @conv { c = Condition(cond) - label = SignExtend(top:imm24:'00', top, 32) + label = SignExtend(imm24:'00', imm24 & 0x800000, 32) } diff --git a/src/arch/arm/v7/opdefs/bl_A8825.d b/src/arch/arm/v7/opdefs/bl_A8825.d index ce4870c..183ba36 100644 --- a/src/arch/arm/v7/opdefs/bl_A8825.d +++ b/src/arch/arm/v7/opdefs/bl_A8825.d @@ -91,7 +91,7 @@ @conv { - imm32 = SignExtend(imm24:'00', 0, 32) + imm32 = SignExtend(imm24:'00', imm24 & 0x800000, 32) } @@ -119,7 +119,7 @@ @conv { - imm32 = SignExtend(imm24:H:'0', 0, 32) + imm32 = SignExtend(imm24:H:'0', imm24 & 0x800000, 32) } diff --git a/src/arch/arm/v7/opdefs/sub_A88221.d b/src/arch/arm/v7/opdefs/sub_A88221.d index 0ef0e11..ec6f241 100644 --- a/src/arch/arm/v7/opdefs/sub_A88221.d +++ b/src/arch/arm/v7/opdefs/sub_A88221.d @@ -101,7 +101,7 @@ Rd = Register(Rd) Rn = Register(Rn) - const = ZeroExtend((i:imm3:imm8, 12, 32) + const = ZeroExtend(i:imm3:imm8, 12, 32) } diff --git a/src/arch/arm/v7/opdefs/sub_A88225.d b/src/arch/arm/v7/opdefs/sub_A88225.d index 9c29624..e37997f 100644 --- a/src/arch/arm/v7/opdefs/sub_A88225.d +++ b/src/arch/arm/v7/opdefs/sub_A88225.d @@ -79,7 +79,7 @@ Rd = Register(Rd) SP = Register(13) - const = ZeroExtend((i:imm3:imm8, 12, 32) + const = ZeroExtend(i:imm3:imm8, 12, 32) } diff --git a/tools/d2c/args.c b/tools/d2c/args.c index 1a2c287..f933160 100644 --- a/tools/d2c/args.c +++ b/tools/d2c/args.c @@ -34,25 +34,13 @@ -/* -#include <assert.h> -#include <ctype.h> - -#include <regex.h> -#include <stdbool.h> -#include <sys/param.h> - - -*/ - - - - /* Types d'expressions représentés */ typedef enum _ConvExprType { CET_NAME, /* Désignation de variable */ CET_NUMBER, /* Valeur codée en dur */ + CET_BINVAL, /* Valeur binaire bxxx */ + CET_HEXVAL, /* Valeur sous forme hexa. */ CET_COMPOSED, /* Agrégat de champs divers */ CET_UNARY, /* Opération unaire */ CET_BINARY, /* Opération binaire */ @@ -83,6 +71,12 @@ struct _arg_expr_t /* CET_NUMBER */ unsigned long number; /* Valeur durablement définie */ + /* CET_BINVAL */ + char *binval; /* Valeur sous forme bxxx */ + + /* CET_HEXVAL */ + char *hexval; /* Valeur sous forme 0xxxx */ + /* CET_COMPOSED */ struct { @@ -199,6 +193,60 @@ arg_expr_t *build_arg_expr_from_number(unsigned long number) /****************************************************************************** * * +* Paramètres : binval = valeur binaire à conserver dans sa forme brute. * +* * +* Description : Conserve une valeur en tant qu'expression de conversion. * +* * +* Retour : Nouvelle expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +arg_expr_t *build_arg_expr_from_binval(char *binval) +{ + arg_expr_t *result; /* Structure à retourner */ + + result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t)); + + result->type = CET_BINVAL; + + result->binval = binval; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : number = valeur hexadécimale à conserver dans sa forme brute.* +* * +* Description : Conserve une valeur en tant qu'expression de conversion. * +* * +* Retour : Nouvelle expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +arg_expr_t *build_arg_expr_from_hexval(char *hexval) +{ + arg_expr_t *result; /* Structure à retourner */ + + result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t)); + + result->type = CET_HEXVAL; + + result->hexval = hexval; + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : item1 = premier élément à agréger. * * item2 = second élément à agréger. * * * @@ -338,6 +386,14 @@ void delete_arg_expr(arg_expr_t *expr) free(expr->name); break; + case CET_BINVAL: + free(expr->binval); + break; + + case CET_HEXVAL: + free(expr->hexval); + break; + case CET_COMPOSED: for (i = 0; i < expr->comp_count; i++) free(expr->comp_items[i]); @@ -856,6 +912,14 @@ bool define_arg_expr(const arg_expr_t *expr, int fd, const coding_bits *bits, co dprintf(fd, "%lu", expr->number); break; + case CET_BINVAL: + dprintf(fd, "b%s", expr->binval); + break; + + case CET_HEXVAL: + dprintf(fd, "0x%s", expr->hexval); + break; + case CET_COMPOSED: result = compute_arg_expr_size(expr, bits, list, &max_size); diff --git a/tools/d2c/args.h b/tools/d2c/args.h index d5855f4..b9f210b 100644 --- a/tools/d2c/args.h +++ b/tools/d2c/args.h @@ -67,6 +67,12 @@ arg_expr_t *build_arg_expr_from_name(char *); /* Conserve une valeur en tant qu'expression de conversion. */ arg_expr_t *build_arg_expr_from_number(unsigned long ); +/* Conserve une valeur en tant qu'expression de conversion. */ +arg_expr_t *build_arg_expr_from_binval(char *); + +/* Conserve une valeur en tant qu'expression de conversion. */ +arg_expr_t *build_arg_expr_from_hexval(char *); + /* Construit une base d'expression de conversion composée. */ arg_expr_t *build_composed_arg_expr(char *, char *); diff --git a/tools/d2c/d2c_gram.y b/tools/d2c/d2c_gram.y index 5d83930..9827b05 100644 --- a/tools/d2c/d2c_gram.y +++ b/tools/d2c/d2c_gram.y @@ -241,10 +241,12 @@ arg_list : arg_expr { $$ = build_arg_list($1); } arg_expr : NAME { $$ = build_arg_expr_from_name($1); } | NUMBER { $$ = build_arg_expr_from_number($1); } + | BINVAL { $$ = build_arg_expr_from_binval($1); } + | HEXVAL { $$ = build_arg_expr_from_hexval($1); } | arg_composed { $$ = $1; } | OP arg_expr CP { $$ = $2; } | arg_expr_un_op arg_expr { $$ = build_unary_arg_expr($2, $1); } - | OP arg_expr arg_expr_bin_op arg_expr CP { $$ = build_binary_arg_expr($2, $4, $3); } + | arg_expr arg_expr_bin_op arg_expr { $$ = build_binary_arg_expr($1, $3, $2); } arg_expr_un_op : NOT { $$ = CUO_NOT; } diff --git a/tools/d2c/d2c_tok.l b/tools/d2c/d2c_tok.l index 08562ce..300508d 100644 --- a/tools/d2c/d2c_tok.l +++ b/tools/d2c/d2c_tok.l @@ -33,9 +33,9 @@ void free_flex_memory(void) ; %x syntax syntax_name syntax_int syntax_ext -%x conv_begin conv_content conv_arg conv_arg_binval +%x conv_begin conv_content -%x arg arg_binval +%x arg arg_binval arg_hexval %x hooks_begin hooks_content @@ -130,12 +130,12 @@ void free_flex_memory(void) ; } } <conv_content>"=" { return EQ; } -<conv_content>"(" { BEGIN(conv_arg); return OP; } +<conv_content>"(" { yy_push_state(arg); return OP; } -<conv_arg>[A-Za-z_][A-Za-z0-9_]* { +<arg>[A-Za-z_][A-Za-z0-9_]* { if (strcmp(yytext, "NOT") == 0) return NOT; else if (strcmp(yytext, "AND") == 0) return AND_LOG; else if (strcmp(yytext, "EOR") == 0) return EOR; @@ -145,45 +145,21 @@ void free_flex_memory(void) ; return NAME; } } -<conv_arg>[0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; } -<conv_arg>"'" { BEGIN(conv_arg_binval); } -<conv_arg_binval>[01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; } -<conv_arg_binval>"'" { BEGIN(conv_arg); } -<conv_arg>"," { return COMMA; } -<conv_arg>":" { return COLON; } -<conv_arg>[ ]+ { } -<conv_arg>")" { BEGIN(conv_content); return CP; } - - - - - - - - - -<arg>[A-Za-z_][A-Za-z0-9_]* { - if (strcmp(yytext, "NOT") == 0) return NOT; - else if (strcmp(yytext, "AND") == 0) return AND_LOG; - else if (strcmp(yytext, "EOR") == 0) return EOR; - else - { - d2c_lval.string = strdup(yytext); - return NAME; - } - } <arg>[0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; } <arg>"'" { BEGIN(arg_binval); } <arg_binval>[01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; } <arg_binval>"'" { BEGIN(arg); } +<arg>"0x" { BEGIN(arg_hexval); } +<arg_hexval>[0-9a-f][0-9a-f]* { d2c_lval.string = strdup(yytext); BEGIN(arg); return HEXVAL; } <arg>"," { return COMMA; } <arg>":" { return COLON; } +<arg>"&" { return AND_LOG; } <arg>[ ]+ { } +<arg>"(" { yy_push_state(arg); return OP; } <arg>")" { yy_pop_state(); return CP; } - <encoding_content>"@hooks" { BEGIN(hooks_begin); return HOOKS; } <hooks_begin>[ ]+ { } <hooks_begin>"{" { BEGIN(hooks_content); } |