; This code provides low level routines that support the Virtual Machine.\r
; for option ROMs.\r
; \r
-; Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-; All rights reserved. This program and the accompanying materials\r
+; Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
; are licensed and made available under the terms and conditions of the BSD License\r
; which accompanies this distribution. The full text of the license may be found at\r
; http://opensource.org/licenses/bsd-license.php\r
; Equate files needed.\r
;---------------------------------------------------------------------------\r
\r
-text SEGMENT\r
+.CODE\r
\r
-;---------------------------------------------------------------------------\r
-;;GenericPostSegment SEGMENT USE16\r
-;---------------------------------------------------------------------------\r
+CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD\r
+EbcInterpret PROTO\r
+ExecuteEbcImageEntryPoint PROTO\r
\r
;****************************************************************************\r
; EbcLLCALLEX\r
;\r
; Destroys no working registers.\r
;****************************************************************************\r
-; VOID EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
-\r
-CopyMem PROTO Destination:PTR DWORD, Source:PTR DWORD, Count:DWORD\r
-\r
-\r
+; INT64 EbcLLCALLEXNative(UINTN FuncAddr, UINTN NewStackPointer, VOID *FramePtr)\r
EbcLLCALLEXNative PROC PUBLIC\r
push rbp\r
push rbx\r
ret\r
EbcLLCALLEXNative ENDP\r
\r
-\r
-; UINTN EbcLLGetEbcEntryPoint(VOID);\r
-; Routine Description:\r
-; The VM thunk code stuffs an EBC entry point into a processor\r
-; register. Since we can't use inline assembly to get it from\r
-; the interpreter C code, stuff it into the return value\r
-; register and return.\r
-;\r
-; Arguments:\r
-; None.\r
-;\r
-; Returns:\r
-; The contents of the register in which the entry point is passed.\r
+;****************************************************************************\r
+; EbcLLEbcInterpret\r
;\r
-EbcLLGetEbcEntryPoint PROC PUBLIC\r
- mov rax, r10\r
+; Begin executing an EBC image.\r
+;****************************************************************************\r
+; UINT64 EbcLLEbcInterpret(VOID)\r
+EbcLLEbcInterpret PROC PUBLIC\r
+ ;\r
+ ;; mov rax, ca112ebccall2ebch\r
+ ;; mov r10, EbcEntryPoint\r
+ ;; mov r11, EbcLLEbcInterpret\r
+ ;; jmp r11\r
+ ;\r
+ ; Caller uses above instruction to jump here\r
+ ; The stack is below:\r
+ ; +-----------+\r
+ ; | RetAddr |\r
+ ; +-----------+\r
+ ; |EntryPoint | (R10)\r
+ ; +-----------+\r
+ ; | Arg1 | <- RDI\r
+ ; +-----------+\r
+ ; | Arg2 |\r
+ ; +-----------+\r
+ ; | ... |\r
+ ; +-----------+\r
+ ; | Arg16 |\r
+ ; +-----------+\r
+ ; | Dummy |\r
+ ; +-----------+\r
+ ; | RDI |\r
+ ; +-----------+\r
+ ; | RSI |\r
+ ; +-----------+\r
+ ; | RBP | <- RBP\r
+ ; +-----------+\r
+ ; | RetAddr | <- RSP is here\r
+ ; +-----------+\r
+ ; | Scratch1 | (RCX) <- RSI\r
+ ; +-----------+\r
+ ; | Scratch2 | (RDX)\r
+ ; +-----------+\r
+ ; | Scratch3 | (R8)\r
+ ; +-----------+\r
+ ; | Scratch4 | (R9)\r
+ ; +-----------+\r
+ ; | Arg5 |\r
+ ; +-----------+\r
+ ; | Arg6 |\r
+ ; +-----------+\r
+ ; | ... |\r
+ ; +-----------+\r
+ ; | Arg16 |\r
+ ; +-----------+\r
+ ;\r
+\r
+ ; save old parameter to stack\r
+ mov [rsp + 08h], rcx\r
+ mov [rsp + 10h], rdx\r
+ mov [rsp + 18h], r8\r
+ mov [rsp + 20h], r9\r
+\r
+ ; Construct new stack\r
+ push rbp\r
+ mov rbp, rsp\r
+ push rsi\r
+ push rdi\r
+ push rbx\r
+ sub rsp, 80h\r
+ push r10\r
+ mov rsi, rbp\r
+ add rsi, 10h\r
+ mov rdi, rsp\r
+ add rdi, 8\r
+ mov rcx, 16\r
+ rep movsq\r
+ \r
+ ; build new paramater calling convention\r
+ mov r9, [rsp + 18h]\r
+ mov r8, [rsp + 10h]\r
+ mov rdx, [rsp + 08h]\r
+ mov rcx, r10\r
+\r
+ ; call C-code\r
+ call EbcInterpret\r
+ add rsp, 88h\r
+ pop rbx\r
+ pop rdi\r
+ pop rsi\r
+ pop rbp\r
ret\r
-EbcLLGetEbcEntryPoint ENDP\r
+EbcLLEbcInterpret ENDP\r
\r
-;/*++\r
-;\r
-;Routine Description:\r
-;\r
-; Return the caller's value of the stack pointer.\r
-;\r
-;Arguments:\r
-;\r
-; None.\r
-;\r
-;Returns:\r
-;\r
-; The current value of the stack pointer for the caller. We\r
-; adjust it by 4 here because when they called us, the return address\r
-; is put on the stack, thereby lowering it by 4 bytes.\r
-;\r
-;--*/\r
-\r
-; UINTN EbcLLGetStackPointer()\r
-EbcLLGetStackPointer PROC PUBLIC\r
- mov rax, rsp ; get current stack pointer\r
- ; Stack adjusted by this much when we were called,\r
- ; For this function, it's 4.\r
- add rax, 4\r
- ret\r
-EbcLLGetStackPointer ENDP\r
-\r
-; UINT64 EbcLLGetReturnValue(VOID);\r
-; Routine Description:\r
-; When EBC calls native, on return the VM has to stuff the return\r
-; value into a VM register. It's assumed here that the value is still\r
-; in the register, so simply return and the caller should get the\r
-; return result properly.\r
-;\r
-; Arguments:\r
-; None.\r
-;\r
-; Returns:\r
-; The unmodified value returned by the native code.\r
+;****************************************************************************\r
+; EbcLLExecuteEbcImageEntryPoint\r
;\r
-EbcLLGetReturnValue PROC PUBLIC\r
+; Begin executing an EBC image.\r
+;****************************************************************************\r
+; UINT64 EbcLLExecuteEbcImageEntryPoint(VOID)\r
+EbcLLExecuteEbcImageEntryPoint PROC PUBLIC\r
+ ;\r
+ ;; mov rax, ca112ebccall2ebch\r
+ ;; mov r10, EbcEntryPoint\r
+ ;; mov r11, EbcLLExecuteEbcImageEntryPoint\r
+ ;; jmp r11\r
+ ;\r
+ ; Caller uses above instruction to jump here\r
+ ; The stack is below:\r
+ ; +-----------+\r
+ ; | RetAddr |\r
+ ; +-----------+\r
+ ; |EntryPoint | (R10)\r
+ ; +-----------+\r
+ ; |ImageHandle|\r
+ ; +-----------+\r
+ ; |SystemTable|\r
+ ; +-----------+\r
+ ; | Dummy |\r
+ ; +-----------+\r
+ ; | Dummy |\r
+ ; +-----------+\r
+ ; | RetAddr | <- RSP is here\r
+ ; +-----------+\r
+ ; |ImageHandle| (RCX)\r
+ ; +-----------+\r
+ ; |SystemTable| (RDX)\r
+ ; +-----------+\r
+ ; \r
+\r
+ ; build new paramater calling convention\r
+ mov r8, rdx\r
+ mov rdx, rcx\r
+ mov rcx, r10\r
+\r
+ ; call C-code\r
+ sub rsp, 28h\r
+ call ExecuteEbcImageEntryPoint\r
+ add rsp, 28h\r
ret\r
-EbcLLGetReturnValue ENDP\r
+EbcLLExecuteEbcImageEntryPoint ENDP\r
\r
-text ENDS\r
END\r
\r