sgx_call.S 1009 字节
Newer Older
1 2 3 4 5
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/**
* Copyright(c) 2016-18 Intel Corporation.
*/

6
#include "sgx_call.h"
7 8 9

	.text

10 11 12 13 14 15 16
	# sgx ecall ABI:
	# - RDI, RSI, RDX, RCX, R8 and R9 are parameters
	# - R10 contains the ecall number
	# - R11 contains the base of TCS
	.global sgx_ecall
	.type sgx_ecall, @function
sgx_ecall:
17
	mov	$1, %rax
18
	push	%rbx
19 20 21 22
	mov	tcs_busy(%rip), %rbx	
	xchgb	(%rbx), %al
	cmpb	$1, %al
	jz	busy_err
23
	push	%rbp
24 25 26 27 28 29
	push	%rdi
	push	%rsi
	push    %r12
	push    %r13
	push    %r14
	push    %r15
30 31 32 33
	# EENTER ABI:
	# - [IN] RAX contains the EENTER leaf number 2
	# - [IN] RBX points to target TCS page
	# - [IN] RCX points to AEP
34
	mov	$0x02, %rax
35 36 37
	mov	%r11, %rbx
	# RCX is used to hold AEP so back up it with R11
	mov	%rcx, %r11
38 39 40
	lea	sgx_async_exit(%rip), %rcx
sgx_async_exit:
	ENCLU
41 42 43
	xor	%rax, %rax
	mov	tcs_busy(%rip), %rbx
	movb	%al, (%rbx)
44 45
	# Return value is saved in RAX.
	mov	%rdx, %rax
46 47 48 49 50 51
	pop	%r15
	pop	%r14
	pop	%r13
	pop	%r12
	pop	%rsi
	pop	%rdi
52
	pop	%rbp
53
busy_err:
54 55
	pop	%rbx
	ret