-
Notifications
You must be signed in to change notification settings - Fork 13
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot compile assembly to the z80 binary #2
Comments
LLVM z80 can't generate binary output, yet. This project is developed like z80 clang and not ready for using. |
I've finally found some time to look closer at the problem. First I must apologize, since I didn't check the most obvious thing: binutils with its GNU assembler can be built for targeting Z80 CPU. clang -target z80-unknown-coff -Wall -S -emit-llvm -c test.c <=== this produces test.ll It turns out that z80-unknown-coff-ld produces binary that can be freely executed on typical Z80 machine like ZX Spectrum. What 'sed' command does is:
...will turn into this:
all these '# 0x...' need to be removed. So with -e 's/#.*$//' sed removes all comments starting with '#'. This result in some complication, since now '#' character should not occur in string literals (like "#") - this will break compilation. println("Hello world"); Unfortunately it produces code as follows:
Error message: {standard input}: Assembler messages: The workaround is: char msg[] = "Hello world"; println(msg); Seems like GNU as does not understand .rodata notation. The same goes to all kinds of global constants: const uint16_t i = 10; turns into:
Error message: {standard input}: Assembler messages: The biggest encountered problem however is that llc sometimes produce invalid assembly code. #define FRAMEBUFFER ((volatile uint8_t *)(16384)) uint8_t i; for (i = 0; i < 192; i++) SETPIXEL(i, i + 8); This will produce error as follows: {standard input}: Assembler messages: Which is caused by following operation:
Fortunately, it's typically possible to find some workaround, e.g. following code that do similar thing will compile: uint8_t i, j; for (i = 0, j = 8; i < 192; i++, j++) SETPIXEL(i, j); |
Thank you for your work on this problem. The code generator creates sometimes incorrect opcodes now. All these problems can be resolved in code generation module. This project is developed by me as a hobby. I will correct this errors in my free time. |
It's been 3 years since this was opened and 4 years since any work has been done on porting the Z80 architecture using LLVM here. Has your project died? Because I am interested in making this project work but I am a complete beginner to LLVM's backend. |
I'd like to ask you, what assembler are you using to build final binary from z80 assembly files outputed by llc.
I tried sdasz80 from sdcc package, it throws a lot of error lines:
bash-3.2$ llc -march=z80 -O0 test.ll
bash-3.2$ sdasz80 test.bin test.s
test.s:1: Error:
Also I tried z80asm:
bash-3.2$ z80asm -v -o test.bin test.s
Assembling....
test.s:1: error: command or comment expected (was .file "test.ll" )
test.s:2: error: command or comment expected (was .text )
test.s:3: error: command or comment expected (was .globl fun )
test.s:4: error: command or comment expected (was .type fun,@function )
test.s:5: error: command or comment expected (was # @fun )
test.s:6: error: command or comment expected (was # BB#0: )
test.s:28: error: command or comment expected (was # =>This Inner Loop Header: Depth=1 )
test.s:38: error: command or comment expected (was # in Loop: Header=BB0_1 Depth=1 )
test.s:50: error: command or comment expected (was # kill: BC )
...
*** 54 errors found ***
Finally, none of them produced test.bin file.
Unfortunately, llc also can't build binary objects:
bash-3.2$ llc -march=z80 -filetype=obj -O0 test.ll
0 llc 0x0000000100e3f084 llvm::sys::PrintStackTrace(sFILE) + 38
1 llc 0x0000000100e3f2b3 PrintStackTraceSignalHandler(void) + 27
2 llc 0x0000000100e3f7bf SignalHandler(int) + 254
3 libSystem.B.dylib 0x00007fff83db21ba sigtramp + 26
4 libSystem.B.dylib 0x0000000102819600 sigtramp + 2124837984
5 llc 0x0000000100932ae7 llvm::LLVMTargetMachine::addPassesToEmitFile(llvm::PassManagerBase&, llvm::formatted_raw_ostream&, llvm::TargetMachine::CodeGenFileType, bool, void const, void const) + 1457
6 llc 0x00000001000347e0 compileModule(char**, llvm::LLVMContext&) + 3454
7 llc 0x00000001000349e3 main + 199
8 llc 0x0000000100033574 start + 52
9 llc 0x0000000000000005 start + 4294757061
Stack dump:
0. Program arguments: llc -march=z80 -filetype=obj -O0 test.ll
Segmentation fault
The text was updated successfully, but these errors were encountered: