]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Sec/Helper.asm
Patch from open source community for CryptoPkg to allow it to build for ARM using...
[mirror_edk2.git] / ArmPlatformPkg / Sec / Helper.asm
CommitLineData
1d5d0ae9 1//\r
2// Copyright (c) 2011, ARM Limited. All rights reserved.\r
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 EXPORT monitor_vector_table\r
15 EXPORT return_from_exception\r
16 EXPORT enter_monitor_mode\r
17 EXPORT copy_cpsr_into_spsr\r
18 \r
19 AREA Helper, CODE, READONLY\r
20\r
21 ALIGN 32\r
22monitor_vector_table\r
23 ldr pc, dead\r
24 ldr pc, dead\r
25 ldr pc, dead\r
26 ldr pc, dead\r
27 ldr pc, dead\r
28 ldr pc, dead\r
29 ldr pc, dead\r
30 ldr pc, dead\r
31\r
32// arg0: Secure Monitor mode stack\r
33enter_monitor_mode\r
34 mov r2, lr // Save current lr\r
35\r
36 mrs r1, cpsr // Save current mode (SVC) in r1\r
37 bic r3, r1, #0x1f // Clear all mode bits\r
38 orr r3, r3, #0x16 // Set bits for Monitor mode\r
39 msr cpsr_cxsf, r3 // We are now in Monitor Mode\r
40\r
41 mov sp, r0 // Use the passed sp\r
42 mov lr, r2 // Use the same lr as before\r
43 \r
44 msr spsr_cxsf, r1 // Use saved mode for the MOVS jump to the kernel\r
45 bx lr\r
46\r
47// We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler.\r
48// When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into\r
49// 'pc'; we will not change the CPSR flag and it will crash.\r
50// The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'.\r
51return_from_exception\r
52 adr lr, returned_exception\r
53 movs pc, lr\r
54returned_exception // We are now in non-secure state\r
55 bx r0\r
56\r
57// Save the current Program Status Register (PSR) into the Saved PSR\r
58copy_cpsr_into_spsr\r
59 mrs r0, cpsr\r
60 msr spsr_cxsf, r0\r
61 bx lr\r
62\r
63dead\r
64 B dead\r
65 \r
66 END\r