Hacking PowerPC Assembly Compiler?

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
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?
 
  • Like
Reactions: CosmoCortney

Neesh

Well-Known Member
Member
Joined
Dec 23, 2015
Messages
122
Trophies
0
XP
153
Country
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.
 

street

Banned!
Banned
Joined
Jan 17, 2016
Messages
85
Trophies
0
XP
-23
Country
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
 

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
Germany
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.
If I stick to "important" instructions only it could be kinda cool and useful :P
 

Onion_Knight

Well-Known Member
Member
Joined
Feb 6, 2014
Messages
878
Trophies
0
Age
45
XP
997
Country
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?

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,

NWPlayer123

Well-Known Member
Member
Joined
Feb 17, 2012
Messages
2,642
Trophies
0
Location
The Everfree Forest
XP
6,693
Country
United States
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?
Just make a project to compile a .S file and use DevKitPPC like we do in libwiiu ???
 

vgmoose

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
360
Trophies
1
Website
github.com
XP
3,063
Country
United States
Just make a project to compile a .S file and use DevKitPPC like we do in libwiiu ???

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
 

Attachments

  • hello_world_asm.zip
    1.6 KB · Views: 323

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
Germany
Just make a project to compile a .S file and use DevKitPPC like we do in libwiiu ???
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,

vgmoose

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
360
Trophies
1
Website
github.com
XP
3,063
Country
United States
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? :(

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?
 

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
Germany
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?
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,

wj44

Well-Known Member
Member
Joined
Jun 18, 2015
Messages
477
Trophies
0
XP
506
Country
Gambia, The
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.
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,

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
Germany
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
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,

wj44

Well-Known Member
Member
Joined
Jun 18, 2015
Messages
477
Trophies
0
XP
506
Country
Gambia, The
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
Code:
ppctools.py
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

Well-Known Member
Member
Joined
Jan 31, 2016
Messages
360
Trophies
1
Website
github.com
XP
3,063
Country
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 looks like gcc expects the registers without the r in front, like this:
I'm not sure why, but when the r is left out it does compile for me.
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
 

cory1492

Well-Known Member
Member
Joined
Jun 23, 2005
Messages
1,497
Trophies
1
Location
Home, WhereElse?
XP
334
Country
Canada
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,

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
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,
Joined
Apr 19, 2015
Messages
1,023
Trophies
1
Location
Stuck in the PowerPC
Website
heyquark.com
XP
3,909
Country
Australia
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?
 

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
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

You've got this all on your PATH, right?
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,

BullyWiiPlaza

Nintendo Hacking <3
OP
Member
Joined
Aug 2, 2014
Messages
1,932
Trophies
0
XP
2,477
Country
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,
  • Like
Reactions: CuriousTommy

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: Ending to the fallout series was lame could've gave us a bit more