SYSTEM.EMITH Problem

Report any suspected bugs that you find
Locked
gray
Posts: 115
Joined: Tue Feb 12, 2019 2:59 am
Location: Mauritius

SYSTEM.EMITH Problem

Post by gray » Wed Dec 27, 2023 1:54 am

This test code

Code: Select all

MODULE TestEMITH;
  IMPORT SYSTEM;
  CONST SEV = 0BF40H;
BEGIN
  SYSTEM.EMITH(SEV)
END TestEMITH.
results in a compiler exception (Astrobe for M0, v9.0.3):

Code: Select all

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Decode.Decode.Op16IfThen(Int32 instr)
   at Decode.Decode.Decode16(Int32 instr)
   at DecObj.DecObj.DecodeFile1(Writer w, Char[] path, Boolean& ok)
   at Compiler.Compiler.Compile(String source, Writer w, Int32& errcnt)
After I had run into this in my "real code" (the SEV = send event instruction is part of the initialisation sequence to get the second CPU core on the RP2040 going), I have tested some other 16 bit values, random and "around" the offending one, which all compiled.

Can I work around this by inserting a NOP together with SEV, and use SYSTEM.EMIT?

Code: Select all

  CONST NOPSEV = 046C0BF40H;
  ...
  SYSTEM.EMIT(NOPSEV)

cfbsoftware
Site Admin
Posts: 497
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: SYSTEM.EMITH Problem

Post by cfbsoftware » Wed Dec 27, 2023 7:08 am

Thank you for your report. The error occurs because the SEV instruction happens to be a "related encoding" variant of the ARMv7-M IT instruction which is not yet recognised by the Astrobe disassemblers. The WFE, WFI, and YIELD instructions behave similarly. This problem will be fixed in the next release of Astrobe for Cortex-M0.

Unfortunately, the only workarounds I can suggest are very low-level and I'm unable to provide any additional assistance:

1. Use SYSTEM.EMIT to generate a placeholder (e.g. a NOP) instead of SEV. Then:

2a. Patch the bin executable file with a binary editor (my favourite is XVI) to replace the NOP with the SEV opcode.

or

2b. Use the program you are using to convert the .bin file into a uf2 file to patch the instruction.

or

2c. Replace the NOP instruction in the assembly source (.s file) generated by the Astrobe Module Disassembler and then use the GNU ARM assembler to generate the .bin file.

Locked