1 #========================================================================================
2 # Copyright (c) 2011, ARM Limited. All rights reserved.
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
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.
12 #=======================================================================================
14 #start of the code section
18 GCC_ASM_EXPORT(monitor_vector_table)
19 GCC_ASM_EXPORT(return_from_exception)
20 GCC_ASM_EXPORT(enter_monitor_mode)
21 GCC_ASM_EXPORT(copy_cpsr_into_spsr)
23 ASM_PFX(monitor_vector_table):
33 # arg0: Secure Monitor mode stack
34 ASM_PFX(enter_monitor_mode):
35 mov r2, lr @ Save current lr
37 mrs r1, cpsr @ Save current mode (SVC) in r1
38 bic r3, r1, #0x1f @ Clear all mode bits
39 orr r3, r3, #0x16 @ Set bits for Monitor mode
40 msr cpsr_cxsf, r3 @ We are now in Monitor Mode
42 mov sp, r0 @ Use the passed sp
43 mov lr, r2 @ Use the same lr as before
45 msr spsr_cxsf, r1 @ Use saved mode for the MOVS jump to the kernel
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 ASM_PFX(return_from_exception):
53 ldr lr, returned_exception
55 #The following instruction breaks the code.
62 returned_exception: @ We are now in non-secure state
65 # Save the current Program Status Register (PSR) into the Saved PSR
66 ASM_PFX(copy_cpsr_into_spsr):
74 ASM_FUNCTION_REMOVE_IF_UNREFERENCED