Is there a way for a program to know if it's executed under the simulator and not on an actual CPU?
It is based on the fact that most flash programming tools modify the program image in such a way that the sum of all interrupt vectors in the boot block will be 0,
But that reasoning, what you're describing isn't what you said you wanted to have. It's a way to detect flash programming tools' checksumming of the vector table, not one to detect the simulator.
And of course, nothing stops the person configuring the simulator from implementing the same kind of checksumming either to the program itself, or as part of the debugger startup script, thus completely fooling your "detection".
Chad,
Yes, this is a good idea too. Its big advantage is that it's CPU-independent (I think you could use it with the 8051 as well), but the disadvantage is that it depends on a script that you have to create for every program that uses it.
Cheers, Sandy
It would be simple to put a sim script in that watched for a particular variable / address to be written then modify it, invert it, or something else specific as desired. You likely would have ignore the zero init of the variable.
In the application, write this item then read it back - treating it as volatile. If it reads back different than written, it would indicate simulator.
This should be quite generic and not rely on specifics of the CPU, build configuration, or simulator flaws (features ) that do not exactly match the CPU.
Hi, Very nice solution...
Do you have a trick also to know if the Ulink is connected(Debug) or when the CPU is stand alone (No Ulink)?
Thanks, Doron
Alright, here's my solution for LPC2xxx chips, in case anyone is interested. It is based on the fact that most flash programming tools modify the program image in such a way that the sum of all interrupt vectors in the boot block will be 0, whereas under the simulator the program is executed "as is", without any modification.
#include <stdint.h> #include <stdbool.h> bool in_simulator(void) { uint32_t sum = 0; uint32_t * p; for (p = 0; p < (uint32_t *)0x20; p++) sum += *p; return sum != 0; }
I doubt that anyone cares, but any criticism and suggestions are welcome :)
View all questions in Keil forum