1/*
2 * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <stdbool.h>
10
11#include <sel4/sel4.h>
12#include <sel4vm/guest_vm.h>
13
14/***
15 * @module guest_vcpu_fault.h
16 * The libsel4vm VCPU fault interface provides a set of useful methods to query and configure vcpu objects that
17 * have faulted during execution. This interface is commonly leveraged by VMM's to process a vcpu fault and handle
18 * it accordingly.
19 */
20
21/***
22 * @function get_vcpu_fault_address(vcpu)
23 * Get current fault address of vcpu
24 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
25 * @return                      Current fault address of vcpu
26 */
27seL4_Word get_vcpu_fault_address(vm_vcpu_t *vcpu);
28
29/***
30 * @function get_vcpu_fault_ip(vcpu)
31 * Get instruction pointer of current vcpu fault
32 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
33 * @return                      Intruction pointer of vcpu fault
34 */
35seL4_Word get_vcpu_fault_ip(vm_vcpu_t *vcpu);
36
37/***
38 * @function get_vcpu_fault_data(vcpu)
39 * Get the data of the current vcpu fault
40 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
41 * @return                      Data of vcpu fault
42 */
43seL4_Word get_vcpu_fault_data(vm_vcpu_t *vcpu);
44
45/***
46 * @function get_vcpu_fault_data_mask(vcpu)
47 * Get data mask of the current vcpu fault
48 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
49 * @return                      Data mask of vcpu fault
50 */
51seL4_Word get_vcpu_fault_data_mask(vm_vcpu_t *vcpu);
52
53/***
54 * @function get_vcpu_fault_size(vcpu)
55 * Get access size of the current vcpu fault
56 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
57 * @return                      Access size of vcpu fault
58 */
59size_t get_vcpu_fault_size(vm_vcpu_t *vcpu);
60
61/***
62 * @function is_vcpu_read_fault(vcpu)
63 * Is current vcpu fault a read fault
64 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
65 * @return                      True if read fault, False if write fault
66 */
67bool is_vcpu_read_fault(vm_vcpu_t *vcpu);
68
69/***
70 * @function set_vcpu_fault_data(vcpu, data)
71 * Set the data of the current vcpu fault
72 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
73 * @param {seL4_Word} data      Data to set for current vcpu fault
74 * @return 0 for success, otherwise -1 for error
75 */
76int set_vcpu_fault_data(vm_vcpu_t *vcpu, seL4_Word data);
77
78/***
79 * @function emulate_vcpu_fault(vcpu, data)
80 * Emulate a read or write fault on a given data value
81 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
82 * @param {seL4_Word} data      Data to perform emulate fault on
83 * @return                      Emulation result of vcpu fault over given data value
84 */
85seL4_Word emulate_vcpu_fault(vm_vcpu_t *vcpu, seL4_Word data);
86
87/***
88 * @function advance_vcpu_fault(vcpu)
89 * Advance the current vcpu fault to the next stage/instruction
90 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
91 */
92void advance_vcpu_fault(vm_vcpu_t *vcpu);
93
94/***
95 * @function restart_vcpu_fault(vcpu)
96 * Restart the current vcpu fault
97 * @param {vm_vcpu_t *} vcpu    Handle to vcpu
98 */
99void restart_vcpu_fault(vm_vcpu_t *vcpu);
100