1//
2//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.
3//
4//  This program and the accompanying materials
5//  are licensed and made available under the terms and conditions of the BSD License
6//  which accompanies this distribution.  The full text of the license may be found at
7//  http://opensource.org/licenses/bsd-license.php
8//
9//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11//
12//
13
14.text
15.align 3
16.arch_extension sec
17
18GCC_ASM_EXPORT(ArmCallSmc)
19
20ASM_PFX(ArmCallSmc):
21    push    {r4-r8}
22    // r0 will be popped just after the SMC call
23    push    {r0}
24
25    // Load the SMC arguments values into the appropriate registers
26    ldr     r7, [r0, #28]
27    ldr     r6, [r0, #24]
28    ldr     r5, [r0, #20]
29    ldr     r4, [r0, #16]
30    ldr     r3, [r0, #12]
31    ldr     r2, [r0, #8]
32    ldr     r1, [r0, #4]
33    ldr     r0, [r0, #0]
34
35    smc     #0
36
37    // Pop the ARM_SMC_ARGS structure address from the stack into r8
38    pop     {r8}
39
40    // Load the SMC returned values into the appropriate registers
41    // A SMC call can return up to 4 values - we do not need to store back r4-r7.
42    str     r3, [r8, #12]
43    str     r2, [r8, #8]
44    str     r1, [r8, #4]
45    str     r0, [r8, #0]
46
47    mov     r0, r8
48
49    // Restore the registers r4-r8
50    pop     {r4-r8}
51
52    bx      lr
53