-
Notifications
You must be signed in to change notification settings - Fork 14
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
ELF code emitter for Z80 architecture (naiive impl.) #10
base: z80
Are you sure you want to change the base?
Commits on Jun 26, 2020
-
Configuration menu - View commit details
-
Copy full SHA for 587fdd3 - Browse repository at this point
Copy the full SHA 587fdd3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0ecf551 - Browse repository at this point
Copy the full SHA 0ecf551View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1d81be5 - Browse repository at this point
Copy the full SHA 1d81be5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 218e7cf - Browse repository at this point
Copy the full SHA 218e7cfView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2026d17 - Browse repository at this point
Copy the full SHA 2026d17View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6495989 - Browse repository at this point
Copy the full SHA 6495989View commit details -
[Bugpoint] Don't give up completely when an invalid module gets gener…
…ated, by default.
Configuration menu - View commit details
-
Copy full SHA for 46f9733 - Browse repository at this point
Copy the full SHA 46f9733View commit details -
Configuration menu - View commit details
-
Copy full SHA for 16dada5 - Browse repository at this point
Copy the full SHA 16dada5View commit details -
[cc1] Initialize all of the passes when -mllvm is passed so that -pri…
…nt-before/after can be parsed correctly.
Configuration menu - View commit details
-
Copy full SHA for 8c9b181 - Browse repository at this point
Copy the full SHA 8c9b181View commit details -
Configuration menu - View commit details
-
Copy full SHA for acf4d1d - Browse repository at this point
Copy the full SHA acf4d1dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5fd5c88 - Browse repository at this point
Copy the full SHA 5fd5c88View commit details -
Configuration menu - View commit details
-
Copy full SHA for b204774 - Browse repository at this point
Copy the full SHA b204774View commit details -
Configuration menu - View commit details
-
Copy full SHA for 92b4a06 - Browse repository at this point
Copy the full SHA 92b4a06View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2ed6977 - Browse repository at this point
Copy the full SHA 2ed6977View commit details -
Configuration menu - View commit details
-
Copy full SHA for 418a0ed - Browse repository at this point
Copy the full SHA 418a0edView commit details -
Configuration menu - View commit details
-
Copy full SHA for 3c72039 - Browse repository at this point
Copy the full SHA 3c72039View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3732596 - Browse repository at this point
Copy the full SHA 3732596View commit details -
Configuration menu - View commit details
-
Copy full SHA for dcd55f9 - Browse repository at this point
Copy the full SHA dcd55f9View commit details
Commits on Jul 13, 2020
-
Add missing Z80 definitions to ELF binary format.
Signed-off-by: Paul Osmialowski <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 2830cfe - Browse repository at this point
Copy the full SHA 2830cfeView commit details -
Fix things that have hit me hard while working on '-fintegrated-as'
Signed-off-by: Paul Osmialowski <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for e1c4140 - Browse repository at this point
Copy the full SHA e1c4140View commit details
Commits on Jul 14, 2020
-
ELF code emitter for Z80 architecture (naiive impl.)
Some caveat: - The Z80 backend emits a lot of compiler library calls as specified in llvm/lib/Target/Z80/Z80ISelLowering.cpp making it slightly harder for practical use The story: Following the ability of the other 8-bit platform supported by LLVM (AVR) to generate ELF object files, I have prepared this crude ELF code emitter for Z80. It was not extensively tested, mostly due to the lack of a compatible runtime library (e.g. for CP/M system). Yet for the testing purposes, I have prepared something rudimentary, some minimalistic mockup of CP/M's libc allowing me to prepare a simple executable .COM file. It consists of the following files: 1. _bdos.s .text .globl __csave __csave: pop hl ; get the return address push iy ; preserve iy push ix ; preserve ix ld ix, 0 add ix, sp ; new frame pointer jp (hl) ; jump to return address .globl __crestore __crestore: ld sp, ix pop ix ; restore ix pop iy ; restore iy ret ; uint16_t _bdos(uint8_t function, uint16_t arg) .globl __bdos __bdos: call __csave ld c, (ix + 6) ; ix + 6: function ld e, (ix + 8) ; ix + 8: arg (LO) ld d, (ix + 9) ; ix + 9: arg (HI) push iy ; preserve iy push ix ; preserve ix call 0x05 ; call BDOS pop ix ; restore ix pop iy ; restore iy ld l, a ; return the result in l rla ; get the highest bit to the carry flag sbc a, a ; keep the carry flag ld h, a ; return the highest bit in h jp __crestore Compile this with the GNU 'as' from binutils built with --target=z80-none-elf 'configure' flag, e.g.: z80-none-elf-as -o _bdos.o _bdos.s 2. _exit.s .text .globl __Exit __Exit: pop hl ; get rid of the return address pop hl ; exit status ld (0x80), hl ; store exit status at the address 0x80 jp 0 ; return to CP/M Similarly: z80-none-elf-as -o _exit.o _exit.s 3. crtcpm.c _Noreturn void _Exit(int); int main(int, char **); _Noreturn void start(void) __attribute__((no_builtin)) { // TODO: parse whatever there is at 0x80 static char *argv[] = { (char *)(0x80) }; _Exit(main(1, argv)); } Compile this (to 'crtcpm.o') with the LLVM compiler built with -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Z80", -DLLVM_TARGETS_TO_BUILD="" and -DLLVM_DEFAULT_TARGET_TRIPLE="z80-none-elf" 'cmake' flags, namely: clang -Wall -O0 -fintegrated-as -fomit-frame-pointer -c crtcpm.c 4. main.c uint16_t _bdos(uint8_t, uint16_t); static void putch(int c) { if ('\n' == c) _bdos(0x02U, '\r'); _bdos(0x02U, c); } int main(int argc, char **argv) { int i; int c; const int n = ((unsigned char)(argv[0][0])); for (i = 0; i < n; i++) { c = ((unsigned char)(argv[0][1 + i])); putch('['); if (' ' == c) { putch('s'); putch('p'); } else putch(c); putch(']'); } putch('\n'); return argc; } Similarly, build 'main.o': clang -Wall -fintegrated-as -c main.c Create rudimentary 'libc.a' library from '_bdos.o' and '_exit.o' using GNU 'ar' and 'runlib' from binutils built as described earlier: z80-none-elf-ar r libc.a _bdos.o _exit.o z80-none-elf-ranlib libc.a Link the final .COM file, e.g.: z80-none-elf-ld -o main.com --oformat binary -Ttext=0x100 crtcpm.o main.o -L. -lc Every CP/M program should start at 0x100, hence the .text segment is set to start at that address. The .data segment will be placed right after last byte of the .text segment. Note that 'crtcpm.o' is kept separately from 'libc.a' and is listed as the very first file needed to link the final program. This ensures that the only function defined in 'crtcpm.o' (the _start() function) will be the very first thing placed at the address 0x100. Copy the 'main.com' file to a disk image and execute it in CP/M. Basically, the 'main.com' program should print whatever was given as parameters with each character put into brackets (and spaces printed as [sp]): A>main hello, world [sp][H][E][L][L][O][,][sp][W][O][R][L][D] Note that CP/M turns all the characters in the command line arguments into upper-case. Signed-off-by: Paul Osmialowski <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for e9a373b - Browse repository at this point
Copy the full SHA e9a373bView commit details