summaryrefslogtreecommitdiffstats
path: root/Nt32Pkg/Sec/StackX64.asm
blob: 2327e2eeac5978592e70123d2eee0521051441cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;------------------------------------------------------------------------------
;
; Copyright (c) 2013, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution.  The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
;   Stack.asm
;
; Abstract:
;
;   Switch the stack from temporary memory to permenent memory.
;
;------------------------------------------------------------------------------

    .code
    
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; SecSwitchStack (
;   UINT32   TemporaryMemoryBase,
;   UINT32   PermenentMemoryBase
;   );
;------------------------------------------------------------------------------    
SecSwitchStack   PROC
    mov [rsp + 08h], rcx
    mov [rsp + 10h], rdx

    ;
    ; Save three register: eax, ebx, ecx
    ;
    push  rax
    push  rbx
    push  rcx
    push  rdx
    
    ;
    ; !!CAUTION!! this function address's is pushed into stack after
    ; migration of whole temporary memory, so need save it to permenent
    ; memory at first!
    ;
    
    mov   rbx, [rsp + 28h]          ; Save the first parameter
    mov   rcx, [rsp + 30h]          ; Save the second parameter
    
    ;
    ; Save this function's return address into permenent memory at first.
    ; Then, Fixup the esp point to permenent memory
    ;
    mov   rax, rsp
    sub   rax, rbx
    add   rax, rcx
    mov   rdx, qword ptr [rsp]         ; copy pushed register's value to permenent memory
    mov   qword ptr [rax], rdx    
    mov   rdx, qword ptr [rsp + 8]
    mov   qword ptr [rax + 8], rdx    
    mov   rdx, qword ptr [rsp + 10h]
    mov   qword ptr [rax + 10h], rdx    
    mov   rdx, qword ptr [rsp + 18h]
    mov   qword ptr [rax + 18h], rdx    
    mov   rdx, qword ptr [rsp + 20h]    ; Update this function's return address into permenent memory
    mov   qword ptr [rax + 20h], rdx    
    mov   rsp, rax                     ; From now, esp is pointed to permenent memory
        
    ;
    ; Fixup the ebp point to permenent memory
    ;
    mov   rax, rbp
    sub   rax, rbx
    add   rax, rcx
    mov   rbp, rax                ; From now, ebp is pointed to permenent memory
    
    pop   rdx
    pop   rcx
    pop   rbx
    pop   rax
    ret
SecSwitchStack   ENDP

;------------------------------------------------------------------------------
; VOID
; EFIAPI
; PeiSwitchStacks (
;   IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
;   IN      VOID                      *Context1,  OPTIONAL
;   IN      VOID                      *Context2,  OPTIONAL
;   IN      VOID                      *Context3,  OPTIONAL
;   IN      VOID                      *NewStack
;   )
;------------------------------------------------------------------------------
PeiSwitchStacks   PROC
    mov  rax, rcx
    mov  rcx, rdx
    mov  rdx, r8
    mov  r8, r9
    mov  rsp, [rsp + 28h]
    sub  rsp, 20h
    call rax
    jmp $
    ret
PeiSwitchStacks   ENDP

    END