summaryrefslogtreecommitdiff
path: root/Core/CPU/x64/ProcessorAsms.Asm
blob: ebd8b03907cac694b98e5e6eb0951d536a9430e8 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
;------------------------------------------------------------------------------
;
; Copyright (c) 2005 - 2007, Intel Corporation                                                         
; All rights reserved. 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:
;   ProcessorAsms.Asm
;
; Abstract:
;   This is separated from processor.c to allow this functions to be built with /O1
;
;
;------------------------------------------------------------------------------

text  SEGMENT


;
; Routine Description:
;   This allows the caller to switch the stack and goes to the new entry point
;
; Arguments:
;   EntryPoint      - Pointer to the location to enter // rcx
;   Parameter       - Parameter to pass in             // rdx
;   NewStack        - New Location of the stack        // r8
;   NewBsp          - New BSP                          // r9 - not used
;
; Returns:
;   Nothing. Goes to the Entry Point passing in the new parameters
;
SwitchStacks  PROC  PUBLIC

    ; Adjust stack for
    ;   1) leave 4 registers space
    ;   2) let it 16 bytes aligned after call
    sub   r8, 20h
    and   r8w, 0fff0h    ; do not assume 16 bytes aligned

    mov   rsp,  r8       ; rsp = NewStack
    mov   r10,  rcx      ; save EntryPoint
    mov   rcx,  rdx      ; Arg1 = Parameter
    call  r10            ; r10 = copy of EntryPoint
 ;
 ; no ret as we have a new stack and we jumped to the new location
 ;     
    ret
  
SwitchStacks    ENDP


EFI_SUCCESS                     equ     0
EFI_WARN_RETURN_FROM_LONG_JUMP  equ     5

;
; Generated by h2inc run manually
;
_EFI_JUMP_BUFFER                STRUCT 2t
_rbx            QWORD           ?
_rsp            QWORD           ?
_rbp            QWORD           ?
_rdi            QWORD           ?
_rsi            QWORD           ?
_r10            QWORD           ?
_r11            QWORD           ?
_r12            QWORD           ?
_r13            QWORD           ?
_r14            QWORD           ?
_r15            QWORD           ?
_rip            QWORD           ?
_MxCsr          DWORD           ?
_XmmBuffer      DB              160 DUP (?)
_EFI_JUMP_BUFFER                ENDS

EFI_JUMP_BUFFER         TYPEDEF         _EFI_JUMP_BUFFER


;
;Routine Description:
;
;  This routine implements the x64 variant of the SetJump call.  Its
;  responsibility is to store system state information for a possible
;  subsequent LongJump.
;
;Arguments:
;
;  Pointer to CPU context save buffer.
;
;Returns:
;
;  EFI_SUCCESS
;
; EFI_STATUS
; EFIAPI
; TransferControlLongJump (
;   IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL  *This,
;   IN EFI_JUMP_BUFFER                    *Jump
;   );
;
; rcx - *This
; rdx - JumpBuffer
;
PUBLIC  TransferControlSetJump
TransferControlSetJump  PROC  
  mov   (EFI_JUMP_BUFFER PTR [rdx])._rbx, rbx
  mov   (EFI_JUMP_BUFFER PTR [rdx])._rsp, rsp
  mov   (EFI_JUMP_BUFFER PTR [rdx])._rbp, rbp
  mov   (EFI_JUMP_BUFFER PTR [rdx])._rdi, rdi
  mov   (EFI_JUMP_BUFFER PTR [rdx])._rsi, rsi
  mov   (EFI_JUMP_BUFFER PTR [rdx])._r10, r10
  mov   (EFI_JUMP_BUFFER PTR [rdx])._r11, r11
  mov   (EFI_JUMP_BUFFER PTR [rdx])._r12, r12
  mov   (EFI_JUMP_BUFFER PTR [rdx])._r13, r13
  mov   (EFI_JUMP_BUFFER PTR [rdx])._r14, r14
  mov   (EFI_JUMP_BUFFER PTR [rdx])._r15, r15
  ; save non-volatile fp registers
  stmxcsr    (EFI_JUMP_BUFFER PTR [rdx])._MxCsr
  lea   rax, (EFI_JUMP_BUFFER PTR [rdx])._XmmBuffer
  movdqu [rax], xmm6
  movdqu [rax + 10h], xmm7
  movdqu [rax + 20h], xmm8
  movdqu [rax + 30h], xmm9
  movdqu [rax + 40h], xmm10
  movdqu [rax + 50h], xmm11
  movdqu [rax + 60h], xmm12
  movdqu [rax + 70h], xmm13
  movdqu [rax + 80h], xmm14
  movdqu [rax + 90h], xmm15
  mov   rax, QWORD PTR [rsp+0]
  mov   (EFI_JUMP_BUFFER PTR [rdx])._rip, rax
  mov   rax, EFI_SUCCESS  
  ret
  
TransferControlSetJump      ENDP

;
; EFI_STATUS
; EFIAPI
; TransferControlLongJump (
;   IN EFI_PEI_TRANSFER_CONTROL_PROTOCOL  *This,  // rcx
;   IN EFI_JUMP_BUFFER                    *Jump   // rdx
;   );
;
;
PUBLIC  TransferControlLongJump
TransferControlLongJump  PROC  
  ; load non-volatile fp registers
  ldmxcsr    (EFI_JUMP_BUFFER PTR [rdx])._MxCsr
  lea   rax, (EFI_JUMP_BUFFER PTR [rdx])._XmmBuffer
  movdqu xmm6, [rax]
  movdqu xmm7, [rax + 10h]
  movdqu xmm8, [rax + 20h]
  movdqu xmm9, [rax + 30h]
  movdqu xmm10, [rax + 40h]
  movdqu xmm11, [rax + 50h]
  movdqu xmm12, [rax + 60h]
  movdqu xmm13, [rax + 70h]
  movdqu xmm14, [rax + 80h]
  movdqu xmm15, [rax + 90h]
  ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP
  mov   rax, EFI_WARN_RETURN_FROM_LONG_JUMP          
  mov   rbx, (EFI_JUMP_BUFFER PTR [rdx])._rbx
  mov   rsp, (EFI_JUMP_BUFFER PTR [rdx])._rsp
  mov   rbp, (EFI_JUMP_BUFFER PTR [rdx])._rbp
  mov   rdi, (EFI_JUMP_BUFFER PTR [rdx])._rdi
  mov   rsi, (EFI_JUMP_BUFFER PTR [rdx])._rsi
  mov   r10, (EFI_JUMP_BUFFER PTR [rdx])._r10
  mov   r11, (EFI_JUMP_BUFFER PTR [rdx])._r11
  mov   r12, (EFI_JUMP_BUFFER PTR [rdx])._r12
  mov   r13, (EFI_JUMP_BUFFER PTR [rdx])._r13
  mov   r14, (EFI_JUMP_BUFFER PTR [rdx])._r14
  mov   r15, (EFI_JUMP_BUFFER PTR [rdx])._r15
  add   rsp, 8                                       ;pop the eip
  jmp   QWORD PTR (EFI_JUMP_BUFFER PTR [rdx])._rip
  ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP
  mov   rax, EFI_WARN_RETURN_FROM_LONG_JUMP
  ret
TransferControlLongJump  ENDP

text  ENDS
END