I'm trying to write emulator for ARM Cortex M3. How can I read the binary file then decode it? I want to use binary files as a resource of my emulator. I created a project with Atmel Studio and I compiled it. Now, I have a .hex file. I can also convert this file to binary file with hex2bin. After that, how can I use that binary file for fetching and decoding instructions ? I'm working on Visual Studio with C/C++.
-
I afraid you must start your C / C++ journey from something much much easier. After 2-3 years of the active programming you can start this project. BTW absolutely pointless task. – 0___________ Aug 02 '17 at 08:33
-
Considering it's M3, I think you need to find where interrupt vector table is located, as it should have addresses of all root functions such as startup code or interrupt handlers. I am not sure if the location of the table is standardised, so you'll need to read on your device/compiler manuals to find out. – user694733 Aug 02 '17 at 08:39
-
having had already done this myself, more than once, it is actually a good task in a number of ways. But if you dont know how to use fopen(), fread(), fclose() then you are not ready for any programming projects much less this one. there are a plethera of possible file formats, all documented, including just a raw memory image, pick one or two or three, do your research, make or find a hex editor/dump program (hexdump for example) and look at the file. Reading the arm docs although not bad docs, to do the instruction decoding is harder than reading the binary file. – old_timer Aug 09 '17 at 17:04
1 Answers
First, need to mention that writing an emulator for a processor is not an easy task, other have already spend lot of time on it, you can take a look at QEmu for example. One project is currenlty using Qemu to emulate a Cortex M3 based board, the ZephyrProject.
An intermediate step, could be to use a tool that already understand/decode hex or bin file, and Radare is one of those kind of tool. With it you will be abvle to disassemble many elf files and get the instructions from it (that you'll then have to emulate ;) ).
That said, if you still really want/need to make the emulation, and start to read and understand the hex or binary files, the first thing to do will to study the Intel Hex file format (yes, even ARM is using this Intel format ;) ). You can find the official specification here or in the technical support website of ARM.
Have fun ;)

- 78,516
- 15
- 127
- 132