How do I disassemble raw MIPS code? How do I disassemble raw MIPS code? linux linux

How do I disassemble raw MIPS code?


Hmm, it seems easier than that. -b elf32-tradlittlemips does not work because the file is not an ELF executable, but binary. So, the correct option to be used is -b binary. The other option, -mmips makes objdump recognize the file as binary for MIPS. Since the target machine is little endian, I also had to add -EL to make the output match the output for x.o.

-mmips only includes the basic instruction set. The AR7 has a MIPS32 processor which has more instructions than just mips. To decode these newer MIPS32 instructions, use -mmips:isa32. A list of available ISAs can be listed with objdump -i -m.

The final command becomes:

mipsel-linux-gnu-objdump -b binary -mmips:isa32 -EL -D vmlinux

This would show registers like $3 instead of their names. To adjust that, I used the next additional options which are mentioned in mipsel-linux-gnu-objdump --help:

-Mgpr-names=32,cp0-names=mips32,cp0-names=mips32,hwr-names=mips32,reg-names=mips32

I chose for mips32 after reading:


??? What's wrong with just:

mipsel-linux-gnu-gcc -c -o x.o x.cmipsel-linux-gnu-objdump -D x.o

Is the problem that -D diassembles all the sections, code or not? Use -d then. Or -S to show assembly interleaved with source (implies -d).

or how about getting the assembly code from gcc:

mipsel-linux-gnu-gcc -S x.c