Intel 64 and IA-32 Architectures. Software Developer’s Manual (2026) - page 67

 

  Index      Manuals     Intel 64 and IA-32 Architectures. Software Developer’s Manual (2026)

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     65      66      67      68     ..

 

 

 

Intel 64 and IA-32 Architectures. Software Developer’s Manual (2026) - page 67

 

 

INTEL® SGX INSTRUCTION REFERENCES
64-Bit Mode Exceptions
#UD
If any of the LOCK/66H/REP/VEX prefixes are used.
If current privilege level is not 3.
If CPUID.12H.00H:EAX.SGX1[0] = 0.
If logical processor is in SMM.
#GP(0)
If IA32_FEATURE_CONTROL.LOCK = 0.
If IA32_FEATURE_CONTROL.SGX_ENABLE = 0.
If input value in EAX encodes an unsupported leaf.
If input value in EAX encodes EENTER/ERESUME and ENCLAVE_MODE = 1.
If input value in EAX encodes EGETKEY/EREPORT/EEXIT/EACCEPT/EACCEPTCOPY/EMODPE
and ENCLAVE_MODE = 0.
If CR0.NE= 0.
#NM
If CR0.TS = 1.
41.3
INTEL® SGX SYSTEM LEAF FUNCTION REFERENCE
Leaf functions available with the ENCLS instruction mnemonic are covered in this section. In general, each instruc-
tion leaf requires EAX to specify the leaf function index and/or additional implicit registers specifying leaf-specific
input parameters. An instruction operand encoding table provides details of each implicit register usage and asso-
ciated input/output semantics.
In many cases, an input parameter specifies an effective address associated with a memory object inside or outside
the EPC, the memory addressing semantics of these memory objects are also summarized in a separate table.
41-12
Vol. 3D
ENCLU-Execute an Enclave User Function of Specified Leaf Number
INTEL® SGX INSTRUCTION REFERENCES
EADD-Add a Page to an Uninitialized Enclave
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 01H
IR
V/V
SGX1
This leaf function adds a page to an uninitialized enclave.
ENCLS[EADD]
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
EADD (In)
Address of a PAGEINFO (In)
Address of the destination EPC page (In)
Description
This leaf function copies a source page from non-enclave memory into the EPC, associates the EPC page with an
SECS page residing in the EPC, and stores the linear address and security attributes in EPCM. As part of the asso-
ciation, the enclave offset and the security attributes are measured and extended into the SECS.MRENCLAVE. This
instruction can only be executed when current privilege level is 0.
RBX contains the effective address of a PAGEINFO structure while RCX contains the effective address of an EPC
page. The table below provides additional information on the memory parameter of EADD leaf function.
EADD Memory Parameter Semantics
PAGEINFO
PAGEINFO.SECS
PAGEINFO.SRCPGE
PAGEINFO.SECINFO
EPCPAGE
Read access permitted
Read/Write access permit-
Read access permitted
Read access permitted
Write access permitted
by Non Enclave
ted by Enclave
by Non Enclave
by Non Enclave
by Enclave
The instruction faults if any of the following:
EADD Faulting Conditions
The operands are not properly aligned.
Unsupported security attributes are set.
Refers to an invalid SECS.
Reference is made to an SECS that is locked by another thread.
The EPC page is locked by another thread.
RCX does not contain an effective address of an EPC page.
The EPC page is already valid.
If security attributes specifies a TCS and the source page specifies unsupported
TCS values or fields.
The SECS has been initialized.
The specified enclave offset is outside of the enclave address space.
Concurrency Restrictions
Table 41-7. Base Concurrency Restrictions of EADD
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EADD
Target [DS:RCX]
Exclusive
#GP
SECS [DS:RBX]PAGEINFO.SECS
Shared
#GP
EADD-Add a Page to an Uninitialized Enclave
Vol. 3D
41-13
INTEL® SGX INSTRUCTION REFERENCES
Table 41-8. Additional Concurrency Restrictions of EADD
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EADD
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
SECS [DS:RBX]PAGE-
Concurrent
Exclusive
#GP
Concurrent
INFO.SECS
Operation
Temp Variables in EADD Operational Flow
Name
Type
Size (bits)
Description
TMP_SRCPGE
Effective Address
32/64
Effective address of the source page.
TMP_SECS
Effective Address
32/64
Effective address of the SECS destination page.
TMP_SECINFO
Effective Address
32/64
Effective address of an SECINFO structure which contains security
attributes of the page to be added.
SCRATCH_SECINFO
SECINFO
512
Scratch storage for holding the contents of DS:TMP_SECINFO.
TMP_LINADDR
Unsigned Integer
64
Holds the linear address to be stored in the EPCM and used to
calculate TMP_ENCLAVEOFFSET.
TMP_ENCLAVEOFFSET
Enclave Offset
64
The page displacement from the enclave base address.
TMPUPDATEFIELD
SHA256 Buffer
512
Buffer used to hold data being added to TMP_SECS.MRENCLAVE.
IF (DS:RBX is not 32Byte Aligned)
THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
TMP_SRCPGE := DS:RBX.SRCPGE;
TMP_SECS := DS:RBX.SECS;
TMP_SECINFO := DS:RBX.SECINFO;
TMP_LINADDR := DS:RBX.LINADDR;
IF (DS:TMP_SRCPGE is not 4KByte aligned or DS:TMP_SECS is not 4KByte aligned or
DS:TMP_SECINFO is not 64Byte aligned or TMP_LINADDR is not 4KByte aligned)
THEN #GP(0); FI;
IF (DS:TMP_SECS does not resolve within an EPC)
THEN #PF(DS:TMP_SECS); FI;
SCRATCH_SECINFO := DS:TMP_SECINFO;
(* Check for misconfigured SECINFO flags*)
IF (SCRATCH_SECINFO reserved fields are not zero or
41-14
Vol. 3D
EADD-Add a Page to an Uninitialized Enclave
INTEL® SGX INSTRUCTION REFERENCES
! (SCRATCH_SECINFO.FLAGS.PT is PT_REG or SCRATCH_SECINFO.FLAGS.PT is PT_TCS or
(SCRATCH_SECINFO.FLAGS.PT is PT_SS_FIRST and CPUID.12H.01H:EAX[6] = 1) or
(SCRATCH_SECINFO.FLAGS.PT is PT_SS_REST and CPUID.12H.01H:EAX[6] = 1)) )
THEN #GP(0); FI;
(* If PT_SS_FIRST/PT_SS_REST page types are requested then CR4.CET must be 1 *)
IF ( (SCRATCH_SECINFO.FLAGS.PT is PT_SS_FIRST OR
SCRATCH_SECINFO.FLAGS.PT is PT_SS_REST) AND CR4.CET == 0)
THEN #GP(0); FI;
(* Check the EPC page for concurrency *)
IF (EPC page is not available for EADD)
THEN
#GP(0); FI;
IF (EPCM(DS:RCX).VALID ≠ 0)
THEN #PF(DS:RCX); FI;
(* Check the SECS for concurrency *)
IF (SECS is not available for EADD)
THEN #GP(0); FI;
IF (EPCM(DS:TMP_SECS).VALID = 0 or EPCM(DS:TMP_SECS).PT ≠ PT_SECS)
THEN #PF(DS:TMP_SECS); FI;
(* Copy 4KBytes from source page to EPC page*)
DS:RCX[32767:0] := DS:TMP_SRCPGE[32767:0];
CASE (SCRATCH_SECINFO.FLAGS.PT)
PT_TCS:
IF (DS:RCX.RESERVED ≠ 0) #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 0) and
((DS:TCS.FSLIMIT & 0FFFH ≠ 0FFFH) or (DS:TCS.GSLIMIT & 0FFFH ≠ 0FFFH) )) #GP(0); FI;
(* Ensure TCS.PREVSSP is zero *)
IF (CPUID.07H.00H:ECX.CET_SS = 1) and (DS:RCX.PREVSSP != 0) #GP(0); FI;
BREAK;
PT_REG:
IF (SCRATCH_SECINFO.FLAGS.W = 1 and SCRATCH_SECINFO.FLAGS.R = 0) #GP(0); FI;
BREAK;
PT_SS_FIRST:
PT_SS_REST:
(* SS pages cannot be created on first or last page of ELRANGE *)
IF ( TMP_LINADDR = DS:TMP_SECS.BASEADDR or TMP_LINADDR = (DS:TMP_SECS.BASEADDR + DS:TMP_SECS.SIZE - 0x1000) )
THEN #GP(0); FI;
IF ( DS:RCX[4087:0] != 0 ) #GP(0); FI;
IF (SCRATCH_SECINFO.FLAGS.PT == PT_SS_FIRST)
THEN
(* Check that valid RSTORSSP token exists *)
IF ( DS:RCX[4095:4088] != ((TMP_LINADDR + 0x1000) | DS:TMP_SECS.ATTRIBUTES.MODE64BIT) ) #GP(0); FI;
ELSE
(* Check the 8 bytes are zero *)
IF ( DS:RCX[4095:4088] != 0 ) #GP(0); FI;
FI;
EADD-Add a Page to an Uninitialized Enclave
Vol. 3D
41-15
INTEL® SGX INSTRUCTION REFERENCES
IF (SCRATCH_SECINFO.FLAGS.W = 0 OR SCRATCH_SECINFO.FLAGS.R = 0 OR
SCRATCH_SECINFO.FLAGS.X = 1) #GP(0); FI;
BREAK;
ESAC;
(* Check the enclave offset is within the enclave linear address space *)
IF (TMP_LINADDR < DS:TMP_SECS.BASEADDR or TMP_LINADDR ≥ DS:TMP_SECS.BASEADDR + DS:TMP_SECS.SIZE)
THEN #GP(0); FI;
(* Check concurrency of measurement resource*)
IF (Measurement being updated)
THEN #GP(0); FI;
(* Check if the enclave to which the page will be added is already in Initialized state *)
IF (DS:TMP_SECS already initialized)
THEN #GP(0); FI;
(* For TCS pages, force EPCM.rwx bits to 0 and no debug access *)
IF (SCRATCH_SECINFO.FLAGS.PT = PT_TCS)
THEN
SCRATCH_SECINFO.FLAGS.R := 0;
SCRATCH_SECINFO.FLAGS.W := 0;
SCRATCH_SECINFO.FLAGS.X := 0;
(DS:RCX).FLAGS.DBGOPTIN := 0; // force TCS.FLAGS.DBGOPTIN off
DS:RCX.CSSA := 0;
DS:RCX.AEP := 0;
DS:RCX.STATE := 0;
FI;
(* Add enclave offset and security attributes to MRENCLAVE *)
TMP_ENCLAVEOFFSET := TMP_LINADDR - DS:TMP_SECS.BASEADDR;
TMPUPDATEFIELD[63:0] := 0000000044444145H; // “EADD”
TMPUPDATEFIELD[127:64] := TMP_ENCLAVEOFFSET;
TMPUPDATEFIELD[511:128] := SCRATCH_SECINFO[375:0]; // 48 bytes
DS:TMP_SECS.MRENCLAVE := SHA256UPDATE(DS:TMP_SECS.MRENCLAVE, TMPUPDATEFIELD)
INC enclave’s MRENCLAVE update counter;
(* Add enclave offset and security attributes to MRENCLAVE *)
EPCM(DS:RCX).R := SCRATCH_SECINFO.FLAGS.R;
EPCM(DS:RCX).W := SCRATCH_SECINFO.FLAGS.W;
EPCM(DS:RCX).X := SCRATCH_SECINFO.FLAGS.X;
EPCM(DS:RCX).PT := SCRATCH_SECINFO.FLAGS.PT;
EPCM(DS:RCX).ENCLAVEADDRESS := TMP_LINADDR;
(* associate the EPCPAGE with the SECS by storing the SECS identifier of DS:TMP_SECS *)
Update EPCM(DS:RCX) SECS identifier to reference DS:TMP_SECS identifier;
(* Set EPCM entry fields *)
EPCM(DS:RCX).BLOCKED := 0;
EPCM(DS:RCX).PENDING := 0;
EPCM(DS:RCX).MODIFIED := 0;
EPCM(DS:RCX).VALID := 1;
41-16
Vol. 3D
EADD-Add a Page to an Uninitialized Enclave
INTEL® SGX INSTRUCTION REFERENCES
Flags Affected
None
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If an enclave memory operand is outside of the EPC.
If an enclave memory operand is the wrong type.
If a memory operand is locked.
If the enclave is initialized.
If the enclave's MRENCLAVE is locked.
If the TCS page reserved bits are set.
If the TCS page PREVSSP field is not zero.
If the PT_SS_REST or PT_SS_REST page is the first or last page in the enclave.
If the PT_SS_FIRST or PT_SS_REST page is not initialized correctly.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the EPC page is valid.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If an enclave memory operand is outside of the EPC.
If an enclave memory operand is the wrong type.
If a memory operand is locked.
If the enclave is initialized.
If the enclave's MRENCLAVE is locked.
If the TCS page reserved bits are set.
If the TCS page PREVSSP field is not zero.
If the PT_SS_REST or PT_SS_REST page is the first or last page in the enclave.
If the PT_SS_FIRST or PT_SS_REST page is not initialized correctly.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the EPC page is valid.
EADD-Add a Page to an Uninitialized Enclave
Vol. 3D
41-17
INTEL® SGX INSTRUCTION REFERENCES
EAUG-Add a Page to an Initialized Enclave
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 0DH
IR
V/V
SGX2
This leaf function adds a page to an initialized enclave.
ENCLS[EAUG]
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
EAUG (In)
Address of a PAGEINFO (In)
Address of the destination EPC page (In)
Description
This leaf function zeroes a page of EPC memory, associates the EPC page with an SECS page residing in the EPC,
and stores the linear address and security attributes in the EPCM. As part of the association, the security attributes
are configured to prevent access to the EPC page until a corresponding invocation of the EACCEPT leaf or EACCEPT-
COPY leaf confirms the addition of the new page into the enclave. This instruction can only be executed when
current privilege level is 0.
RBX contains the effective address of a PAGEINFO structure while RCX contains the effective address of an EPC
page. The table below provides additional information on the memory parameter of the EAUG leaf function.
EAUG Memory Parameter Semantics
PAGEINFO
PAGEINFO.SECS
PAGEINFO.SRCPGE
PAGEINFO.SECINFO
EPCPAGE
Read access permit-
Read/Write access permit-
Read access permitted by
Write access permitted by
Must be zero
ted by Non Enclave
ted by Enclave
Non Enclave
Enclave
The instruction faults if any of the following:
EAUG Faulting Conditions
The operands are not properly aligned.
Unsupported security attributes are set.
Refers to an invalid SECS.
Reference is made to an SECS that is locked by another thread.
The EPC page is locked by another thread.
RCX does not contain an effective address of an EPC page.
The EPC page is already valid.
The specified enclave offset is outside of the enclave address space.
The SECS has been initialized.
Concurrency Restrictions
Table 41-9. Base Concurrency Restrictions of EAUG
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EAUG
Target [DS:RCX]
Exclusive
#GP
SECS [DS:RBX]PAGEINFO.SECS
Shared
#GP
41-18
Vol. 3D
EAUG-Add a Page to an Initialized Enclave
INTEL® SGX INSTRUCTION REFERENCES
Table 41-10. Additional Concurrency Restrictions of EAUG
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EAUG
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
SECS [DS:RBX]PAGE-
Concurrent
Concurrent
Concurrent
INFO.SECS
Operation
Temp Variables in EAUG Operational Flow
Name
Type
Size (bits)
Description
TMP_SECS
Effective Address
32/64
Effective address of the SECS destination page.
TMP_SECINFO
Effective Address
32/64
Effective address of an SECINFO structure which contains security
attributes of the page to be added.
SCRATCH_SECINFO
SECINFO
512
Scratch storage for holding the contents of DS:TMP_SECINFO.
TMP_LINADDR
Unsigned Integer
64
Holds the linear address to be stored in the EPCM and used to
calculate TMP_ENCLAVEOFFSET.
IF (DS:RBX is not 32Byte Aligned)
THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
TMP_SECS := DS:RBX.SECS;
TMP_SECINFO := DS:RBX.SECINFO;
IF (DS:RBX.SECINFO is not 0)
THEN
IF (DS:TMP_SECINFO is not 64B aligned)
THEN #GP(0); FI;
FI;
TMP_LINADDR := DS:RBX.LINADDR;
IF ( DS:TMP_SECS is not 4KByte aligned or TMP_LINADDR is not 4KByte aligned )
THEN #GP(0); FI;
IF DS:RBX.SRCPAGE is not 0
THEN #GP(0); FI;
IF (DS:TMP_SECS does not resolve within an EPC)
THEN #PF(DS:TMP_SECS); FI;
(* Check the EPC page for concurrency *)
EAUG-Add a Page to an Initialized Enclave
Vol. 3D
41-19
INTEL® SGX INSTRUCTION REFERENCES
IF (EPC page is not available for EAUG)
THEN
#GP(0); FI;
IF (EPCM(DS:RCX).VALID ≠ 0)
THEN #PF(DS:RCX); FI;
(* copy SECINFO contents into a scratch SECINFO *)
IF (DS:RBX.SECINFO is 0)
THEN
(* allocate and initialize a new scratch SECINFO structure *)
SCRATCH_SECINFO.PT := PT_REG;
SCRATCH_SECINFO.R := 1;
SCRATCH_SECINFO.W := 1;
SCRATCH_SECINFO.X := 0;
<< zero out remaining fields of SCRATCH_SECINFO >>
ELSE
(* copy SECINFO contents into scratch SECINFO *)
SCRATCH_SECINFO := DS:TMP_SECINFO;
(* check SECINFO flags for misconfiguration *)
(* reserved flags must be zero *)
(* SECINFO.FLAGS.PT must either be PT_SS_FIRST, or PT_SS_REST *)
IF ( (SCRATCH_SECINFO reserved fields are not 0) or
CPUID.12H.01H:EAX[6] is 0) OR
(SCRATCH_SECINFO.PT is not PT_SS_FIRST, or PT_SS_REST) OR
( (SCRATCH_SECINFO.FLAGS.R is 0) OR (SCRATCH_SECINFO.FLAGS.W is 0) OR (SCRATCH_SECINFO.FLAGS.X is 1) ) )
THEN #GP(0); FI;
FI;
(* Check if PT_SS_FIRST/PT_SS_REST page types are requested then CR4.CET must be 1 *)
IF ( (SCRATCH_SECINFO.PT is PT_SS_FIRST OR SCRATCH_SECINFO.PT is PT_SS_REST) AND CR4.CET == 0 )
THEN #GP(0); FI;
(* Check the SECS for concurrency *)
IF (SECS is not available for EAUG)
THEN #GP(0); FI;
IF (EPCM(DS:TMP_SECS).VALID = 0 or EPCM(DS:TMP_SECS).PT ≠ PT_SECS)
THEN #PF(DS:TMP_SECS); FI;
(* Check if the enclave to which the page will be added is in the Initialized state *)
IF (DS:TMP_SECS is not initialized)
THEN #GP(0); FI;
(* Check the enclave offset is within the enclave linear address space *)
IF ( (TMP_LINADDR < DS:TMP_SECS.BASEADDR) or (TMP_LINADDR ≥ DS:TMP_SECS.BASEADDR + DS:TMP_SECS.SIZE) )
THEN #GP(0); FI;
IF ( (SCRATCH_SECINFO.PT is PT_SS_FIRST OR SCRATCH_SECINFO.PT is PT_SS_REST) )
THEN
(* SS pages cannot created on first or last page of ELRANGE *)
IF ( TMP_LINADDR == DS:TMP_SECS.BASEADDR OR
TMP_LINADDR == (DS:TMP_SECS.BASEADDR + DS:TMP_SECS.SIZE - 0x1000) )
THEN
#GP(0); FI;
41-20
Vol. 3D
EAUG-Add a Page to an Initialized Enclave
INTEL® SGX INSTRUCTION REFERENCES
FI;
(* Clear the content of EPC page*)
DS:RCX[32767:0] := 0;
IF (CPUID.07H.00H:ECX.CET_SS = 1)
THEN
(* set up shadow stack RSTORSSP token *)
IF (SCRATCH_SECINFO.PT is PT_SS_FIRST)
THEN
DS:RCX[0xFF8] := (TMP_LINADDR + 0x1000) | TMP_SECS.ATTRIBUTES.MODE64BIT; FI;
FI;
(* Set EPCM security attributes *)
EPCM(DS:RCX).R := SCRATCH_SECINFO.FLAGS.R;
EPCM(DS:RCX).W := SCRATCH_SECINFO.FLAGS.W;
EPCM(DS:RCX).X := SCRATCH_SECINFO.FLAGS.X;
EPCM(DS:RCX).PT := SCRATCH_SECINFO.FLAGS.PT;
EPCM(DS:RCX).ENCLAVEADDRESS := TMP_LINADDR;
EPCM(DS:RCX).BLOCKED := 0;
EPCM(DS:RCX).PENDING := 1;
EPCM(DS:RCX).MODIFIED := 0;
EPCM(DS:RCX).PR := 0;
(* associate the EPCPAGE with the SECS by storing the SECS identifier of DS:TMP_SECS *)
Update EPCM(DS:RCX) SECS identifier to reference DS:TMP_SECS identifier;
(* Set EPCM valid fields *)
EPCM(DS:RCX).VALID := 1;
Flags Affected
None
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If a memory operand is locked.
If the enclave is not initialized.
#PF(error code)
If a page fault occurs in accessing memory operands.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If a memory operand is locked.
If the enclave is not initialized.
#PF(error code)
If a page fault occurs in accessing memory operands.
EAUG-Add a Page to an Initialized Enclave
Vol. 3D
41-21
INTEL® SGX INSTRUCTION REFERENCES
EBLOCK-Mark a page in EPC as Blocked
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 09H
IR
V/V
SGX1
This leaf function marks a page in the EPC as blocked.
ENCLS[EBLOCK]
Instruction Operand Encoding
Op/En
EAX
RCX
IR
EBLOCK (In)
Return error code (Out)
Effective address of the EPC page (In)
Description
This leaf function causes an EPC page to be marked as BLOCKED. This instruction can only be executed when
current privilege level is 0.
The content of RCX is an effective address of an EPC page. The DS segment is used to create linear address.
Segment override is not supported.
An error code is returned in RAX.
The table below provides additional information on the memory parameter of EBLOCK leaf function.
EBLOCK Memory Parameter Semantics
EPCPAGE
Read/Write access permitted by Enclave
The error codes are:
Table 41-11. EBLOCK Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EBLOCK successful.
SGX_BLKSTATE
Page already blocked. This value is used to indicate to a VMM that the page was already in
BLOCKED state as a result of EBLOCK and thus will need to be restored to this state when it is
eventually reloaded (using ELDB).
SGX_ENTRYEPOCH_LOCKED
SECS locked for Entry Epoch update. This value indicates that an ETRACK is currently
executing on the SECS. The EBLOCK should be reattempted.
SGX_NOTBLOCKABLE
Page type is not one which can be blocked.
SGX_PG_INVLD
Page is not valid and cannot be blocked.
SGX_EPC_PAGE_CONFLICT
Page is being written by EADD, EAUG, ECREATE, ELDU/B, EMODT, or EWB.
Concurrency Restrictions
Table 41-12. Base Concurrency Restrictions of EBLOCK
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EBLOCK
Target [DS:RCX]
Shared
SGX_EPC_PAGE_CONFLICT
41-22
Vol. 3D
EBLOCK-Mark a page in EPC as Blocked
INTEL® SGX INSTRUCTION REFERENCES
Table 41-13. Additional Concurrency Restrictions of EBLOCK
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EBLOCK
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in EBLOCK Operational Flow
Name
Type
Size (Bits)
Description
TMP_BLKSTATE
Integer
64
Page is already blocked.
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
RFLAGS.ZF,CF,PF,AF,OF,SF := 0;
RAX := 0;
(* Check the EPC page for concurrency*)
IF (EPC page in use)
THEN
RFLAGS.ZF := 1;
RAX := SGX_EPC_PAGE_CONFLICT;
GOTO DONE;
FI;
IF (EPCM(DS:RCX). VALID = 0)
THEN
RFLAGS.ZF := 1;
RAX := SGX_PG_INVLD;
GOTO DONE;
FI;
IF ( (EPCM(DS:RCX).PT ≠ PT_REG) and (EPCM(DS:RCX).PT ≠ PT_TCS) and (EPCM(DS:RCX).PT ≠ PT_TRIM)
and EPCM(DS:RCX).PT ≠ PT_SS_FIRST) and (EPCM(DS:RCX).PT ≠ PT_SS_REST))
THEN
RFLAGS.CF := 1;
IF (EPCM(DS:RCX).PT = PT_SECS)
THEN RAX := SGX_PG_IS_SECS;
ELSE RAX := SGX_NOTBLOCKABLE;
FI;
GOTO DONE;
FI;
(* Check if the page is already blocked and report blocked state *)
TMP_BLKSTATE := EPCM(DS:RCX).BLOCKED;
EBLOCK-Mark a page in EPC as Blocked
Vol. 3D
41-23
INTEL® SGX INSTRUCTION REFERENCES
(* at this point, the page must be valid and PT_TCS or PT_REG or PT_TRIM*)
IF (TMP_BLKSTATE = 1)
THEN
RFLAGS.CF := 1;
RAX := SGX_BLKSTATE;
ELSE
EPCM(DS:RCX).BLOCKED := 1
FI;
DONE:
Flags Affected
Sets ZF if SECS is in use or invalid, otherwise cleared. Sets CF if page is BLOCKED or not blockable, otherwise
cleared. Clears PF, AF, OF, SF.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If the specified EPC resource is in use.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If the specified EPC resource is in use.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
41-24
Vol. 3D
EBLOCK-Mark a page in EPC as Blocked
INTEL® SGX INSTRUCTION REFERENCES
ECREATE-Create an SECS page in the Enclave Page Cache
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 00H
IR
V/V
SGX1
This leaf function begins an enclave build by creating an SECS
ENCLS[ECREATE]
page in EPC.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
ECREATE (In)
Address of a PAGEINFO (In)
Address of the destination SECS page (In)
Description
ENCLS[ECREATE] is the first instruction executed in the enclave build process. ECREATE copies an SECS structure
outside the EPC into an SECS page inside the EPC. The internal structure of SECS is not accessible to software.
ECREATE will set up fields in the protected SECS and mark the page as valid inside the EPC. ECREATE initializes or
checks unused fields.
Software sets the following fields in the source structure: SECS:BASEADDR, SECS:SIZE in bytes, ATTRIBUTES,
CONFIGID, and CONFIGSVN. SECS:BASEADDR must be naturally aligned on an SECS.SIZE boundary. SECS.SIZE
must be at least 2 pages (8192).
The source operand RBX contains an effective address of a PAGEINFO structure. PAGEINFO contains an effective
address of a source SECS and an effective address of an SECINFO. The SECS field in PAGEINFO is not used.
The RCX register is the effective address of the destination SECS. It is an address of an empty slot in the EPC. The
SECS structure must be page aligned. SECINFO flags must specify the page as an SECS page.
ECREATE Memory Parameter Semantics
PAGEINFO
PAGEINFO.SRCPGE
PAGEINFO.SECINFO
EPCPAGE
Read access permitted by
Read access permitted by
Read access permitted by Non
Write access permitted by
Non Enclave
Non Enclave
Enclave
Enclave
ECREATE will fault if the SECS target page is in use; already valid; outside the EPC. It will also fault if addresses are
not aligned; unused PAGEINFO fields are not zero.
If the amount of space needed to store the SSA frame is greater than the amount specified in SECS.SSAFRAME-
SIZE, a #GP(0) results. The amount of space needed for an SSA frame is computed based on DS:TMP_-
SECS.ATTRIBUTES.XFRM size. Details of computing the size can be found Section 42.7.
Concurrency Restrictions
Table 41-14. Base Concurrency Restrictions of ECREATE
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
ECREATE
SECS [DS:RCX]
Exclusive
#GP
ECREATE-Create an SECS page in the Enclave Page Cache
Vol. 3D
41-25
INTEL® SGX INSTRUCTION REFERENCES
Table 41-15. Additional Concurrency Restrictions of ECREATE
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
ECREATE
SECS [DS:RCX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in ECREATE Operational Flow
Name
Type
Size (Bits)
Description
TMP_SRCPGE
Effective Address
32/64
Effective address of the SECS source page.
TMP_SECS
Effective Address
32/64
Effective address of the SECS destination page.
TMP_SECINFO
Effective Address
32/64
Effective address of an SECINFO structure which contains security
attributes of the SECS page to be added.
TMP_XSIZE
SSA Size
64
The size calculation of SSA frame.
TMP_MISC_SIZE
MISC Field Size
64
Size of the selected MISC field components.
TMPUPDATEFIELD
SHA256 Buffer
512
Buffer used to hold data being added to TMP_SECS.MRENCLAVE.
IF (DS:RBX is not 32Byte Aligned)
THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
TMP_SRCPGE := DS:RBX.SRCPGE;
TMP_SECINFO := DS:RBX.SECINFO;
IF (DS:TMP_SRCPGE is not 4KByte aligned or DS:TMP_SECINFO is not 64Byte aligned)
THEN #GP(0); FI;
IF (DS:RBX.LINADDR ! = 0 or DS:RBX.SECS ≠ 0)
THEN #GP(0); FI;
(* Check for misconfigured SECINFO flags*)
IF (DS:TMP_SECINFO reserved fields are not zero or DS:TMP_SECINFO.FLAGS.PT ≠ PT_SECS)
THEN #GP(0); FI;
TMP_SECS := RCX;
IF (EPC entry in use)
THEN #GP(0); FI;
IF (EPCM(DS:RCX).VALID = 1)
THEN #PF(DS:RCX); FI;
41-26
Vol. 3D
ECREATE-Create an SECS page in the Enclave Page Cache
INTEL® SGX INSTRUCTION REFERENCES
(* Copy 4KBytes from source page to EPC page*)
DS:RCX[32767:0] := DS:TMP_SRCPGE[32767:0];
(* Check lower 2 bits of XFRM are set *)
IF ( ( DS:TMP_SECS.ATTRIBUTES.XFRM BitwiseAND 03H) ≠ 03H)
THEN #GP(0); FI;
IF (XFRM is illegal)
THEN #GP(0); FI;
(* Check legality of CET_ATTRIBUTES *)
IF ((DS:TMP_SECS.ATTRIBUTES.CET = 0 and DS:TMP_SECS.CET_ATTRIBUTES ≠ 0) ||
(DS:TMP_SECS.ATTRIBUTES.CET = 0 and DS:TMP_SECS.CET_LEG_BITMAP_OFFSET ≠ 0) ||
(CPUID.07H.00H:EDX.CET_IBT = 0 and DS:TMP_SECS.CET_LEG_BITMAP_OFFSET ≠ 0) ||
(CPUID.07H.00H:EDX.CET_IBT = 0 and DS:TMP_SECS.CET_ATTRIBUTES[5:2] ≠ 0) ||
(CPUID.07H.00H:ECX.CET_SS = 0 and DS:TMP_SECS.CET_ATTRIBUTES[1:0] ≠ 0) ||
(DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 1 and
(DS:TMP_SECS.BASEADDR + DS:TMP_SECS.CET_LEG_BITMAP_OFFSET) not canonical) ||
(DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 0 and
(DS:TMP_SECS.BASEADDR + DS:TMP_SECS.CET_LEG_BITMAP_OFFSET) & 0xFFFFFFFF00000000) ||
(DS:TMP_SECS.CET_ATTRIBUTES.reserved fields not 0) or
(DS:TMP_SECS.CET_LEG_BITMAP_OFFSET) is not page aligned))
THEN
#GP(0);
FI;
(* Make sure that the SECS does not have any unsupported MISCSELECT options*)
IF ( !(CPUID.12H.00H:EBX[31:0] & DS:TMP_SECS.MISCSELECT[31:0]) )
THEN
EPCM(DS:TMP_SECS).EntryLock.Release();
#GP(0);
FI;
( * Compute size of MISC area *)
TMP_MISC_SIZE := compute_misc_region_size();
(* Compute the size required to save state of the enclave on async exit, see Section 42.7.2.2*)
TMP_XSIZE := compute_xsave_size(DS:TMP_SECS.ATTRIBUTES.XFRM) + GPR_SIZE + TMP_MISC_SIZE;
(* Ensure that the declared area is large enough to hold XSAVE and GPR stat *)
IF ( DS:TMP_SECS.SSAFRAMESIZE*4096 < TMP_XSIZE)
THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 1) and (DS:TMP_SECS.BASEADDR is not canonical) )
THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 0) and (DS:TMP_SECS.BASEADDR and 0FFFFFFFF00000000H) )
THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 0) and (DS:TMP_SECS.SIZE ≥ 2 ^ (CPUID.12H.00H:EDX[7:0]) ) )
THEN #GP(0); FI;
IF ( (DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 1) and (DS:TMP_SECS.SIZE ≥ 2 ^ (CPUID.12H.00H:EDX[15:8]) ) )
ECREATE-Create an SECS page in the Enclave Page Cache
Vol. 3D
41-27
INTEL® SGX INSTRUCTION REFERENCES
THEN #GP(0); FI;
(* Enclave size must be at least 8192 bytes and must be power of 2 in bytes*)
IF (DS:TMP_SECS.SIZE < 8192 or popcnt(DS:TMP_SECS.SIZE) > 1)
THEN #GP(0); FI;
(* Ensure base address of an enclave is aligned on size*)
IF ( ( DS:TMP_SECS.BASEADDR and (DS:TMP_SECS.SIZE-1) ) )
THEN #GP(0); FI;
(* Ensure the SECS does not have any unsupported attributes*)
IF ( DS:TMP_SECS.ATTRIBUTES and (~CR_SGX_ATTRIBUTES_MASK) )
THEN #GP(0); FI;
IF ( DS:TMP_SECS reserved fields are not zero)
THEN #GP(0); FI;
(* Verify that CONFIGID/CONFIGSVN are not set with attribute *)
IF ( ((DS:TMP_SECS.CONFIGID ≠ 0) or (DS:TMP_SECS.CONFIGSVN ≠0)) AND (DS:TMP_SECS.ATTRIBUTES.KSS == 0 ))
THEN #GP(0); FI;
Clear DS:TMP_SECS to Uninitialized;
DS:TMP_SECS.MRENCLAVE := SHA256INITIALIZE(DS:TMP_SECS.MRENCLAVE);
DS:TMP_SECS.ISVSVN := 0;
DS:TMP_SECS.ISVPRODID := 0;
(* Initialize hash updates etc*)
Initialize enclave’s MRENCLAVE update counter;
(* Add “ECREATE” string and SECS fields to MRENCLAVE *)
TMPUPDATEFIELD[63:0] := 0045544145524345H; // “ECREATE”
TMPUPDATEFIELD[95:64] := DS:TMP_SECS.SSAFRAMESIZE;
TMPUPDATEFIELD[159:96] := DS:TMP_SECS.SIZE;
IF (CPUID.07H.00H:EDX.CET_IBT = 1)
THEN
TMPUPDATEFIELD[223:160] := DS:TMP_SECS.CET_LEG_BITMAP_OFFSET;
ELSE
TMPUPDATEFIELD[223:160] := 0;
FI;
TMPUPDATEFIELD[511:160] := 0;
DS:TMP_SECS.MRENCLAVE := SHA256UPDATE(DS:TMP_SECS.MRENCLAVE, TMPUPDATEFIELD)
INC enclave’s MRENCLAVE update counter;
(* Set EID *)
DS:TMP_SECS.EID := LockedXAdd(CR_NEXT_EID, 1);
(* Set the EPCM entry, first create SECS identifier and store the identifier in EPCM *)
EPCM(DS:TMP_SECS).PT := PT_SECS;
EPCM(DS:TMP_SECS).ENCLAVEADDRESS := 0;
EPCM(DS:TMP_SECS).R := 0;
EPCM(DS:TMP_SECS).W := 0;
EPCM(DS:TMP_SECS).X := 0;
(* Set EPCM entry fields *)
41-28
Vol. 3D
ECREATE-Create an SECS page in the Enclave Page Cache
INTEL® SGX INSTRUCTION REFERENCES
EPCM(DS:RCX).BLOCKED := 0;
EPCM(DS:RCX).PENDING := 0;
EPCM(DS:RCX).MODIFIED := 0;
EPCM(DS:RCX).PR := 0;
EPCM(DS:RCX).VALID := 1;
Flags Affected
None
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If the reserved fields are not zero.
If PAGEINFO.SECS is not zero.
If PAGEINFO.LINADDR is not zero.
If the SECS destination is locked.
If SECS.SSAFRAMESIZE is insufficient.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the SECS destination is outside the EPC.
64-Bit Mode Exceptions
#GP(0)
If a memory address is non-canonical form.
If a memory operand is not properly aligned.
If the reserved fields are not zero.
If PAGEINFO.SECS is not zero.
If PAGEINFO.LINADDR is not zero.
If the SECS destination is locked.
If SECS.SSAFRAMESIZE is insufficient.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the SECS destination is outside the EPC.
ECREATE-Create an SECS page in the Enclave Page Cache
Vol. 3D
41-29
INTEL® SGX INSTRUCTION REFERENCES
EDBGRD-Read From a Debug Enclave
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 04H
IR
V/V
SGX1
This leaf function reads a dword/quadword from a debug enclave.
ENCLS[EDBGRD]
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
Return error
IR
EDBGRD (In)
Data read from a debug enclave (Out)
Address of source memory in the EPC (In)
code (Out)
Description
This leaf function copies a quadword/doubleword from an EPC page belonging to a debug enclave into the RBX
register. Eight bytes are read in 64-bit mode, four bytes are read in non-64-bit modes. The size of data read cannot
be overridden.
The effective address of the source location inside the EPC is provided in the register RCX.
EDBGRD Memory Parameter Semantics
EPCQW
Read access permitted by Enclave
The error codes are:
Table 41-16. EDBGRD Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EDBGRD successful.
SGX_PAGE_NOT_DEBUGGABLE
The EPC page cannot be accessed because it is in the PENDING or MODIFIED state.
The instruction faults if any of the following:
EDBGRD Faulting Conditions
RCX points into a page that is an SECS.
RCX does not resolve to a naturally aligned linear address.
RCX points to a page that does not belong to an
RCX points to a location inside a TCS that is beyond the architectural size of the
enclave that is in debug mode.
TCS (SGX_TCS_LIMIT).
An operand causing any segment violation.
May page fault.
CPL > 0.
This instruction ignores the EPCM RWX attributes on the enclave page. Consequently, violation of EPCM RWX attri-
butes via EDBGRD does not result in a #GP.
41-30
Vol. 3D
EDBGRD-Read From a Debug Enclave
INTEL® SGX INSTRUCTION REFERENCES
Concurrency Restrictions
Table 41-17. Base Concurrency Restrictions of EDBGRD
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EDBGRD
Target [DS:RCX]
Shared
#GP
Table 41-18. Additional Concurrency Restrictions of EDBGRD
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EDBGRD
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in EDBGRD Operational Flow
Name
Type
Size (Bits)
Description
TMP_MODE64
Binary
1
((IA32_EFER.LMA = 1) && (CS.L = 1))
TMP_SECS
64
Physical address of SECS of the enclave to which source operand belongs.
TMP_MODE64 := ((IA32_EFER.LMA = 1) && (CS.L = 1));
IF ( (TMP_MODE64 = 1) and (DS:RCX is not 8Byte Aligned) )
THEN #GP(0); FI;
IF ( (TMP_MODE64 = 0) and (DS:RCX is not 4Byte Aligned) )
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* make sure no other Intel SGX instruction is accessing the same EPCM entry *)
IF (Another instruction modifying the same EPCM entry is executing)
THEN #GP(0); FI;
IF (EPCM(DS:RCX).VALID = 0)
THEN #PF(DS:RCX); FI;
(* make sure that DS:RCX (SOURCE) is pointing to a PT_REG or PT_TCS or PT_VA or PT_SS_FIRST or PT_SS_REST *)
IF ( (EPCM(DS:RCX).PT ≠ PT_REG) and (EPCM(DS:RCX).PT ≠ PT_TCS) and (EPCM(DS:RCX).PT ≠ PT_VA)
and (EPCM(DS:RCX).PT ≠ PT_SS_FIRST) and (EPCM(DS:RCX).PT ≠ PT_SS_REST))
THEN #PF(DS:RCX); FI;
(* make sure that DS:RCX points to an accessible EPC page *)
IF (EPCM(DS:RCX).PENDING is not 0 or (EPCM(DS:RCX).MODIFIED is not 0) )
THEN
RFLAGS.ZF := 1;
EDBGRD-Read From a Debug Enclave
Vol. 3D
41-31
INTEL® SGX INSTRUCTION REFERENCES
RAX := SGX_PAGE_NOT_DEBUGGABLE;
GOTO DONE;
FI;
(* If source is a TCS, then make sure that the offset into the page is not beyond the TCS size*)
IF ( ( EPCM(DS:RCX). PT = PT_TCS) and ((DS:RCX) & FFFH ≥ SGX_TCS_LIMIT) )
THEN #GP(0); FI;
(* make sure the enclave owning the PT_REG or PT_TCS page allow debug *)
IF ( (EPCM(DS:RCX).PT = PT_REG) or (EPCM(DS:RCX).PT = PT_TCS) )
THEN
TMP_SECS := GET_SECS_ADDRESS;
IF (TMP_SECS.ATTRIBUTES.DEBUG = 0)
THEN #GP(0); FI;
IF ( (TMP_MODE64 = 1) )
THEN RBX[63:0] := (DS:RCX)[63:0];
ELSE EBX[31:0] := (DS:RCX)[31:0];
FI;
ELSE
TMP_64BIT_VAL[63:0] := (DS:RCX)[63:0] & (~07H); // Read contents from VA slot
IF (TMP_MODE64 = 1)
THEN
IF (TMP_64BIT_VAL ≠ 0H)
THEN RBX[63:0] := 0FFFFFFFFFFFFFFFFH;
ELSE RBX[63:0] := 0H;
FI;
ELSE
IF (TMP_64BIT_VAL ≠ 0H)
THEN EBX[31:0] := 0FFFFFFFFH;
ELSE EBX[31:0] := 0H;
FI;
FI;
(* clear EAX and ZF to indicate successful completion *)
RAX := 0;
RFLAGS.ZF := 0;
DONE:
(* clear flags *)
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
ZF is set if the page is MODIFIED or PENDING; RAX contains the error code. Otherwise ZF is cleared and RAX is set
to 0. CF, PF, AF, OF, SF are cleared.
Protected Mode Exceptions
#GP(0)
If the address in RCS violates DS limit or access rights.
If DS segment is unusable.
If RCX points to a memory location not 4Byte-aligned.
If the address in RCX points to a page belonging to a non-debug enclave.
If the address in RCX points to a page which is not PT_TCS, PT_REG or PT_VA.
If the address in RCX points to a location inside TCS that is beyond SGX_TCS_LIMIT.
41-32
Vol. 3D
EDBGRD-Read From a Debug Enclave
INTEL® SGX INSTRUCTION REFERENCES
#PF(error code)
If a page fault occurs in accessing memory operands.
If the address in RCX points to a non-EPC page.
If the address in RCX points to an invalid EPC page.
64-Bit Mode Exceptions
#GP(0)
If RCX is non-canonical form.
If RCX points to a memory location not 8Byte-aligned.
If the address in RCX points to a page belonging to a non-debug enclave.
If the address in RCX points to a page which is not PT_TCS, PT_REG or PT_VA.
If the address in RCX points to a location inside TCS that is beyond SGX_TCS_LIMIT.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the address in RCX points to a non-EPC page.
If the address in RCX points to an invalid EPC page.
EDBGRD-Read From a Debug Enclave
Vol. 3D
41-33
INTEL® SGX INSTRUCTION REFERENCES
EDBGWR-Write to a Debug Enclave
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 05H
IR
V/V
SGX1
This leaf function writes a dword/quadword to a debug enclave.
ENCLS[EDBGWR]
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
Return error
IR
EDBGWR (In)
Data to be written to a debug enclave (In)
Address of Target memory in the EPC (In)
code (Out)
Description
This leaf function copies the content in EBX/RBX to an EPC page belonging to a debug enclave. Eight bytes are
written in 64-bit mode, four bytes are written in non-64-bit modes. The size of data cannot be overridden.
The effective address of the target location inside the EPC is provided in the register RCX.
EDBGWR Memory Parameter Semantics
EPCQW
Write access permitted by Enclave
The instruction faults if any of the following:
EDBGWR Faulting Conditions
RCX points into a page that is an SECS.
RCX does not resolve to a naturally aligned linear address.
RCX points to a page that does not belong to an
RCX points to a location inside a TCS that is not the FLAGS word.
enclave that is in debug mode.
An operand causing any segment violation.
May page fault.
CPL > 0.
The error codes are:
Table 41-19. EDBGWR Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EDBGWR successful.
SGX_PAGE_NOT_DEBUGGABLE
The EPC page cannot be accessed because it is in the PENDING or MODIFIED state.
This instruction ignores the EPCM RWX attributes on the enclave page. Consequently, violation of EPCM RWX attri-
butes via EDBGRD does not result in a #GP.
41-34
Vol. 3D
EDBGWR-Write to a Debug Enclave
INTEL® SGX INSTRUCTION REFERENCES
Concurrency Restrictions
Table 41-20. Base Concurrency Restrictions of EDBGWR
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EDBGWR
Target [DS:RCX]
Shared
#GP
Table 41-21. Additional Concurrency Restrictions of EDBGWR
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EDBGWR
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in EDBGWR Operational Flow
Name
Type
Size (Bits)
Description
TMP_MODE64
Binary
1
((IA32_EFER.LMA = 1) && (CS.L = 1)).
TMP_SECS
64
Physical address of SECS of the enclave to which source operand belongs.
TMP_MODE64 := ((IA32_EFER.LMA = 1) && (CS.L = 1));
IF ( (TMP_MODE64 = 1) and (DS:RCX is not 8Byte Aligned) )
THEN #GP(0); FI;
IF ( (TMP_MODE64 = 0) and (DS:RCX is not 4Byte Aligned) )
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* make sure no other Intel SGX instruction is accessing the same EPCM entry *)
IF (Another instruction modifying the same EPCM entry is executing)
THEN #GP(0); FI;
IF (EPCM(DS:RCX).VALID = 0)
THEN #PF(DS:RCX); FI;
(* make sure that DS:RCX (DST) is pointing to a PT_REG or PT_TCS or PT_SS_FIRST or PT_SS_REST *)
IF ( (EPCM(DS:RCX).PT ≠ PT_REG) and (EPCM(DS:RCX).PT ≠ PT_TCS)
and (EPCM(DS:RCX).PT ≠ PT_SS_FIRST) and (EPCM(DS:RCX).PT ≠ PT_SS_REST))
THEN #PF(DS:RCX); FI;
(* make sure that DS:RCX points to an accessible EPC page *)
IF ( (EPCM(DS:RCX).PENDING is not 0) or (EPCM(DS:RCS).MODIFIED is not 0) )
THEN
RFLAGS.ZF := 1;
EDBGWR-Write to a Debug Enclave
Vol. 3D
41-35
INTEL® SGX INSTRUCTION REFERENCES
RAX := SGX_PAGE_NOT_DEBUGGABLE;
GOTO DONE;
FI;
(* If destination is a TCS, then make sure that the offset into the page can only point to the FLAGS field*)
IF ( ( EPCM(DS:RCX). PT = PT_TCS) and ((DS:RCX) & FF8H ≠ offset_of_FLAGS & 0FF8H) )
THEN #GP(0); FI;
(* Locate the SECS for the enclave to which the DS:RCX page belongs *)
TMP_SECS := GET_SECS_PHYS_ADDRESS(EPCM(DS:RCX).ENCLAVESECS);
(* make sure the enclave owning the PT_REG or PT_TCS page allow debug *)
IF (TMP_SECS.ATTRIBUTES.DEBUG = 0)
THEN #GP(0); FI;
IF ( (TMP_MODE64 = 1) )
THEN (DS:RCX)[63:0] := RBX[63:0];
ELSE (DS:RCX)[31:0] := EBX[31:0];
FI;
(* clear EAX and ZF to indicate successful completion *)
RAX := 0;
RFLAGS.ZF := 0;
DONE:
(* clear flags *)
RFLAGS.CF,PF,AF,OF,SF := 0
Flags Affected
ZF is set if the page is MODIFIED or PENDING; RAX contains the error code. Otherwise ZF is cleared and RAX is set
to 0. CF, PF, AF, OF, SF are cleared.
Protected Mode Exceptions
#GP(0)
If the address in RCS violates DS limit or access rights.
If DS segment is unusable.
If RCX points to a memory location not 4Byte-aligned.
If the address in RCX points to a page belonging to a non-debug enclave.
If the address in RCX points to a page which is not PT_TCS or PT_REG.
If the address in RCX points to a location inside TCS that is not the FLAGS word.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the address in RCX points to a non-EPC page.
If the address in RCX points to an invalid EPC page.
64-Bit Mode Exceptions
#GP(0)
If RCX is non-canonical form.
If RCX points to a memory location not 8Byte-aligned.
If the address in RCX points to a page belonging to a non-debug enclave.
If the address in RCX points to a page which is not PT_TCS or PT_REG.
If the address in RCX points to a location inside TCS that is not the FLAGS word.
41-36
Vol. 3D
EDBGWR-Write to a Debug Enclave
INTEL® SGX INSTRUCTION REFERENCES
#PF(error code)
If a page fault occurs in accessing memory operands.
If the address in RCX points to a non-EPC page.
If the address in RCX points to an invalid EPC page.
EDBGWR-Write to a Debug Enclave
Vol. 3D
41-37
INTEL® SGX INSTRUCTION REFERENCES
EEXTEND-Extend Uninitialized Enclave Measurement by 256 Bytes
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 06H
IR
V/V
SGX1
This leaf function measures 256 bytes of an uninitialized enclave
ENCLS[EEXTEND]
page.
Instruction Operand Encoding
Op/En
EAX
EBX
RCX
Effective address of the SECS of the
IR
EEXTEND (In)
Effective address of a 256-byte chunk in the EPC (In)
data chunk (In)
Description
This leaf function updates the MRENCLAVE measurement register of an SECS with the measurement of an EXTEND
string compromising of “EEXTEND” || ENCLAVEOFFSET || PADDING || 256 bytes of the enclave page. This instruc-
tion can only be executed when current privilege level is 0 and the enclave is uninitialized.
RBX contains the effective address of the SECS of the region to be measured. The address must be the same as the
one used to add the page into the enclave.
RCX contains the effective address of the 256 byte region of an EPC page to be measured. The DS segment is used
to create linear addresses. Segment override is not supported.
EEXTEND Memory Parameter Semantics
EPC[RCX]
Read access by Enclave
The instruction faults if any of the following:
EEXTEND Faulting Conditions
RBX points to an address not 4KBytes aligned.
RBX does not resolve to an SECS.
RBX does not point to an SECS page.
RBX does not point to the SECS page of the data chunk.
RCX points to an address not 256B aligned.
RCX points to an unused page or a SECS.
RCX does not resolve in an EPC page.
If SECS is locked.
If the SECS is already initialized.
May page fault.
CPL > 0.
Concurrency Restrictions
Table 41-22. Base Concurrency Restrictions of EEXTEND
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EEXTEND
Target [DS:RCX]
Shared
#GP
SECS [DS:RBX]
Concurrent
41-38
Vol. 3D
EEXTEND-Extend Uninitialized Enclave Measurement by 256 Bytes
INTEL® SGX INSTRUCTION REFERENCES
Table 41-23. Additional Concurrency Restrictions of EEXTEND
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EEXTEND
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
SECS [DS:RBX]
Concurrent
Exclusive
#GP
Concurrent
Operation
Temp Variables in EEXTEND Operational Flow
Name
Type
Size (Bits)
Description
TMP_SECS
64
Physical address of SECS of the enclave to which source operand belongs.
TMP_ENCLAVEOFFS
Enclave Offset
64
The page displacement from the enclave base address.
ET
TMPUPDATEFIELD
SHA256 Buffer
512
Buffer used to hold data being added to TMP_SECS.MRENCLAVE.
TMP_MODE64 := ((IA32_EFER.LMA = 1) && (CS.L = 1));
IF (DS:RBX is not 4096 Byte Aligned)
THEN #GP(0); FI;
IF (DS:RBX does not resolve to an EPC page)
THEN #PF(DS:RBX); FI;
IF (DS:RCX is not 256Byte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* make sure no other Intel SGX instruction is accessing EPCM *)
IF (Other instructions accessing EPCM)
THEN #GP(0); FI;
IF (EPCM(DS:RCX). VALID = 0)
THEN #PF(DS:RCX); FI;
(* make sure that DS:RCX (DST) is pointing to a PT_REG or PT_TCS or PT_SS_FIRST or PT_SS_REST *)
IF ( (EPCM(DS:RCX).PT ≠ PT_REG) and (EPCM(DS:RCX).PT ≠ PT_TCS)
and (EPCM(DS:RCX).PT ≠ PT_SS_FIRST) and (EPCM(DS:RCX).PT ≠ PT_SS_REST))
THEN #PF(DS:RCX); FI;
TMP_SECS := Get_SECS_ADDRESS();
IF (DS:RBX does not resolve to TMP_SECS)
THEN #GP(0); FI;
(* make sure no other instruction is accessing MRENCLAVE or ATTRIBUTES.INIT *)
IF ( (Other instruction accessing MRENCLAVE) or (Other instructions checking or updating the initialized state of the SECS))
EEXTEND-Extend Uninitialized Enclave Measurement by 256 Bytes
Vol. 3D
41-39
INTEL® SGX INSTRUCTION REFERENCES
THEN #GP(0); FI;
(* Calculate enclave offset *)
TMP_ENCLAVEOFFSET := EPCM(DS:RCX).ENCLAVEADDRESS - TMP_SECS.BASEADDR;
TMP_ENCLAVEOFFSET := TMP_ENCLAVEOFFSET + (DS:RCX & 0FFFH)
(* Add EEXTEND message and offset to MRENCLAVE *)
TMPUPDATEFIELD[63:0] := 00444E4554584545H; // “EEXTEND”
TMPUPDATEFIELD[127:64] := TMP_ENCLAVEOFFSET;
TMPUPDATEFIELD[511:128] := 0; // 48 bytes
TMP_SECS.MRENCLAVE := SHA256UPDATE(TMP_SECS.MRENCLAVE, TMPUPDATEFIELD)
INC enclave’s MRENCLAVE update counter;
(*Add 256 bytes to MRENCLAVE, 64 byte at a time *)
TMP_SECS.MRENCLAVE := SHA256UPDATE(TMP_SECS.MRENCLAVE, DS:RCX[511:0] );
TMP_SECS.MRENCLAVE := SHA256UPDATE(TMP_SECS.MRENCLAVE, DS:RCX[1023: 512] );
TMP_SECS.MRENCLAVE := SHA256UPDATE(TMP_SECS.MRENCLAVE, DS:RCX[1535: 1024] );
TMP_SECS.MRENCLAVE := SHA256UPDATE(TMP_SECS.MRENCLAVE, DS:RCX[2047: 1536] );
INC enclave’s MRENCLAVE update counter by 4;
Flags Affected
None
Protected Mode Exceptions
#GP(0)
If the address in RBX is outside the DS segment limit.
If RBX points to an SECS page which is not the SECS of the data chunk.
If the address in RCX is outside the DS segment limit.
If RCX points to a memory location not 256Byte-aligned.
If another instruction is accessing MRENCLAVE.
If another instruction is checking or updating the SECS.
If the enclave is already initialized.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the address in RBX points to a non-EPC page.
If the address in RCX points to a page which is not PT_TCS or PT_REG.
If the address in RCX points to a non-EPC page.
If the address in RCX points to an invalid EPC page.
64-Bit Mode Exceptions
#GP(0)
If RBX is non-canonical form.
If RBX points to an SECS page which is not the SECS of the data chunk.
If RCX is non-canonical form.
If RCX points to a memory location not 256 Byte-aligned.
If another instruction is accessing MRENCLAVE.
If another instruction is checking or updating the SECS.
If the enclave is already initialized.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the address in RBX points to a non-EPC page.
If the address in RCX points to a page which is not PT_TCS or PT_REG.
If the address in RCX points to a non-EPC page.
If the address in RCX points to an invalid EPC page.
41-40
Vol. 3D
EEXTEND-Extend Uninitialized Enclave Measurement by 256 Bytes
INTEL® SGX INSTRUCTION REFERENCES
EINIT-Initialize an Enclave for Execution
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 02H
IR
V/V
SGX1
This leaf function initializes the enclave and makes it ready to
ENCLS[EINIT]
execute enclave code.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
RDX
IR
EINIT (In)
Error code (Out)
Address of SIGSTRUCT (In)
Address of SECS (In)
Address of EINITTOKEN (In)
Description
This leaf function is the final instruction executed in the enclave build process. After EINIT, the MRENCLAVE
measurement is complete, and the enclave is ready to start user code execution using the EENTER instruction.
EINIT takes the effective address of a SIGSTRUCT and EINITTOKEN. The SIGSTRUCT describes the enclave
including MRENCLAVE, ATTRIBUTES, ISVSVN, a 3072 bit RSA key, and a signature using the included key.
SIGSTRUCT must be populated with two values, q1 and q2. These are calculated using the formulas shown below:
q1 = floor(Signature2 / Modulus);
q2 = floor((Signature3 - q1 * Signature * Modulus) / Modulus);
The EINITTOKEN contains the MRENCLAVE, MRSIGNER, and ATTRIBUTES. These values must match the corre-
sponding values in the SECS. If the EINITTOKEN was created with a debug launch key, the enclave must be in
debug mode as well.
Signature
Ve
rify
PubKey
Hashed
ATTRIBUTES
ATTRIBUTEMASK
Check
MRENCLAVE
SIGSTRUCT
MRSIGNER
If VALID=1,
Check
MRSIGNER
D
S:RBX
ATTRIBUTES
If VALID=1,
MRENCLAVE
DS:RDX
Check
EINIT
EINITTOKEN
Copy
ATTRIBUTES
SECS
DS:RCX
MRENCLAVE
Check
ENCLAVE
EPC
Figure 41-1. Relationships Between SECS, SIGSTRUCT, and EINITTOKEN
EINIT-Initialize an Enclave for Execution
Vol. 3D
41-41
INTEL® SGX INSTRUCTION REFERENCES
EINIT Memory Parameter Semantics
SIGSTRUCT
SECS
EINITTOKEN
Access by non-Enclave
Read/Write access by Enclave
Access by non-Enclave
EINIT performs the following steps, which can be seen in Figure 41-1:
1. Validates that SIGSTRUCT is signed using the enclosed public key.
2. Checks that the completed computation of SECS.MRENCLAVE equals SIGSTRUCT.HASHENCLAVE.
3. Checks that no controlled ATTRIBUTES bits are set in SIGSTRUCT.ATTRIBUTES unless the SHA256 digest of
SIGSTRUCT.MODULUS equals IA32_SGX_LEPUBKEYHASH.
4. Checks that the result of bitwise and-ing SIGSTRUCT.ATTRIBUTEMASK with SIGSTRUCT.ATTRIBUTES equals
the result of bitwise and-ing SIGSTRUCT.ATTRIBUTEMASK with SECS.ATTRIBUTES.
5. If EINITTOKEN.VALID is 0, checks that the SHA256 digest of SIGSTRUCT.MODULUS equals IA32_SGX_LEPUB-
KEYHASH.
6. If EINITTOKEN.VALID is 1, checks the validity of EINITTOKEN.
7. If EINITTOKEN.VALID is 1, checks that EINITTOKEN.MRENCLAVE equals SECS.MRENCLAVE.
8. If EINITTOKEN.VALID is 1 and EINITTOKEN.ATTRIBUTES.DEBUG is 1, SECS.ATTRIBUTES.DEBUG must be 1.
9. Commits SECS.MRENCLAVE, and sets SECS.MRSIGNER, SECS.ISVSVN, and SECS.ISVPRODID based on
SIGSTRUCT.
10. Update the SECS as Initialized.
Periodically, EINIT polls for certain asynchronous events. If such an event is detected, it completes with failure code
(ZF=1 and RAX = SGX_UNMASKED_EVENT), and RIP is incremented to point to the next instruction. These events
includes external interrupts, non-maskable interrupts, system-management interrupts, machine checks, INIT
signals, and the VMX-preemption timer. EINIT does not fail if the pending event is inhibited (e.g., external inter-
rupts could be inhibited due to blocking by MOV SS blocking or by STI).
The following bits in RFLAGS are cleared: CF, PF, AF, OF, and SF. When the instruction completes with an error,
RFLAGS.ZF is set to 1, and the corresponding error bit is set in RAX. If no error occurs, RFLAGS.ZF is cleared and
RAX is set to 0.
The error codes are:
Table 41-24. EINIT Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EINIT successful.
SGX_INVALID_SIG_STRUCT
If SIGSTRUCT contained an invalid value.
SGX_INVALID_ATTRIBUTE
If SIGSTRUCT contains an unauthorized attributes mask.
SGX_INVALID_MEASUREMENT
If SIGSTRUCT contains an incorrect measurement.
If EINITTOKEN contains an incorrect measurement.
SGX_INVALID_SIGNATURE
If signature does not validate with enclosed public key.
SGX_INVALID_LICENSE
If license is invalid.
SGX_INVALID_CPUSVN
If license SVN is unsupported.
SGX_UNMASKED_EVENT
If an unmasked event is received before the instruction completes its operation.
41-42
Vol. 3D
EINIT-Initialize an Enclave for Execution
INTEL® SGX INSTRUCTION REFERENCES
Concurrency Restrictions
Table 41-25. Base Concurrency Restrictions of EINIT
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EINIT
SECS [DS:RCX]
Shared
#GP
Table 41-26. Additional Concurrency Restrictions of ENIT
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EINIT
SECS [DS:RCX]
Concurrent
Exclusive
#GP
Concurrent
Operation
Temp Variables in EINIT Operational Flow
Name
Type
Size
Description
TMP_SIG
SIGSTRUCT
1808Bytes
Temp space for SIGSTRUCT.
TMP_TOKEN
EINITTOKEN
304Bytes
Temp space for EINITTOKEN.
TMP_MRENCLAVE
32Bytes
Temp space for calculating MRENCLAVE.
TMP_MRSIGNER
32Bytes
Temp space for calculating MRSIGNER.
CONTROLLED_ATTRIBU
ATTRIBUTES
16Bytes
Constant mask of all ATTRIBUTE bits that can only be set for authorized
TES
enclaves.
TMP_KEYDEPENDENCIE
Buffer
224Bytes
Temp space for key derivation.
S
TMP_EINITTOKENKEY
16Bytes
Temp space for the derived EINITTOKEN Key.
TMP_SIG_PADDING
PKCS Padding
352Bytes
The value of the top 352 bytes from the computation of Signature3
Buffer
modulo MRSIGNER.
(* make sure SIGSTRUCT and SECS are aligned *)
IF ( (DS:RBX is not 4KByte Aligned) or (DS:RCX is not 4KByte Aligned) )
THEN #GP(0); FI;
(* make sure the EINITTOKEN is aligned *)
IF (DS:RDX is not 512Byte Aligned)
THEN #GP(0); FI;
(* make sure the SECS is inside the EPC *)
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
TMP_SIG[14463:0] := DS:RBX[14463:0]; // 1808 bytes
TMP_TOKEN[2423:0] := DS:RDX[2423:0]; // 304 bytes
EINIT-Initialize an Enclave for Execution
Vol. 3D
41-43
INTEL® SGX INSTRUCTION REFERENCES
(* Verify SIGSTRUCT Header. *)
IF ( (TMP_SIG.HEADER ≠ 06000000E10000000000010000000000h) or
((TMP_SIG.VENDOR ≠ 0) and (TMP_SIG.VENDOR ≠ 00008086h) ) or
(TMP_SIG HEADER2 ≠ 01010000600000006000000001000000h) or
(TMP_SIG.EXPONENT
≠ 00000003h) or (Reserved space is not 0’s) )
THEN
RFLAGS.ZF := 1;
RAX := SGX_INVALID_SIG_STRUCT;
GOTO EXIT;
FI;
(* Open “Event Window” Check for Interrupts. Verify signature using embedded public key, q1, and q2. Save upper 352 bytes of the
PKCS1.5 encoded message into the TMP_SIG_PADDING*)
IF (interrupt was pending) THEN
RFLAGS.ZF := 1;
RAX := SGX_UNMASKED_EVENT;
GOTO EXIT;
FI
IF (signature failed to verify) THEN
RFLAGS.ZF := 1;
RAX := SGX_INVALID_SIGNATURE;
GOTO EXIT;
FI;
(*Close “Event Window” *)
(* make sure no other Intel SGX instruction is modifying SECS*)
IF (Other instructions modifying SECS)
THEN #GP(0); FI;
IF ( (EPCM(DS:RCX). VALID = 0) or (EPCM(DS:RCX).PT ≠ PT_SECS) )
THEN #PF(DS:RCX); FI;
(* Verify ISVFAMILYID is not used on an enclave with KSS disabled *)
IF ((TMP_SIG.ISVFAMILYID != 0) AND (DS:RCX.ATTRIBUTES.KSS == 0))
THEN
RFLAGS.ZF := 1;
RAX := SGX_INVALID_SIG_STRUCT;
GOTO EXIT;
FI;
(* make sure no other instruction is accessing MRENCLAVE or ATTRIBUTES.INIT *)
IF ( (Other instruction modifying MRENCLAVE) or (Other instructions modifying the SECS’s Initialized state))
THEN #GP(0); FI;
(* Calculate finalized version of MRENCLAVE *)
(* SHA256 algorithm requires one last update that compresses the length of the hashed message into the output SHA256 digest *)
TMP_ENCLAVE := SHA256FINAL( (DS:RCX).MRENCLAVE, enclave’s MRENCLAVE update count *512);
(* Verify MRENCLAVE from SIGSTRUCT *)
IF (TMP_SIG.ENCLAVEHASH ≠ TMP_MRENCLAVE)
RFLAGS.ZF := 1;
RAX := SGX_INVALID_MEASUREMENT;
GOTO EXIT;
FI;
41-44
Vol. 3D
EINIT-Initialize an Enclave for Execution
INTEL® SGX INSTRUCTION REFERENCES
TMP_MRSIGNER := SHA256(TMP_SIG.MODULUS)
(* if controlled ATTRIBUTES are set, SIGSTRUCT must be signed using an authorized key *)
CONTROLLED_ATTRIBUTES := 0000000000000020H;
IF ( ( (DS:RCX.ATTRIBUTES & CONTROLLED_ATTRIBUTES) ≠ 0) and (TMP_MRSIGNER ≠ IA32_SGXLEPUBKEYHASH) )
RFLAGS.ZF := 1;
RAX := SGX_INVALID_ATTRIBUTE;
GOTO EXIT;
FI;
(* Verify SIGSTRUCT.ATTRIBUTE requirements are met *)
IF ( (DS:RCX.ATTRIBUTES & TMP_SIG.ATTRIBUTEMASK) ≠ (TMP_SIG.ATTRIBUTE & TMP_SIG.ATTRIBUTEMASK) )
RFLAGS.ZF := 1;
RAX := SGX_INVALID_ATTRIBUTE;
GOTO EXIT;
FI;
( *Verify SIGSTRUCT.MISCSELECT requirements are met *)
IF ( (DS:RCX.MISCSELECT & TMP_SIG.MISCMASK) ≠ (TMP_SIG.MISCSELECT & TMP_SIG.MISCMASK) )
THEN
RFLAGS.ZF := 1;
RAX := SGX_INVALID_ATTRIBUTE;
GOTO EXIT
FI;
IF (CPUID.12H.01H:EAX[6] = 1)
IF ( DS:RCX.CET_ATTRIBUTES & TMP_SIG.CET_ATTRIBUTES_MASK ≠ TMP_SIG.CET_ATTRIBUTES &
TMP_SIG.CET_ATTRIB-UTES_MASK )
THEN
RFLAGS.ZF := 1;
RAX := SGX_INVALID_ATTRIBUTE;
GOTO EXIT
FI;
FI;
(* If EINITTOKEN.VALID[0] is 0, verify the enclave is signed by an authorized key *)
IF (TMP_TOKEN.VALID[0] = 0)
IF (TMP_MRSIGNER ≠ IA32_SGXLEPUBKEYHASH)
RFLAGS.ZF := 1;
RAX := SGX_INVALID_EINITTOKEN;
GOTO EXIT;
FI;
GOTO COMMIT;
FI;
(* Debug Launch Enclave cannot launch Production Enclaves *)
IF ( (DS:RDX.MASKEDATTRIBUTESLE.DEBUG = 1) and (DS:RCX.ATTRIBUTES.DEBUG = 0) )
RFLAGS.ZF := 1;
RAX := SGX_INVALID_EINITTOKEN;
GOTO EXIT;
FI;
EINIT-Initialize an Enclave for Execution
Vol. 3D
41-45
INTEL® SGX INSTRUCTION REFERENCES
(* Check reserve space in EINIT token includes reserved regions and upper bits in valid field *)
IF (TMP_TOKEN reserved space is not clear)
RFLAGS.ZF := 1;
RAX := SGX_INVALID_EINITTOKEN;
GOTO EXIT;
FI;
(* EINIT token must not have been created by a configuration beyond the current CPU configuration *)
IF (TMP_TOKEN.CPUSVN must not be a configuration beyond CR_CPUSVN)
RFLAGS.ZF := 1;
RAX := SGX_INVALID_CPUSVN;
GOTO EXIT;
FI;
(* Derive Launch key used to calculate EINITTOKEN.MAC *)
HARDCODED_PKCS1_5_PADDING[15:0] := 0100H;
HARDCODED_PKCS1_5_PADDING[2655:16] := SignExtend330Byte(-1); // 330 bytes of 0FFH
HARDCODED_PKCS1_5_PADDING[2815:2656] := 2004000501020403650148866009060D30313000H;
TMP_KEYDEPENDENCIES.KEYNAME := EINITTOKEN_KEY;
TMP_KEYDEPENDENCIES.ISVFAMILYID := 0;
TMP_KEYDEPENDENCIES.ISVEXTPRODID := 0;
TMP_KEYDEPENDENCIES.ISVPRODID := TMP_TOKEN.ISVPRODIDLE;
TMP_KEYDEPENDENCIES.ISVSVN := TMP_TOKEN.ISVSVNLE;
TMP_KEYDEPENDENCIES.SGXOWNEREPOCH := CR_SGXOWNEREPOCH;
TMP_KEYDEPENDENCIES.ATTRIBUTES := TMP_TOKEN.MASKEDATTRIBUTESLE;
TMP_KEYDEPENDENCIES.ATTRIBUTESMASK := 0;
TMP_KEYDEPENDENCIES.MRENCLAVE := 0;
TMP_KEYDEPENDENCIES.MRSIGNER := IA32_SGXLEPUBKEYHASH;
TMP_KEYDEPENDENCIES.KEYID := TMP_TOKEN.KEYID;
TMP_KEYDEPENDENCIES.SEAL_KEY_FUSES := CR_SEAL_FUSES;
TMP_KEYDEPENDENCIES.CPUSVN := TMP_TOKEN.CPUSVNLE;
TMP_KEYDEPENDENCIES.MISCSELECT := TMP_TOKEN.MASKEDMISCSELECTLE;
TMP_KEYDEPENDENCIES.MISCMASK := 0;
TMP_KEYDEPENDENCIES.PADDING := HARDCODED_PKCS1_5_PADDING;
TMP_KEYDEPENDENCIES.KEYPOLICY := 0;
TMP_KEYDEPENDENCIES.CONFIGID := 0;
TMP_KEYDEPENDENCIES.CONFIGSVN := 0;
IF (CPUID.12H.01H:EAX[6] = 1))
TMP_KEYDEPENDENCIES.CET_ATTRIBUTES := TMP_TOKEN.CET_MASKED_ATTRIBUTES_ LE;
TMP_KEYDEPENDENCIES.CET_ATTRIBUTES_MASK := 0;
FI;
(* Calculate the derived key*)
TMP_EINITTOKENKEY := derivekey(TMP_KEYDEPENDENCIES);
(* Verify EINITTOKEN was generated using this CPU's Launch key and that it has not been modified since issuing by the Launch
Enclave. Only 192 bytes of EINITTOKEN are CMACed *)
IF (TMP_TOKEN.MAC ≠ CMAC(TMP_EINITTOKENKEY, TMP_TOKEN[1535:0] ) )
RFLAGS.ZF := 1;
RAX := SGX_INVALID_EINITTOKEN;
GOTO EXIT;
FI;
41-46
Vol. 3D
EINIT-Initialize an Enclave for Execution
INTEL® SGX INSTRUCTION REFERENCES
(* Verify EINITTOKEN (RDX) is for this enclave *)
IF ( (TMP_TOKEN.MRENCLAVE ≠ TMP_MRENCLAVE) or (TMP_TOKEN.MRSIGNER ≠ TMP_MRSIGNER) )
RFLAGS.ZF := 1;
RAX := SGX_INVALID_MEASUREMENT;
GOTO EXIT;
FI;
(* Verify ATTRIBUTES in EINITTOKEN are the same as the enclave’s *)
IF (TMP_TOKEN.ATTRIBUTES ≠ DS:RCX.ATTRIBUTES)
RFLAGS.ZF := 1;
RAX := SGX_INVALID_EINIT_ATTRIBUTE;
GOTO EXIT;
FI;
COMMIT:
(* Commit changes to the SECS; Set ISVPRODID, ISVSVN, MRSIGNER, INIT ATTRIBUTE fields in SECS (RCX) *)
DS:RCX.MRENCLAVE := TMP_MRENCLAVE;
(* MRSIGNER stores a SHA256 in little endian implemented natively on x86 *)
DS:RCX.MRSIGNER := TMP_MRSIGNER;
DS:RCX.ISVEXTPRODID := TMP_SIG.ISVEXTPRODID;
DS:RCX.ISVPRODID := TMP_SIG.ISVPRODID;
DS:RCX.ISVSVN := TMP_SIG.ISVSVN;
DS:RCX.ISVFAMILYID := TMP_SIG.ISVFAMILYID;
DS:RCX.PADDING := TMP_SIG_PADDING;
(* Mark the SECS as initialized *)
Update DS:RCX to initialized;
(* Set RAX and ZF for success*)
RFLAGS.ZF := 0;
RAX := 0;
EXIT:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
ZF is cleared if successful, otherwise ZF is set and RAX contains the error code. CF, PF, AF, OF, SF are cleared.
Protected Mode Exceptions
#GP(0)
If a memory operand is not properly aligned.
If another instruction is modifying the SECS.
If the enclave is already initialized.
If the SECS.MRENCLAVE is in use.
#PF(error code)
If a page fault occurs in accessing memory operands.
If RCX does not resolve in an EPC page.
If the memory address is not a valid, uninitialized SECS.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is not properly aligned.
If another instruction is modifying the SECS.
If the enclave is already initialized.
If the SECS.MRENCLAVE is in use.
EINIT-Initialize an Enclave for Execution
Vol. 3D
41-47
INTEL® SGX INSTRUCTION REFERENCES
#PF(error code)
If a page fault occurs in accessing memory operands.
If RCX does not resolve in an EPC page.
If the memory address is not a valid, uninitialized SECS.
41-48
Vol. 3D
EINIT-Initialize an Enclave for Execution
INTEL® SGX INSTRUCTION REFERENCES
ELDB/ELDU-Load an EPC Page and Mark its State
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 07H
IR
V/V
SGX1
This leaf function loads, verifies an EPC page and marks the page
ENCLS[ELDB]
as blocked.
EAX = 08H
IR
V/V
SGX1
This leaf function loads, verifies an EPC page and marks the page
ENCLS[ELDU]
as unblocked.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
RDX
ELDB/ELDU
Return error
Address of the PAGEINFO
Address of the EPC page
Address of the version-
IR
(In)
code (Out)
(In)
(In)
array slot (In)
Description
This leaf function copies a page from regular main memory to the EPC. As part of the copying process, the page is
cryptographically authenticated and decrypted. This instruction can only be executed when current privilege level
is 0.
The ELDB leaf function sets the BLOCK bit in the EPCM entry for the destination page in the EPC after copying. The
ELDU leaf function clears the BLOCK bit in the EPCM entry for the destination page in the EPC after copying.
RBX contains the effective address of a PAGEINFO structure; RCX contains the effective address of the destination
EPC page; RDX holds the effective address of the version array slot that holds the version of the page.
The table below provides additional information on the memory parameter of ELDB/ELDU leaf functions.
ELDB/ELDU Memory Parameter Semantics
PAGEINFO
PAGEINFO.SRCPGE
PAGEINFO.PCMD
PAGEINFO.SECS
EPCPAGE
Version-Array Slot
Non-enclave
Non-enclave read
Non-enclave read
Enclave read/write
Read/Write access
Read/Write access per-
read access
access
access
access
permitted by Enclave
mitted by Enclave
The error codes are:
Table 41-27. ELDB/ELDU Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
ELDB/ELDU successful.
SGX_MAC_COMPARE_FAIL
If the MAC check fails.
Concurrency Restrictions
Table 41-28. Base Concurrency Restrictions of ELDB/ELDU
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
ELDB/ELDU
Target [DS:RCX]
Exclusive
#GP
VA [DS:RDX]
Shared
#GP
SECS [DS:RBX]PAGEINFO.SECS
Shared
#GP
ELDB/ELDU-Load an EPC Page and Mark its State
Vol. 3D
41-49
INTEL® SGX INSTRUCTION REFERENCES
Table 41-29. Additional Concurrency Restrictions of ELDB/ELDU
Additional Concurrency Restrictions
vs. EACCEPT,
vs. EADD, EEXTEND,
Leaf
Parameter
EACCEPTCOPY, EMODPE,
vs. ETRACK
EINIT
EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
ELDB/ELDU
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
VA [DS:RDX]
Concurrent
Concurrent
Concurrent
SECS [DS:RBX]PAGEINFO.SECS
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in ELDB/ELDU Operational Flow
Name
Type
Size (Bits)
Description
TMP_SRCPGE
Memory page
4KBytes
TMP_SECS
Memory page
4KBytes
TMP_PCMD
PCMD
128 Bytes
TMP_HEADER
MACHEADER
128 Bytes
TMP_VER
UINT64
64
TMP_MAC
UINT128
128
TMP_PK
UINT128
128
Page encryption/MAC key.
SCRATCH_PCMD
PCMD
128 Bytes
(* Check PAGEINFO and EPCPAGE alignment *)
IF ( (DS:RBX is not 32Byte Aligned) or (DS:RCX is not 4KByte Aligned) )
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* Check VASLOT alignment *)
IF (DS:RDX is not 8Byte aligned)
THEN #GP(0); FI;
IF (DS:RDX does not resolve within an EPC)
THEN #PF(DS:RDX); FI;
TMP_SRCPGE := DS:RBX.SRCPGE;
TMP_SECS := DS:RBX.SECS;
TMP_PCMD := DS:RBX.PCMD;
(* Check alignment of PAGEINFO (RBX) linked parameters. Note: PCMD pointer is overlaid on top of PAGEINFO.SECINFO field *)
IF ( (DS:TMP_PCMD is not 128Byte aligned) or (DS:TMP_SRCPGE is not 4KByte aligned) )
THEN #GP(0); FI;
(* Check concurrency of EPC by other Intel SGX instructions *)
IF (other instructions accessing EPC)
41-50
Vol. 3D
ELDB/ELDU-Load an EPC Page and Mark its State
INTEL® SGX INSTRUCTION REFERENCES
THEN
#GP(0); FI;
(* Check concurrency of EPC and VASLOT by other Intel SGX instructions *)
IF (Other instructions modifying VA slot)
THEN
#GP(0); FI;
(* Verify EPCM attributes of EPC page, VA, and SECS *)
IF (EPCM(DS:RCX).VALID = 1)
THEN #PF(DS:RCX); FI;
IF ( (EPCM(DS:RDX & ~0FFFH).VALID = 0) or (EPCM(DS:RDX & ~0FFFH).PT ≠ PT_VA) )
THEN #PF(DS:RDX); FI;
(* Copy PCMD into scratch buffer *)
SCRATCH_PCMD[1023: 0] := DS:TMP_PCMD[1023:0];
(* Zero out TMP_HEADER*)
TMP_HEADER[sizeof(TMP_HEADER)-1: 0] := 0;
TMP_HEADER.SECINFO := SCRATCH_PCMD.SECINFO;
TMP_HEADER.RSVD := SCRATCH_PCMD.RSVD;
TMP_HEADER.LINADDR := DS:RBX.LINADDR;
(* Verify various attributes of SECS parameter *)
IF ( (TMP_HEADER.SECINFO.FLAGS.PT = PT_REG) or (TMP_HEADER.SECINFO.FLAGS.PT = PT_TCS) or
(TMP_HEADER.SECINFO.FLAGS.PT = PT_TRIM) or
(TMP_HEADER.SECINFO.FLAGS.PT = PT_SS_FIRST and CPUID.12H.01H:EAX[6] = 1) or
(TMP_HEADER.SECINFO.FLAGS.PT = PT_SS_REST and CPUID.12H.01H:EAX[6] = 1))
THEN
IF ( DS:TMP_SECS is not 4KByte aligned)
THEN #GP(0) FI;
IF (DS:TMP_SECS does not resolve within an EPC)
THEN #PF(DS:TMP_SECS) FI;
IF (Another instruction is currently modifying the SECS)
THEN
#GP(0); Fl;
TMP_HEADER.EID := DS:TMP_SECS.EID;
ELSE
(* TMP_HEADER.SECINFO.FLAGS.PT is PT_SECS or PT_VA which do not have a parent SECS, and hence no EID binding *)
TMP_HEADER.EID := 0;
IF (DS:TMP_SECS ≠ 0)
THEN #GP(0) FI;
FI;
(* Copy 4KBytes SRCPGE to secure location *)
DS:RCX[32767: 0] := DS:TMP_SRCPGE[32767: 0];
TMP_VER := DS:RDX[63:0];
(* Decrypt and MAC page. AES_GCM_DEC has 2 outputs, {plain text, MAC} *)
(* Parameters for AES_GCM_DEC {Key, Counter, ..} *)
{DS:RCX, TMP_MAC} := AES_GCM_DEC(CR_BASE_PK, TMP_VER << 32, TMP_HEADER, 128, DS:RCX, 4096);
ELDB/ELDU-Load an EPC Page and Mark its State
Vol. 3D
41-51
INTEL® SGX INSTRUCTION REFERENCES
IF ( (TMP_MAC ≠ DS:TMP_PCMD.MAC) )
THEN
RFLAGS.ZF := 1;
RAX := SGX_MAC_COMPARE_FAIL;
GOTO ERROR_EXIT;
FI;
(* Clear VA Slot *)
DS:RDX := 0
(* Commit EPCM changes *)
EPCM(DS:RCX).PT := TMP_HEADER.SECINFO.FLAGS.PT;
EPCM(DS:RCX).RWX := TMP_HEADER.SECINFO.FLAGS.RWX;
EPCM(DS:RCX).PENDING := TMP_HEADER.SECINFO.FLAGS.PENDING;
EPCM(DS:RCX).MODIFIED := TMP_HEADER.SECINFO.FLAGS.MODIFIED;
EPCM(DS:RCX).PR := TMP_HEADER.SECINFO.FLAGS.PR;
EPCM(DS:RCX).ENCLAVEADDRESS := TMP_HEADER.LINADDR;
IF ( (EAX = 07H) and (TMP_HEADER.SECINFO.FLAGS.PT is NOT PT_SECS or PT_VA) )
THEN
EPCM(DS:RCX).BLOCKED := 1;
ELSE
EPCM(DS:RCX).BLOCKED := 0;
FI;
EPCM(DS:RCX). VALID := 1;
RAX := 0;
RFLAGS.ZF := 0;
ERROR_EXIT:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
Sets ZF if unsuccessful, otherwise cleared and RAX returns error code. Clears CF, PF, AF, OF, SF.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If the instruction’s EPC resource is in use by others.
If the instruction fails to verify MAC.
If the version-array slot is in use.
If the parameters fail consistency checks.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand expected to be in EPC does not resolve to an EPC page.
If one of the EPC memory operands has incorrect page type.
If the destination EPC page is already valid.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If the instruction’s EPC resource is in use by others.
41-52
Vol. 3D
ELDB/ELDU-Load an EPC Page and Mark its State
INTEL® SGX INSTRUCTION REFERENCES
If the instruction fails to verify MAC.
If the version-array slot is in use.
If the parameters fail consistency checks.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand expected to be in EPC does not resolve to an EPC page.
If one of the EPC memory operands has incorrect page type.
If the destination EPC page is already valid.
ELDB/ELDU-Load an EPC Page and Mark its State
Vol. 3D
41-53
INTEL® SGX INSTRUCTION REFERENCES
EMODPR-Restrict the Permissions of an EPC Page
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 0EH
IR
V/V
SGX2
This leaf function restricts the access rights associated with a
ENCLS[EMODPR]
EPC page in an initialized enclave.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
EMODPR (In)
Return Error Code (Out)
Address of a SECINFO (In)
Address of the destination EPC page (In)
Description
This leaf function restricts the access rights associated with an EPC page in an initialized enclave. THE RWX bits of
the SECINFO parameter are treated as a permissions mask; supplying a value that does not restrict the page
permissions will have no effect. This instruction can only be executed when current privilege level is 0.
RBX contains the effective address of a SECINFO structure while RCX contains the effective address of an EPC page.
The table below provides additional information on the memory parameter of the EMODPR leaf function.
EMODPR Memory Parameter Semantics
SECINFO
EPCPAGE
Read access permitted by Non Enclave
Read/Write access permitted by Enclave
The instruction faults if any of the following:
EMODPR Faulting Conditions
The operands are not properly aligned.
If unsupported security attributes are set.
The Enclave is not initialized.
SECS is locked by another thread.
The EPC page is locked by another thread.
RCX does not contain an effective address of an EPC page in the running enclave.
The EPC page is not valid.
The error codes are:
Table 41-30. EMODPR Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EMODPR successful.
SGX_PAGE_NOT_MODIFIABLE
The EPC page cannot be modified because it is in the PENDING or MODIFIED state.
SGX_EPC_PAGE_CONFLICT
Page is being written by EADD, EAUG, ECREATE, ELDU/B, EMODT, or EWB.
Concurrency Restrictions
Table 41-31. Base Concurrency Restrictions of EMODPR
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EMODPR
Target [DS:RCX]
Shared
#GP
41-54
Vol. 3D
EMODPR-Restrict the Permissions of an EPC Page
INTEL® SGX INSTRUCTION REFERENCES
Table 41-32. Additional Concurrency Restrictions of EMODPR
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EMODPR
Target [DS:RCX]
Exclusive
SGX_EP-
Concurrent
Concurrent
C_PAGE_CON-
FLICT
Operation
Temp Variables in EMODPR Operational Flow
Name
Type
Size (bits)
Description
TMP_SECS
Effective Address
32/64
Physical address of SECS to which EPC operand belongs.
SCRATCH_SECINFO
SECINFO
512
Scratch storage for holding the contents of DS:RBX.
IF (DS:RBX is not 64Byte Aligned)
THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
SCRATCH_SECINFO := DS:RBX;
(* Check for misconfigured SECINFO flags*)
IF ( (SCRATCH_SECINFO reserved fields are not zero ) or
(SCRATCH_SECINFO.FLAGS.R is 0 and SCRATCH_SECINFO.FLAGS.W is not 0) )
THEN #GP(0); FI;
(* Check concurrency with SGX1 or SGX2 instructions on the EPC page *)
IF (SGX1 or other SGX2 instructions accessing EPC page)
THEN #GP(0); FI;
IF (EPCM(DS:RCX).VALID is 0 )
THEN #PF(DS:RCX); FI;
(* Check the EPC page for concurrency *)
IF (EPC page in use by another SGX2 instruction)
THEN
RFLAGS.ZF := 1;
RAX := SGX_EPC_PAGE_CONFLICT;
GOTO DONE;
FI;
IF (EPCM(DS:RCX).PENDING is not 0 or (EPCM(DS:RCX).MODIFIED is not 0) )
THEN
RFLAGS.ZF := 1;
EMODPR-Restrict the Permissions of an EPC Page
Vol. 3D
41-55
INTEL® SGX INSTRUCTION REFERENCES
RAX := SGX_PAGE_NOT_MODIFIABLE;
GOTO DONE;
FI;
IF (EPCM(DS:RCX).PT is not PT_REG)
THEN #PF(DS:RCX); FI;
TMP_SECS := GET_SECS_ADDRESS
IF (TMP_SECS.ATTRIBUTES.INIT = 0)
THEN #GP(0); FI;
(* Set the PR bit to indicate that permission restriction is in progress *)
EPCM(DS:RCX).PR := 1;
(* Update EPCM permissions *)
EPCM(DS:RCX).R := EPCM(DS:RCX).R & SCRATCH_SECINFO.FLAGS.R;
EPCM(DS:RCX).W := EPCM(DS:RCX).W & SCRATCH_SECINFO.FLAGS.W;
EPCM(DS:RCX).X := EPCM(DS:RCX).X & SCRATCH_SECINFO.FLAGS.X;
RFLAGS.ZF := 0;
RAX := 0;
DONE:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
Sets ZF if page is not modifiable or if other SGX2 instructions are executing concurrently, otherwise cleared. Clears
CF, PF, AF, OF, SF.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If a memory operand is locked.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If a memory operand is locked.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
41-56
Vol. 3D
EMODPR-Restrict the Permissions of an EPC Page
INTEL® SGX INSTRUCTION REFERENCES
EMODT-Change the Type of an EPC Page
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 0FH
IR
V/V
SGX2
This leaf function changes the type of an existing EPC page.
ENCLS[EMODT]
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
EMODT (In)
Return Error Code (Out)
Address of a SECINFO (In)
Address of the destination EPC page (In)
Description
This leaf function modifies the type of an EPC page. The security attributes are configured to prevent access to the
EPC page at its new type until a corresponding invocation of the EACCEPT leaf confirms the modification. This
instruction can only be executed when current privilege level is 0.
RBX contains the effective address of a SECINFO structure while RCX contains the effective address of an EPC
page. The table below provides additional information on the memory parameter of the EMODT leaf function.
EMODT Memory Parameter Semantics
SECINFO
EPCPAGE
Read access permitted by Non Enclave
Read/Write access permitted by Enclave
The instruction faults if any of the following:
EMODT Faulting Conditions
The operands are not properly aligned.
If unsupported security attributes are set.
The Enclave is not initialized.
SECS is locked by another thread.
The EPC page is locked by another thread.
RCX does not contain an effective address of an EPC page in the running enclave.
The EPC page is not valid.
The error codes are:
Table 41-33. EMODT Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EMODT successful.
SGX_PAGE_NOT_MODIFIABLE
The EPC page cannot be modified because it is in the PENDING or MODIFIED state.
SGX_EPC_PAGE_CONFLICT
Page is being written by EADD, EAUG, ECREATE, ELDU/B, EMODPR, or EWB.
Concurrency Restrictions
Table 41-34. Base Concurrency Restrictions of EMODT
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EMODT
Target [DS:RCX]
Exclusive
SGX_EPC_PAGE_CONFLICT
EMODT-Change the Type of an EPC Page
Vol. 3D
41-57
INTEL® SGX INSTRUCTION REFERENCES
Table 41-35. Additional Concurrency Restrictions of EMODT
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EMODT
Target [DS:RCX]
Exclusive
SGX_EP-
Concurrent
Concurrent
C_PAGE_CON-
FLICT
Operation
Temp Variables in EMODT Operational Flow
Name
Type
Size (bits)
Description
TMP_SECS
Effective Address
32/64
Physical address of SECS to which EPC operand belongs.
SCRATCH_SECINFO
SECINFO
512
Scratch storage for holding the contents of DS:RBX.
IF (DS:RBX is not 64Byte Aligned)
THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
SCRATCH_SECINFO := DS:RBX;
(* Check for misconfigured SECINFO flags*)
IF ( (SCRATCH_SECINFO reserved fields are not zero ) or
!(SCRATCH_SECINFO.FLAGS.PT is PT_TCS or SCRATCH_SECINFO.FLAGS.PT is PT_TRIM) )
THEN #GP(0); FI;
(* Check concurrency with SGX1 instructions on the EPC page *)
IF (other SGX1 instructions accessing EPC page)
THEN
RFLAGS.ZF := 1;
RAX := SGX_EPC_PAGE_CONFLICT;
GOTO DONE;
FI;
IF (EPCM(DS:RCX).VALID is 0)
THEN #PF(DS:RCX); FI;
(* Check the EPC page for concurrency *)
IF (EPC page in use by another SGX2 instruction)
THEN
RFLAGS.ZF := 1;
RAX := SGX_EPC_PAGE_CONFLICT;
GOTO DONE;
FI;
41-58
Vol. 3D
EMODT-Change the Type of an EPC Page
INTEL® SGX INSTRUCTION REFERENCES
IF (!(EPCM(DS:RCX).PT is PT_REG or
((EPCM(DS:RCX).PT is PT_TCS or PT_SS_FIRST or PT_SS_REST) and SCRATCH_SECINFO.FLAGS.PT is PT_TRIM)))
THEN #PF(DS:RCX); FI;
IF (EPCM(DS:RCX).PENDING is not 0 or (EPCM(DS:RCX).MODIFIED is not 0) )
THEN
RFLAGS.ZF := 1;
RAX := SGX_PAGE_NOT_MODIFIABLE;
GOTO DONE;
FI;
TMP_SECS := GET_SECS_ADDRESS
IF (TMP_SECS.ATTRIBUTES.INIT = 0)
THEN #GP(0); FI;
(* Update EPCM fields *)
EPCM(DS:RCX).PR := 0;
EPCM(DS:RCX).MODIFIED := 1;
EPCM(DS:RCX).R := 0;
EPCM(DS:RCX).W := 0;
EPCM(DS:RCX).X := 0;
EPCM(DS:RCX).PT := SCRATCH_SECINFO.FLAGS.PT;
RFLAGS.ZF := 0;
RAX := 0;
DONE:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
Sets ZF if page is not modifiable or if other SGX2 instructions are executing concurrently, otherwise cleared. Clears
CF, PF, AF, OF, SF.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If a memory operand is locked.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If a memory operand is locked.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
EMODT-Change the Type of an EPC Page
Vol. 3D
41-59
INTEL® SGX INSTRUCTION REFERENCES
EPA-Add Version Array
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 0AH
IR
V/V
SGX1
This leaf function adds a Version Array to the EPC.
ENCLS[EPA]
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
EPA (In)
PT_VA (In, Constant)
Effective address of the EPC page (In)
Description
This leaf function creates an empty version array in the EPC page whose logical address is given by DS:RCX, and
sets up EPCM attributes for that page. At the time of execution of this instruction, the register RBX must be set to
PT_VA.
The table below provides additional information on the memory parameter of EPA leaf function.
EPA Memory Parameter Semantics
EPCPAGE
Write access permitted by Enclave
Concurrency Restrictions
Table 41-36. Base Concurrency Restrictions of EPA
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EPA
VA [DS:RCX]
Exclusive
#GP
Table 41-37. Additional Concurrency Restrictions of EPA
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EPA
VA [DS:RCX]
Concurrent
L
Concurrent
Concurrent
Operation
IF (RBX ≠ PT_VA or DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* Check concurrency with other Intel SGX instructions *)
IF (Other Intel SGX instructions accessing the page)
THEN
#GP(0); FI;
41-60
Vol. 3D
EPA-Add Version Array
INTEL® SGX INSTRUCTION REFERENCES
(* Check EPC page must be empty *)
IF (EPCM(DS:RCX). VALID ≠ 0)
THEN #PF(DS:RCX); FI;
(* Clears EPC page *)
DS:RCX[32767:0] := 0;
EPCM(DS:RCX).PT := PT_VA;
EPCM(DS:RCX).ENCLAVEADDRESS := 0;
EPCM(DS:RCX).BLOCKED := 0;
EPCM(DS:RCX).PENDING := 0;
EPCM(DS:RCX).MODIFIED := 0;
EPCM(DS:RCX).PR := 0;
EPCM(DS:RCX).RWX := 0;
EPCM(DS:RCX).VALID := 1;
Flags Affected
None
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If another Intel SGX instruction is accessing the EPC page.
If RBX is not set to PT_VA.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
If the EPC page is valid.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If another Intel SGX instruction is accessing the EPC page.
If RBX is not set to PT_VA.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
If the EPC page is valid.
EPA-Add Version Array
Vol. 3D
41-61
INTEL® SGX INSTRUCTION REFERENCES
EREMOVE-Remove a page from the EPC
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 03H
IR
V/V
SGX1
This leaf function removes a page from the EPC.
ENCLS[EREMOVE]
Instruction Operand Encoding
Op/En
EAX
RCX
IR
EREMOVE (In)
Return error code (Out)
Effective address of the EPC page (In)
Description
This leaf function causes an EPC page to be un-associated with its SECS and be marked as unused. This instruction
leaf can only be executed when the current privilege level is 0.
The content of RCX is an effective address of an EPC page. The DS segment is used to create linear address.
Segment override is not supported.
The instruction fails if the operand is not properly aligned or does not refer to an EPC page or the page is in use by
another thread, or other threads are running in the enclave to which the page belongs. In addition the instruction
fails if the operand refers to an SECS with associations.
EREMOVE Memory Parameter Semantics
EPCPAGE
Write access permitted by Enclave
The instruction faults if any of the following:
EREMOVE Faulting Conditions
The memory operand is not properly aligned.
The memory operand does not resolve in an EPC page.
Refers to an invalid SECS.
Refers to an EPC page that is locked by another thread.
Another Intel SGX instruction is accessing the EPC page.
RCX does not contain an effective address of an EPC page.
the EPC page refers to an SECS with associations.
The error codes are:
Table 41-38. EREMOVE Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EREMOVE successful.
SGX_CHILD_PRESENT
If the SECS still have enclave pages loaded into EPC.
SGX_ENCLAVE_ACT
If there are still logical processors executing inside the enclave.
41-62
Vol. 3D
EREMOVE-Remove a page from the EPC
INTEL® SGX INSTRUCTION REFERENCES
Concurrency Restrictions
Table 41-39. Base Concurrency Restrictions of EREMOVE
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EREMOVE
Target [DS:RCX]
Exclusive
#GP
Table 41-40. Additional Concurrency Restrictions of EREMOVE
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EREMOVE
Target [DS:RCX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in EREMOVE Operational Flow
Name
Type
Size (Bits)
Description
TMP_SECS
Effective Address
32/64
Effective address of the SECS destination page.
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve to an EPC page)
THEN #PF(DS:RCX); FI;
TMP_SECS := Get_SECS_ADDRESS();
(* Check the EPC page for concurrency *)
IF (EPC page being referenced by another Intel SGX instruction)
THEN
#GP(0); FI;
(* if DS:RCX is already unused, nothing to do*)
IF ( (EPCM(DS:RCX).VALID = 0) or (EPCM(DS:RCX).PT = PT_TRIM AND EPCM(DS:RCX).MODIFIED = 0))
THEN GOTO DONE;
FI;
IF ( (EPCM(DS:RCX).PT = PT_VA) OR
((EPCM(DS:RCX).PT = PT_TRIM) AND (EPCM(DS:RCX).MODIFIED = 0)) )
THEN
EPCM(DS:RCX).VALID := 0;
GOTO DONE;
FI;
IF (EPCM(DS:RCX).PT = PT_SECS)
THEN
IF (DS:RCX has an EPC page associated with it)
THEN
EREMOVE-Remove a page from the EPC
Vol. 3D
41-63
INTEL® SGX INSTRUCTION REFERENCES
RFLAGS.ZF := 1;
RAX := SGX_CHILD_PRESENT;
GOTO ERROR_EXIT;
FI;
EPCM(DS:RCX).VALID := 0;
GOTO DONE;
FI;
IF (Other threads active using SECS)
THEN
RFLAGS.ZF := 1;
RAX := SGX_ENCLAVE_ACT;
GOTO ERROR_EXIT;
FI;
IF ( (EPCM(DS:RCX).PT is PT_REG) or (EPCM(DS:RCX).PT is PT_TCS) or (EPCM(DS:RCX).PT is PT_TRIM) or
(EPCM(DS:RCX).PT is PT_SS_FIRST) or (EPCM(DS:RCX).PT is PT_SS_REST))
THEN
EPCM(DS:RCX).VALID := 0;
GOTO DONE;
FI;
DONE:
RAX := 0;
RFLAGS.ZF := 0;
ERROR_EXIT:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
Sets ZF if unsuccessful, otherwise cleared and RAX returns error code. Clears CF, PF, AF, OF, SF.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If another Intel SGX instruction is accessing the page.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the memory operand is not an EPC page.
64-Bit Mode Exceptions
#GP(0)
If the memory operand is non-canonical form.
If a memory operand is not properly aligned.
If another Intel SGX instruction is accessing the page.
#PF(error code)
If a page fault occurs in accessing memory operands.
If the memory operand is not an EPC page.
41-64
Vol. 3D
EREMOVE-Remove a page from the EPC
INTEL® SGX INSTRUCTION REFERENCES
ETRACK-Activates EBLOCK Checks
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 0CH
IR
V/V
SGX1
This leaf function activates EBLOCK checks.
ENCLS[ETRACK]
Instruction Operand Encoding
Op/En
EAX
RCX
IR
ETRACK (In)
Return error code (Out)
Pointer to the SECS of the EPC page (In)
Description
This leaf function provides the mechanism for hardware to track that software has completed the required TLB
address clears successfully. The instruction can only be executed when the current privilege level is 0.
The content of RCX is an effective address of an EPC page.
The table below provides additional information on the memory parameter of ETRACK leaf function.
ETRACK Memory Parameter Semantics
EPCPAGE
Read/Write access permitted by Enclave
The error codes are:
Table 41-41. ETRACK Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
ETRACK successful.
SGX_PREV_TRK_INCMPL
All processors did not complete the previous shoot-down sequence.
Concurrency Restrictions
Table 41-42. Base Concurrency Restrictions of ETRACK
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
ETRACK
SECS [DS:RCX]
Shared
#GP
Table 41-43. Additional Concurrency Restrictions of ETRACK
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
ETRACK
SECS [DS:RCX]
Concurrent
Concurrent
Exclusive
SGX_EP-
C_PAGE_CON-
FLICT
ETRACK-Activates EBLOCK Checks
Vol. 3D
41-65
INTEL® SGX INSTRUCTION REFERENCES
Operation
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* Check concurrency with other Intel SGX instructions *)
IF (Other Intel SGX instructions using tracking facility on this SECS)
THEN
#GP(0); FI;
IF (EPCM(DS:RCX). VALID = 0)
THEN #PF(DS:RCX); FI;
IF (EPCM(DS:RCX).PT ≠ PT_SECS)
THEN #PF(DS:RCX); FI;
(* All processors must have completed the previous tracking cycle*)
IF ( (DS:RCX).TRACKING ≠ 0) )
THEN
RFLAGS.ZF := 1;
RAX := SGX_PREV_TRK_INCMPL;
GOTO DONE;
ELSE
RAX := 0;
RFLAGS.ZF := 0;
FI;
DONE:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
Sets ZF if SECS is in use or invalid, otherwise cleared. Clears CF, PF, AF, OF, SF.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If another thread is concurrently using the tracking facility on this SECS.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If the specified EPC resource is in use.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
41-66
Vol. 3D
ETRACK-Activates EBLOCK Checks
INTEL® SGX INSTRUCTION REFERENCES
EUPDATESVN-Update CR_CPUSVN
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 18H
None
V/V
Bit 10
This leaf function updates the CR_CPUSVN if microcode has been
ENCLS[EUPDATESVN]
updated and EPC is ready.
Description
If EPC is ready for SVN update, this leaf function updates CR_CPUSVN to the currently loaded microcode update
SVN and generates new cryptographic assets. The EPC is ready when no page in the EPC is valid. EREMOVE should
be used to mark all pages as unused.
It is the responsibility of system software to ensure that no other thread is executing or attempts to execute any
ENCLS leaf while executing EUPDATESVN. Concurrency violations between EUPDATESVN and some ENCLS leaves
may cause the ENCLS leaf to generate #GP(0) in ways unexpected to legacy software. System software should also
prevent unnecessary software from having access to EUPDATESVN. For example, enable ENCLS exiting should be
used to prevent VMs that are not part of the management system software from using EUPDATESVN.
The EUPDATESVN leaf function fails if an ENCLS instruction is in progress on any thread, the EPC is not ready for
an update, or there is insufficient entropy in the random number generator. The ZF flag will be set to indicate an
error and a code returned in RAX. If EUPDATESVN was successful but CR_CPUSVN was already up to date, the CF
flag will be set and RAX will indicate that no update occurred.
If insufficient entropy causes a failure, software should repeat the instruction.
The error codes are:
Table 41-44. EUPDATESVN Return Value in RAX
Error Code (see Table 41-3)
Value
Description
No Error
0
EUPDATESVN successful.
SGX_EPC_PAGE_CONFLICT
7
An instruction concurrency rule was violated.
SGX_INSUFFICIENT_ENTROPY
29
RNG contains insufficient entropy.
SGX_EPC_NOT_READY
30
EPC is not ready for SVN update.
SGX_NO_UPDATE
31
EUPDATESVN was successful, but CR_CPUSVN was not updated because
the current SVN is older than CR_CPUSVN.
Concurrency Restrictions
Table 41-45. Base Concurrency Restrictions of EUPDATESVN
Base Concurrency Restrictions
Leaf
Access
On Conflict
EUPDATESVN
Exclusive
SGX_EPC_PAGE_CONFLICT
Table 41-46. Additional Concurrency Restrictions of EUPDATESVN
Additional Concurrency Restrictions
Leaf
vs. EADD, EAUG, ECREATE, ELDB, EPA, EREMOVE, EWB
Access
On Conflict
EUPDATESVN
Exclusive
SGX_EPC_PAGE_CONFLICT
EUPDATESVN-Update CR_CPUSVN
Vol. 3D
41-67
INTEL® SGX INSTRUCTION REFERENCES
Operation
Temp Variables in EUPDATESVN Operational Flow
Name
Type
Size (Bytes)
Description
TMP_CPUSVN
CPUSVN
16
Temporary copy of CR_CPUSVN prior to update.
TMP_KEY
Key
16
Temporary copy of new paging key.
RFLAGS.ZF,CF,PF,AF,OF,SF := 0;
RAX := 0;
IF (Other logical processor is executing an SGX instruction that accesses EPC) THEN
RFLAGS.ZF := 1
RAX := SGX_EPC_PAGE_CONFLICT;
GOTO ERROR_EXIT;
FI
(* Verify EPC is ready *)
IF (the EPC contains any valid pages) THEN
RFLAGS.ZF := 1;
RAX := SGX_EPC_NOT_READY;
GOTO ERROR_EXIT;
FI
(* Refresh paging key *)
TMP_KEY = (* Generate a 128-bit cryptographically random number *)
IF (insufficient entropy available) THEN
RFLAGS.ZF := 1;
RAX := SGX_INSUFFICIENT_ENTROPY;
GOTO ERROR_EXIT;
FI
(* Commit *)
TMP_CPUSVN := CR_CPUSVN;
(* Update CR_CPUSVN to reflect current microcode update SVN *)
(* Determine if info status is needed *)
IF (TMP_CPUSVN = CR_CPUSVN) THEN
RFLAGS.CF := 1;
RAX := SGX_NO_UPDATE;
ELSE
CR_BASE_PK := TMP_KEY[127:0];
FI
ERROR_EXIT:
Flags Affected
ZF is set if an error occurs; otherwise, cleared.
CF is set when the instruction is completed successfully and no SVN update was needed.
PF, AF, OF, and SF are cleared.
41-68
Vol. 3D
EUPDATESVN-Update CR_CPUSVN
INTEL® SGX INSTRUCTION REFERENCES
EWB-Invalidate an EPC Page and Write out to Main Memory
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 0BH
IR
V/V
SGX1
This leaf function invalidates an EPC page and writes it out to
ENCLS[EWB]
main memory.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
RDX
IR
EWB (In)
Error code (Out)
Address of an PAGEINFO (In)
Address of the EPC page (In)
Address of a VA slot (In)
Description
This leaf function copies a page from the EPC to regular main memory. As part of the copying process, the page is
cryptographically protected. This instruction can only be executed when current privilege level is 0.
The table below provides additional information on the memory parameter of EPA leaf function.
EWB Memory Parameter Semantics
PAGEINFO
PAGEINFO.SRCPGE
PAGEINFO.PCMD
EPCPAGE
VASLOT
Non-EPC R/W access
Non-EPC R/W access
Non-EPC R/W access
EPC R/W access
EPC R/W access
The error codes are:
Table 41-47. EWB Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EWB successful.
SGX_PAGE_NOT_BLOCKED
If page is not marked as blocked.
SGX_NOT_TRACKED
If EWB is racing with ETRACK instruction.
SGX_VA_SLOT_OCCUPIED
Version array slot contained valid entry.
SGX_CHILD_PRESENT
Child page present while attempting to page out enclave.
Concurrency Restrictions
Table 41-48. Base Concurrency Restrictions of EWB
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EWB
Source [DS:RCX]
Exclusive
#GP
VA [DS:RDX]
Shared
#GP
Table 41-49. Additional Concurrency Restrictions of EWB
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EWB
Source [DS:RCX]
Concurrent
Concurrent
Concurrent
VA [DS:RDX]
Concurrent
Concurrent
Exclusive
EWB-Invalidate an EPC Page and Write out to Main Memory
Vol. 3D
41-69
INTEL® SGX INSTRUCTION REFERENCES
Operation
Temp Variables in EWB Operational Flow
Name
Type
Size (Bytes)
Description
TMP_SRCPGE
Memory page
4096
TMP_PCMD
PCMD
128
TMP_SECS
SECS
4096
TMP_BPEPOCH
UINT64
8
TMP_BPREFCOUNT
UINT64
8
TMP_HEADER
MAC Header
128
TMP_PCMD_ENCLAVEID
UINT64
8
TMP_VER
UINT64
8
TMP_PK
UINT128
16
IF ( (DS:RBX is not 32Byte Aligned) or (DS:RCX is not 4KByte Aligned) )
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
IF (DS:RDX is not 8Byte Aligned)
THEN #GP(0); FI;
IF (DS:RDX does not resolve within an EPC)
THEN #PF(DS:RDX); FI;
(* EPCPAGE and VASLOT should not resolve to the same EPC page*)
IF (DS:RCX and DS:RDX resolve to the same EPC page)
THEN #GP(0); FI;
TMP_SRCPGE := DS:RBX.SRCPGE;
(* Note PAGEINFO.PCMD is overlaid on top of PAGEINFO.SECINFO *)
TMP_PCMD := DS:RBX.PCMD;
If (DS:RBX.LINADDR ≠ 0) OR (DS:RBX.SECS ≠ 0)
THEN #GP(0); FI;
IF ( (DS:TMP_PCMD is not 128Byte Aligned) or (DS:TMP_SRCPGE is not 4KByte Aligned) )
THEN #GP(0); FI;
(* Check for concurrent Intel SGX instruction access to the page *)
IF (Other Intel SGX instruction is accessing page)
THEN
#GP(0); FI;
(*Check if the VA Page is being removed or changed*)
IF (VA Page is being modified)
THEN #GP(0); FI;
41-70
Vol. 3D
EWB-Invalidate an EPC Page and Write out to Main Memory
INTEL® SGX INSTRUCTION REFERENCES
(* Verify that EPCPAGE and VASLOT page are valid EPC pages and DS:RDX is VA *)
IF (EPCM(DS:RCX).VALID = 0)
THEN #PF(DS:RCX); FI;
IF ( (EPCM(DS:RDX & ~0FFFH).VALID = 0) or (EPCM(DS:RDX & ~FFFH).PT is not PT_VA) )
THEN #PF(DS:RDX); FI;
(* Perform page-type-specific exception checks *)
IF ( (EPCM(DS:RCX).PT is PT_REG) or (EPCM(DS:RCX).PT is PT_TCS) or (EPCM(DS:RCX).PT is PT_TRIM ) or
(EPCM(DS:RCX).PT is PT_SS_FIRST ) or (EPCM(DS:RCX).PT is PT_SS_REST))
THEN
TMP_SECS = Obtain SECS through EPCM(DS:RCX)
(* Check that EBLOCK has occurred correctly *)
IF (EBLOCK is not correct)
THEN #GP(0); FI;
FI;
RFLAGS.ZF,CF,PF,AF,OF,SF := 0;
RAX := 0;
(* Zero out TMP_HEADER*)
TMP_HEADER[ sizeof(TMP_HEADER) - 1 : 0] := 0;
(* Perform page-type-specific checks *)
IF ( (EPCM(DS:RCX).PT is PT_REG) or (EPCM(DS:RCX).PT is PT_TCS) or (EPCM(DS:RCX).PT is PT_TRIM )or
(EPCM(DS:RCX).PT is PT_SS_FIRST ) or (EPCM(DS:RCX).PT is PT_SS_REST))
THEN
(* check to see if the page is evictable *)
IF (EPCM(DS:RCX).BLOCKED = 0)
THEN
RAX := SGX_PAGE NOT_BLOCKED;
RFLAGS.ZF := 1;
GOTO ERROR_EXIT;
FI;
(* Check if tracking done correctly *)
IF (Tracking not correct)
THEN
RAX := SGX_NOT_TRACKED;
RFLAGS.ZF := 1;
GOTO ERROR_EXIT;
FI;
(* Obtain EID to establish cryptographic binding between the paged-out page and the enclave *)
TMP_HEADER.EID := TMP_SECS.EID;
(* Obtain EID as an enclave handle for software *)
TMP_PCMD_ENCLAVEID := TMP_SECS.EID;
ELSE IF (EPCM(DS:RCX).PT is PT_SECS)
(*check that there are no child pages inside the enclave *)
IF (DS:RCX has an EPC page associated with it)
THEN
RAX := SGX_CHILD_PRESENT;
RFLAGS.ZF := 1;
GOTO ERROR_EXIT;
EWB-Invalidate an EPC Page and Write out to Main Memory
Vol. 3D
41-71
INTEL® SGX INSTRUCTION REFERENCES
FI:
TMP_HEADER.EID := 0;
(* Obtain EID as an enclave handle for software *)
TMP_PCMD_ENCLAVEID := (DS:RCX).EID;
ELSE IF (EPCM(DS:RCX).PT is PT_VA)
TMP_HEADER.EID := 0; // Zero is not a special value
(* No enclave handle for VA pages*)
TMP_PCMD_ENCLAVEID := 0;
FI;
TMP_HEADER.LINADDR := EPCM(DS:RCX).ENCLAVEADDRESS;
TMP_HEADER.SECINFO.FLAGS.PT := EPCM(DS:RCX).PT;
TMP_HEADER.SECINFO.FLAGS.RWX := EPCM(DS:RCX).RWX;
TMP_HEADER.SECINFO.FLAGS.PENDING := EPCM(DS:RCX).PENDING;
TMP_HEADER.SECINFO.FLAGS.MODIFIED := EPCM(DS:RCX).MODIFIED;
TMP_HEADER.SECINFO.FLAGS.PR := EPCM(DS:RCX).PR;
(* Encrypt the page, DS:RCX could be encrypted in place. AES-GCM produces 2 values, {ciphertext, MAC}. *)
(* AES-GCM input parameters: key, GCM Counter, MAC_HDR, MAC_HDR_SIZE, SRC, SRC_SIZE)*)
{DS:TMP_SRCPGE, DS:TMP_PCMD.MAC} := AES_GCM_ENC(CR_BASE_PK), (TMP_VER << 32),
TMP_HEADER, 128, DS:RCX, 4096);
(* Write the output *)
Zero out DS:TMP_PCMD.SECINFO
DS:TMP_PCMD.SECINFO.FLAGS.PT := EPCM(DS:RCX).PT;
DS:TMP_PCMD.SECINFO.FLAGS.RWX := EPCM(DS:RCX).RWX;
DS:TMP_PCMD.SECINFO.FLAGS.PENDING := EPCM(DS:RCX).PENDING;
DS:TMP_PCMD.SECINFO.FLAGS.MODIFIED := EPCM(DS:RCX).MODIFIED;
DS:TMP_PCMD.SECINFO.FLAGS.PR := EPCM(DS:RCX).PR;
DS:TMP_PCMD.RESERVED := 0;
DS:TMP_PCMD.ENCLAVEID := TMP_PCMD_ENCLAVEID;
DS:RBX.LINADDR := EPCM(DS:RCX).ENCLAVEADDRESS;
(*Check if version array slot was empty *)
IF ([DS.RDX])
THEN
RAX := SGX_VA_SLOT_OCCUPIED
RFLAGS.CF := 1;
FI;
(* Write version to Version Array slot *)
[DS.RDX] := TMP_VER;
(* Free up EPCM Entry *)
EPCM.(DS:RCX).VALID := 0;
ERROR_EXIT:
Flags Affected
ZF is set if page is not blocked, not tracked, or a child is present. Otherwise cleared.
CF is set if VA slot is previously occupied, Otherwise cleared.
Protected Mode Exceptions
#GP(0)
If a memory operand effective address is outside the DS segment limit.
41-72
Vol. 3D
EWB-Invalidate an EPC Page and Write out to Main Memory
INTEL® SGX INSTRUCTION REFERENCES
If a memory operand is not properly aligned.
If the EPC page and VASLOT resolve to the same EPC page.
If another Intel SGX instruction is concurrently accessing either the target EPC, VA, or SECS
pages.
If the tracking resource is in use.
If the EPC page or the version array page is invalid.
If the parameters fail consistency checks.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
If one of the EPC memory operands has incorrect page type.
64-Bit Mode Exceptions
#GP(0)
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If the EPC page and VASLOT resolve to the same EPC page.
If another Intel SGX instruction is concurrently accessing either the target EPC, VA, or SECS
pages.
If the tracking resource is in use.
If the EPC page or the version array page in invalid.
If the parameters fail consistency checks.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
If one of the EPC memory operands has incorrect page type.
41.4
INTEL® SGX USER LEAF FUNCTION REFERENCE
Leaf functions available with the ENCLU instruction mnemonic are covered in this section. In general, each instruc-
tion leaf requires EAX to specify the leaf function index and/or additional registers specifying leaf-specific input
parameters. An instruction operand encoding table provides details of the implicitly-encoded register usage and
associated input/output semantics.
In many cases, an input parameter specifies an effective address associated with a memory object inside or
outside the EPC, the memory addressing semantics of these memory objects are also summarized in a separate
table.
EWB-Invalidate an EPC Page and Write out to Main Memory
Vol. 3D
41-73
INTEL® SGX INSTRUCTION REFERENCES
EACCEPT-Accept Changes to an EPC Page
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 05H
IR
V/V
SGX2
This leaf function accepts changes made by system software to
ENCLU[EACCEPT]
an EPC page in the running enclave.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
IR
EACCEPT (In)
Return Error Code (Out)
Address of a SECINFO (In)
Address of the destination EPC page (In)
Description
This leaf function accepts changes to a page in the running enclave by verifying that the security attributes speci-
fied in the SECINFO match the security attributes of the page in the EPCM. This instruction leaf can only be
executed when inside the enclave.
RBX contains the effective address of a SECINFO structure while RCX contains the effective address of an EPC page.
The table below provides additional information on the memory parameter of the EACCEPT leaf function.
EACCEPT Memory Parameter Semantics
SECINFO
EPCPAGE (Destination)
Read access permitted by Non Enclave
Read access permitted by Enclave
The instruction faults if any of the following:
EACCEPT Faulting Conditions
The operands are not properly aligned.
RBX does not contain an effective address in an EPC page in the running enclave.
The EPC page is locked by another thread.
RCX does not contain an effective address of an EPC page in the running enclave.
The EPC page is not valid.
Page type is PT_REG and MODIFIED bit is 0.
SECINFO contains an invalid request.
Page type is PT_TCS or PT_TRIM and PENDING bit is 0 and MODIFIED bit is 1.
If security attributes of the SECINFO page make
the page inaccessible.
The error codes are:
Table 41-50. EACCEPT Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EACCEPT successful.
SGX_PAGE_ATTRIBUTES_MISMATCH
The attributes of the target EPC page do not match the expected values.
SGX_NOT_TRACKED
The OS did not complete an ETRACK on the target page.
41-74
Vol. 3D
EACCEPT-Accept Changes to an EPC Page
INTEL® SGX INSTRUCTION REFERENCES
Concurrency Restrictions
Table 41-51. Base Concurrency Restrictions of EACCEPT
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EACCEPT
Target [DS:RCX]
Shared
#GP
SECINFO [DS:RBX]
Concurrent
Table 41-52. Additional Concurrency Restrictions of EACCEPT
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EACCEPT
Target [DS:RCX]
Exclusive
#GP
Concurrent
Concurrent
SECINFO [DS:RBX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in EACCEPT Operational Flow
Name
Type
Size (bits)
Description
TMP_SECS
Effective Address
32/64
Physical address of SECS to which EPC operands belongs.
SCRATCH_SECINFO
SECINFO
512
Scratch storage for holding the contents of DS:RBX.
IF (DS:RBX is not 64Byte Aligned)
THEN #GP(0); FI;
IF (DS:RBX is not within CR_ELRANGE)
THEN #GP(0); FI;
IF (DS:RBX does not resolve within an EPC)
THEN #PF(DS:RBX); FI;
IF ( (EPCM(DS:RBX &~FFFH).VALID = 0) or (EPCM(DS:RBX &~FFFH).R = 0) or (EPCM(DS:RBX &~FFFH).PENDING ≠ 0) or
(EPCM(DS:RBX &~FFFH).MODIFIED ≠ 0) or (EPCM(DS:RBX &~FFFH).BLOCKED ≠ 0) or
(EPCM(DS:RBX &~FFFH).PT ≠ PT_REG) or (EPCM(DS:RBX &~FFFH).ENCLAVESECS ≠ CR_ACTIVE_SECS) or
(EPCM(DS:RBX &~FFFH).ENCLAVEADDRESS ≠ (DS:RBX & FFFH)) )
THEN #PF(DS:RBX); FI;
(* Copy 64 bytes of contents *)
SCRATCH_SECINFO := DS:RBX;
(* Check for misconfigured SECINFO flags*)
IF (SCRATCH_SECINFO reserved fields are not zero )
THEN #GP(0); FI;
IF (DS:RCX is not 4KByte Aligned)
THEN #GP(0); FI;
EACCEPT-Accept Changes to an EPC Page
Vol. 3D
41-75
INTEL® SGX INSTRUCTION REFERENCES
IF (DS:RCX is not within CR_ELRANGE)
THEN #GP(0); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
(* Check that the combination of requested PT, PENDING, and MODIFIED is legal *)
IF (CPUID.12H.01H:EAX[6] = 0 )
THEN
IF (NOT (((SCRATCH_SECINFO.FLAGS.PT is PT_REG) and
((SCRATCH_SECINFO.FLAGS.PR is 1) or
(SCRATCH_SECINFO.FLAGS.PENDING is 1)) and
(SCRATCH_SECINFO.FLAGS.MODIFIED is 0)) or
((SCRATCH_SECINFO.FLAGS.PT is PT_TCS or PT_TRIM) and
(SCRATCH_SECINFO.FLAGS.PR is 0) and
(SCRATCH_SECINFO.FLAGS.PENDING is 0) and
(SCRATCH_SECINFO.FLAGS.MODIFIED is 1) )))
THEN #GP(0); FI
ELSE
IF (NOT (((SCRATCH_SECINFO.FLAGS.PT is PT_REG) AND
((SCRATCH_SECINFO.FLAGS.PR is 1) OR
(SCRATCH_SECINFO.FLAGS.PENDING is 1)) AND
(SCRATCH_SECINFO.FLAGS.MODIFIED is 0)) OR
((SCRATCH_SECINFO.FLAGS.PT is PT_TCS OR PT_TRIM) AND
(SCRATCH_SECINFO.FLAGS.PENDING is 0) AND
(SCRATCH_SECINFO.FLAGS.MODIFIED is 1) AND
(SCRATCH_SECINFO.FLAGS.PR is 0)) OR
((SCRATCH_SECINFO.FLAGS.PT is PT_SS_FIRST or PT_SS_REST) AND
(SCRATCH_SECINFO.FLAGS.PENDING is 1) AND
(SCRATCH_SECINFO.FLAGS.MODIFIED is 0) AND
(SCRATCH_SECINFO.FLAGS.PR is 0))))
THEN #GP(0); FI;
FI;
(* Check security attributes of the destination EPC page *)
IF ( (EPCM(DS:RCX).VALID is 0) or (EPCM(DS:RCX).BLOCKED is not 0) or
((EPCM(DS:RCX).PT is not PT_REG) and (EPCM(DS:RCX).PT is not PT_TCS) and (EPCM(DS:RCX).PT is not PT_TRIM)
and (EPCM(DS:RCX).PT is not PT_SS_FIRST) and (EPCM(DS:RCX).PT is not PT_SS_REST)) or
(EPCM(DS:RCX).ENCLAVESECS ≠ CR_ACTIVE_SECS))
THEN #PF((DS:RCX); FI;
(* Check the destination EPC page for concurrency *)
IF ( EPC page in use )
THEN #GP(0); FI;
(* Re-Check security attributes of the destination EPC page *)
IF ( (EPCM(DS:RCX).VALID is 0) or (EPCM(DS:RCX).ENCLAVESECS ≠ CR_ACTIVE_SECS) )
THEN #PF(DS:RCX); FI;
(* Verify that accept request matches current EPC page settings *)
IF ( (EPCM(DS:RCX).ENCLAVEADDRESS ≠ DS:RCX) or (EPCM(DS:RCX).PENDING ≠ SCRATCH_SECINFO.FLAGS.PENDING) or
(EPCM(DS:RCX).MODIFIED ≠ SCRATCH_SECINFO.FLAGS.MODIFIED) or (EPCM(DS:RCX).R ≠ SCRATCH_SECINFO.FLAGS.R) or
(EPCM(DS:RCX).W ≠ SCRATCH_SECINFO.FLAGS.W) or (EPCM(DS:RCX).X ≠ SCRATCH_SECINFO.FLAGS.X) or
(EPCM(DS:RCX).PT ≠ SCRATCH_SECINFO.FLAGS.PT) )
41-76
Vol. 3D
EACCEPT-Accept Changes to an EPC Page
INTEL® SGX INSTRUCTION REFERENCES
THEN
RFLAGS.ZF := 1;
RAX := SGX_PAGE_ATTRIBUTES_MISMATCH;
GOTO DONE;
FI;
(* Check that all required threads have left enclave *)
IF (Tracking not correct)
THEN
RFLAGS.ZF := 1;
RAX := SGX_NOT_TRACKED;
GOTO DONE;
FI;
(* Get pointer to the SECS to which the EPC page belongs *)
TMP_SECS = << Obtain physical address of SECS through EPCM(DS:RCX)>>
(* For TCS pages, perform additional checks *)
IF (SCRATCH_SECINFO.FLAGS.PT = PT_TCS)
THEN
IF (DS:RCX.RESERVED ≠ 0) #GP(0); FI;
(* Check that TCS.FLAGS.DBGOPTIN, TCS stack, and TCS status are correctly initialized *)
(* check that TCS.PREVSSP is 0 *)
IF ( ((DS:RCX).FLAGS.DBGOPTIN is not 0) or ((DS:RCX).CSSA ≥ (DS:RCX).NSSA) or ((DS:RCX).AEP is not 0) or ((DS:RCX).STATE is not 0) or
((CPUID.07H.00H:ECX.CET_SS = 1) AND ((DS:RCX).PREVSSP != 0)))
THEN #GP(0); FI;
(* Check consistency of FS & GS Limit *)
IF ( (TMP_SECS.ATTRIBUTES.MODE64BIT is 0) and ((DS:RCX.FSLIMIT & FFFH ≠ FFFH) or (DS:RCX.GSLIMIT & FFFH ≠ FFFH)) )
THEN #GP(0); FI;
FI;
(* Clear PENDING/MODIFIED flags to mark accept operation complete *)
EPCM(DS:RCX).PENDING := 0;
EPCM(DS:RCX).MODIFIED := 0;
EPCM(DS:RCX).PR := 0;
(* Clear EAX and ZF to indicate successful completion *)
RFLAGS.ZF := 0;
RAX := 0;
DONE:
RFLAGS.CF,PF,AF,OF,SF := 0;
Flags Affected
Sets ZF if page cannot be accepted, otherwise cleared. Clears CF, PF, AF, OF, SF
EACCEPT-Accept Changes to an EPC Page
Vol. 3D
41-77
INTEL® SGX INSTRUCTION REFERENCES
Protected Mode Exceptions
#GP(0)
If executed outside an enclave.
If a memory operand effective address is outside the DS segment limit.
If a memory operand is not properly aligned.
If a memory operand is locked.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
If EPC page has incorrect page type or security attributes.
64-Bit Mode Exceptions
#GP(0)
If executed outside an enclave.
If a memory operand is non-canonical form.
If a memory operand is not properly aligned.
If a memory operand is locked.
#PF(error code)
If a page fault occurs in accessing memory operands.
If a memory operand is not an EPC page.
If EPC page has incorrect page type or security attributes.
41-78
Vol. 3D
EACCEPT-Accept Changes to an EPC Page
INTEL® SGX INSTRUCTION REFERENCES
EACCEPTCOPY-Initialize a Pending Page
Opcode/
Op/En
64/32
CPUID
Description
Instruction
bit Mode
Feature
Support
Flag
EAX = 07H
IR
V/V
SGX2
This leaf function initializes a dynamically allocated EPC page
ENCLU[EACCEPTCOPY]
from another page in the EPC.
Instruction Operand Encoding
Op/En
EAX
RBX
RCX
RDX
Return Error Code
Address of the destina-
Address of the
IR
EACCEPTCOPY (In)
Address of a SECINFO (In)
(Out)
tion EPC page (In)
source EPC page (In)
Description
This leaf function copies the contents of an existing EPC page into an uninitialized EPC page (created by EAUG).
After initialization, the instruction may also modify the access rights associated with the destination EPC page. This
instruction leaf can only be executed when inside the enclave.
RBX contains the effective address of a SECINFO structure while RCX and RDX each contain the effective address
of an EPC page. The table below provides additional information on the memory parameter of the EACCEPTCOPY
leaf function.
EACCEPTCOPY Memory Parameter Semantics
SECINFO
EPCPAGE (Destination)
EPCPAGE (Source)
Read access permitted by Non Enclave
Read/Write access permitted by Enclave
Read access permitted by Enclave
The instruction faults if any of the following:
EACCEPTCOPY Faulting Conditions
The operands are not properly aligned.
If security attributes of the SECINFO page make the page inaccessible.
The EPC page is locked by another thread.
If security attributes of the source EPC page make the page inaccessible.
The EPC page is not valid.
RBX does not contain an effective address in an EPC page in the running enclave.
SECINFO contains an invalid request.
RCX/RDX does not contain an effective address of an EPC page in the running
enclave.
The error codes are:
Table 41-53. EACCEPTCOPY Return Value in RAX
Error Code (see Table 41-3)
Description
No Error
EACCEPTCOPY successful.
SGX_PAGE_ATTRIBUTES_MISMATCH
The attributes of the target EPC page do not match the expected values.
EACCEPTCOPY-Initialize a Pending Page
Vol. 3D
41-79
INTEL® SGX INSTRUCTION REFERENCES
Concurrency Restrictions
Table 41-54. Base Concurrency Restrictions of EACCEPTCOPY
Base Concurrency Restrictions
Leaf
Parameter
Access
On Conflict
EACCEPTCOPY
Target [DS:RCX]
Concurrent
Source [DS:RDX]
Concurrent
SECINFO [DS:RBX]
Concurrent
Table 41-55. Additional Concurrency Restrictions of EACCEPTCOPY
Additional Concurrency Restrictions
vs. EACCEPT, EACCEPTCOPY,
Leaf
Parameter
vs. EADD, EEXTEND, EINIT
vs. ETRACK
EMODPE, EMODPR, EMODT
Access
On Conflict
Access
On Conflict
Access
On Conflict
EACCEPTCOPY
Target [DS:RCX]
Exclusive
#GP
Concurrent
Concurrent
Source [DS:RDX]
Concurrent
Concurrent
Concurrent
SECINFO [DS:RBX]
Concurrent
Concurrent
Concurrent
Operation
Temp Variables in EACCEPTCOPY Operational Flow
Name
Type
Size (bits)
Description
SCRATCH_SECINFO
SECINFO
512
Scratch storage for holding the contents of DS:RBX.
IF (DS:RBX is not 64Byte Aligned)
THEN #GP(0); FI;
IF ( (DS:RCX is not 4KByte Aligned) or (DS:RDX is not 4KByte Aligned) )
THEN #GP(0); FI;
IF ((DS:RBX is not within CR_ELRANGE) or (DS:RCX is not within CR_ELRANGE) or (DS:RDX is not within CR_ELRANGE))
THEN #GP(0); FI;
IF (DS:RBX does not resolve within an EPC)
THEN #PF(DS:RBX); FI;
IF (DS:RCX does not resolve within an EPC)
THEN #PF(DS:RCX); FI;
IF (DS:RDX does not resolve within an EPC)
THEN #PF(DS:RDX); FI;
IF ( (EPCM(DS:RBX &~FFFH).VALID = 0) or (EPCM(DS:RBX &~FFFH).R = 0) or (EPCM(DS:RBX &~FFFH).PENDING ≠ 0) or
(EPCM(DS:RBX &~FFFH).MODIFIED ≠ 0) or (EPCM(DS:RBX &~FFFH).BLOCKED ≠ 0) or (EPCM(DS:RBX &~FFFH).PT ≠ PT_REG) or
(EPCM(DS:RBX &~FFFH).ENCLAVESECS ≠ CR_ACTIVE_SECS) or
(EPCM(DS:RBX &~FFFH).ENCLAVEADDRESS ≠ DS:RBX) )
THEN #PF(DS:RBX); FI;
41-80
Vol. 3D
EACCEPTCOPY-Initialize a Pending Page
INTEL® SGX INSTRUCTION REFERENCES
(* Copy 64 bytes of contents *)
SCRATCH_SECINFO := DS:RBX;
(* Check for misconfigured SECINFO flags*)
IF ( (SCRATCH_SECINFO reserved fields are not zero ) or (SCRATCH_SECINFO.FLAGS.R=0) AND(SCRATCH_SECINFO.FLAGS.W≠0 ) or
(SCRATCH_SECINFO.FLAGS.PT is not PT_REG) )
THEN #GP(0); FI;
(* Check security attributes of the source EPC page *)
IF ( (EPCM(DS:RDX).VALID = 0) or (EPCM(DS:RCX).R = 0) or (EPCM(DS:RDX).PENDING ≠ 0) or (EPCM(DS:RDX).MODIFIED ≠ 0) or
(EPCM(DS:RDX).BLOCKED ≠ 0) or (EPCM(DS:RDX).PT ≠ PT_REG) or (EPCM(DS:RDX).ENCLAVESECS ≠ CR_ACTIVE_SECS) or
(EPCM(DS:RDX).ENCLAVEADDRESS ≠ DS:RDX))
THEN #PF(DS:RDX); FI;
(* Check security attributes of the destination EPC page *)
IF ( (EPCM(DS:RCX).VALID = 0) or (EPCM(DS:RCX).PENDING ≠ 1) or (EPCM(DS:RCX).MODIFIED ≠ 0) or
(EPCM(DS:RDX).BLOCKED ≠ 0) or (EPCM(DS:RCX).PT ≠ PT_REG) or (EPCM(DS:RCX).ENCLAVESECS ≠ CR_ACTIVE_SECS) )
THEN
RFLAGS.ZF := 1;
RAX := SGX_PAGE_ATTRIBUTES_MISMATCH;
GOTO DONE;
FI;
(* Check the destination EPC page for concurrency *)
IF (destination EPC page in use )
THEN #GP(0); FI;
(* Re-Check security attributes of the destination EPC page *)
IF ( (EPCM(DS:RCX).VALID = 0) or (EPCM(DS:RCX).PENDING ≠ 1) or (EPCM(DS:RCX).MODIFIED ≠ 0) or
(EPCM(DS:RCX).R ≠ 1) or (EPCM(DS:RCX).W ≠ 1) or (EPCM(DS:RCX).X ≠ 0) or
(EPCM(DS:RCX).PT ≠ SCRATCH_SECINFO.FLAGS.PT) or (EPCM(DS:RCX).ENCLAVESECS ≠ CR_ACTIVE_SECS) or
(EPCM(DS:RCX).ENCLAVEADDRESS ≠ DS:RCX))
THEN
RFLAGS.ZF := 1;
RAX := SGX_PAGE_ATTRIBUTES_MISMATCH;
GOTO DONE;
FI;
(* Copy 4KBbytes form the source to destination EPC page*)
DS:RCX[32767:0] := DS:RDX[32767:0];
(* Update EPCM permissions *)
EPCM(DS:RCX).R := SCRATCH_SECINFO.FLAGS.R;
EPCM(DS:RCX).W := SCRATCH_SECINFO.FLAGS.W;
EPCM(DS:RCX).X := SCRATCH_SECINFO.FLAGS.X;
EPCM(DS:RCX).PENDING := 0;
RFLAGS.ZF := 0;
RAX := 0;
DONE:
RFLAGS.CF,PF,AF,OF,SF := 0;
EACCEPTCOPY-Initialize a Pending Page
Vol. 3D
41-81

 

 

 

 

 

 

 

Content      ..     65      66      67      68     ..