Stack.asm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. .586p
  12. .model flat,C
  13. .code
  14. ;------------------------------------------------------------------------------
  15. ; VOID
  16. ; EFIAPI
  17. ; SecSwitchStack (
  18. ; UINT32 TemporaryMemoryBase,
  19. ; UINT32 PermenentMemoryBase
  20. ; );
  21. ;------------------------------------------------------------------------------
  22. SecSwitchStack PROC
  23. ;
  24. ; Save three register: eax, ebx, ecx
  25. ;
  26. push eax
  27. push ebx
  28. push ecx
  29. push edx
  30. ;
  31. ; !!CAUTION!! this function address's is pushed into stack after
  32. ; migration of whole temporary memory, so need save it to permenent
  33. ; memory at first!
  34. ;
  35. mov ebx, [esp + 20] ; Save the first parameter
  36. mov ecx, [esp + 24] ; Save the second parameter
  37. ;
  38. ; Save this function's return address into permenent memory at first.
  39. ; Then, Fixup the esp point to permenent memory
  40. ;
  41. mov eax, esp
  42. sub eax, ebx
  43. add eax, ecx
  44. mov edx, dword ptr [esp] ; copy pushed register's value to permenent memory
  45. mov dword ptr [eax], edx
  46. mov edx, dword ptr [esp + 4]
  47. mov dword ptr [eax + 4], edx
  48. mov edx, dword ptr [esp + 8]
  49. mov dword ptr [eax + 8], edx
  50. mov edx, dword ptr [esp + 12]
  51. mov dword ptr [eax + 12], edx
  52. mov edx, dword ptr [esp + 16] ; Update this function's return address into permenent memory
  53. mov dword ptr [eax + 16], edx
  54. mov esp, eax ; From now, esp is pointed to permenent memory
  55. ;
  56. ; Fixup the ebp point to permenent memory
  57. ;
  58. mov eax, ebp
  59. sub eax, ebx
  60. add eax, ecx
  61. mov ebp, eax ; From now, ebp is pointed to permenent memory
  62. pop edx
  63. pop ecx
  64. pop ebx
  65. pop eax
  66. ret
  67. SecSwitchStack ENDP
  68. END