Description
Hi,
I'm trying to create a complete eZ80 tool chain based on your work and using the Z80 binutils (version 2.37) for assembling and linking (as is done by NuttX as well). For this to work, I applied the changes made by codebje to have bin utils compatible syntax (I had to make some fixes for that as well). My personal hope is that we then get a nice tool chain for an affordable, eZ80 based 8 bit computer which would allow us to port bigger applications (e.g. Lua would be nice but can't be compiled with the Zilog ZDS II tools).
I'm in the process of adapting the ZDS II code to work with this setup to have some minimal C library to build upon.
The first issue I stumbled upon is that when an offset is 0, it's not printed. E.g.:
LEA HL,IX+0
would be
LEA HL,IX
Unfortunately, the bin utils assembler (ez80-none-elf-as
) doesn't like this syntax and quits.
After a bit of searching I found a simple fix:
diff --git a/llvm/lib/Target/Z80/MCTargetDesc/Z80InstPrinterCommon.cpp b/llvm/lib/Target/Z80/MCTargetDesc/Z80InstPrinterCommon.cpp
index e92f3020b..36bf5228f 100644
--- a/llvm/lib/Target/Z80/MCTargetDesc/Z80InstPrinterCommon.cpp
+++ b/llvm/lib/Target/Z80/MCTargetDesc/Z80InstPrinterCommon.cpp
@@ -104,7 +104,7 @@ void Z80InstPrinterCommon::printAddr(const MCInst *MI, unsigned Op,
printOperand(MI, Op, OS);
auto Off = MI->getOperand(Op + 1).getImm();
assert(isInt<8>(Off) && "Offset out of range!");
- if (Off > 0)
+ if (Off >= 0)
OS << " + " << int(Off);
else if (Off < 0)
OS << " - " << -int(Off);
Now, the offset is always printed and the assembler is happy.
I do have 2 other, more serious problems:
__attribute__((__interrupt__))
does not generate correct code. At this moment, I'm able to generate the needed instructions but I see that offsets in the stack for the variables are wrong and I can't find a solution for that (it's the first time I'm looking into the code for a compiler and it's a bit overwhelming).- Variadic arguments don't work. Again because offsets to the stack are not correct.
I'll write up more detailed reports for that.
Koen