]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Protocol/Ebc.h
MdePkg/Include/Protocol/Tls.h: pack structures from the TLS RFC
[mirror_edk2.git] / MdePkg / Include / Protocol / Ebc.h
index 9bcd5beb30dd9462c1b8229673b1534fe6eefe8b..0fcb82bce85b10aa7f2e77e9aedf4350f7edc2f8 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Describes the protocol interface to the EBC interpreter.\r
 \r
-  Copyright (c) 2006, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
+  Copyright (c) 2006 - 2008, 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
   }\r
 \r
 //\r
-// Protocol Guid Name defined in spec.\r
+// Define OPCODES\r
 //\r
-#define EFI_EBC_PROTOCOL_GUID EFI_EBC_INTERPRETER_PROTOCOL_GUID\r
+#define OPCODE_BREAK    0x00\r
+#define OPCODE_JMP      0x01\r
+#define OPCODE_JMP8     0x02\r
+#define OPCODE_CALL     0x03\r
+#define OPCODE_RET      0x04\r
+#define OPCODE_CMPEQ    0x05\r
+#define OPCODE_CMPLTE   0x06\r
+#define OPCODE_CMPGTE   0x07\r
+#define OPCODE_CMPULTE  0x08\r
+#define OPCODE_CMPUGTE  0x09\r
+#define OPCODE_NOT      0x0A\r
+#define OPCODE_NEG      0x0B\r
+#define OPCODE_ADD      0x0C\r
+#define OPCODE_SUB      0x0D\r
+#define OPCODE_MUL      0x0E\r
+#define OPCODE_MULU     0x0F\r
+#define OPCODE_DIV      0x10\r
+#define OPCODE_DIVU     0x11\r
+#define OPCODE_MOD      0x12\r
+#define OPCODE_MODU     0x13\r
+#define OPCODE_AND      0x14\r
+#define OPCODE_OR       0x15\r
+#define OPCODE_XOR      0x16\r
+#define OPCODE_SHL      0x17\r
+#define OPCODE_SHR      0x18\r
+#define OPCODE_ASHR     0x19\r
+#define OPCODE_EXTNDB   0x1A\r
+#define OPCODE_EXTNDW   0x1B\r
+#define OPCODE_EXTNDD   0x1C\r
+#define OPCODE_MOVBW    0x1D\r
+#define OPCODE_MOVWW    0x1E\r
+#define OPCODE_MOVDW    0x1F\r
+#define OPCODE_MOVQW    0x20\r
+#define OPCODE_MOVBD    0x21\r
+#define OPCODE_MOVWD    0x22\r
+#define OPCODE_MOVDD    0x23\r
+#define OPCODE_MOVQD    0x24\r
+#define OPCODE_MOVSNW   0x25  // Move signed natural with word index\r
+#define OPCODE_MOVSND   0x26  // Move signed natural with dword index\r
+//\r
+// #define OPCODE_27         0x27\r
+//\r
+#define OPCODE_MOVQQ    0x28  // Does this go away?\r
+#define OPCODE_LOADSP   0x29\r
+#define OPCODE_STORESP  0x2A\r
+#define OPCODE_PUSH     0x2B\r
+#define OPCODE_POP      0x2C\r
+#define OPCODE_CMPIEQ   0x2D\r
+#define OPCODE_CMPILTE  0x2E\r
+#define OPCODE_CMPIGTE  0x2F\r
+#define OPCODE_CMPIULTE 0x30\r
+#define OPCODE_CMPIUGTE 0x31\r
+#define OPCODE_MOVNW    0x32\r
+#define OPCODE_MOVND    0x33\r
+//\r
+// #define OPCODE_34         0x34\r
+//\r
+#define OPCODE_PUSHN  0x35\r
+#define OPCODE_POPN   0x36\r
+#define OPCODE_MOVI   0x37\r
+#define OPCODE_MOVIN  0x38\r
+#define OPCODE_MOVREL 0x39\r
+\r
+//\r
+// Bit masks for opcode encodings\r
+//\r
+#define OPCODE_M_OPCODE       0x3F  // bits of interest for first level decode\r
+#define OPCODE_M_IMMDATA      0x80\r
+#define OPCODE_M_IMMDATA64    0x40\r
+#define OPCODE_M_64BIT        0x40  // for CMP\r
+#define OPCODE_M_RELADDR      0x10  // for CALL instruction\r
+#define OPCODE_M_CMPI32_DATA  0x80  // for CMPI\r
+#define OPCODE_M_CMPI64       0x40  // for CMPI 32 or 64 bit comparison\r
+#define OPERAND_M_MOVIN_N     0x80\r
+#define OPERAND_M_CMPI_INDEX  0x10\r
+\r
+//\r
+// Masks for instructions that encode presence of indexes for operand1 and/or\r
+// operand2.\r
+//\r
+#define OPCODE_M_IMMED_OP1  0x80\r
+#define OPCODE_M_IMMED_OP2  0x40\r
+\r
+//\r
+// Bit masks for operand encodings\r
+//\r
+#define OPERAND_M_INDIRECT1 0x08\r
+#define OPERAND_M_INDIRECT2 0x80\r
+#define OPERAND_M_OP1       0x07\r
+#define OPERAND_M_OP2       0x70\r
+\r
+//\r
+// Masks for data manipulation instructions\r
+//\r
+#define DATAMANIP_M_64      0x40  // 64-bit width operation\r
+#define DATAMANIP_M_IMMDATA 0x80\r
+\r
+//\r
+// For MOV instructions, need a mask for the opcode when immediate\r
+// data applies to R2.\r
+//\r
+#define OPCODE_M_IMMED_OP2  0x40\r
+\r
+//\r
+// The MOVI/MOVIn instructions use bit 6 of operands byte to indicate\r
+// if an index is present. Then bits 4 and 5 are used to indicate the width\r
+// of the move.\r
+//\r
+#define MOVI_M_IMMDATA    0x40\r
+#define MOVI_M_DATAWIDTH  0xC0\r
+#define MOVI_DATAWIDTH16  0x40\r
+#define MOVI_DATAWIDTH32  0x80\r
+#define MOVI_DATAWIDTH64  0xC0\r
+#define MOVI_M_MOVEWIDTH  0x30\r
+#define MOVI_MOVEWIDTH8   0x00\r
+#define MOVI_MOVEWIDTH16  0x10\r
+#define MOVI_MOVEWIDTH32  0x20\r
+#define MOVI_MOVEWIDTH64  0x30\r
 \r
 //\r
