Stack.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #------------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 2013, 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. # Abstract:
  13. #
  14. # Switch the stack from temporary memory to permanent memory.
  15. #
  16. #------------------------------------------------------------------------------
  17. #------------------------------------------------------------------------------
  18. # VOID
  19. # EFIAPI
  20. # SecSwitchStack (
  21. # UINT32 TemporaryMemoryBase,
  22. # UINT32 PermenentMemoryBase
  23. # )#
  24. #------------------------------------------------------------------------------
  25. ASM_GLOBAL ASM_PFX (SecSwitchStack)
  26. ASM_PFX(SecSwitchStack):
  27. #
  28. # Save standard registers so they can be used to change stack
  29. #
  30. pushl %eax
  31. pushl %ebx
  32. pushl %ecx
  33. pushl %edx
  34. #
  35. # !!CAUTION!! this function address's is pushed into stack after
  36. # migration of whole temporary memory, so need save it to permanent
  37. # memory at first!
  38. #
  39. movl 20(%esp), %ebx # Save the first parameter
  40. movl 24(%esp), %ecx # Save the second parameter
  41. #
  42. # Save this function's return address into permanent memory at first.
  43. # Then, Fixup the esp point to permanent memory
  44. #
  45. movl %esp, %eax
  46. subl %ebx, %eax
  47. addl %ecx, %eax
  48. movl 0(%esp), %edx # copy pushed register's value to permanent memory
  49. movl %edx, 0(%eax)
  50. movl 4(%esp), %edx
  51. movl %edx, 4(%eax)
  52. movl 8(%esp), %edx
  53. movl %edx, 8(%eax)
  54. movl 12(%esp), %edx
  55. movl %edx, 12(%eax)
  56. movl 16(%esp), %edx # Update this function's return address into permanent memory
  57. movl %edx, 16(%eax)
  58. movl %eax, %esp # From now, esp is pointed to permanent memory
  59. #
  60. # Fixup the ebp point to permanent memory
  61. #
  62. movl %ebp, %eax
  63. subl %ebx, %eax
  64. addl %ecx, %eax
  65. movl %eax, %ebp # From now, ebp is pointed to permanent memory
  66. popl %edx
  67. popl %ecx
  68. popl %ebx
  69. popl %eax
  70. ret