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