This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SMC instruction

Note: This was originally posted on 22nd January 2013 at http://forums.arm.com

Good day.

I have a question - where I can get the #immediate value (4bit) in Secure Monitor Exception Handler, when called SMC instruction with non zero parametr - #imm-4 ?
Don't found this value in any registers.


From ARM documentation.
-------------------------------------

SMC
Secure Monitor Call.


Syntax
SMC{cond} #imm4 where:

[i]imm4[/i]is a 4-bit immediate value. This is ignored by the ARM processor, but can be used by the SMC exception handler to determine what service is being requested.


Thanks.
  • Note: This was originally posted on 27th January 2013 at http://forums.arm.com

    Bear in mind that the SMC instruction is used to switch worlds, so you tend to get an address in the "other world's" virtual address map in LR, which in many cases may not be the same as the currently running software. Direct access of the address in LR is therefore unlikely to do what you want - it may well page fault, or at least return utterly unrelated data.

    This generally makes it very hard to use this feature of the SMC instruction; at least it makes it more hassle than it is worth - in most cases putting a constant in a register by hand as part of the cross-world smc call API is much easier.

    HTH,
    Iso
  • Note: This was originally posted on 22nd January 2013 at http://forums.arm.com

    The immediate value passed with the SMC instruction can be retrieved by reading back the SMC instruction opcode. The address of SMC instruction can known from the link register of monitor mode. Consider the following code sequence:

    IA        Instructions
    ------------------------------------------
    ...     ...
    0x840    i0
    0x844    i1

    0x848    SMC #10
    0x84C    i3
    ....              ...

    where IA is the instruction address

    When the SMC instruction is executed, a software exception is generated changing the CPU state with LR_mon/R14_mon getting updated with 0x84C (basically address of SMC instruction+4 irrespective of whether the SMC was executed in ARM or Thumb mode). So in the monitor exception handler, we can read back the SMC instruction opcode and extract the immediate value in the following way:
    ... initial code for monitor handler....
    LDR r0, [r14, # - 4]
    AND r0, r0, #0xF   (The immediate value is encoded in bits[3:0] of SMC instruction for both ARM and Thumb encoding)

    Hope this helps.