summaryrefslogtreecommitdiff
path: root/tools/pragma/README.md
blob: 3823b42080e9dd9c5b8d519c5a616780a6a4897c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# pragma.py
#### Pragma processor for GameCube/Wii decompilation projects
###### by Max Parisi

This is a custom pragma processor meant for use with matching decompilation projects for GameCube and Wii games. It currently adds support for `#pragma regswap` and `#pragma iswap`.

If some reconstructed C/C++ source code compiles to object binary whose only differences with a target binary are misassigned registers, you can use `#pragma regswap` 
to correct the register assignment. This is an alternative to the strategy of inlining the desired assembly that aims to be more compact, self-documenting, and convenient. 

`pragma.py` will compile your source code, then perform the register and instruction swaps by patching the range of the object file specified in each pragma invocation.

## Usage
Invoke `#pragma regswap` one or more times in a C or C++ source file with the following parameters:
```
#pragma regswap start end regA regB startFile
```

where, 
* `start` - absolute address of start of affected region in hexadecimal format
* `end` - absolute address of end of affected region (in hex)
* `regA` - register to be swapped with `regB` (r0-r31 or f0-f31)
* `regB` - register to swapped with `regA` (r0-r31 or f0-f31)
* `startFile` - absolute address of the first function provided by this file (in hex)

Invoke `#pragma iswap` with the following parameters:
```
#pragma iswap addrA addrB startFile
```
where,
* `addrA` and `addrB` - absolute addresses of the instructions to be swapped


Then, invoke the pragma processor:
```
python3 pragma.py [-h] cc cflags output source
```


## Future Work
* Support for more architectures besides Gekko/Broadway PowerPC