]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmSvcLib: Add ArmSvcLib implementation.
authorSupreeth Venkatesh <supreeth.venkatesh@arm.com>
Wed, 20 Sep 2017 19:48:11 +0000 (20:48 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 6 Oct 2017 21:35:41 +0000 (22:35 +0100)
This patch adds a library that enables invocation of SVCs from Exception
Level EL0. It will be used by the Standalone MM environment to request
services from a software running in a privileged EL e.g. ARM Trusted
Firmware. The library is derived directly from Arm SMC Library.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
[ardb: assign frame pointer (AArch64)
       keep stack alignment (ARM)]
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
ArmPkg/ArmPkg.dsc
ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S [new file with mode: 0644]
ArmPkg/Library/ArmSvcLib/Arm/ArmSvc.S [new file with mode: 0644]
ArmPkg/Library/ArmSvcLib/Arm/ArmSvc.asm [new file with mode: 0644]
ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf [new file with mode: 0644]

index fc24a788df571b5fe2bb4d5e536fea7d40e677a3..cf9a5c12108b03f0dd2328f09f46e3d9c355a379 100644 (file)
   ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf\r
   ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf\r
   ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf\r
   ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf\r
   ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf\r
   ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf\r
+  ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf\r
 \r
   ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
 \r
 \r
   ArmPkg/Filesystem/SemihostFs/SemihostFs.inf\r
 \r
diff --git a/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S b/ArmPkg/Library/ArmSvcLib/AArch64/ArmSvc.S
new file mode 100644 (file)
index 0000000..7b8e4a9
--- /dev/null
@@ -0,0 +1,46 @@
+//\r
+//  Copyright (c) 2012 - 2017, 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
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+.text\r
+.align 3\r
+\r
+GCC_ASM_EXPORT(ArmCallSvc)\r
+\r
+ASM_PFX(ArmCallSvc):\r
+  // Push frame pointer and return address on the stack\r
+  stp   x29, x30, [sp, #-32]!\r
+  mov   x29, sp\r
+\r
+  // Push x0 on the stack - The stack must always be quad-word aligned\r
+  str   x0, [sp, #16]\r
+\r
+  // Load the SVC 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
+  svc   #0\r
+\r
+  // Pop the ARM_SVC_ARGS structure address from the stack into x9\r
+  ldr   x9, [sp, #16]\r
+\r
+  // Store the SVC returned values into the ARM_SVC_ARGS structure.\r
+  // A SVC call can return up to 4 values - we do not need to store back x4-x7.\r
+  stp   x0, x1, [x9, #0]\r
+  stp   x2, x3, [x9, #16]\r
+\r
+  mov   x0, x9\r
+\r
+  ldp   x29, x30, [sp], #32\r
+  ret\r
diff --git a/ArmPkg/Library/ArmSvcLib/Arm/ArmSvc.S b/ArmPkg/Library/ArmSvcLib/Arm/ArmSvc.S
new file mode 100644 (file)
index 0000000..29bf8e4
--- /dev/null
@@ -0,0 +1,39 @@
+//\r
+//  Copyright (c) 2016 - 2017, 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
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+.text\r
+.align 3\r
+\r
+GCC_ASM_EXPORT(ArmCallSvc)\r
+\r
+ASM_PFX(ArmCallSvc):\r
+    // r0 will be popped just after the SVC call\r
+    push    {r0, r4-r8}\r
+\r
+    // Load the SVC arguments values into the appropriate registers\r
+    ldm     r0, {r0-r7}\r
+\r
+    svc     #0\r
+\r
+    // Load the ARM_SVC_ARGS structure address from the stack into r8\r
+    ldr     r8, [sp]\r
+\r
+    // Load the SVC returned values into the appropriate registers\r
+    // A SVC call can return up to 4 values - we do not need to store back r4-r7.\r
+    stm     r8, {r0-r3}\r
+\r
+    mov     r0, r8\r
+\r
+    // Restore the registers r4-r8\r
+    pop     {r1, r4-r8}\r
+    bx      lr\r
diff --git a/ArmPkg/Library/ArmSvcLib/Arm/ArmSvc.asm b/ArmPkg/Library/ArmSvcLib/Arm/ArmSvc.asm
new file mode 100644 (file)
index 0000000..8f9ad17
--- /dev/null
@@ -0,0 +1,39 @@
+//\r
+//  Copyright (c) 2016 - 2017, 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
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+\r
+    INCLUDE AsmMacroExport.inc\r
+\r
+ RVCT_ASM_EXPORT ArmCallSvc\r
+    // r0 will be popped just after the SVC call\r
+    push     {r0, r4-r8}\r
+\r
+    // Load the SVC arguments values into the appropriate registers\r
+    ldm     r0, {r0-r7}\r
+\r
+    svc     #0\r
+\r
+    // Load the ARM_SVC_ARGS structure address from the stack into r8\r
+    ldr     r8, [sp]\r
+\r
+    // Load the SVC returned values into the appropriate registers\r
+    // A SVC call can return up to 4 values - we do not need to store back r4-r7.\r
+    stm     r8, {r0-r3}\r
+\r
+    mov     r0, r8\r
+\r
+    // Restore the registers r4-r8\r
+    pop     {r1, r4-r8}\r
+    bx      lr\r
+\r
+    END\r
diff --git a/ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf b/ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf
new file mode 100644 (file)
index 0000000..12658c7
--- /dev/null
@@ -0,0 +1,31 @@
+#/** @file\r
+#\r
+#  Copyright (c) 2016 - 2017, ARM Ltd. All rights reserved.<BR>\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x0001001A\r
+  BASE_NAME                      = ArmSvcLib\r
+  FILE_GUID                      = 8e3618d7-f01d-4d65-b32b-4c70aacc8e49\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmSvcLib\r
+\r
+[Sources.ARM]\r
+  Arm/ArmSvc.asm    | RVCT\r
+  Arm/ArmSvc.S      | GCC\r
+\r
+[Sources.AARCH64]\r
+  AArch64/ArmSvc.S\r
+\r
+[Packages]\r
+  ArmPkg/ArmPkg.dec\r
+  MdePkg/MdePkg.dec\r