Stack.S 2.1 KB

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