How do I parse raw MIPS code?

Similarly How to parse raw x86 code? but then for the MIPS architecture: how to parse the raw MIPS code with objdump

? I want to check the instructions in the vmlinux image, but for that I now need:

: > 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 this? I have tried the following 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 that helps, here's 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]

      

Target - AR7 processor.

+3


source to share


3 answers


Hmm, it seems easier. -b elf32-tradlittlemips

doesn't work because the file is not an ELF executable but a binary one. So, the correct option to be used is -b binary

. Another option -mmips

makes objdump recognize the file as binary for MIPS. Since the target machine is slightly oriented, I also had to add -EL

to make the output match the output for x.o

.

-mmips

includes only a basic set of commands. The AR7 has a MIPS32 processor that has more instructions than just mips. To decode these new MIPS32 instructions use -mmips:isa32

. The list of available ISAs can be specified with objdump -i -m

.

Final command:

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

      



This will cause type registers to appear $3

instead of their names. To configure this, I used the following additional options, which are listed 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:

+4


source


??? What's wrong:

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

      

Is it a problem that -D

all sections are flattened out by code or not? Then use -D

. Or -S

to show an assembly alternating with a source (implied -D

).



or how to get the assembly code from gcc:

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

      

0


source


Use ODA, an online disassembler:

http://www.onlinedisassembler.com

0


source







All Articles