How can a program detect the uVision simulator?

Is there a way for a program to know if it's executed under the simulator and not on an actual CPU?

Parents
  • 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 :)

Reply
  • 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 :)

Children
More questions in this forum