6

Similarly to How do I disassemble raw x86 code?, but then for the MIPS architecture: how do I disassemble raw MIPS code with objdump? I want to check the instructions in a vmlinux image, but to do so I now have to:

: > x.c
mipsel-linux-gnu-gcc -c -o x.o x.c
mipsel-linux-gnu-objcopy --add-section raw=vmlinux x.o
mipsel-linux-gnu-objcopy --remove-section .comment x.o
mipsel-linux-gnu-objdump -D x.o | less

Is there an easier way to do it? I've tried the below to no avail:

mipsel-linux-gnu-objdump -b elf32-tradlittlemips -mmips -Mgpr-names=O32,cp0-names=mips1,cp0-names=mips1,hwr-names=mips1,reg-names=mips1 -D vmlinux | less

It just spits out:

mipsel-linux-gnu-objdump: vmlinux: File format not recognized

If it helps, here is the output of some commands:

$ file x.o
x.o: ELF 32-bit LSB relocatable, MIPS, MIPS-I version 1 (SYSV), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x1040000, not stripped
$ mipsel-linux-gnu-objdump -p x.o

x.o:     file format elf32-tradlittlemips
private flags = 1006: [abi=O32] [mips1] [not 32bitmode] [PIC] [CPIC]

The target is an AR7 CPU.

Community
  • 1
  • 1
Lekensteyn
  • 58,351
  • 21
  • 146
  • 179

3 Answers3

6

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:

Lekensteyn
  • 58,351
  • 21
  • 146
  • 179
0

??? What's wrong with just:

mipsel-linux-gnu-gcc -c -o x.o x.c
mipsel-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
Kaz
  • 48,579
  • 8
  • 85
  • 132
  • vmlinux does not contain any sections, it is contains instructions only. The problem is, I don't have the gcc and objcopy tools installed, only in a VM. Since there was a way to get objdump skip the gcc/objcopy path in x86, I was wondering if it's possible on mips as well? – Lekensteyn Mar 28 '12 at 21:53
  • I see; your object file `x.o` is just a dummy, and you're pulling in sections from `vmlinux`. That's odd; I've always been able to just run `objdump` on `vmlinux`, for various architectures: MIPS, ARM, ... What does that `mipsel-linux-gnu-objdump` spit out if you just call it with `-d vmlinux`, without those other arguments? Also: `file vmlinux`. – Kaz Mar 28 '12 at 21:59
-1

Use ODA, the online disassembler:

http://www.onlinedisassembler.com

Anthony DeRosa
  • 767
  • 6
  • 6
  • ODA limits file size to upload up to 256KB only. Also, its web interface isn't very intuitive, too. – fxgreen Aug 02 '18 at 18:25