Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/usr.sbin/bhyve/amd64/mem_x86.c
107189 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2025 The FreeBSD Foundation
5
*
6
* This software was developed by Konstantin Belousov <[email protected]>
7
* under sponsorship from the FreeBSD Foundation.
8
*
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
11
* are met:
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in the
16
* documentation and/or other materials provided with the distribution.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
* SUCH DAMAGE.
29
*/
30
31
#include <sys/types.h>
32
#include <sys/errno.h>
33
#include <sys/tree.h>
34
#include <machine/vmm.h>
35
36
#include <stdio.h>
37
38
#include "debug.h"
39
#include "mem.h"
40
41
static int
42
no_mem_handler(struct vcpu *vcpu __unused, int dir, uint64_t addr __unused,
43
int size, uint64_t *val, void *arg1 __unused, long arg2 __unused)
44
{
45
if (dir == MEM_F_READ) {
46
switch (size) {
47
case 1:
48
*val = 0xff;
49
break;
50
case 2:
51
*val = 0xffff;
52
break;
53
case 4:
54
*val = 0xffffffff;
55
break;
56
case 8:
57
*val = 0xffffffffffffffff;
58
break;
59
}
60
}
61
return (0);
62
}
63
64
static struct mem_range fb_entry = {
65
.handler = no_mem_handler,
66
.base = 0,
67
.size = 0xffffffffffffffff,
68
};
69
70
/*
71
* x86 hardware ignores writes without receiver, and returns all 1's
72
* from reads without response to transaction.
73
*/
74
int
75
mmio_handle_non_backed_mem(struct vcpu *vcpu __unused, uint64_t paddr,
76
struct mem_range **mr_paramp)
77
{
78
*mr_paramp = &fb_entry;
79
EPRINTLN("Emulating access to non-existent address to %#lx\n",
80
paddr);
81
return (0);
82
}
83
84