]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Sec/Helper.S
Fix SmmCryptLib issue when calling time() in RealTimeClock.c
[mirror_edk2.git] / ArmPlatformPkg / Sec / Helper.S
CommitLineData
1d5d0ae9 1#========================================================================================\r
8cc852f7 2# Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
1d5d0ae9 3# \r
4# This program and the accompanying materials \r
5# are licensed and made available under the terms and conditions of the BSD License \r
6# which accompanies this distribution. The full text of the license may be found at \r
7# http:#opensource.org/licenses/bsd-license.php \r
8#\r
9# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11#\r
12#=======================================================================================\r
13\r
14#start of the code section\r
15.text \r
16.align 3\r
17\r
1d5d0ae9 18GCC_ASM_EXPORT(return_from_exception)\r
19GCC_ASM_EXPORT(enter_monitor_mode)\r
20GCC_ASM_EXPORT(copy_cpsr_into_spsr)\r
513aa349 21GCC_ASM_EXPORT(set_non_secure_mode)\r
1d5d0ae9 22\r
a8530889 23# r0: Monitor World EntryPoint\r
24# r1: MpId\r
25# r2: Secure Monitor mode stack\r
1d5d0ae9 26ASM_PFX(enter_monitor_mode):\r
59a2b365 27 cmp r2, #0 @ If a Secure Monitor stack base has not been defined then use the Secure stack\r
28 moveq r2, sp\r
29\r
30 mrs r4, cpsr @ Save current mode (SVC) in r4\r
a8530889 31 bic r3, r4, #0x1f @ Clear all mode bits\r
1d5d0ae9 32 orr r3, r3, #0x16 @ Set bits for Monitor mode\r
33 msr cpsr_cxsf, r3 @ We are now in Monitor Mode\r
34\r
59a2b365 35 mov sp, r2 @ Set the stack of the Monitor Mode\r
a8530889 36\r
37 mov lr, r0 @ Use the pass entrypoint as lr\r
1d5d0ae9 38 \r
a8530889 39 msr spsr_cxsf, r4 @ Use saved mode for the MOVS jump to the kernel\r
40\r
41 mov r4, r0 @ Swap EntryPoint and MpId registers\r
42 mov r0, r1\r
43\r
44 bx r4\r
1d5d0ae9 45\r
46# We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler.\r
47# When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into\r
48# 'pc'; we will not change the CPSR flag and it will crash.\r
49# The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'.\r
50ASM_PFX(return_from_exception):\r
51 ldr lr, returned_exception\r
52\r
53 #The following instruction breaks the code.\r
54 #movs pc, lr\r
55 mrs r2, cpsr\r
56 bic r2, r2, #0x1f\r
57 orr r2, r2, #0x13\r
58 msr cpsr_c, r2\r
59\r
60returned_exception: @ We are now in non-secure state\r
61 bx r0\r
62\r
63# Save the current Program Status Register (PSR) into the Saved PSR\r
64ASM_PFX(copy_cpsr_into_spsr):\r
65 mrs r0, cpsr\r
66 msr spsr_cxsf, r0\r
67 bx lr\r
68\r
513aa349 69# Set the Non Secure Mode\r
70ASM_PFX(set_non_secure_mode):\r
71 push { r1 }\r
72 and r0, r0, #0x1f @ Keep only the mode bits\r
73 mrs r1, spsr @ Read the spsr\r
74 bic r1, r1, #0x1f @ Clear all mode bits\r
75 orr r1, r1, r0\r
76 msr spsr_cxsf, r1 @ write back spsr (may have caused a mode switch)\r
77 isb\r
78 pop { r1 }\r
79 bx lr @ return (hopefully thumb-safe!)\r
80\r
1d5d0ae9 81dead:\r
6377d2f1 82 b dead\r
1d5d0ae9 83 \r
6377d2f1 84ASM_FUNCTION_REMOVE_IF_UNREFERENCED\r