From 549cbc0502e848fe5136f776bf1dc0e2b173d619 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 7 Oct 2024 23:46:23 +0900 Subject: [PATCH] [Arduino] Fix pseudo instruction lookup on Arduino --- src/arduino_example.h | 34 ++++++++++++++++++---------------- src/asm_base.cpp | 4 ++-- src/asm_base.h | 2 +- src/pseudos.h | 17 ++++++++--------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/arduino_example.h b/src/arduino_example.h index 485b95fb..b0c80c43 100644 --- a/src/arduino_example.h +++ b/src/arduino_example.h @@ -140,22 +140,20 @@ struct Example { _cli.println(F("unknown CPU")); return true; } - if (strcasecmp_P(line, PSTR("ORG")) == 0 || strncasecmp_P(line, PSTR("ORG "), 4) == 0) { + if (!isAsm() && strncasecmp_P(line, PSTR("ORG "), 4) == 0) { const auto org = skipSpaces(line + 3); - if (*org) { - uint32_t addr; - const auto p = StrMemory::readNumber(org, &addr); - if (p == org) { - _cli.println(F("illegal ORG address")); - return true; - } - const auto max = addrMax(); - if (max && addr >= max) { - _cli.println(F("ORG overflow range")); - return true; - } - _origin = addr; + uint32_t addr; + const auto p = StrMemory::readNumber(org, &addr); + if (p == org) { + _cli.println(F("illegal ORG address")); + return true; } + const auto max = addrMax(); + if (max && addr >= max) { + _cli.println(F("ORG overflow range")); + return true; + } + _origin = addr; printAddress(_origin); _cli.println(); return true; @@ -302,8 +300,12 @@ struct Example { printAddress(insn.address(), ':'); printBytes(insn.bytes(), insn.length()); _cli.println(); - _origin += insn.length() / addrUnit(); - _origin &= max - 1; + if (insn.address() == _origin) { + _origin += insn.length() / addrUnit(); + _origin &= max - 1; + } else { + _origin = insn.address(); + } } } diff --git a/src/asm_base.cpp b/src/asm_base.cpp index 4934065e..087930f0 100644 --- a/src/asm_base.cpp +++ b/src/asm_base.cpp @@ -45,7 +45,7 @@ PROGMEM constexpr Pseudos PSEUDO_TABLE{ARRAY_RANGE(PSEUDOS)}; Assembler::Assembler( const ValueParser::Plugins &plugins, const Pseudos &pseudos, const OptionBase *option) : _parser(plugins), - _pseudos(pseudos), + _pseudos(&pseudos), _commonOptions(&_opt_listRadix), _options(option), _opt_listRadix(this, &Assembler::setListRadix, OPT_INT_LIST_RADIX, OPT_DESC_LIST_RADIX, @@ -103,7 +103,7 @@ Error Assembler::encode(const char *line, Insn &insn, const SymbolTable *symtab) } Error Assembler::processPseudo(StrScanner &scan, Insn &insn) { - const auto *p = _pseudos.search(insn); + const auto *p = _pseudos->search(insn); if (p == nullptr) p = PSEUDO_TABLE.search(insn); return p ? p->invoke(this, scan, insn) : UNKNOWN_DIRECTIVE; diff --git a/src/asm_base.h b/src/asm_base.h index 06ec92a8..f17cdc4c 100644 --- a/src/asm_base.h +++ b/src/asm_base.h @@ -91,7 +91,7 @@ struct Assembler { protected: const ValueParser _parser; - const pseudo::Pseudos _pseudos; + const pseudo::Pseudos *const _pseudos; const Options _commonOptions; const Options _options; const IntOption _opt_listRadix; diff --git a/src/pseudos.h b/src/pseudos.h index 8c9949db..4846399e 100644 --- a/src/pseudos.h +++ b/src/pseudos.h @@ -32,7 +32,7 @@ struct Pseudo { using Handler = Error (Assembler::*)(StrScanner &scan, Insn &insn, uint8_t); constexpr Pseudo(const /*PROGMEM*/ char *name_P, Handler handler, uint8_t extra = 0) - : _name_P(name_P), _handler(handler), _extra(extra) {} + : _name_P(name_P), _handler_P(handler), _extra_P(extra) {} const /*PROGMEM*/ char *name_P() const { return reinterpret_cast(pgm_read_ptr(&_name_P)); @@ -45,24 +45,23 @@ struct Pseudo { private: const /*PROGMEM*/ char *const _name_P; - const Handler _handler; - const uint8_t _extra; + const Handler _handler_P; + const uint8_t _extra_P; Handler handler() const { Handler h; - memcpy_P(&h, &_handler, sizeof(Handler)); + memcpy_P(&h, &_handler_P, sizeof(Handler)); return h; } - uint8_t extra() const { return pgm_read_byte(&_extra); } + uint8_t extra() const { return pgm_read_byte(&_extra_P); } }; struct Pseudos { - constexpr Pseudos(const /*PROGMEM*/ Pseudo *table, const /*PROGMEM*/ Pseudo *end) : _table(table, end) {} + constexpr Pseudos(const /*PROGMEM*/ Pseudo *table_P, const /*PROGMEM*/ Pseudo *end_P) + : _table(table_P, end_P) {} - const Pseudo *search(const Insn &insn) const { - return _table.binarySearch(insn, comparator); - } + const Pseudo *search(const Insn &insn) const { return _table.binarySearch(insn, comparator); } private: const table::Table _table;