+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Member level 3
    Points: 873, Level: 6

    Join Date
    Oct 2014
    Posts
    55
    Helped
    0 / 0
    Points
    873
    Level
    6

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

    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

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 5
    Points: 23,418, Level: 37
    barry's Avatar
    Join Date
    Mar 2005
    Location
    California, USA
    Posts
    4,488
    Helped
    992 / 992
    Points
    23,418
    Level
    37

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

    I tried to look at the documentation for the uP, but they won't give it out freely. Not a way to win new customers, in my opinion.

    Regardless, my best solution if there's no way to directly load the PC would be maybe call a subroutine, which puts the program counter on the stack. Then have your subroutine modify that location in the stack so when you return from the subroutine, voila, bad PC!


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #3
    Full Member level 4
    Points: 2,273, Level: 11
    Achievements:
    7 years registered

    Join Date
    May 2012
    Posts
    215
    Helped
    10 / 10
    Points
    2,273
    Level
    11

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

    I think you cannot write into a program counter register. It is read only register. If there is mistake in the code cpu will automatically generates illegal instruction. If you want to write data into a particular address define a pointer to that address and try writing some data into that address and cpu will generate illegal address interrupt.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 74,965, Level: 66
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,199
    Helped
    3464 / 3464
    Points
    74,965
    Level
    66

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

    Hi,

    Writing into a PC register is the same as performing an unconditional absolute jump.
    But maybe the compiler/assembler detects an error when you jump to an illegal address.

    The modifed_stack_and_return method should work either way.

    Klaus



  5. #5
    Member level 4
    Points: 1,080, Level: 7
    Altaero's Avatar
    Join Date
    Dec 2013
    Location
    St-Petersburg, Russia
    Posts
    78
    Helped
    24 / 24
    Points
    1,080
    Level
    7

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

    I didn't try it, but it should work. Try to use pointer to a function like this:
    Code C - [expand]
    1
    2
    
    int (*func)(void) = 0x00FFFFFC;
        func();



    •   AltAdvertisement

        
       

  6. #6
    Advanced Member level 5
    Points: 9,012, Level: 22
    Achievements:
    7 years registered
    Easyrider83's Avatar
    Join Date
    Oct 2011
    Location
    Tallinn, Estonia
    Posts
    1,588
    Helped
    362 / 362
    Points
    9,012
    Level
    22

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

    Small fix: int (*func)(void) = (void*)0x00FFFFFC;
    Love me or hate me. All infractions will be ignored.



--[[ ]]--