Stack.nasm 2.1 KB

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