avast / avast/retdec

r3000 MIPS output issues

Open
#32 2 comments 0 reactions 1 assignee Claimed by @PeterMatula View on GitHub
bug C-bin2llvmir enhancement P-output
Dominant language
C++
Stars
8.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Hi folks,

first of all, thank you very much for open-sourcing, I've been looking for a decent MIPS decompiler for a long time.

I work on really old binaries (GCC 2.X era), so not sure if reports like this would be usefull or even apply to modern MIPS code, therefore any code pointers that may help me to debug on my own would be appreciated too.

[asm example](https://onlinedisassembler.com/odaweb/uAvx0qFn/0)

`bash .\bin\decompile.sh .\mips\ex1.bin -a mips -m raw -e little --raw-entry-point 0x8002DFF0 --raw-section-vma 0x8002DFF0`

```
int32_t entry_point(int32_t a1, int32_t a2) {
*(int32_t *)-0x7ffaff04 = 0x10000 * a2 - 0x10000;
*(int32_t *)-0x7ffaff08 = a1;
return 0;
}
```

1. Minor, but annoying: Params are 1-based but all MIPS docs/tools that I am aware (including IDA) are using a0 - a3 for function params.

2. Pointers got miscalculated. In the original code the pair

```
lui at, 0x8005
sw a1, 0xFC(at)
```

should be equal to `[(0x8005 << 16) + 0xFC] = a1`, but something got confused with signed/unsigned bit?

3. `0x10000 * a2 - 0x10000;` part is weird while functionally equivalent. I would expect something simpler like `(a2 - 1) << 16;`

**tldr: Desired output**
```
int32_t entry_point(int32_t a0, int32_t a1) {
*(int32_t *)0x800500FC = (a1 - 1) << 16;
*(int32_t *)0x800500F8 = a0;
return 0;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.