From 949973b6c033918489e935869a5d2391e4feacb0 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Mon, 14 Dec 2015 16:08:27 +0000 Subject: [PATCH] ArmPlatformPkg/Sec: fix return_from_exception code and comment The return_from_exception implementation in Sec/Helper.S (the GCC version) deviates from the RVCT version, in a way that suggests that both may have been broken at some point, and that they weren't fixed in the same way nor at the same time. So bring the GCC version in line with the RVCT version, and at the same time, deobfuscate the comment. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19244 6f19259b-4bc3-4df7-8a09-765794883524 --- ArmPlatformPkg/Sec/Arm/Helper.S | 17 ++++------------- ArmPlatformPkg/Sec/Arm/Helper.asm | 6 ++---- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/ArmPlatformPkg/Sec/Arm/Helper.S b/ArmPlatformPkg/Sec/Arm/Helper.S index ac40102218..1922321565 100644 --- a/ArmPlatformPkg/Sec/Arm/Helper.S +++ b/ArmPlatformPkg/Sec/Arm/Helper.S @@ -46,20 +46,11 @@ ASM_PFX(enter_monitor_mode): bx r4 -# We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler. -# When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into -# 'pc'; we will not change the CPSR flag and it will crash. -# The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'. +# Return-from-exception is not an interworking return, so we must do it +# in two steps, in case r0 has the Thumb bit set. ASM_PFX(return_from_exception): - ldr lr, returned_exception - - #The following instruction breaks the code. - #movs pc, lr - mrs r2, cpsr - bic r2, r2, #0x1f - orr r2, r2, #0x13 - msr cpsr_c, r2 - + adr lr, returned_exception + movs pc, lr returned_exception: @ We are now in non-secure state bx r0 diff --git a/ArmPlatformPkg/Sec/Arm/Helper.asm b/ArmPlatformPkg/Sec/Arm/Helper.asm index 8aa7d7840d..0a2baaf19e 100644 --- a/ArmPlatformPkg/Sec/Arm/Helper.asm +++ b/ArmPlatformPkg/Sec/Arm/Helper.asm @@ -45,10 +45,8 @@ enter_monitor_mode FUNCTION bx r4 ENDFUNC -// We cannot use the instruction 'movs pc, lr' because the caller can be written either in ARM or Thumb2 assembler. -// When we will jump into this function, we will set the CPSR flag to ARM assembler. By copying directly 'lr' into -// 'pc'; we will not change the CPSR flag and it will crash. -// The way to fix this limitation is to do the movs into the ARM assmbler code and then do a 'bx'. +// Return-from-exception is not an interworking return, so we must do it +// in two steps, in case r0 has the Thumb bit set. return_from_exception adr lr, returned_exception movs pc, lr -- 2.39.2