Stacks.s 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #------------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
  4. # SPDX-License-Identifier: BSD-2-Clause-Patent
  5. #
  6. # Abstract:
  7. #
  8. # Switch the stack from temporary memory to permenent memory.
  9. #
  10. #------------------------------------------------------------------------------
  11. ASM_GLOBAL ASM_PFX(SecSwitchStack)
  12. #------------------------------------------------------------------------------
  13. # VOID
  14. # EFIAPI
  15. # SecSwitchStack (
  16. # UINT32 TemporaryMemoryBase,
  17. # UINT32 PermenentMemoryBase
  18. # )
  19. #------------------------------------------------------------------------------
  20. ASM_GLOBAL ASM_PFX(SecSwitchStack)
  21. ASM_PFX(SecSwitchStack):
  22. #
  23. # Save four registers: eax, ebx, ecx, edx
  24. #
  25. pushl %eax
  26. pushl %ebx
  27. pushl %ecx
  28. pushl %edx
  29. #
  30. # !!CAUTION!! this function address's is pushed into stack after
  31. # migration of whole temporary memory, so need save it to permenent
  32. # memory at first!
  33. #
  34. movl 20(%esp), %ebx # Save the first parameter
  35. movl 24(%esp), %ecx # Save the second parameter
  36. #
  37. # Save this function's return address into permenent memory at first.
  38. # Then, Fixup the esp point to permenent memory
  39. #
  40. movl %esp, %eax
  41. subl %ebx, %eax
  42. addl %ecx, %eax
  43. movl (%esp), %edx # copy pushed register's value to permenent memory
  44. movl %edx, (%eax)
  45. movl 4(%esp), %edx
  46. movl %edx, 4(%eax)
  47. movl 8(%esp), %edx
  48. movl %edx, 8(%eax)
  49. movl 12(%esp), %edx
  50. movl %edx, 12(%eax)
  51. movl 16(%esp), %edx # Update this function's return address into permenent memory
  52. movl %edx, 16(%eax)
  53. movl %eax, %esp # From now, esp is pointed to permenent memory
  54. #
  55. # Fixup the ebp point to permenent memory
  56. #
  57. movl %ebp, %eax
  58. subl %ebx, %eax
  59. addl %ecx, %eax
  60. movl %eax, %ebp # From now, ebp is pointed to permenent memory
  61. #
  62. # Fixup callee's ebp point for PeiDispatch
  63. #
  64. # movl %ebp, %eax
  65. # subl %ebx, %eax
  66. # addl %ecx, %eax
  67. # movl %eax, %ebp # From now, ebp is pointed to permenent memory
  68. popl %edx
  69. popl %ecx
  70. popl %ebx
  71. popl %eax
  72. ret