-// Define for forward reference.\r
+// Masks for CALL instruction encodings\r
 //\r
+#define OPERAND_M_RELATIVE_ADDR 0x10\r
+#define OPERAND_M_NATIVE_CALL   0x20\r
+\r
+//\r
+// Masks for decoding push/pop instructions\r
+//\r
+#define PUSHPOP_M_IMMDATA 0x80  // opcode bit indicating immediate data\r
+#define PUSHPOP_M_64      0x40  // opcode bit indicating 64-bit operation\r
+//\r
+// Mask for operand of JMP instruction\r
+//\r
+#define JMP_M_RELATIVE    0x10\r
+#define JMP_M_CONDITIONAL 0x80\r
+#define JMP_M_CS          0x40\r
+\r
+//\r
+// Macros to determine if a given operand is indirect\r
+//\r
+#define OPERAND1_INDIRECT(op) ((op) & OPERAND_M_INDIRECT1)\r
+#define OPERAND2_INDIRECT(op) ((op) & OPERAND_M_INDIRECT2)\r
+\r
+//\r
+// Macros to extract the operands from second byte of instructions\r
+//\r
+#define OPERAND1_REGNUM(op)       ((op) & OPERAND_M_OP1)\r
+#define OPERAND2_REGNUM(op)       (((op) & OPERAND_M_OP2) >> 4)\r
+\r
+#define OPERAND1_CHAR(op)         ('0' + OPERAND1_REGNUM (op))\r
+#define OPERAND2_CHAR(op)         ('0' + OPERAND2_REGNUM (op))\r
+\r
+//\r
+// Condition masks usually for byte 1 encodings of code\r
+//\r
+#define CONDITION_M_CONDITIONAL 0x80\r
+#define CONDITION_M_CS          0x40\r
+\r
+///\r
+/// Protocol Guid Name defined in spec.\r
+///\r
+#define EFI_EBC_PROTOCOL_GUID EFI_EBC_INTERPRETER_PROTOCOL_GUID\r
+\r
+///\r
+/// Define for forward reference.\r
+///\r
 typedef struct _EFI_EBC_PROTOCOL EFI_EBC_PROTOCOL;\r
 \r
 /**\r
-  Create a thunk for an image entry point. In short, given the physical address\r
-  of the entry point for a loaded image, create a thunk that does some \r
-  fixup of arguments (and perform any other necessary overhead) and then\r
-  calls the original entry point. The caller can then use the returned pointer\r
-  to the created thunk as the new entry point to image.\r
-\r
-  @param  This          protocol instance pointer\r
-  @param  ImageHandle   handle to the image. The EBC interpreter may use this to keep\r
-                        track of any resource allocations performed in loading and\r
-                        executing the image.\r
-  @param  EbcEntryPoint the entry point for the image (as defined in the file header)\r
-  @param  Thunk pointer to thunk pointer where the address of the created\r
-                        thunk is returned.\r
-\r
-  @return Standard EFI_STATUS\r
+  Creates a thunk for an EBC entry point, returning the address of the thunk.\r
+  \r
+  A PE32+ EBC image, like any other PE32+ image, contains an optional header that specifies the\r
+  entry point for image execution. However, for EBC images, this is the entry point of EBC\r
+  instructions, so is not directly executable by the native processor. Therefore, when an EBC image is\r
+  loaded, the loader must call this service to get a pointer to native code (thunk) that can be executed,\r
+  which will invoke the interpreter to begin execution at the original EBC entry point.\r
+\r
+  @param  This          A pointer to the EFI_EBC_PROTOCOL instance.\r
+  @param  ImageHandle   Handle of image for which the thunk is being created.\r
+  @param  EbcEntryPoint Address of the actual EBC entry point or protocol service the thunk should call.\r
+  @param  Thunk         Returned pointer to a thunk created.\r
 \r
+  @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER  Image entry point is not 2-byte aligned.\r
+  @retval EFI_OUT_OF_RESOURCES   Memory could not be allocated for the thunk.\r
 **/\r
 typedef\r
 EFI_STATUS\r
