From 8da9c2bbf6b4e9467d362f0af242189b5173a94f Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 19 Jul 2022 14:46:08 +0100 Subject: [PATCH] Correct bit number for lone 'a' in config_gram.y When an SPI command has a lone 'a' the initialisation now is as would be expected by all commands that take an address. Atmel's opcodes for SPI programming are consistent in this respect. This commit makes specifying the bit number in avrdude.conf optional. Instead of read_lo = "0 0 1 0 0 0 0 0 0 0 a13 a12 a11 a10 a9 a8 a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o"; one can now use read_lo = "0 0 1 0 0 0 0 0 0 0 a a a a a a a a a a a a a a o o o o o o o o"; --- src/config_gram.y | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/config_gram.y b/src/config_gram.y index 2c6c1f46..71553aaa 100644 --- a/src/config_gram.y +++ b/src/config_gram.y @@ -45,7 +45,7 @@ int yywarning(char * errmsg, ...); static int assign_pin(int pinno, TOKEN * v, int invert); static int assign_pin_list(int invert); static int which_opcode(TOKEN * opcode); -static int parse_cmdbits(OPCODE * op); +static int parse_cmdbits(OPCODE * op, int opnum); static int pin_name; %} @@ -1317,7 +1317,8 @@ part_parm : free_token($1); YYABORT; } - if(0 != parse_cmdbits(op)) YYABORT; + if(0 != parse_cmdbits(op, opnum)) + YYABORT; if (current_part->op[opnum] != NULL) { /*yywarning("operation redefined");*/ avr_free_opcode(current_part->op[opnum]); @@ -1455,7 +1456,8 @@ mem_spec : free_token($1); YYABORT; } - if(0 != parse_cmdbits(op)) YYABORT; + if(0 != parse_cmdbits(op, opnum)) + YYABORT; if (current_mem->op[opnum] != NULL) { /*yywarning("operation redefined");*/ avr_free_opcode(current_mem->op[opnum]); @@ -1579,7 +1581,7 @@ static int which_opcode(TOKEN * opcode) } -static int parse_cmdbits(OPCODE * op) +static int parse_cmdbits(OPCODE * op, int opnum) { TOKEN * t; int bitno; @@ -1635,7 +1637,10 @@ static int parse_cmdbits(OPCODE * op) case 'a': op->bit[bitno].type = AVR_CMDBIT_ADDRESS; op->bit[bitno].value = 0; - op->bit[bitno].bitno = 8*(bitno/8) + bitno % 8; + op->bit[bitno].bitno = bitno < 8 || bitno > 23? 0: + opnum == AVR_OP_LOAD_EXT_ADDR? bitno+8: bitno-8; /* correct bit number for lone 'a' */ + if(bitno < 8 || bitno > 23) + yywarning("address bits don't normally appear in Byte 0 or Byte 3 of SPI programming commands"); break; case 'i': op->bit[bitno].type = AVR_CMDBIT_INPUT; @@ -1679,5 +1684,8 @@ static int parse_cmdbits(OPCODE * op) } /* while */ + if(bitno > 0) + yywarning("too few opcode bits in instruction"); + return rv; }