-
Notifications
You must be signed in to change notification settings - Fork 6
How to covert a ELF binary file into a Chisel readable text file.
Jianfeng An edited this page May 28, 2017
·
2 revisions
All the following files can be downloade from: https://pan.baidu.com/s/1gfaJEvh passwd: k3pe
- Copy mips-sde-elf-i686-pc-linux-gnu.tar in your diretory. Unzip the file by:
tar xvf mips-sde-elf-i686-pc-linux-gnu.tar
- Write a C/C++ file in your favorate text editor, such as gedit, and save it with the name add.c.
// add.c
int add(int a, int b) {
return a+b;
}
- Compile add.c into ELF by:
// You should change the path to point your mips-4.3
./mips-4.3/bin/mips-sde-elf-gcc -o add add.c
- Look the content in add ELF file:
cpu@deric-VirtualBox:~/anjf/mipsgcc$ xxd add
0000000: 7f45 4c46 0102 0100 0000 0000 0000 0000 .ELF............
0000010: 0002 0008 0000 0001 0040 00b0 0000 0034 [email protected]
0000020: 0000 0368 7000 1001 0034 0020 0002 0028 ...hp....4. ...(
0000030: 0012 000f 0000 0001 0000 0000 0040 0000 .............@..
0000040: 0040 0000 0000 0254 0000 0254 0000 0005 [email protected]....
0000050: 0001 0000 0000 0001 0000 0254 0041 0254 ...........T.A.T
0000060: 0041 0254 0000 0018 0000 0038 0000 0006 .A.T.......8....
0000070: 0001 0000 0000 0000 0000 0000 0000 0000 ................
0000080: 0000 0000 0000 0000 0000 0000 27bd ffe0 ............'...
0000090: afbf 0014 0c10 0057 0000 0000 0c10 007b .......W.......{
00000a0: 0000 0000 8fbf 0014 03e0 0008 27bd 0020 ............'..
00000b0: 3c02 0041 9042 026c 27bd ffe0 afbf 001c <..A.B.l'.......
00000c0: afb2 0018 afb1 0014 1440 001e afb0 0010 .........@......
00000d0: 3c03 0041 3c02 0041 2463 025c 2442 0260 <..A<..A$c.\$B.`
00000e0: 0043 1023 0002 1083 2450 ffff 0060 9021 .C.#....$P...`.!
00000f0: 0810 0041 3c11 0041 8c62 0000 0040 f809 ...A<..A.b...@..
0000100: ae24 0270 8e22 0270 2444 0001 0004 1880 .$.p.".p$D......
0000110: 0050 102b 1440 fff8 0072 1821 3c02 0000 [email protected].!<...
0000120: 2442 0000 1040 0005 2403 0001 3c04 0040 $B...@..$...<..@
0000130: 0c00 0000 2484 0250 2403 0001 3c02 0041 ....$..P$...<..A
0000140: a043 026c 8fbf 001c 8fb2 0018 8fb1 0014 .C.l............
0000150: 8fb0 0010 03e0 0008 27bd 0020 3c02 0000 ........'.. <...
0000160: 27bd ffe8 2442 0000 1040 0006 afbf 0014 '...$B...@......
0000170: 3c04 0040 3c05 0041 2484 0250 0c00 0000 <..@<..A$..P....
0000180: 24a5 0274 3c04 0041 8c82 0264 1040 0007 $..t<..A...d.@..
0000190: 3c02 0000 2459 0000 1320 0004 8fbf 0014 <...$Y... ......
00001a0: 2484 0264 0320 0008 27bd 0018 8fbf 0014 $..d. ..'.......
00001b0: 03e0 0008 27bd 0018 27bd fff8 afbe 0004 ....'...'.......
00001c0: 03a0 f021 afc4 0008 afc5 000c 8fc3 0008 ...!............
00001d0: 8fc2 000c 0062 1021 03c0 e821 8fbe 0004 .....b.!...!....
00001e0: 27bd 0008 03e0 0008 0000 0000 27bd ffe0 '...........'...
00001f0: 3c02 0041 afb1 0018 afb0 0014 afbf 001c <..A............
0000200: 2450 0254 0810 0085 2411 ffff 0040 f809 $P.T....$....@..
0000210: 0000 0000 8e02 0000 1451 fffc 2610 fffc .........Q..&...
0000220: 8fbf 001c 8fb1 0018 8fb0 0014 03e0 0008 ................
0000230: 27bd 0020 27bd ffe0 afbf 0014 0c10 002c '.. '..........,
0000240: 0000 0000 8fbf 0014 03e0 0008 27bd 0020 ............'..
0000250: 0000 0000 ffff ffff 0000 0000 ffff ffff ................
0000260: 0000 0000 0000 0000 0000 0000 a000 0000 ................
0000270: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000280: 0041 8260 0047 4343 3a20 2853 6f75 7263 .A.`.GCC: (Sourc
0000290: 6572 7920 472b 2b20 4c69 7465 2034 2e33 ery G++ Lite 4.3
00002a0: 2d38 3129 2034 2e33 2e32 0041 0000 000f -81) 4.3.2.A....
00002b0: 676e 7500 0100 0000 0704 0100 0040 01b8 gnu..........@..
00002c0: 4000 0000 ffff fffc 0000 0000 0000 0000 @...............
00002d0: 0000 0008 0000 001e 0000 001f 002e 7379 ..............sy
00002e0: 6d74 6162 002e 7374 7274 6162 002e 7368 mtab..strtab..sh
00002f0: 7374 7274 6162 002e 7265 6769 6e66 6f00 strtab..reginfo.
0000300: 2e69 6e69 7400 2e74 6578 7400 2e66 696e .init..text..fin
0000310: 6900 2e65 685f 6672 616d 6500 2e63 746f i..eh_frame..cto
0000320: 7273 002e 6474 6f72 7300 2e6a 6372 002e rs..dtors..jcr..
0000330: 7364 6174 6100 2e62 7373 002e 636f 6d6d sdata..bss..comm
0000340: 656e 7400 2e67 6e75 2e61 7474 7269 6275 ent..gnu.attribu
0000350: 7465 7300 2e6d 6465 6275 672e 6162 6933 tes..mdebug.abi3
0000360: 3200 2e70 6472 0000 0000 0000 0000 0000 2..pdr..........
0000370: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000380: 0000 0000 0000 0000 0000 0000 0000 0000 ................
0000390: 0000 001b 7000 0006 0000 0000 0040 0074 [email protected]
00003a0: 0000 026c 0000 0018 0000 0000 0000 0000 ...l............
00003b0: 0000 0004 0000 0018 0000 0024 0000 0001 ...........$....
00003c0: 0000 0006 0040 008c 0000 008c 0000 0024 .....@.........$
00003d0: 0000 0000 0000 0000 0000 0001 0000 0000 ................
00003e0: 0000 002a 0000 0001 0000 0006 0040 00b0 ...*.........@..
00003f0: 0000 00b0 0000 0184 0000 0000 0000 0000 ................
0000400: 0000 0004 0000 0000 0000 0030 0000 0001 ...........0....
0000410: 0000 0006 0040 0234 0000 0234 0000 001c [email protected]....
0000420: 0000 0000 0000 0000 0000 0001 0000 0000 ................
0000430: 0000 0036 0000 0001 0000 0002 0040 0250 [email protected]
0000440: 0000 0250 0000 0004 0000 0000 0000 0000 ...P............
0000450: 0000 0004 0000 0000 0000 0040 0000 0001 ...........@....
0000460: 0000 0003 0041 0254 0000 0254 0000 0008 .....A.T...T....
0000470: 0000 0000 0000 0000 0000 0004 0000 0000 ................
0000480: 0000 0047 0000 0001 0000 0003 0041 025c ...G.........A.\
0000490: 0000 025c 0000 0008 0000 0000 0000 0000 ...\............
00004a0: 0000 0004 0000 0000 0000 004e 0000 0001 ...........N....
00004b0: 0000 0003 0041 0264 0000 0264 0000 0004 .....A.d...d....
00004c0: 0000 0000 0000 0000 0000 0004 0000 0000 ................
00004d0: 0000 0053 0000 0001 1000 0003 0041 0268 ...S.........A.h
00004e0: 0000 0268 0000 0004 0000 0000 0000 0000 ...h............
00004f0: 0000 0004 0000 0000 0000 005a 0000 0008 ...........Z....
0000500: 0000 0003 0041 026c 0000 026c 0000 0020 .....A.l...l...
0000510: 0000 0000 0000 0000 0000 0004 0000 0000 ................
0000520: 0000 005f 0000 0001 0000 0000 0000 0000 ..._............
0000530: 0000 0284 0000 0027 0000 0000 0000 0000 .......'........
0000540: 0000 0001 0000 0000 0000 0068 6fff fff5 ...........ho...
0000550: 0000 0000 0000 0000 0000 02ab 0000 0010 ................
0000560: 0000 0000 0000 0000 0000 0001 0000 0000 ................
0000570: 0000 0078 0000 0001 0000 0000 0000 0030 ...x...........0
0000580: 0000 02bb 0000 0000 0000 0000 0000 0000 ................
0000590: 0000 0001 0000 0000 0000 0086 0000 0001 ................
00005a0: 0000 0000 0000 0000 0000 02bc 0000 0020 ...............
00005b0: 0000 0000 0000 0000 0000 0004 0000 0000 ................
00005c0: 0000 0011 0000 0003 0000 0000 0000 0000 ................
00005d0: 0000 02dc 0000 008b 0000 0000 0000 0000 ................
00005e0: 0000 0001 0000 0000 0000 0001 0000 0002 ................
00005f0: 0000 0000 0000 0000 0000 0638 0000 02e0 ...........8....
0000600: 0000 0011 0000 001f 0000 0004 0000 0010 ................
0000610: 0000 0009 0000 0003 0000 0000 0000 0000 ................
0000620: 0000 0918 0000 0172 0000 0000 0000 0000 .......r........
0000630: 0000 0001 0000 0000 0000 0000 0000 0000 ................
0000640: 0000 0000 0000 0000 0000 0000 0040 0074 [email protected]
0000650: 0000 0000 0300 0001 0000 0000 0040 008c .............@..
0000660: 0000 0000 0300 0002 0000 0000 0040 00b0 .............@..
0000670: 0000 0000 0300 0003 0000 0000 0040 0234 [email protected]
0000680: 0000 0000 0300 0004 0000 0000 0040 0250 [email protected]
0000690: 0000 0000 0300 0005 0000 0000 0041 0254 .............A.T
00006a0: 0000 0000 0300 0006 0000 0000 0041 025c .............A.\
00006b0: 0000 0000 0300 0007 0000 0000 0041 0264 .............A.d
00006c0: 0000 0000 0300 0008 0000 0000 0041 0268 .............A.h
00006d0: 0000 0000 0300 0009 0000 0000 0041 026c .............A.l
00006e0: 0000 0000 0300 000a 0000 0000 0000 0000 ................
00006f0: 0000 0000 0300 000b 0000 0000 0000 0000 ................
0000700: 0000 0000 0300 000c 0000 0000 0000 0030 ...............0
0000710: 0000 0000 0300 000d 0000 0000 0000 0000 ................
0000720: 0000 0000 0300 000e 0000 0001 0000 0000 ................
0000730: 0000 0000 0400 fff1 0000 000c 0041 0254 .............A.T
0000740: 0000 0000 0100 0006 0000 001a 0041 025c .............A.\
0000750: 0000 0000 0100 0007 0000 0028 0040 0250 ...........([email protected]
0000760: 0000 0000 0100 0005 0000 003b 0041 0264 ...........;.A.d
0000770: 0000 0000 0100 0008 0000 0048 0040 00b0 ...........H.@..
0000780: 0000 0000 0000 0003 0000 005e 0041 026c ...........^.A.l
0000790: 0000 0001 0100 000a 0000 006d 0041 0270 ...........m.A.p
00007a0: 0000 0004 0100 000a 0000 007b 0040 015c ...........{.@.\
00007b0: 0000 0000 0000 0003 0000 0087 0041 0274 .............A.t
00007c0: 0000 0018 0100 000a 0000 0001 0000 0000 ................
00007d0: 0000 0000 0400 fff1 0000 0093 0041 0258 .............A.X
00007e0: 0000 0000 0100 0006 0000 00a0 0040 0250 [email protected]
00007f0: 0000 0000 0100 0005 0000 00ae 0041 0264 .............A.d
0000800: 0000 0000 0100 0008 0000 00ba 0040 01ec .............@..
0000810: 0000 0000 0000 0003 0000 00d0 0000 0000 ................
0000820: 0000 0000 0400 fff1 0000 00d6 0041 0268 .............A.h
0000830: 0000 0000 1000 0009 0000 00dd 0041 8260 .............A.`
0000840: 0000 0000 1000 fff1 0000 00e1 0041 0260 .............A.`
0000850: 0000 0000 1102 0007 0000 00ee 0041 0268 .............A.h
0000860: 0000 0000 1102 0009 0000 00fb 0040 008c .............@..
0000870: 0000 0000 1200 0002 0000 0101 0040 01b8 .............@..
0000880: 0000 0034 1200 0003 0000 0105 0000 0000 ...4............
0000890: 0000 0000 2000 0000 0000 011d 0040 00b0 .... ........@..
00008a0: 0000 0000 1000 0003 0000 0124 0041 026c ...........$.A.l
00008b0: 0000 0000 1000 fff1 0000 0130 0040 0234 [email protected]
00008c0: 0000 0000 1200 0004 0000 0136 0041 026c ...........6.A.l
00008d0: 0000 0000 1000 fff1 0000 013d 0041 028c ...........=.A..
00008e0: 0000 0000 1000 fff1 0000 0142 0000 0000 ...........B....
00008f0: 0000 0000 2000 0000 0000 0156 0041 026c .... ......V.A.l
0000900: 0000 0000 1000 fff1 0000 015c 0000 0000 ...........\....
0000910: 0000 0000 2000 0000 0063 7274 7374 7566 .... ....crtstuf
0000920: 662e 6300 5f5f 4354 4f52 5f4c 4953 545f f.c.__CTOR_LIST_
0000930: 5f00 5f5f 4454 4f52 5f4c 4953 545f 5f00 _.__DTOR_LIST__.
0000940: 5f5f 4548 5f46 5241 4d45 5f42 4547 494e __EH_FRAME_BEGIN
0000950: 5f5f 005f 5f4a 4352 5f4c 4953 545f 5f00 __.__JCR_LIST__.
0000960: 5f5f 646f 5f67 6c6f 6261 6c5f 6474 6f72 __do_global_dtor
0000970: 735f 6175 7800 636f 6d70 6c65 7465 642e s_aux.completed.
0000980: 3432 3130 0064 746f 725f 6964 782e 3432 4210.dtor_idx.42
0000990: 3132 0066 7261 6d65 5f64 756d 6d79 006f 12.frame_dummy.o
00009a0: 626a 6563 742e 3432 3332 005f 5f43 544f bject.4232.__CTO
00009b0: 525f 454e 445f 5f00 5f5f 4652 414d 455f R_END__.__FRAME_
00009c0: 454e 445f 5f00 5f5f 4a43 525f 454e 445f END__.__JCR_END_
00009d0: 5f00 5f5f 646f 5f67 6c6f 6261 6c5f 6374 _.__do_global_ct
00009e0: 6f72 735f 6175 7800 6164 642e 6300 5f66 ors_aux.add.c._f
00009f0: 6461 7461 005f 6770 005f 5f44 544f 525f data._gp.__DTOR_
0000a00: 454e 445f 5f00 5f5f 6473 6f5f 6861 6e64 END__.__dso_hand
0000a10: 6c65 005f 696e 6974 0061 6464 005f 5f64 le._init.add.__d
0000a20: 6572 6567 6973 7465 725f 6672 616d 655f eregister_frame_
0000a30: 696e 666f 005f 6674 6578 7400 5f5f 6273 info._ftext.__bs
0000a40: 735f 7374 6172 7400 5f66 696e 6900 5f65 s_start._fini._e
0000a50: 6461 7461 005f 656e 6400 5f4a 765f 5265 data._end._Jv_Re
0000a60: 6769 7374 6572 436c 6173 7365 7300 5f66 gisterClasses._f
0000a70: 6273 7300 5f5f 7265 6769 7374 6572 5f66 bss.__register_f
0000a80: 7261 6d65 5f69 6e66 6f00 rame_info.
- Change the add ELF file into a text file.
cpu@deric-VirtualBox:~/anjf/mipsgcc$ gcc Bin2Mem.c -o Bin2Mem
cpu@deric-VirtualBox:~/anjf/mipsgcc$ ./Bin2Mem -f add -o add.txt
cpu@deric-VirtualBox:~/anjf/mipsgcc$ more add.txt
7f454c46
01020100
00000000
00000000
00020008
00000001
004000b0
00000034
00000368
70001001
00340020
00020028
0012000f
......
- The add.txt is a text file, which can be opened by Chisel for simulation.