test_encl.c (1444B)
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright(c) 2016-20 Intel Corporation. */ 3 4#include <stddef.h> 5#include "defines.h" 6 7/* 8 * Data buffer spanning two pages that will be placed first in .data 9 * segment. Even if not used internally the second page is needed by 10 * external test manipulating page permissions. 11 */ 12static uint8_t encl_buffer[8192] = { 1 }; 13 14static void *memcpy(void *dest, const void *src, size_t n) 15{ 16 size_t i; 17 18 for (i = 0; i < n; i++) 19 ((char *)dest)[i] = ((char *)src)[i]; 20 21 return dest; 22} 23 24static void do_encl_op_put_to_buf(void *op) 25{ 26 struct encl_op_put_to_buf *op2 = op; 27 28 memcpy(&encl_buffer[0], &op2->value, 8); 29} 30 31static void do_encl_op_get_from_buf(void *op) 32{ 33 struct encl_op_get_from_buf *op2 = op; 34 35 memcpy(&op2->value, &encl_buffer[0], 8); 36} 37 38static void do_encl_op_put_to_addr(void *_op) 39{ 40 struct encl_op_put_to_addr *op = _op; 41 42 memcpy((void *)op->addr, &op->value, 8); 43} 44 45static void do_encl_op_get_from_addr(void *_op) 46{ 47 struct encl_op_get_from_addr *op = _op; 48 49 memcpy(&op->value, (void *)op->addr, 8); 50} 51 52static void do_encl_op_nop(void *_op) 53{ 54 55} 56 57void encl_body(void *rdi, void *rsi) 58{ 59 const void (*encl_op_array[ENCL_OP_MAX])(void *) = { 60 do_encl_op_put_to_buf, 61 do_encl_op_get_from_buf, 62 do_encl_op_put_to_addr, 63 do_encl_op_get_from_addr, 64 do_encl_op_nop, 65 }; 66 67 struct encl_op_header *op = (struct encl_op_header *)rdi; 68 69 if (op->type < ENCL_OP_MAX) 70 (*encl_op_array[op->type])(op); 71}