We are using ARM Toolset , Toolchain MDK-ARM Professional Version 5.21a and Device is LPC2388.
We are trying to create a "undefined instruction exception" on a "BL" instruction in the thumb mode. When we tried to alter the H fllag in the first part of the instruction, we were unable to single step through the instruction as the instruction decoding was not successful. But when we moved the H flag altering to the second part of the instruction, the single stepping went through the instruction and proceeded to the next.
I wonder how on both the occasions the undefined instruction exception was created. This might cause a controller reliability issue in a mission critical system.
Can someone explain why the undefined instruction exception was not entered in our case and suggest a way of creating undef-exception on a BL instruction.
Thanks in advance.
Can someone explain why the undefined instruction exception was not entered in our case
BL with the H bit set is a valid thumb instruction and BL with the H bit not set is a valid thumb instruction. Since these are valid instructions the processor will not generate an undefined instruction exception.
and suggest a way of creating undef-exception on a BL instruction.
There is no way to make a defined instruction generate and undefined instruction exception. You would have to take the defined instruction (such as the BL instructions) and change it to something different that is undefined - but then it would no longer be the BL instruction it would be an undefined instruction.
This might cause a controller reliability issue in a mission critical system.
The 2 BL instructions are meant to be called back to back, the H bit not set in the first instruction and the H bit set in the 2nd one. Not doing this is highly likely to cause reliability issues in mission critical systems as well as non mission critical systems. You would not want to do this in either type of system.
Hello Robert
Thanks for your reply.
We managed to create a "Undefined instruction exception" and inside the exception handler, while the processor (CPSR)is still in "undefined" state and while so we are trying to execute a "BX" instruction.
With R0 containing 0x1B8 as the adddress, we execute a "BX R0" instruction. But to our surprise, we see the execution goes to 0x1C4. We had tried "MOV R15, R0". But that also results the same. To our surprise we note that register R4 is also getting modified when we execute the BX instruction.
FYI, the code at location 0x1B8 is a thumb instruction, as we are building the application code in thumb mode.
Can you or someone explain why PC = 0x1C4 instead of 0x1B8 that we wrote.
Do we need to take care of executing few other instructions inside our Undef_handler and leave the processor in a defined state to get the BX instruction execution correctly?
Please help us resolve this issue.
Thanks