PowerPC Assembly Compiler?

Discussion in 'Wii U - Hacking & Backup Loaders' started by BullyWiiPlaza, Feb 21, 2016.

  1. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    What are my best options for a PowerPC assembly to bytecode compiler? I want to write assembly code and assemble it to be used on the Wii U. The Wii has a tool called ASMWiiRd however, it seems to deadlock for me when I run it after extraction. If I run it from the archive, it compiles assembly just fine. I'm on Windows 10. Another old Wii tool is PyiiASMH but installing all dependent libraries is painful and non-user friendly. Python is literally terrible with all those different versions and incompatibility galore.

    If I implemented the whole thing manually in Java, would it be a good idea? Any hints, tips I could use to cut down on the tedious work of parsing every instruction/definition manually? I also didn't find any other PowerPC assembly compilers out there so I might be missing something obvious. Is the Wii U assembly even identical to the Wii's? It seems to be for the most part at least. Are there even differences?
     
    CosmoCortney likes this.


  2. Neesh

    Neesh GBAtemp Regular

    Member
    122
    64
    Dec 23, 2015
    United States
    Well, i don't think it's a real good idea to implement the whole thing to java(Java's awesome and everything but.... come on! it's a pain in the but!) So i would just stick with it originally.
     
  3. street

    street Banned

    Banned
    85
    15
    Jan 17, 2016
    i think they would be differences as one is far more powerful ive trolled the net and also only found the one for the wii or unity for wii u
     
  4. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    If I stick to "important" instructions only it could be kinda cool and useful :P
     
  5. Onion_Knight

    Onion_Knight GBAtemp Advanced Fan

    Member
    878
    832
    Feb 6, 2014
    Marcan talked about the fact that the Wii U processor is an evolved Wii Processor. So its based on the 750 PPC architecture.

    I don't know about windows support but qemu would fit the bill, you can use qemu-ppc to install a minimal (no gui) ppc vm with the 750 architecture that should allow you to compile PPC assembly that should run natively on the wii u.
     
    Last edited by Onion_Knight, Feb 21, 2016
  6. NWPlayer123

    NWPlayer123 GBAtemp Addict

    Member
    2,632
    6,232
    Feb 17, 2012
    United States
    The Everfree Forest
    Just make a project to compile a .S file and use DevKitPPC like we do in libwiiu ???
     
    BullyWiiPlaza and Kakkoii like this.
  7. vgmoose

    vgmoose GBAtemp Regular

    Member
    229
    627
    Jan 31, 2016
    United States
    Yes, gcc has a pretty weird feature where you can just compile .S files like you would .C files. You can also generate .S files with the -S flag.

    Attached is an example of a hello world assembly project. The main difference is all references to *.c in the Makefile are replaced with *.s. I think this should always work... but I haven't really played around
     

    Attached Files:

    NWPlayer123 and BullyWiiPlaza like this.
  8. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    Thanks! This was quite obvious after all. I also looked at Hawkeye's source code and it is doing something similar.

    I tried to compile some random assembly in a file named ASM.S with the contents
    Code:
    li r0, 5
    nop
    but the result was this:
    Code:
    >powerpc-eabi-gcc ASM.S -o ASM.o
    ASM.S: Assembler messages:
    ASM.S:1: Error: unsupported relocation against r0
    A small s as file extension doesn't change anything. Well, I just want to compile the assembly, how can I do it? :(
     
    Last edited by BullyWiiPlaza, Feb 21, 2016
  9. vgmoose

    vgmoose GBAtemp Regular

    Member
    229
    627
    Jan 31, 2016
    United States
    It looks like gcc expects the registers without the r in front, like this:
    Code:
    li 0, 5
    nop
    I've seen it both ways online: this site has the r's in its examples, and this one does not. I'm not sure why, but when the r is left out it does compile for me. Does it still do what you expect it to?
     
  10. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    Well, no. I can't get it to compile something at all:
    Code:
    >powerpc-eabi-gcc ASM.s -o ASM.o
    c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.8.2/../../../../powerpc-eabi/lib/crt0.o: In function `_start':
    /home/davem/projects/devkitpro/buildscripts/.devkitPPC-i686-w64-mingw32/powerpc-eabi/newlib/powerpc-eabi/libgloss/rs6000/crt0.S:122: undefined reference to `main'
    collect2.exe: error: ld returned 1 exit status
    Without a new line at the end:
    Code:
    >powerpc-eabi-gcc ASM.s -o ASM.o
    ASM.s: Assembler messages:
    ASM.s: Warning: end of file not at end of a line; newline inserted
    c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.8.2/../../../../powerpc-eabi/lib/crt0.o: In function `_start':
    /home/davem/projects/devkitpro/buildscripts/.devkitPPC-i686-w64-mingw32/powerpc-eabi/newlib/powerpc-eabi/libgloss/rs6000/crt0.S:122: undefined reference to `main'
    collect2.exe: error: ld returned 1 exit status
    Trying to compile just nop for example also doesn't work.
     
    Last edited by BullyWiiPlaza, Feb 21, 2016
  11. wj44

    wj44 GBAtemp Fan

    Member
    477
    354
    Jun 18, 2015
    Gambia, The
    powerpc-eabi-as -mregnames -mgekko asm.s -o asm.o
    powerpc-eabi-ld -Ttext 0x80000000 asm.o
    powerpc-eabi-objcopy -O binary asm.o asm.bin
     
    Last edited by wj44, Feb 21, 2016
  12. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    Code:
    >powerpc-eabi-as -mregnames -mgekko asm.s -o asm.o
    Assembler messages:
    Error: invalid switch -mgekko
    Error: unrecognized option -mgekko
    Weird, apparently it works like that in ppctools.py.
     
    Last edited by BullyWiiPlaza, Nov 28, 2016
  13. wj44

    wj44 GBAtemp Fan

    Member
    477
    354
    Jun 18, 2015
    Gambia, The
    Use the files included in TCPGecko:
    powerpc-gekko-as -mregnames -mgekko asm.s -o asm.o
    powerpc-gekko-ld -Ttext 0x80000000 asm.o
    powerpc-gekko-objcopy -O binary asm.o asm.bin
     
    vgmoose and BullyWiiPlaza like this.
  14. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    It worked with the files from here, thanks mate :D
     
    wj44 and vgmoose like this.
  15. vgmoose

    vgmoose GBAtemp Regular

    Member
    229
    627
    Jan 31, 2016
    United States
    Leaving this here for anyone using powerpc-eabi-gcc:
    Code:
    $ cat asm.s
    li 0, 4
    nop
    $ powerpc-eabi-gcc -nostdinc -fno-builtin -c  *.s
    $ ls | grep *.o
    asm.o
    $ powerpc-eabi-ld -Ttext 1800000 --oformat binary *.o -o asm.bin
    powerpc-eabi-ld: warning: cannot find entry symbol _start; defaulting to 01800000
    $ ls | grep *.bin
    asm.bin
    
    And there's also the hello world example I attached above, which does produce a working hello world binary when you cd into it and run make.

    It seems that it's the use of -mregnames:
    Code:
    $ cat asm.s
    li r0, 4
    nop
    $ powerpc-eabi-gcc -nostdinc -fno-builtin -mregnames -c  *.s
    $ powerpc-eabi-ld -Ttext 1800000 --oformat binary *.o -o asm.bin
    powerpc-eabi-ld: warning: cannot find entry symbol _start; defaulting to 01800000
    $ ls | grep *.bin
    asm.bin
    
     
    wj44 and BullyWiiPlaza like this.
  16. cory1492

    cory1492 GBAtemp Maniac

    Member
    1,497
    24
    Jun 23, 2005
    Canada
    Home, WhereElse?
    afaik without -mregnames it expects either %r0 or (possibly, on ppc you can use 0 for a zero-offset-instead-of-register-with-zero-in-it for some instructions) 0 for register names, where with it you can also use r0

    If you want to generate position independent code (ie: you don't have to specify text offset), I use this on x360/xenon toolchain, skipping gcc for .s files:
    Code:
    xenon-as.exe -be -many -mregnames input.S -o output.elf
    xenon-objcopy.exe output.elf -O binary output.bin
    presumably your toolchain should have powerpc-eabi-as and powerpc-eabi-objcopy, though may not support the -be or -many flags, and for whatever reason I chose to name the objects as .elf instead of .o... oh well xD
     
    Last edited by cory1492, Feb 21, 2016
  17. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    On Kali Linux 2016.2 release, I'm getting this strange error:
    Code:
    ./powerpc-eabi-gcc -nostdinc -fno-builtin -mregnames -c assembly.s -o assembly.o
    as: unrecognized option '-m750cl'
    Documentation:
    Code:
    ./powerpc-eabi-gcc --h
    Usage: powerpc-eabi-gcc [options] file...
    Options:
      -pass-exit-codes         Exit with highest error code from a phase
      --help                   Display this information
      --target-help            Display target specific command line options
      --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...]
                               Display specific types of command line options
      (Use '-v --help' to display command line options of sub-processes)
      --version                Display compiler version information
      -dumpspecs               Display all of the built in spec strings
      -dumpversion             Display the version of the compiler
      -dumpmachine             Display the compiler's target processor
      -print-search-dirs       Display the directories in the compiler's search path
      -print-libgcc-file-name  Display the name of the compiler's companion library
      -print-file-name=<lib>   Display the full path to library <lib>
      -print-prog-name=<prog>  Display the full path to compiler component <prog>
      -print-multiarch         Display the target's normalized GNU triplet, used as
                               a component in the library path
      -print-multi-directory   Display the root directory for versions of libgcc
      -print-multi-lib         Display the mapping between command line options and
                               multiple library search directories
      -print-multi-os-directory Display the relative path to OS libraries
      -print-sysroot           Display the target libraries directory
      -print-sysroot-headers-suffix Display the sysroot suffix used to find headers
      -Wa,<options>            Pass comma-separated <options> on to the assembler
      -Wp,<options>            Pass comma-separated <options> on to the preprocessor
      -Wl,<options>            Pass comma-separated <options> on to the linker
      -Xassembler <arg>        Pass <arg> on to the assembler
      -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
      -Xlinker <arg>           Pass <arg> on to the linker
      -save-temps              Do not delete intermediate files
      -save-temps=<arg>        Do not delete intermediate files
      -no-canonical-prefixes   Do not canonicalize paths when building relative
                               prefixes to other gcc components
      -pipe                    Use pipes rather than intermediate files
      -time                    Time the execution of each subprocess
      -specs=<file>            Override built-in specs with the contents of <file>
      -std=<standard>          Assume that the input sources are for <standard>
      --sysroot=<directory>    Use <directory> as the root directory for headers
                               and libraries
      -B <directory>           Add <directory> to the compiler's search paths
      -v                       Display the programs invoked by the compiler
      -###                     Like -v but options quoted and commands not executed
      -E                       Preprocess only; do not compile, assemble or link
      -S                       Compile only; do not assemble or link
      -c                       Compile and assemble, but do not link
      -o <file>                Place the output into <file>
      -pie                     Create a position independent executable
      -shared                  Create a shared library
      -x <language>            Specify the language of the following input files
                               Permissible languages include: c c++ assembler none
                               'none' means revert to the default behavior of
                               guessing the language based on the file's extension
    
    Options starting with -g, -f, -m, -O, -W, or --param are automatically
    passed on to the various sub-processes invoked by powerpc-eabi-gcc.  In order to pass
    other options on to these processes the -W<letter> options must be used.
    
    For bug reporting instructions, please see:
    <http://wiki.devkitpro.org/index.php/Bug_Reports>.
    Linux binaries download: https://mega.nz/#!K5sz0BjJ!cKL8N8r52-pboMuejRp-JF7VUTlaqC_-s-GtntX9Vn4

    On Windows, the same command is working:
    Code:
    powerpc-eabi-gcc -nostdinc -fno-builtin -mregnames -c assembly.s -o assembly.o
    assembly.s: Assembler messages:
    assembly.s: Warning: end of file not at end of a line; newline inserted
    Also apparently the command line arguments are the same.

    Windows binaries download: https://mega.nz/#!C5NhFbCB!PNClMrO1Ebk50rqDj2Ou5BWYkG91LrJEog6Lmrn5UNA
     
    Last edited by BullyWiiPlaza, Oct 23, 2016
  18. QuarkTheAwesome

    QuarkTheAwesome Working for Hugs

    Member
    808
    1,989
    Apr 19, 2015
    Australia
    Stuck in the PowerPC
    Just a quick note; the whole "unsupported relocation against r0" thing is because of one of those weird little Assembly idiosyncrasies. There's three main styles of PowerPC - Intel (li r3, 5) AT&T (li %r3, 5) and what I like to call "raw" syntax (li 3, 5). There's a few other small things around variable declarations that seperate the three as well. Anyway, devKitPPC uses a rather old version of GCC that only supports AT&T and raw syntax. Not all is lost; @FIX94 has a legendary .h file that somehow #defines Intel syntax into working just fine.

    As for your problem, looks like a borked devKitPPC. Can it compile something like HBL alright? The ./ also messes with me a bit. You've got this all on your PATH, right?
     
  19. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    So can you get it working on Linux somehow? I didn't do any further testing. Then I can take those files for my tools since some Linux folks are crying that there is no disassembly support right now :P

    The file is locally in the same folder, not the PATH since I don't require people to have a "full" devkitPro installation just for two files. Check out the Java project here.
     
    Last edited by BullyWiiPlaza, Oct 23, 2016
  20. BullyWiiPlaza
    OP

    BullyWiiPlaza Nintendo Hacking <3

    Member
    1,743
    1,422
    Aug 2, 2014
    Germany
    Alright, the following bash script works for me on Kali Linux 64-bit 2016.2 release :D
    Code:
    root@kali:~/Desktop/PyiiASMH/lib/linux2_x86_64# cat asm.s
    li r0, 0
    nop
    root@kali:~/Desktop/PyiiASMH/lib/linux2_x86_64# ./compile.sh
    3800000060000000
    compile.sh:
    Code:
    #!/bin/sh
    
    # Compile the source to object code
    ./powerpc-eabi-as -mregnames -mgekko asm.s -o asm.o
    
    # Build the binary from object code
    ./powerpc-eabi-objcopy -O "binary" asm.o asm
    
    # Delete the object code file
    rm asm.o
    
    # Print out the hexadecimal binary file contents
    xxd -p asm
    
    # Remove the compiled binary
    rm asm
    The necessary powerpc binaries are here.
     
    Last edited by BullyWiiPlaza, Nov 28, 2016
    CuriousTommy likes this.