@@ -58,15 +219,18 @@ EFI_STATUS
   );\r
 \r
 /**\r
-  Perform any cleanup necessary when an image is unloaded. Basically it gives\r
-  the EBC interpreter the chance to free up any resources allocated during\r
-  load and execution of an EBC image.\r
+  Called prior to unloading an EBC image from memory.\r
 \r
-  @param  This        protocol instance pointer\r
-  @param  ImageHandle the handle of the image being unloaded.\r
+  This function is called after an EBC image has exited, but before the image is actually unloaded. It\r
+  is intended to provide the interpreter with the opportunity to perform any cleanup that may be\r
+  necessary as a result of loading and executing the image.\r
 \r
-  @return Standard EFI_STATUS.\r
+  @param  This          A pointer to the EFI_EBC_PROTOCOL instance.\r
+  @param  ImageHandle   Image handle of the EBC image that is being unloaded from memory.\r
 \r
+  @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER  Image handle is not recognized as belonging \r
+                                 to an EBC image that has been executed.\r
 **/\r
 typedef\r
 EFI_STATUS\r
@@ -76,13 +240,13 @@ EFI_STATUS
   );\r
 \r
 /**\r
-  The I-Cache-flush registration service takes a pointer to a function to\r
-  call to flush the I-Cache. Here's the prototype for that function pointer.\r
+  This is the prototype for the Flush callback routine. A pointer to a routine \r
+  of this type is passed to the EBC EFI_EBC_REGISTER_ICACHE_FLUSH protocol service.\r
 \r
-  @param  Start  physical start address of CPU instruction cache to flush.\r
-  @param  Length how many bytes to flush of the instruction cache.\r
+  @param  Start  The beginning physical address to flush from the processor's instruction cache.\r
+  @param  Length The number of bytes to flush from the processor's instruction cache.\r
 \r
-  @return Standard EFI_STATUS.\r
+  @retval EFI_SUCCESS            The function completed successfully.\r
 \r
 **/\r
 typedef\r
@@ -93,15 +257,13 @@ EFI_STATUS
   );\r
 \r
 /**\r
-  This routine is called by the core firmware to provide the EBC driver with\r
-  a function to call to flush the CPU's instruction cache following creation\r
-  of a thunk. It is not required.\r
+  Registers a callback function that the EBC interpreter calls to flush \r
+  the processor instruction cache following creation of thunks.\r
 \r
-  @param  This  protocol instance pointer\r
-  @param  Flush pointer to the function to call to flush the CPU instruction\r
-  cache.\r
+  @param  This       A pointer to the EFI_EBC_PROTOCOL instance.\r
+  @param  Flush      Pointer to a function of type EBC_ICACH_FLUSH.\r
 \r
-  @return Standard EFI_STATUS.\r
+  @retval EFI_SUCCESS            The function completed successfully.\r
 \r
 **/\r
 typedef\r
@@ -112,13 +274,16 @@ EFI_STATUS
   );\r
 \r
 /**\r
-  This routine can be called to get the VM revision. It returns the same\r
-  value as the EBC BREAK 1 instruction returns.\r
+  Called to get the version of the interpreter.\r
+\r
+  This function is called to get the version of the loaded EBC interpreter. The value and format of the\r
+  returned version is identical to that returned by the EBC BREAK 1 instruction.\r
 \r
-  @param  This    protocol instance pointer\r
-  @param  Version pointer to where to return the VM version\r
+  @param  This       A pointer to the EFI_EBC_PROTOCOL instance.  \r
+  @param  Version    Pointer to where to store the returned version of the interpreter.\r
 \r
-  @return Standard EFI_STATUS.\r
+  @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER  Version pointer is NULL.\r
 \r
 **/\r
 typedef\r
@@ -128,9 +293,12 @@ EFI_STATUS
   IN OUT UINT64                 *Version\r
   );\r
 \r
-//\r
-// Prototype for the actual EBC protocol interface\r
-//\r
+///\r
+/// The EFI EBC protocol provides services to load and execute EBC images, which will typically be\r
+/// loaded into option ROMs. The image loader will load the EBC image, perform standard relocations,\r
+/// and invoke the CreateThunk() service to create a thunk for the EBC image's entry point. The\r
+/// image can then be run using the standard EFI start image services.\r
+///\r
 struct _EFI_EBC_PROTOCOL {\r
   EFI_EBC_CREATE_THUNK          CreateThunk;\r
   EFI_EBC_UNLOAD_IMAGE          UnloadImage;\r