emSim is a program that allows you to run SEGGER Embedded Studio's instruction set simulator from the command line.

The primary purpose of emSim is to enable command line tests to be run. The debug I/O provided by SEGGER Embedded Studio is supported, as are command line arguments and exit.

emSim will accept a single elf file, it will allocate and load memory regions based on the program sections in the elf file. emSim will start execution from the entry point symbol contained in the elf file. emSim will terminate when exit is called or execution reaches a specified symbol.

Example

Assuming that app.c contains the following

#include <stdio.h>
#include <stdlib.h>
int 
main(int argc, const char *argv[])
{
  int i;
  for (i = 1; i < argc; i++)
    printf("argv[%d]=%s\n", i, argv[i]);
  exit(EXIT_SUCCESS);
}

and app.elf has been built with the preprocessor definition FULL_LIBRARY then

emSim app.elf hello world 

will produce the output

argv[1]=hello
argv[2]=world

if the debug I/O implementation has to set breakpoints or poll memory locations then you can supply the name of the symbol to breakpoint on that will enable the debug I/O

emSim app.elf -startup __startup_complete hello world 

if the application uses memory that isn't allocated in the elf file then you can supply the memory segments that the simulator should create

emSim app.elf -segments 0x08000000;0x10000;0x20000000;0x10000 

and there is an alternative form of this

emSim app.elf -memory-segments "FLASH RX 0x08000000 0x10000;SRAM RWX 0x20000000 0x10000" 

The simulator attempts to determine the machine architecture from data in the elf file this can be override using

If the simulator doesn't support the architecture then the the list of supported architectures will be displayed.

The simulator will start executing at the entry point symbol in the elf file. If the application doesn't set the stack pointer then you can supply this

emSim app.elf -stackpointer __stack_end__ 

If the application doesn't call exit then you can supply a symbol to breakpoint on that will terminate the simulation

emSim app.elf -end _Exit 

You can show an instruction trace

emSim app.elf -trace 

Which will show the addresses of instructions, the instruction opcode and the disassembly

0x000002d8 E59F003C    ldr r0, =0xE01FC000
0x000002dc E3A01000    mov r1, #0
0x000002e0 E5801000    str r1, [r0]
0x000002e4 E3A01003    mov r1, #3
0x000002e8 E5801004    str r1, [r0, #4]
0x000002ec E3A01002    mov r1, #2

You can display the instruction execution counts at the end of the simulation

emSim app.elf -counts 

Which will show the addresses of instructions, with the number of times executed

0x08000298=1
0x0800029a=1
...
0x080008ac=278
0x080008ae=2
...

You can supply a list of memory word values to simulate ROM or hardware status registers

emSim app.elf -values "0xE0082000=0xFEEDFACE"  

Which will always return 0XFEEDFACE when the address 0xE0082000 is read or fetched.

Similarly to you can supply a list of memory half word values

emSim app.elf -values2 "0xE0082000=0xFACE;0xE0082000=0xFEED"  
Usage:

emSim file [options] args

Option Description
-arch 'a' Specify architecture to simulate
-arch list List supported architectures
-counts Show execution counts when the simulation ends
-end 's' Specify the symbol to end simulation
-max 'c' Specify the maximum number of instructions to simulate
-memory-segments 'name [access] start size;…' Specify the list of memory segments
-segments 'start;size;…' Specify the list of memory segments
-stackpointer 's' Specify the starting stackpoint symbol
-startup 's' Specify the startup completion point symbol
-trace Show instruction execution
-values 'address=value;…' Specify a list of fixed memory word values
-values2 'address=value;…' Specify a list of fixed memory half word values