summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/EbcDxe/X64/EbcLowLevel.asm
blob: 2f968cac2fcbc82b466b3195f44c0c532a6e2974 (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
;/** @file
;  
;    This code provides low level routines that support the Virtual Machine.
;    for option ROMs.
;  
;  Copyright (c) 2006 - 2008, Intel Corporation. <BR>
;  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.
;  
;**/

  page    ,132
  title   VM ASSEMBLY LANGUAGE ROUTINES

;---------------------------------------------------------------------------
; Equate files needed.
;---------------------------------------------------------------------------

text SEGMENT

;---------------------------------------------------------------------------
;;GenericPostSegment      SEGMENT USE16
;---------------------------------------------------------------------------

;****************************************************************************
; EbcLLCALLEX
;
; This function is called to execute an EBC CALLEX instruction.
; This instruction requires that we thunk out to external native
; code. For x64, we switch stacks, copy the arguments to the stack
; and jump to the specified function.
; On return, we restore the stack pointer to its original location.
;
; Destroys no working registers.
;****************************************************************************
; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)

CopyMem  PROTO  Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD


EbcLLCALLEXNative        PROC    PUBLIC
      push   rbp
      push   rbx
      mov    rbp, rsp
      ; Function prolog

      ; Copy FuncAddr to a preserved register.
      mov    rbx, rcx

      ; Set stack pointer to new value
      sub    r8,  rdx
      sub    rsp, r8
      mov    rcx, rsp
      sub    rsp, 20h
      call   CopyMem
      add    rsp, 20h

      ; Considering the worst case, load 4 potiential arguments
      ; into registers.
      mov    rcx, qword ptr [rsp]
      mov    rdx, qword ptr [rsp+8h]
      mov    r8,  qword ptr [rsp+10h]
      mov    r9,  qword ptr [rsp+18h]

      ; Now call the external routine
      call  rbx

      ; Function epilog
      mov      rsp, rbp
      pop      rbx
      pop      rbp
      ret
EbcLLCALLEXNative    ENDP


; UINTN EbcLLGetEbcEntryPoint(VOID);
; Routine Description:
;   The VM thunk code stuffs an EBC entry point into a processor
;   register. Since we can't use inline assembly to get it from
;   the interpreter C code, stuff it into the return value
;   register and return.
;
; Arguments:
;     None.
;
; Returns:
;     The contents of the register in which the entry point is passed.
;
EbcLLGetEbcEntryPoint        PROC    PUBLIC
    mov  rax, r10
    ret
EbcLLGetEbcEntryPoint    ENDP

;/*++
;
;Routine Description:
;
;  Return the caller's value of the stack pointer.
;
;Arguments:
;
;  None.
;
;Returns:
;
;  The current value of the stack pointer for the caller. We
;  adjust it by 4 here because when they called us, the return address
;  is put on the stack, thereby lowering it by 4 bytes.
;
;--*/

; UINTN EbcLLGetStackPointer()
EbcLLGetStackPointer        PROC    PUBLIC
    mov    rax, rsp      ; get current stack pointer
    ; Stack adjusted by this much when we were called,
    ; For this function, it's 4.
    add   rax, 4
    ret
EbcLLGetStackPointer    ENDP

; UINT64 EbcLLGetReturnValue(VOID);
; Routine Description:
;   When EBC calls native, on return the VM has to stuff the return
;   value into a VM register. It's assumed here that the value is still
;    in the register, so simply return and the caller should get the
;   return result properly.
;
; Arguments:
;     None.
;
; Returns:
;     The unmodified value returned by the native code.
;
EbcLLGetReturnValue   PROC    PUBLIC
    ret
EbcLLGetReturnValue    ENDP

text  ENDS
END