3 // Contains low level routines for the Virtual Machine implementation
4 // on an Itanium-based platform.
6 // Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
7 // This program and the accompanying materials
8 // are licensed and made available under the terms and conditions of the BSD License
9 // which accompanies this distribution. The full text of the license may be found at
10 // http://opensource.org/licenses/bsd-license.php
12 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #define PROCEDURE_ENTRY(name) .##text; \
20 .##type name, @function; \
24 #define PROCEDURE_EXIT(name) .##endp name
26 // Note: use of NESTED_SETUP requires number of locals (l) >= 3
28 #define NESTED_SETUP(i,l,o,r) \
29 alloc loc1=ar##.##pfs,i,l,o,r ;\
32 #define NESTED_RETURN \
34 mov ar##.##pfs=loc1 ;;\
35 br##.##ret##.##dpnt b0;;
37 .type CopyMem, @function;
39 //-----------------------------------------------------------------------------
43 // Implements the low level EBC CALLEX instruction. Sets up the
44 // stack pointer, does the spill of function arguments, and
45 // calls the native function. On return it restores the original
46 // stack pointer and returns to the caller.
51 // in0 = Address of native code to call
52 // in1 = New stack pointer
56 // As per static calling conventions.
59 //---------------------------------------------------------------------------
60 ;// void EbcAsmLLCALLEX (UINTN FunctionAddr, UINTN EbcStackPointer)
61 PROCEDURE_ENTRY(EbcAsmLLCALLEX)
62 NESTED_SETUP (2,6,8,0)
64 // NESTED_SETUP uses loc0 and loc1 for context save
67 // Save a copy of the EBC VM stack pointer
72 // Copy stack arguments from EBC stack into registers.
73 // Assume worst case and copy 8.
85 // Save the original stack pointer
95 // Set the new aligned stack pointer. Reserve space for the required
96 // 16-bytes of scratch area as well.
101 // Now call the function. Load up the function address from the descriptor
102 // pointed to by in0. Then get the gp from the descriptor at the following
103 // address in the descriptor.
109 (p0) br.call.dptk.many b0 = b1;;
112 // Restore the original stack pointer and gp
122 PROCEDURE_EXIT(EbcAsmLLCALLEX)
124 //-----------------------------------------------------------------------------
128 // This function is called to execute an EBC CALLEX instruction.
129 // This instruction requires that we thunk out to external native
130 // code. On return, we restore the stack pointer to its original location.
131 // Destroys no working registers. For IPF, at least 8 register slots
132 // must be allocated on the stack frame to support any number of
133 // arguments beiung passed to the external native function. The
134 // size of the stack frame is FramePtr - EbcSp. If this size is less
135 // than 64-bytes, the amount of stack frame allocated is rounded up
138 // Arguments On Entry :
139 // in0 = CallAddr The function address.
140 // in1 = EbcSp The new EBC stack pointer.
141 // in2 = FramePtr The frame pointer.
146 // C Function Prototype:
149 // EbcLLCALLEXNative (
150 // IN UINTN CallAddr,
155 //---------------------------------------------------------------------------
157 PROCEDURE_ENTRY(EbcLLCALLEXNative)
158 NESTED_SETUP (3,6,3,0)
160 mov loc2 = in2;; // loc2 = in2 = FramePtr
161 mov loc3 = in1;; // loc3 = in1 = EbcSp
162 sub loc2 = loc2, loc3;; // loc2 = loc2 - loc3 = FramePtr - EbcSp
163 mov out2 = loc2;; // out2 = loc2 = FramePtr - EbcSp
164 mov loc4 = 0x40;; // loc4 = 0x40
165 cmp.leu p6 = out2, loc4;; // IF out2 < loc4 THEN P6=1 ELSE P6=0; IF (FramePtr - EbcSp) < 0x40 THEN P6 = 1 ELSE P6=0
166 (p6) mov loc2 = loc4;; // IF P6==1 THEN loc2 = loc4 = 0x40
167 mov loc4 = r12;; // save sp
168 or loc5 = r1, r0 // save gp
170 sub r12 = r12, loc2;; // sp = sp - loc2 = sp - MAX (0x40, FramePtr - EbcSp)
172 and r12 = -0x10, r12 // Round sp down to the nearest 16-byte boundary
173 mov out1 = in1;; // out1 = EbcSp
174 mov out0 = r12;; // out0 = sp
176 (p0) br.call.dptk.many b0 = CopyMem;; // CopyMem (sp, EbcSp, (FramePtr - EbcSp))
179 mov out0 = in0;; // out0 = CallAddr
180 mov out1 = r12;; // out1 = sp
181 (p0) br.call.dptk.many b0 = EbcAsmLLCALLEX;; // EbcAsmLLCALLEX (CallAddr, sp)
182 mov r12 = loc4;; // restore sp
183 or r1 = loc5, r0 // restore gp
186 PROCEDURE_EXIT(EbcLLCALLEXNative)
190 // UINTN EbcLLGetEbcEntryPoint(VOID)
193 // Simply return, so that the caller retrieves the return register
194 // contents (R8). That's where the thunk-to-ebc code stuffed the
197 PROCEDURE_ENTRY(EbcLLGetEbcEntryPoint)
199 PROCEDURE_EXIT(EbcLLGetEbcEntryPoint)