1#------------------------------------------------------------------------------ 2# 3# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR> 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# Module Name: 13# 14# Stack.asm 15# 16# Abstract: 17# 18# Switch the stack from temporary memory to permenent memory. 19# 20#------------------------------------------------------------------------------ 21 22 .text 23 24 25//------------------------------------------------------------------------------ 26// VOID 27// EFIAPI 28// SecSwitchStack ( 29// UINT32 TemporaryMemoryBase, 30// UINT32 PermenentMemoryBase 31// )// 32//------------------------------------------------------------------------------ 33ASM_GLOBAL ASM_PFX(SecSwitchStack) 34ASM_PFX(SecSwitchStack): 35# 36# Save three register: eax, ebx, ecx 37# 38 push %eax 39 push %ebx 40 push %ecx 41 push %edx 42 43# 44# !!CAUTION!! this function address's is pushed into stack after 45# migration of whole temporary memory, so need save it to permenent 46# memory at first! 47# 48 49 movl 20(%esp), %ebx # Save the first parameter 50 movl 24(%esp), %ecx # Save the second parameter 51 52# 53# Save this function's return address into permenent memory at first. 54# Then, Fixup the esp point to permenent memory 55# 56 57 movl %esp, %eax 58 subl %ebx, %eax 59 addl %ecx, %eax 60 movl (%esp), %edx # copy pushed register's value to permenent memory 61 movl %edx, (%eax) 62 movl 4(%esp), %edx 63 movl %edx, 4(%eax) 64 movl 8(%esp), %edx 65 movl %edx, 8(%eax) 66 movl 12(%esp), %edx 67 movl %edx, 12(%eax) 68 movl 16(%esp), %edx 69 movl %edx, 16(%eax) 70 movl %eax, %esp # From now, esp is pointed to permenent memory 71 72# 73# Fixup the ebp point to permenent memory 74# 75#ifndef __APPLE__ 76 movl %ebp, %eax 77 subl %ebx, %eax 78 addl %ecx, %eax 79 movl %eax, %ebp # From now, ebp is pointed to permenent memory 80 81# 82# Fixup callee's ebp point for PeiDispatch 83# 84 movl (%ebp), %eax 85 subl %ebx, %eax 86 addl %ecx, %eax 87 movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permenent memory 88#endif 89 90 pop %edx 91 pop %ecx 92 pop %ebx 93 pop %eax 94 ret 95 96