]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Sec/Arm/Helper.asm
8aa7d7840d56459bab93c7b9a8a149237efe77a2
[mirror_edk2.git] / ArmPlatformPkg / Sec / Arm / Helper.asm
1 //
2 // Copyright (c) 2011-2012, 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 EXPORT return_from_exception
15 EXPORT enter_monitor_mode
16 EXPORT copy_cpsr_into_spsr
17 EXPORT set_non_secure_mode
18
19 AREA Helper, CODE, READONLY
20
21 // r0: Monitor World EntryPoint
22 // r1: MpId
23 // r2: SecBootMode
24 // r3: Secure Monitor mode stack
25 enter_monitor_mode FUNCTION
26 cmp r3, #0 // If a Secure Monitor stack base has not been defined then use the Secure stack
27 moveq r3, sp
28
29 mrs r4, cpsr // Save current mode (SVC) in r4
30 bic r5, r4, #0x1f // Clear all mode bits
31 orr r5, r5, #0x16 // Set bits for Monitor mode
32 msr cpsr_cxsf, r5 // We are now in Monitor Mode
33
34 mov sp, r3 // Set the stack of the Monitor Mode
35
36 mov lr, r0 // Use the pass entrypoint as lr
37
38 msr spsr_cxsf, r4 // Use saved mode for the MOVS jump to the kernel
39
40 mov r4, r0 // Swap EntryPoint and MpId registers
41 mov r0, r1
42 mov r1, r2
43 mov r2, r3
44
45 bx r4
46 ENDFUNC
47
48 // We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler.
49 // When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into
50 // 'pc'; we will not change the CPSR flag and it will crash.
51 // The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'.
52 return_from_exception
53 adr lr, returned_exception
54 movs pc, lr
55 returned_exception // We are now in non-secure state
56 bx r0
57
58 // Save the current Program Status Register (PSR) into the Saved PSR
59 copy_cpsr_into_spsr
60 mrs r0, cpsr
61 msr spsr_cxsf, r0
62 bx lr
63
64 // Set the Non Secure Mode
65 set_non_secure_mode
66 push { r1 }
67 and r0, r0, #0x1f // Keep only the mode bits
68 mrs r1, spsr // Read the spsr
69 bic r1, r1, #0x1f // Clear all mode bits
70 orr r1, r1, r0
71 msr spsr_cxsf, r1 // write back spsr (may have caused a mode switch)
72 isb
73 pop { r1 }
74 bx lr // return (hopefully thumb-safe!)
75
76 dead
77 B dead
78
79 END