123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /*
- * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- /*
- * Description:
- * The file provides `enclave_entry' function to switch code between
- * trusted and untrusted envronment.
- */
- .file "trts_pic.S"
- #include "trts_pic.h"
- /* .text */
- .section .nipx,"ax",@progbits
-
- /*
- * ------------------------------------------------------------------------
- * extern "C" int do_egetkey(key_request_t *key_request, key_128bit_t *key)
- * return value:
- * 0 - success
- * none-zeor - EGETKEY error code
- * EGETKEY: rbx - the address of KEYREQUEST structure
- * rcx - the address where the key is outputted
- * ------------------------------------------------------------------------
- */
- DECLARE_LOCAL_FUNC do_egetkey
- SE_PROLOG
- mov $SE_EGETKEY, %xax /* EGETKEY leaf */
- ENCLU
- #ifdef SE_SIM
- cmp $SGX_SUCCESS, %xax /* In simulation mode, ZF flag will not be set */
- jnz .Legetkey_done /* because the stack clean operation will always clean ZF flag */
- #else
- jz .Legetkey_done /* if EGETKEY error, ZF flag is set and error code is set to xax */
- #endif
- xor %xax, %xax
- .Legetkey_done:
- SE_EPILOG
- /*
- * -------------------------------------------------------------------------
- * extern "C" void do_ereport(sgx_target_info_t *target_info, sgx_report_data_t *report_data, sgx_report_t *report);
- * EREPORT: rbx - the address of TARGETINFO;
- * rcx - the address of REPORTDATA;
- * rdx - the address where REPORT is outputted
- * -------------------------------------------------------------------------
- */
- DECLARE_LOCAL_FUNC do_ereport
- SE_PROLOG
- mov $SE_EREPORT, %xax /* EREPORT leaf */
- ENCLU
- SE_EPILOG
-
- DECLARE_GLOBAL_FUNC do_eaccept
- SE_PROLOG
- mov $SE_EACCEPT, %eax
- ENCLU
- cmp $SGX_SUCCESS, %eax
- jnz abort
- SE_EPILOG
- DECLARE_GLOBAL_FUNC do_emodpe
- SE_PROLOG
- mov $SE_EMODPE, %eax
- ENCLU
- SE_EPILOG
- #define _RDRAND_RETRY_TIMES 10
- /*
- * -------------------------------------
- * extern "C" uint32_t do_rdrand(uint32_t *rand);
- * return value:
- * non-zero: rdrand succeeded
- * zero: rdrand failed
- * -------------------------------------
- */
- DECLARE_LOCAL_FUNC do_rdrand
- mov $_RDRAND_RETRY_TIMES, %ecx
- .Lrdrand_retry:
- .byte 0x0F, 0xC7, 0xF0 /* rdrand %eax */
- jc .Lrdrand_return
- dec %ecx
- jnz .Lrdrand_retry
- xor %xax, %xax
- ret
- .Lrdrand_return:
- #ifdef LINUX32
- mov SE_WORDSIZE(%esp), %ecx
- #else
- mov %rdi, %rcx
- #endif
- movl %eax, (%xcx)
- mov $1, %xax
- ret
- /*
- * ---------------------------------------------------------------------
- * Function: thread_data_t* get_thread_data(void);
- *
- * Get the address of thread_data
- * ---------------------------------------------------------------------
- */
- DECLARE_LOCAL_FUNC get_thread_data
- READ_TD_DATA self_addr
- ret
|