]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmSmcLib: Fixed SMC helper functions
authorOlivier Martin <olivier.martin@arm.com>
Mon, 4 Aug 2014 14:18:13 +0000 (14:18 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 4 Aug 2014 14:18:13 +0000 (14:18 +0000)
The SMC helper functions were buggy as they were assuming that
the values in x1-x7 registers were preserved across an SMC call,
which is not the case.  This patch fixes this issue.

It also simplifies the code by providing only 1 version of the SMC
helper function.  We used to have 4 versions depending on the number
of arguments.  The problem with this approach was that the number of
arguments also dictated the number of return values, which is
completely unrelated.  E.g. you can have an SMC call that takes
1 argument but returns 4 values.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15748 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Include/Library/ArmSmcLib.h
ArmPkg/Library/ArmSmcLib/AArch64/ArmSmc.S
ArmPkg/Library/ArmSmcLib/Arm/ArmSmc.S
ArmPkg/Library/ArmSmcLib/Arm/ArmSmc.asm
ArmPkg/Library/ArmSmcLibNull/AArch64/ArmSmcNull.S
ArmPkg/Library/ArmSmcLibNull/Arm/ArmSmcNull.S
ArmPkg/Library/ArmSmcLibNull/Arm/ArmSmcNull.asm

index ff946f2deaa96728ccd5ef246c81170ff92b6e5f..168e3bb4265ba49acb42e0128c01b5e6fdf913c1 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2012, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD License\r
 #ifndef __ARM_SMC_LIB__\r
 #define __ARM_SMC_LIB__\r
 \r
-VOID\r
-ArmCallSmc (\r
-  IN OUT UINTN *Rx\r
-  );\r
+/**\r
+ * The size of the SMC arguments are different between AArch64 and AArch32.\r
+ * The native size is used for the arguments.\r
+ */\r
+typedef struct {\r
+  UINTN  Arg0;\r
+  UINTN  Arg1;\r
+  UINTN  Arg2;\r
+  UINTN  Arg3;\r
+  UINTN  Arg4;\r
+  UINTN  Arg5;\r
+  UINTN  Arg6;\r
+  UINTN  Arg7;\r
+} ARM_SMC_ARGS;\r
 \r
-VOID\r
-ArmCallSmcArg1 (\r
-  IN OUT UINTN *Rx,\r
-  IN OUT UINTN *Arg1\r
-  );\r
+/**\r
+  Trigger an SMC call\r
 \r
-VOID\r
-ArmCallSmcArg2 (\r
-  IN OUT UINTN *Rx,\r
-  IN OUT UINTN *Arg1,\r
-  IN OUT UINTN *Arg2\r
-  );\r
+  SMC calls can take up to 7 arguments and return up to 4 return values.\r
+  Therefore, the 4 first fields in the ARM_SMC_ARGS structure are used\r
+  for both input and output values.\r
 \r
+**/\r
 VOID\r
-ArmCallSmcArg3 (\r
-  IN OUT UINTN *Rx,\r
-  IN OUT UINTN *Arg1,\r
-  IN OUT UINTN *Arg2,\r
-  IN OUT UINTN *Arg3\r
+ArmCallSmc (\r
+  IN OUT ARM_SMC_ARGS *Args\r
   );\r
 \r
 #endif\r
index 579a73e96c9bae44b56d7f6f59fb2c046919b28d..f73c98cfc38bde9c88f590ccd04e82f275c240b5 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2012-2013, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 .align 3\r
 \r
 GCC_ASM_EXPORT(ArmCallSmc)\r
-GCC_ASM_EXPORT(ArmCallSmcArg1)\r
-GCC_ASM_EXPORT(ArmCallSmcArg2)\r
-GCC_ASM_EXPORT(ArmCallSmcArg3)\r
 \r
 ASM_PFX(ArmCallSmc):\r
-  str   x1, [sp, #-0x10]!\r
-  mov   x1, x0\r
-  ldr   x0,[x1]\r
-  smc   #0\r
-  str   x0,[x1]\r
-  ldr   x1, [sp], #0x10\r
-  ret\r
+  // Push x0 on the stack\r
+  str   x0, [sp, #-8]!\r
 \r
-ASM_PFX(ArmCallSmcArg1):\r
-  stp   x2, x3, [sp, #-0x10]!\r
-  mov   x2, x0\r
-  mov   x3, x1\r
-  ldr   x0,[x2]\r
-  ldr   x1,[x3]\r
-  smc   #0\r
-  str   x0,[x2]\r
-  str   x1,[x3]\r
-  ldp   x2, x3, [sp], #0x10\r
-  ret\r
+  // Load the SMC arguments values into the appropriate registers\r
+  ldp   x6, x7, [x0, #48]\r
+  ldp   x4, x5, [x0, #32]\r
+  ldp   x2, x3, [x0, #16]\r
+  ldp   x0, x1, [x0, #0]\r
 \r
-ASM_PFX(ArmCallSmcArg2):\r
-  stp   x3, x4, [sp, #-0x10]!\r
-  str   x5, [sp, #-8]!\r
-  mov   x3, x0\r
-  mov   x4, x1\r
-  mov   x5, x2\r
-  ldr   x0,[x3]\r
-  ldr   x1,[x4]\r
-  ldr   x2,[x5]\r
   smc   #0\r
-  str   x0,[x3]\r
-  str   x1,[x4]\r
-  str   x2,[x5]\r
-  ldr   x5, [sp], #8\r
-  ldp   x3, x4, [sp], #0x10\r
-  ret\r
 \r
-ASM_PFX(ArmCallSmcArg3):\r
-  stp   x4, x5, [sp, #-0x10]!\r
-  stp   x6, x7, [sp, #-0x10]!\r
-  mov   x4, x0\r
-  mov   x5, x1\r
-  mov   x6, x2\r
-  mov   x7, x3\r
-  ldr   x0,[x4]\r
-  ldr   x1,[x5]\r
-  ldr   x2,[x6]\r
-  ldr   x3,[x7]\r
-  smc   #0\r
-  str   x0,[x4]\r
-  str   x1,[x5]\r
-  str   x2,[x6]\r
-  str   x3,[x7]\r
-  ldp   x4, x5, [sp], #0x10\r
-  ldp   x6, x7, [sp], #0x10\r
+  // Pop the ARM_SMC_ARGS structure address from the stack into x9\r
+  ldr   x9, [sp], #8\r
+\r
+  // Store the SMC returned values into the appropriate registers\r
+  // A SMC call can return up to 4 values - we do not need to store back x4-x7.\r
+  stp   x2, x3, [x9, #16]\r
+  stp   x0, x1, [x9, #0]\r
+\r
+  mov   x0, x9\r
+\r
   ret\r
index c9c0740febe8707e77174861d685fbf017a4619e..260fb10fe86b9bf696b8908967f48f51a7414892 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2012, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 .arch_extension sec\r
 \r
 GCC_ASM_EXPORT(ArmCallSmc)\r
-GCC_ASM_EXPORT(ArmCallSmcArg1)\r
-GCC_ASM_EXPORT(ArmCallSmcArg2)\r
-GCC_ASM_EXPORT(ArmCallSmcArg3)\r
 \r
 ASM_PFX(ArmCallSmc):\r
-    push    {r1}\r
-    mov     r1, r0\r
-    ldr     r0,[r1]\r
-    smc     #0\r
-    str     r0,[r1]\r
-    pop     {r1}\r
-    bx      lr\r
+    push    {r4-r8}\r
+    // r0 will be popped just after the SMC call\r
+    push    {r0}\r
 \r
-ASM_PFX(ArmCallSmcArg1):\r
-    push    {r2-r3}\r
-    mov     r2, r0\r
-    mov     r3, r1\r
-    ldr     r0,[r2]\r
-    ldr     r1,[r3]\r
-    smc     #0\r
-    str     r0,[r2]\r
-    str     r1,[r3]\r
-    pop     {r2-r3}\r
-    bx      lr\r
+    // Load the SMC arguments values into the appropriate registers\r
+    ldr     r7, [r0, #28]\r
+    ldr     r6, [r0, #24]\r
+    ldr     r5, [r0, #20]\r
+    ldr     r4, [r0, #16]\r
+    ldr     r3, [r0, #12]\r
+    ldr     r2, [r0, #8]\r
+    ldr     r1, [r0, #4]\r
+    ldr     r0, [r0, #0]\r
 \r
-ASM_PFX(ArmCallSmcArg2):\r
-    push    {r3-r5}\r
-    mov     r3, r0\r
-    mov     r4, r1\r
-    mov     r5, r2\r
-    ldr     r0,[r3]\r
-    ldr     r1,[r4]\r
-    ldr     r2,[r5]\r
     smc     #0\r
-    str     r0,[r3]\r
-    str     r1,[r4]\r
-    str     r2,[r5]\r
-    pop     {r3-r5}\r
-    bx      lr\r
 \r
-ASM_PFX(ArmCallSmcArg3):\r
-    push    {r4-r7}\r
-    mov     r4, r0\r
-    mov     r5, r1\r
-    mov     r6, r2\r
-    mov     r7, r3\r
-    ldr     r0,[r4]\r
-    ldr     r1,[r5]\r
-    ldr     r2,[r6]\r
-    ldr     r3,[r7]\r
-    smc     #0\r
-    str     r0,[r4]\r
-    str     r1,[r5]\r
-    str     r2,[r6]\r
-    str     r3,[r7]\r
-    pop     {r4-r7}\r
+    // Pop the ARM_SMC_ARGS structure address from the stack into r8\r
+    pop     {r8}\r
+\r
+    // Load the SMC returned values into the appropriate registers\r
+    // A SMC call can return up to 4 values - we do not need to store back r4-r7.\r
+    str     r3, [r8, #12]\r
+    str     r2, [r8, #8]\r
+    str     r1, [r8, #4]\r
+    str     r0, [r8, #0]\r
+\r
+    mov     r0, r8\r
+\r
+    // Restore the registers r4-r8\r
+    pop     {r4-r8}\r
+\r
     bx      lr\r
index f46bd7ecd42471fc902fe289151dc38b21210dac..ad55ae7752af8b29f7619cbdbb1d7a465f624c65 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2012, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 //\r
 \r
     EXPORT ArmCallSmc\r
-    EXPORT ArmCallSmcArg1\r
-    EXPORT ArmCallSmcArg2\r
-    EXPORT ArmCallSmcArg3\r
 \r
     AREA   ArmSmc, CODE, READONLY\r
 \r
 ArmCallSmc\r
-    push    {r1}\r
-    mov     r1, r0\r
-    ldr     r0,[r1]\r
-    smc     #0\r
-    str     r0,[r1]\r
-    pop     {r1}\r
-    bx      lr\r
+    push    {r4-r8}\r
+    // r0 will be popped just after the SMC call\r
+    pop     {r0}\r
 \r
-ArmCallSmcArg1\r
-    push    {r2-r3}\r
-    mov     r2, r0\r
-    mov     r3, r1\r
-    ldr     r0,[r2]\r
-    ldr     r1,[r3]\r
-    smc     #0\r
-    str     r0,[r2]\r
-    str     r1,[r3]\r
-    pop     {r2-r3}\r
-    bx      lr\r
+    // Load the SMC arguments values into the appropriate registers\r
+    ldr     r7, [r0, #28]\r
+    ldr     r6, [r0, #24]\r
+    ldr     r5, [r0, #20]\r
+    ldr     r4, [r0, #16]\r
+    ldr     r3, [r0, #12]\r
+    ldr     r2, [r0, #8]\r
+    ldr     r1, [r0, #4]\r
+    ldr     r0, [r0, #0]\r
 \r
-ArmCallSmcArg2\r
-    push    {r3-r5}\r
-    mov     r3, r0\r
-    mov     r4, r1\r
-    mov     r5, r2\r
-    ldr     r0,[r3]\r
-    ldr     r1,[r4]\r
-    ldr     r2,[r5]\r
     smc     #0\r
-    str     r0,[r3]\r
-    str     r1,[r4]\r
-    str     r2,[r5]\r
-    pop     {r3-r5}\r
-    bx      lr\r
 \r
-ArmCallSmcArg3\r
-    push    {r4-r7}\r
-    mov     r4, r0\r
-    mov     r5, r1\r
-    mov     r6, r2\r
-    mov     r7, r3\r
-    ldr     r0,[r4]\r
-    ldr     r1,[r5]\r
-    ldr     r2,[r6]\r
-    ldr     r3,[r7]\r
-    smc     #0\r
-    str     r0,[r4]\r
-    str     r1,[r5]\r
-    str     r2,[r6]\r
-    str     r3,[r7]\r
-    pop     {r4-r7}\r
+    // Pop the ARM_SMC_ARGS structure address from the stack into r8\r
+    pop     {r8}\r
+\r
+    // Load the SMC returned values into the appropriate registers\r
+    // A SMC call can return up to 4 values - we do not need to store back r4-r7.\r
+    str     r3, [r8, #12]\r
+    str     r2, [r8, #8]\r
+    str     r1, [r8, #4]\r
+    str     r0, [r8, #0]\r
+\r
+    mov     r0, r8\r
+\r
+    // Restore the registers r4-r8\r
+    pop     {r4-r8}\r
+\r
     bx      lr\r
 \r
     END\r
index ec6e067ac318e656124d3903755f91ce2626e75f..a6ef0e04da822fbbf1becaad34d563b94eb8be39 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2012-2013, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 .align 3\r
 \r
 GCC_ASM_EXPORT(ArmCallSmc)\r
-GCC_ASM_EXPORT(ArmCallSmcArg1)\r
-GCC_ASM_EXPORT(ArmCallSmcArg2)\r
-GCC_ASM_EXPORT(ArmCallSmcArg3)\r
 \r
 ASM_PFX(ArmCallSmc):\r
   ret\r
-\r
-ASM_PFX(ArmCallSmcArg1):\r
-  ret\r
-\r
-ASM_PFX(ArmCallSmcArg2):\r
-  ret\r
-\r
-ASM_PFX(ArmCallSmcArg3):\r
-  ret\r
index 4896dd0c9b2318b7dc3ba108ee31b149a84a5651..9eaefd30cff472a24708f963c9c2dd9b2f856619 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2012-2013, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 .align 3\r
 \r
 GCC_ASM_EXPORT(ArmCallSmc)\r
-GCC_ASM_EXPORT(ArmCallSmcArg1)\r
-GCC_ASM_EXPORT(ArmCallSmcArg2)\r
-GCC_ASM_EXPORT(ArmCallSmcArg3)\r
 \r
 ASM_PFX(ArmCallSmc):\r
   bx     lr\r
-\r
-// Arg1 in R1\r
-ASM_PFX(ArmCallSmcArg1):\r
-  bx     lr\r
-\r
-ASM_PFX(ArmCallSmcArg2):\r
-  bx     lr\r
-\r
-ASM_PFX(ArmCallSmcArg3):\r
-  bx     lr\r
index 24c20752e3e35650201a397e48832615cd7e525a..3d3f5545542d897fca2f25905b7858c6f9bf931b 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2012-2013, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
 //\r
 \r
     EXPORT ArmCallSmc\r
-    EXPORT ArmCallSmcArg1\r
-    EXPORT ArmCallSmcArg2\r
-    EXPORT ArmCallSmcArg3\r
 \r
     AREA   ArmSmc, CODE, READONLY\r
 \r
 ArmCallSmc\r
   bx     lr\r
 \r
-// Arg1 in R1\r
-ArmCallSmcArg1\r
-  bx     lr\r
-\r
-ArmCallSmcArg2\r
-  bx     lr\r
-\r
-ArmCallSmcArg3\r
-  bx     lr\r
-\r
   END\r