]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuExceptionHandler: Make XCODE5 changes toolchain specific
authorLendacky, Thomas <thomas.lendacky@amd.com>
Thu, 7 May 2020 13:06:48 +0000 (08:06 -0500)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 11 May 2020 19:25:33 +0000 (19:25 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2340

Commit 2db0ccc2d7fe ("UefiCpuPkg: Update CpuExceptionHandlerLib pass
XCODE5 tool chain") introduced binary patching into the exception handling
support. CPU exception handling is allowed during SEC and this results in
binary patching of flash, which should not be done.

Separate the changes from commit 2db0ccc2d7fe into an XCODE5 toolchain
specific file, Xcode5ExceptionHandlerAsm.nasm, and create a new SEC INF
file for the XCODE5 version of CpuExceptionHandlerLib.

Since binary patching is allowed when running outside of flash, switch
the Dxe, Pei and Smm versions of the CpuExceptionHandlerLib over to use
the Xcode5ExceptionHandlerAsm.nasm file to retain current functionality.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <9075570487616c731033a5738f6a444a15d71b74.1588856809.git.thomas.lendacky@amd.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm [new file with mode: 0644]
UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf [new file with mode: 0644]
UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.uni [new file with mode: 0644]
UefiCpuPkg/UefiCpuPkg.dsc

index e413835730436ee03b23119b8a496c51d68b5fe0..61e2ec30b0891bf9f03b5cade83c2421e48f380f 100644 (file)
@@ -28,7 +28,7 @@
   Ia32/ArchInterruptDefs.h\r
 \r
 [Sources.X64]\r
-  X64/ExceptionHandlerAsm.nasm\r
+  X64/Xcode5ExceptionHandlerAsm.nasm\r
   X64/ArchExceptionHandler.c\r
   X64/ArchInterruptDefs.h\r
 \r
index f31423ac0f91a166cbbbf15abced41f1197c343f..093374944df685d26d2a8104ca5dc9e86452066b 100644 (file)
@@ -28,7 +28,7 @@
   Ia32/ArchInterruptDefs.h\r
 \r
 [Sources.X64]\r
-  X64/ExceptionHandlerAsm.nasm\r
+  X64/Xcode5ExceptionHandlerAsm.nasm\r
   X64/ArchExceptionHandler.c\r
   X64/ArchInterruptDefs.h\r
 \r
index 66c7f59e3c91b8df2c5f5ec575508d628c530e7c..2ffbbccc302f01d41f41582cee11b78a8005850b 100644 (file)
@@ -28,7 +28,7 @@
   Ia32/ArchInterruptDefs.h\r
 \r
 [Sources.X64]\r
-  X64/ExceptionHandlerAsm.nasm\r
+  X64/Xcode5ExceptionHandlerAsm.nasm\r
   X64/ArchExceptionHandler.c\r
   X64/ArchInterruptDefs.h\r
 \r
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm
new file mode 100644 (file)
index 0000000..19198f2
--- /dev/null
@@ -0,0 +1,396 @@
+;------------------------------------------------------------------------------ ;\r
+; Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+; Module Name:\r
+;\r
+;   ExceptionHandlerAsm.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   x64 CPU Exception Handler\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+;\r
+; CommonExceptionHandler()\r
+;\r
+\r
+extern ASM_PFX(mErrorCodeFlag)    ; Error code flags for exceptions\r
+extern ASM_PFX(mDoFarReturnFlag)  ; Do far return flag\r
+extern ASM_PFX(CommonExceptionHandler)\r
+\r
+SECTION .data\r
+\r
+DEFAULT REL\r
+SECTION .text\r
+\r
+ALIGN   8\r
+\r
+AsmIdtVectorBegin:\r
+%rep  32\r
+    db      0x6a        ; push  #VectorNum\r
+    db      ($ - AsmIdtVectorBegin) / ((AsmIdtVectorEnd - AsmIdtVectorBegin) / 32) ; VectorNum\r
+    push    rax\r
+    mov     rax, strict qword 0 ;    mov     rax, ASM_PFX(CommonInterruptEntry)\r
+    jmp     rax\r
+%endrep\r
+AsmIdtVectorEnd:\r
+\r
+HookAfterStubHeaderBegin:\r
+    db      0x6a        ; push\r
+@VectorNum:\r
+    db      0          ; 0 will be fixed\r
+    push    rax\r
+    mov     rax, strict qword 0 ;     mov     rax, HookAfterStubHeaderEnd\r
+JmpAbsoluteAddress:\r
+    jmp     rax\r
+HookAfterStubHeaderEnd:\r
+    mov     rax, rsp\r
+    and     sp,  0xfff0        ; make sure 16-byte aligned for exception context\r
+    sub     rsp, 0x18           ; reserve room for filling exception data later\r
+    push    rcx\r
+    mov     rcx, [rax + 8]\r
+    bt      [ASM_PFX(mErrorCodeFlag)], ecx\r
+    jnc     .0\r
+    push    qword [rsp]             ; push additional rcx to make stack alignment\r
+.0:\r
+    xchg    rcx, [rsp]        ; restore rcx, save Exception Number in stack\r
+    push    qword [rax]             ; push rax into stack to keep code consistence\r
+\r
+;---------------------------------------;\r
+; CommonInterruptEntry                  ;\r
+;---------------------------------------;\r
+; The follow algorithm is used for the common interrupt routine.\r
+; Entry from each interrupt with a push eax and eax=interrupt number\r
+; Stack frame would be as follows as specified in IA32 manuals:\r
+;\r
+; +---------------------+ <-- 16-byte aligned ensured by processor\r
+; +    Old SS           +\r
+; +---------------------+\r
+; +    Old RSP          +\r
+; +---------------------+\r
+; +    RFlags           +\r
+; +---------------------+\r
+; +    CS               +\r
+; +---------------------+\r
+; +    RIP              +\r
+; +---------------------+\r
+; +    Error Code       +\r
+; +---------------------+\r
+; +   Vector Number     +\r
+; +---------------------+\r
+; +    RBP              +\r
+; +---------------------+ <-- RBP, 16-byte aligned\r
+; The follow algorithm is used for the common interrupt routine.\r
+global ASM_PFX(CommonInterruptEntry)\r
+ASM_PFX(CommonInterruptEntry):\r
+    cli\r
+    pop     rax\r
+    ;\r
+    ; All interrupt handlers are invoked through interrupt gates, so\r
+    ; IF flag automatically cleared at the entry point\r
+    ;\r
+    xchg    rcx, [rsp]      ; Save rcx into stack and save vector number into rcx\r
+    and     rcx, 0xFF\r
+    cmp     ecx, 32         ; Intel reserved vector for exceptions?\r
+    jae     NoErrorCode\r
+    bt      [ASM_PFX(mErrorCodeFlag)], ecx\r
+    jc      HasErrorCode\r
+\r
+NoErrorCode:\r
+\r
+    ;\r
+    ; Push a dummy error code on the stack\r
+    ; to maintain coherent stack map\r
+    ;\r
+    push    qword [rsp]\r
+    mov     qword [rsp + 8], 0\r
+HasErrorCode:\r
+    push    rbp\r
+    mov     rbp, rsp\r
+    push    0             ; clear EXCEPTION_HANDLER_CONTEXT.OldIdtHandler\r
+    push    0             ; clear EXCEPTION_HANDLER_CONTEXT.ExceptionDataFlag\r
+\r
+    ;\r
+    ; Stack:\r
+    ; +---------------------+ <-- 16-byte aligned ensured by processor\r
+    ; +    Old SS           +\r
+    ; +---------------------+\r
+    ; +    Old RSP          +\r
+    ; +---------------------+\r
+    ; +    RFlags           +\r
+    ; +---------------------+\r
+    ; +    CS               +\r
+    ; +---------------------+\r
+    ; +    RIP              +\r
+    ; +---------------------+\r
+    ; +    Error Code       +\r
+    ; +---------------------+\r
+    ; + RCX / Vector Number +\r
+    ; +---------------------+\r
+    ; +    RBP              +\r
+    ; +---------------------+ <-- RBP, 16-byte aligned\r
+    ;\r
+\r
+    ;\r
+    ; Since here the stack pointer is 16-byte aligned, so\r
+    ; EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64\r
+    ; is 16-byte aligned\r
+    ;\r
+\r
+;; UINT64  Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;; UINT64  R8, R9, R10, R11, R12, R13, R14, R15;\r
+    push r15\r
+    push r14\r
+    push r13\r
+    push r12\r
+    push r11\r
+    push r10\r
+    push r9\r
+    push r8\r
+    push rax\r
+    push qword [rbp + 8]   ; RCX\r
+    push rdx\r
+    push rbx\r
+    push qword [rbp + 48]  ; RSP\r
+    push qword [rbp]       ; RBP\r
+    push rsi\r
+    push rdi\r
+\r
+;; UINT64  Gs, Fs, Es, Ds, Cs, Ss;  insure high 16 bits of each is zero\r
+    movzx   rax, word [rbp + 56]\r
+    push    rax                      ; for ss\r
+    movzx   rax, word [rbp + 32]\r
+    push    rax                      ; for cs\r
+    mov     rax, ds\r
+    push    rax\r
+    mov     rax, es\r
+    push    rax\r
+    mov     rax, fs\r
+    push    rax\r
+    mov     rax, gs\r
+    push    rax\r
+\r
+    mov     [rbp + 8], rcx               ; save vector number\r
+\r
+;; UINT64  Rip;\r
+    push    qword [rbp + 24]\r
+\r
+;; UINT64  Gdtr[2], Idtr[2];\r
+    xor     rax, rax\r
+    push    rax\r
+    push    rax\r
+    sidt    [rsp]\r
+    mov     bx, word [rsp]\r
+    mov     rax, qword [rsp + 2]\r
+    mov     qword [rsp], rax\r
+    mov     word [rsp + 8], bx\r
+\r
+    xor     rax, rax\r
+    push    rax\r
+    push    rax\r
+    sgdt    [rsp]\r
+    mov     bx, word [rsp]\r
+    mov     rax, qword [rsp + 2]\r
+    mov     qword [rsp], rax\r
+    mov     word [rsp + 8], bx\r
+\r
+;; UINT64  Ldtr, Tr;\r
+    xor     rax, rax\r
+    str     ax\r
+    push    rax\r
+    sldt    ax\r
+    push    rax\r
+\r
+;; UINT64  RFlags;\r
+    push    qword [rbp + 40]\r
+\r
+;; UINT64  Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
+    mov     rax, cr8\r
+    push    rax\r
+    mov     rax, cr4\r
+    or      rax, 0x208\r
+    mov     cr4, rax\r
+    push    rax\r
+    mov     rax, cr3\r
+    push    rax\r
+    mov     rax, cr2\r
+    push    rax\r
+    xor     rax, rax\r
+    push    rax\r
+    mov     rax, cr0\r
+    push    rax\r
+\r
+;; UINT64  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+    mov     rax, dr7\r
+    push    rax\r
+    mov     rax, dr6\r
+    push    rax\r
+    mov     rax, dr3\r
+    push    rax\r
+    mov     rax, dr2\r
+    push    rax\r
+    mov     rax, dr1\r
+    push    rax\r
+    mov     rax, dr0\r
+    push    rax\r
+\r
+;; FX_SAVE_STATE_X64 FxSaveState;\r
+    sub rsp, 512\r
+    mov rdi, rsp\r
+    db 0xf, 0xae, 0x7 ;fxsave [rdi]\r
+\r
+;; UEFI calling convention for x64 requires that Direction flag in EFLAGs is clear\r
+    cld\r
+\r
+;; UINT32  ExceptionData;\r
+    push    qword [rbp + 16]\r
+\r
+;; Prepare parameter and call\r
+    mov     rcx, [rbp + 8]\r
+    mov     rdx, rsp\r
+    ;\r
+    ; Per X64 calling convention, allocate maximum parameter stack space\r
+    ; and make sure RSP is 16-byte aligned\r
+    ;\r
+    sub     rsp, 4 * 8 + 8\r
+    call    ASM_PFX(CommonExceptionHandler)\r
+    add     rsp, 4 * 8 + 8\r
+\r
+    cli\r
+;; UINT64  ExceptionData;\r
+    add     rsp, 8\r
+\r
+;; FX_SAVE_STATE_X64 FxSaveState;\r
+\r
+    mov rsi, rsp\r
+    db 0xf, 0xae, 0xE ; fxrstor [rsi]\r
+    add rsp, 512\r
+\r
+;; UINT64  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+;; Skip restoration of DRx registers to support in-circuit emualators\r
+;; or debuggers set breakpoint in interrupt/exception context\r
+    add     rsp, 8 * 6\r
+\r
+;; UINT64  Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
+    pop     rax\r
+    mov     cr0, rax\r
+    add     rsp, 8   ; not for Cr1\r
+    pop     rax\r
+    mov     cr2, rax\r
+    pop     rax\r
+    mov     cr3, rax\r
+    pop     rax\r
+    mov     cr4, rax\r
+    pop     rax\r
+    mov     cr8, rax\r
+\r
+;; UINT64  RFlags;\r
+    pop     qword [rbp + 40]\r
+\r
+;; UINT64  Ldtr, Tr;\r
+;; UINT64  Gdtr[2], Idtr[2];\r
+;; Best not let anyone mess with these particular registers...\r
+    add     rsp, 48\r
+\r
+;; UINT64  Rip;\r
+    pop     qword [rbp + 24]\r
+\r
+;; UINT64  Gs, Fs, Es, Ds, Cs, Ss;\r
+    pop     rax\r
+    ; mov     gs, rax ; not for gs\r
+    pop     rax\r
+    ; mov     fs, rax ; not for fs\r
+    ; (X64 will not use fs and gs, so we do not restore it)\r
+    pop     rax\r
+    mov     es, rax\r
+    pop     rax\r
+    mov     ds, rax\r
+    pop     qword [rbp + 32]  ; for cs\r
+    pop     qword [rbp + 56]  ; for ss\r
+\r
+;; UINT64  Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;; UINT64  R8, R9, R10, R11, R12, R13, R14, R15;\r
+    pop     rdi\r
+    pop     rsi\r
+    add     rsp, 8               ; not for rbp\r
+    pop     qword [rbp + 48] ; for rsp\r
+    pop     rbx\r
+    pop     rdx\r
+    pop     rcx\r
+    pop     rax\r
+    pop     r8\r
+    pop     r9\r
+    pop     r10\r
+    pop     r11\r
+    pop     r12\r
+    pop     r13\r
+    pop     r14\r
+    pop     r15\r
+\r
+    mov     rsp, rbp\r
+    pop     rbp\r
+    add     rsp, 16\r
+    cmp     qword [rsp - 32], 0  ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler\r
+    jz      DoReturn\r
+    cmp     qword [rsp - 40], 1  ; check EXCEPTION_HANDLER_CONTEXT.ExceptionDataFlag\r
+    jz      ErrorCode\r
+    jmp     qword [rsp - 32]\r
+ErrorCode:\r
+    sub     rsp, 8\r
+    jmp     qword [rsp - 24]\r
+\r
+DoReturn:\r
+    cmp     qword [ASM_PFX(mDoFarReturnFlag)], 0   ; Check if need to do far return instead of IRET\r
+    jz      DoIret\r
+    push    rax\r
+    mov     rax, rsp          ; save old RSP to rax\r
+    mov     rsp, [rsp + 0x20]\r
+    push    qword [rax + 0x10]       ; save CS in new location\r
+    push    qword [rax + 0x8]        ; save EIP in new location\r
+    push    qword [rax + 0x18]       ; save EFLAGS in new location\r
+    mov     rax, [rax]        ; restore rax\r
+    popfq                     ; restore EFLAGS\r
+    DB      0x48               ; prefix to composite "retq" with next "retf"\r
+    retf                      ; far return\r
+DoIret:\r
+    iretq\r
+\r
+;-------------------------------------------------------------------------------------\r
+;  GetTemplateAddressMap (&AddressMap);\r
+;-------------------------------------------------------------------------------------\r
+; comments here for definition of address map\r
+global ASM_PFX(AsmGetTemplateAddressMap)\r
+ASM_PFX(AsmGetTemplateAddressMap):\r
+    lea     rax, [AsmIdtVectorBegin]\r
+    mov     qword [rcx], rax\r
+    mov     qword [rcx + 0x8],  (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32\r
+    lea     rax, [HookAfterStubHeaderBegin]\r
+    mov     qword [rcx + 0x10], rax\r
+\r
+; Fix up CommonInterruptEntry address\r
+    lea    rax, [ASM_PFX(CommonInterruptEntry)]\r
+    lea    rcx, [AsmIdtVectorBegin]\r
+%rep  32\r
+    mov    qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)], rax\r
+    add    rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32\r
+%endrep\r
+; Fix up HookAfterStubHeaderEnd\r
+    lea    rax, [HookAfterStubHeaderEnd]\r
+    lea    rcx, [JmpAbsoluteAddress]\r
+    mov    qword [rcx - 8], rax\r
+\r
+    ret\r
+\r
+;-------------------------------------------------------------------------------------\r
+;  AsmVectorNumFixup (*NewVectorAddr, VectorNum, *OldVectorAddr);\r
+;-------------------------------------------------------------------------------------\r
+global ASM_PFX(AsmVectorNumFixup)\r
+ASM_PFX(AsmVectorNumFixup):\r
+    mov     rax, rdx\r
+    mov     [rcx + (@VectorNum - HookAfterStubHeaderBegin)], al\r
+    ret\r
+\r
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
new file mode 100644 (file)
index 0000000..7e21bea
--- /dev/null
@@ -0,0 +1,55 @@
+## @file\r
+#  CPU Exception Handler library instance for SEC/PEI modules.\r
+#\r
+#  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+#  Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#  This is the XCODE5 variant of the SEC/PEI CpuExceptionHandlerLib. This\r
+#  variant performs binary patching to fix up addresses that allow the\r
+#  XCODE5 toolchain to be used.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Xcode5SecPeiCpuExceptionHandlerLib\r
+  MODULE_UNI_FILE                = Xcode5SecPeiCpuExceptionHandlerLib.uni\r
+  FILE_GUID                      = 49C481AF-1621-42F3-8FA1-27C64143E304\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.1\r
+  LIBRARY_CLASS                  = CpuExceptionHandlerLib|SEC PEI_CORE PEIM\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources.Ia32]\r
+  Ia32/ExceptionHandlerAsm.nasm\r
+  Ia32/ExceptionTssEntryAsm.nasm\r
+  Ia32/ArchExceptionHandler.c\r
+  Ia32/ArchInterruptDefs.h\r
+\r
+[Sources.X64]\r
+  X64/Xcode5ExceptionHandlerAsm.nasm\r
+  X64/ArchExceptionHandler.c\r
+  X64/ArchInterruptDefs.h\r
+\r
+[Sources.common]\r
+  CpuExceptionCommon.h\r
+  CpuExceptionCommon.c\r
+  SecPeiCpuException.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UefiCpuPkg/UefiCpuPkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  SerialPortLib\r
+  PrintLib\r
+  LocalApicLib\r
+  PeCoffGetEntryPointLib\r
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.uni b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.uni
new file mode 100644 (file)
index 0000000..a63b25f
--- /dev/null
@@ -0,0 +1,18 @@
+// /** @file\r
+// XCODE5 CPU Exception Handler library instance for SEC/PEI modules.\r
+//\r
+// CPU Exception Handler library instance for SEC/PEI modules when built\r
+// using the XCODE5 toolchain.\r
+//\r
+// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+// Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// SPDX-License-Identifier: BSD-2-Clause-Patent\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "CPU Exception Handler library instance for SEC/PEI modules with the XCODE5 toolchain."\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "CPU Exception Handler library instance for SEC/PEI modules with the XCODE5 toolchain."\r
+\r
index d28cb5cccb52e064e8b75200e46ac09dc144145a..afa30412822144a1ea1131063cb05c9761521b7b 100644 (file)
 \r
 [LibraryClasses.common.SEC]\r
   PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf\r
+!if $(TOOL_CHAIN_TAG) == "XCODE5"\r
+  CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf\r
+!else\r
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf\r
+!endif\r
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf\r
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
   UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf\r
   UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.inf\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf\r
+!if $(TOOL_CHAIN_TAG) != "XCODE5"\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf\r
+!endif\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf\r
   UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf\r
+  UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf\r
   UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf\r
   UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf\r
   UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf\r