1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

How to set program counter to illegal address while code is running ?

Discussion in 'Microcontrollers' started by jani12, Jun 20, 2017.

  1. jani12

    jani12 Member

    Joined:
    Oct 16, 2014
    Messages:
    54
    Likes:
    0
    I'm trying to create illegal instruction reset.

    I'm programming Infineon TC29x Aurix Tricore Microcontroller based embedded system in 'C' language.

    I need to set program counter to illegal address, i.e. 0x00FF FFFC. Can this be done with assembly language instructions?
    If yes, please instrument assembly language instruction that would set program counter to 0x00FF FFFC while code is running.
     
  2. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    6,051
    Likes:
    519
    Location:
    Cleveland, OH, USA
    ONLINE
    So far as I know, an "illegal" memory location will appear as something else, but won't simulate or run.

    In this example of code for a 12F1840, I assign 0xFFFF as an illegal location for the CBLOCK directive. In theory, it rolls over:
    upload_2017-6-20_18-43-9.png
    The disassembly is shown on the left (MPLab 8.92). Notice that register "temp" is set as 0x1. That will, of course cause problems. The Watch window for an attempted simulation shows:

    upload_2017-6-20_18-45-16.png

    I could try to force something more, but first, why do you want to do that?

    John
     
  3. jani12

    jani12 Member

    Joined:
    Oct 16, 2014
    Messages:
    54
    Likes:
    0
    I'm doing this to test if our software correctly handles illegal instruction reset.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    6,051
    Likes:
    519
    Location:
    Cleveland, OH, USA
    ONLINE

    Sorry, I cannot help you with that MCU.
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK
    If you are using C, why would there be a illegal instruction?? I doubt your compiler is that bad!!

    Its possible to run code on the wrong chip, but then it would possibly not run at all...
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,150
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    Even in C execution of random areas can happen, with a table of pointers to functions and an out of bounds index would do it. In fact, that is the answer to the ops question, a pointer to a function with a random address should produce the required result.

    Mike.
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,302
    Likes:
    914
    Location:
    Rochdale UK
    Hi Mike... Problem here is... Even with a bad pointer, no exception will be generated.. One of C golden rules.. Initialise pointers as you get no warnings in runtime...
     
  9. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,150
    Likes:
    337
    Location:
    Brisbane Australia
    ONLINE
    I'm assuming the chip he is using generates exceptions and he wants to test his exception handler. I'm not familiar with the chip.

    Mike.
     
  10. BobW

    BobW Active Member

    Joined:
    Apr 28, 2010
    Messages:
    521
    Likes:
    54
    Location:
    Canada
    If you have access to the return stack, you could put the illegal address on the return stack and then execute a return instruction.
     

Share This Page