Add MIPS64 (n64 ABI) Linux support#1631
Conversation
Introduce QL_ARCH.MIPS64 so Qiling can emulate MIPS64 Linux user-space
shellcode in both big- and little-endian. The native backends already
support it (Unicorn UC_MODE_MIPS64, Capstone/Keystone CS/KS_MODE_MIPS64).
- QlArchMIPS64: 64-bit arch class reusing the shared MIPS register map
- n64 calling convention and syscall ABI: the first eight arguments are
passed in registers (a0-a3 and a4-a7, the physical registers $8-$11)
with no on-stack shadow space, unlike o32
- n64 syscall table (base 5000) generated from the Linux uapi header
asm/unistd_n64.h
- wire MIPS64 through the Linux/blob OS layers, ELF machine detection
(EM_MIPS + ELFCLASS64) and n64 doubleword stack alignment
- add big- and little-endian MIPS64 shellcode tests
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow-up note: reconcile with #1630This PR and #1630 both modify the MIPS branch in #1630 introduces a shared Once both land, MIPS64 should also be wired to |
Demonstrate MIPS64 (n64 ABI) Linux shellcode emulation in both big- and little-endian, using a write/exit_group shellcode that prints to stdout. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The Linux/POSIX syscall layer has several arch-specific code paths keyed on QL_ARCH.MIPS (open flags, socket type/domain/level/option/ip-option tables, mmap flags, SHMLBA, the sigset/sigaction layout, SIGSTOP=23, the MIPS sigprocmask variant, the MIPS stat struct, the pipe()-returns-in-registers convention and set_thread_area). These values are MIPS-arch-specific and shared by the n64 ABI, so MIPS64 must take the same paths. Notably the MIPS64 stat struct already existed but was reached via QL_ARCH.MIPS + bits==64; with a distinct QL_ARCH.MIPS64 type that branch was missed and stat fell back to the x86 layout. The struct definitions are parameterised on arch.bits/native_type, so the n64 layouts fall out correctly once the branch fires. pread64's o32 stack-offset hack is intentionally left MIPS-only: under n64 the 64-bit offset arrives in a register, so the generic argument handling is already correct. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds
QL_ARCH.MIPS64so Qiling can emulate MIPS64 Linux user-space code in both big- and little-endian. The native backends already support MIPS64 (UnicornUC_MODE_MIPS64, Capstone/KeystoneCS/KS_MODE_MIPS64); this wires it through the framework.What's included
QlArchMIPS64(qiling/arch/mips64.py) — 64-bit arch class reusing the shared MIPS register map.a0-a3anda4-a7, i.e. the physical registers$8-$11) with no on-stack shadow space, unlike o32.asm/unistd_n64.h.EM_MIPS+ELFCLASS64), and n64 doubleword stack alignment.tests/test_shellcode.py.Testing
python3 -m unittest test_shellcodepasses, including the newtest_linux_mips64eb/test_linux_mips64el(awrite+exit_groupshellcode assembled withbinutilsmips64-linux-gnuabi64-as).Scope
This is user-space shellcode-level support. Full MIPS64 ELF binary loading and rootfs samples are not part of this PR.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com