summaryrefslogtreecommitdiff
path: root/EDK/Foundation/Library/Pei/PeiLib/ia32/ProcessorAsms.Asm
blob: 86f460607bf396977d3699611a7078ce1e2e8542 (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
;
; Copyright (c) 2004, 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
;
; Notes:
; - Masm uses "This", "ebx", etc as a directive.
; - H2INC is still not embedded in our build process so I translated the struc manually.
; - Unreferenced variables/arguments (This, NewBsp, NewStack) were causing compile errors and 
;       did not know of "pragma" mechanism in MASM and I did not want to reduce the warning level. 
;       Instead, I did a dummy referenced.
;

  .686P
  .MMX
  .MODEL SMALL
  .CODE

EFI_SUCCESS                     equ     0
EFI_WARN_RETURN_FROM_LONG_JUMP  equ     5

;
; Generated by h2inc run manually
;
_EFI_JUMP_BUFFER                STRUCT 2t
_ebx            DWORD           ?
_esi            DWORD           ?
_edi            DWORD           ?
_ebp            DWORD           ?
_esp            DWORD           ?
_eip            DWORD           ?
_EFI_JUMP_BUFFER                ENDS

EFI_JUMP_BUFFER         TYPEDEF         _EFI_JUMP_BUFFER

TransferControlSetJump      PROTO  C \
        _This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
        Jump:PTR EFI_JUMP_BUFFER

TransferControlLongJump     PROTO  C \
        _This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
        Jump:PTR EFI_JUMP_BUFFER

SwitchStacks    PROTO  C \
   EntryPoint:PTR DWORD, \
   Parameter:DWORD, \
   NewStack:PTR DWORD, \
   NewBsp:PTR DWORD
   
SwitchIplStacks PROTO  C \
   EntryPoint:PTR DWORD, \
   Parameter1:DWORD, \
   Parameter2:DWORD, \
   NewStack:PTR DWORD, \
   NewBsp:PTR DWORD

;
;Routine Description:
;
;  This routine implements the IA32 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
;
TransferControlSetJump      PROC  C \
  _This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
  Jump:PTR EFI_JUMP_BUFFER
    
  mov   eax, _This 
  mov   ecx, Jump
  mov   (EFI_JUMP_BUFFER PTR [ecx])._ebx, ebx
  mov   (EFI_JUMP_BUFFER PTR [ecx])._esi, esi
  mov   (EFI_JUMP_BUFFER PTR [ecx])._edi, edi
  mov   eax, [ebp]
  mov   (EFI_JUMP_BUFFER PTR [ecx])._ebp, eax
  lea   eax, [ebp+4]
  mov   (EFI_JUMP_BUFFER PTR [ecx])._esp, eax
  mov   eax, [ebp+4]
  mov   (EFI_JUMP_BUFFER PTR [ecx])._eip, eax
  mov   eax, EFI_SUCCESS
  
  ret
  
TransferControlSetJump      ENDP

;
; Routine Description:
; 
;  This routine implements the IA32 variant of the LongJump call.  Its
;  responsibility is restore the system state to the Context Buffer and
;  pass control back.
;
; Arguments:
; 
;  Pointer to CPU context save buffer.
;
; Returns:
;
;  EFI_WARN_RETURN_FROM_LONG_JUMP
;

TransferControlLongJump     PROC  C \
        _This:PTR EFI_PEI_TRANSFER_CONTROL_PROTOCOL, \
        Jump:PTR EFI_JUMP_BUFFER

  push  ebx
  push  esi
  push  edi

  mov   eax, _This
    ; set return from SetJump to EFI_WARN_RETURN_FROM_LONG_JUMP
  mov   eax, EFI_WARN_RETURN_FROM_LONG_JUMP          
  mov   ecx, Jump
  mov   ebx, (EFI_JUMP_BUFFER PTR [ecx])._ebx
  mov   esi, (EFI_JUMP_BUFFER PTR [ecx])._esi
  mov   edi, (EFI_JUMP_BUFFER PTR [ecx])._edi
  mov   ebp, (EFI_JUMP_BUFFER PTR [ecx])._ebp
  mov   esp, (EFI_JUMP_BUFFER PTR [ecx])._esp
  add   esp, 4                                       ;pop the eip
  jmp   DWORD PTR (EFI_JUMP_BUFFER PTR [ecx])._eip
  mov   eax, EFI_WARN_RETURN_FROM_LONG_JUMP
  
  pop   edi
  pop   esi
  pop   ebx
  ret
  
TransferControlLongJump     ENDP

;
; 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
;       Parameter       - Parameter to pass in
;       NewStack        - New Location of the stack
;       NewBsp          - New BSP
;
; Returns:
;
;       Nothing. Goes to the Entry Point passing in the new parameters
;
SwitchStacks    PROC  C \
  EntryPoint:PTR DWORD, \
  Parameter:DWORD, \
  NewStack:PTR DWORD, \
  NewBsp:PTR DWORD
  
  push  ebx
  mov   eax, NewBsp
  mov   ebx, Parameter
  mov   ecx, EntryPoint
  mov   eax, NewStack
  mov   esp, eax
  push  ebx
  push  0
  jmp   ecx
  
  pop   ebx
  ret
  
SwitchStacks    ENDP

;
; 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
;       Parameter1/Parameter2   - Parameter to pass in
;       NewStack                - New Location of the stack
;       NewBsp                  - New BSP
;
; Returns:
;
;       Nothing. Goes to the Entry Point passing in the new parameters
;
SwitchIplStacks PROC  C \
  EntryPoint:PTR DWORD, \
  Parameter1:DWORD, \
  Parameter2:DWORD, \
  NewStack:PTR DWORD, \
  NewBsp:PTR DWORD
  
  push  ebx
  mov   eax, NewBsp         
  mov   ebx, Parameter1
  mov   edx, Parameter2
  mov   ecx, EntryPoint
  mov   eax, NewStack
  mov   esp, eax

  push  edx
  push  ebx
  call  ecx
  
  pop   ebx
  ret
  
SwitchIplStacks ENDP

  END