12164af29SRuslan Bukin/*- 22164af29SRuslan Bukin * Copyright (c) 2017 Ruslan Bukin <br@bsdpad.com> 32164af29SRuslan Bukin * All rights reserved. 42164af29SRuslan Bukin * 52164af29SRuslan Bukin * This software was developed by BAE Systems, the University of Cambridge 62164af29SRuslan Bukin * Computer Laboratory, and Memorial University under DARPA/AFRL contract 72164af29SRuslan Bukin * FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent Computing 82164af29SRuslan Bukin * (TC) research program. 92164af29SRuslan Bukin * 102164af29SRuslan Bukin * Redistribution and use in source and binary forms, with or without 112164af29SRuslan Bukin * modification, are permitted provided that the following conditions 122164af29SRuslan Bukin * are met: 132164af29SRuslan Bukin * 1. Redistributions of source code must retain the above copyright 142164af29SRuslan Bukin * notice, this list of conditions and the following disclaimer. 152164af29SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright 162164af29SRuslan Bukin * notice, this list of conditions and the following disclaimer in the 172164af29SRuslan Bukin * documentation and/or other materials provided with the distribution. 182164af29SRuslan Bukin * 192164af29SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 202164af29SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 212164af29SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 222164af29SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 232164af29SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 242164af29SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 252164af29SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 262164af29SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 272164af29SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 282164af29SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 292164af29SRuslan Bukin * SUCH DAMAGE. 302164af29SRuslan Bukin */ 312164af29SRuslan Bukin 322164af29SRuslan Bukin#include <machine/asmacros.h> 332164af29SRuslan Bukin#include <amd64/sgx/sgxvar.h> 342164af29SRuslan Bukin 35*fc2a8776SEd Maste#include "assym.inc" 362164af29SRuslan Bukin 372164af29SRuslan Bukin .text 382164af29SRuslan Bukin 392164af29SRuslan Bukin/* 402164af29SRuslan Bukin * int 412164af29SRuslan Bukin * sgx_encls(uint32_t eax, uint64_t rbx, uint64_t rcx, uint64_t rdx); 422164af29SRuslan Bukin * %edi, %rsi, %rdx, %rcx 432164af29SRuslan Bukin */ 442164af29SRuslan BukinENTRY(sgx_encls) 452164af29SRuslan Bukin PUSH_FRAME_POINTER 462164af29SRuslan Bukin pushq %rbx 472164af29SRuslan Bukin movq PCPU(CURPCB),%r8 482164af29SRuslan Bukin movl %edi,%eax 492164af29SRuslan Bukin movq %rsi,%rbx 502164af29SRuslan Bukin xchgq %rdx,%rcx 512164af29SRuslan Bukin movq $sgx_onfault,PCB_ONFAULT(%r8) 522164af29SRuslan Bukin .byte 0x0f, 0x01, 0xcf 532164af29SRuslan Bukin movq $0,PCB_ONFAULT(%r8) 542164af29SRuslan Bukin popq %rbx 552164af29SRuslan Bukin POP_FRAME_POINTER 562164af29SRuslan Bukin ret 572164af29SRuslan BukinEND(sgx_encls) 582164af29SRuslan Bukin 592164af29SRuslan Bukin/* 602164af29SRuslan Bukin * SGX operations fault handler 612164af29SRuslan Bukin */ 622164af29SRuslan Bukin ALIGN_TEXT 632164af29SRuslan Bukinsgx_onfault: 642164af29SRuslan Bukin movq $0,PCB_ONFAULT(%r8) 652164af29SRuslan Bukin movl $SGX_EFAULT,%eax 662164af29SRuslan Bukin popq %rbx 672164af29SRuslan Bukin POP_FRAME_POINTER 682164af29SRuslan Bukin ret 69