I am implementing a small OS as a university project in a A9 chip (a Xilinx Zynq). I am using trustzone to implement some features and I want to pass through SVC calls from user mode directly to monitor, so I issue an SMC in my SVC handler. Here it is a version of the vector table plus handler which works (I removed other handler code for simplicity):
secure_vectors:ldr pc, _secure_resetb _secure_undefb _secure_svcb _secure_prefAbortb _secure_dataAbortb . /* reserved for HYP mode - not supported */b _secure_irqb . /* reserved for MON mode */
_secure_undef:b ._secure_svc:smc #0movs pc, lr_secure_prefAbort:b ._secure_dataAbort:b ._secure_irq:b
However, I am having an issue if I position my handler code immediately after the vector table. If I position the handler as below, sometimes the SMC call is not issued. When debugging I step through the instruction, but it is as if it never happened since the monitor vector table does not receive the SMC exception:
_secure_svc:smc #0movs pc, lr_secure_undef:b ._secure_prefAbort:b ._secure_dataAbort:b ._secure_irq:b
Even a "NOP" instruction before the handler solves the problem:
nop_secure_svc:smc #0movs pc, lr_secure_undef:b ._secure_prefAbort:b ._secure_dataAbort:b ._secure_irq:b
I really don't understand why this happens. Am I missing missing something obvious?
Thank you for your reply Bastian. I already know that monitor uses a differente table - I setup and use that table. I don't think you understood my question, but thank you any way.
Sorry, right. I was confused by the FIQ vector.
Did you try your code with caches disabled?Do you copy vectors? If so, is the copy routine correct? Means. it copies 32 bytes not, 33 or more? Did you check if the "NOP" is intact?
Different story: If you use FIQ, check which mode has been interrupted. You might not want to interrupt any exception handling (svc, abort, undef and prefetch).
Thank you once again for your interest in my problem. As for your questions:
- I run with caches disabled.
- I do not copy the vectors. Their address is defined in the linker script and placed there by the elf loader.
- I don't understand what you mean by "the NOP is intact", because the problem happens when the nop is not there!
- No interrupts happen during this. The sequence of events is quite simple. User issues SVC, svc issues SMC.
You wrote:
josecm said:Even a "NOP" instruction before the handler solves the problem:
so I understood, with "nop" the sequence works w/o it doesn't.Anyway, I am out of ideas. If you happen to find the problem, please post it.