mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-24 14:58:11 +00:00
7fe1504224
there are 2 use cases to deal with: 1: fixed CPU models per board/soc 2: boards with user configurable cpu_model and fallback to default cpu_model if user hasn't specified one explicitly For the 1st drop intermediate cpu_model parsing and use const cpu type directly, which replaces: typename = object_class_get_name( cpu_class_by_name(TYPE_ARM_CPU, cpu_model)) object_new(typename) with object_new(FOO_CPU_TYPE_NAME) or cpu_generic_init(BASE_CPU_TYPE, "my cpu model") with cpu_create(FOO_CPU_TYPE_NAME) as result 1st use case doesn't have to invoke not necessary translation and not needed code is removed. For the 2nd 1: set default cpu type with MachineClass::default_cpu_type and 2: use generic cpu_model parsing that done before machine_init() is run and: 2.1: drop custom cpu_model parsing where pattern is: typename = object_class_get_name( cpu_class_by_name(TYPE_ARM_CPU, cpu_model)) [parse_features(typename, cpu_model, &err) ] 2.2: or replace cpu_generic_init() which does what 2.1 does + create_cpu(typename) with just create_cpu(machine->cpu_type) as result cpu_name -> cpu_type translation is done using generic machine code one including parsing optional features if supported/present (removes a bunch of duplicated cpu_model parsing code) and default cpu type is defined in an uniform way within machine_class_init callbacks instead of adhoc places in boadr's machine_init code. Backports commit ba1ba5cca3962a9cc400c713c736b4fb8db1f38e from qemu
164 lines
4.8 KiB
C
164 lines
4.8 KiB
C
/*
|
|
* ARM mach-virt emulation
|
|
*
|
|
* Copyright (c) 2013 Linaro Limited
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Emulate a virtual board which works by passing Linux all the information
|
|
* it needs about what devices are present via the device tree.
|
|
* There are some restrictions about what we can do here:
|
|
* + we can only present devices whose Linux drivers will work based
|
|
* purely on the device tree with no platform data at all
|
|
* + we want to present a very stripped-down minimalist platform,
|
|
* both because this reduces the security attack surface from the guest
|
|
* and also because it reduces our exposure to being broken when
|
|
* the kernel updates its device tree bindings and requires further
|
|
* information in a device binding that we aren't providing.
|
|
* This is essentially the same approach kvmtool uses.
|
|
*/
|
|
|
|
/* Unicorn Emulator Engine */
|
|
/* By Nguyen Anh Quynh, 2015 */
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qapi/error.h"
|
|
#include "qemu-common.h"
|
|
#include "cpu.h"
|
|
#include "hw/arm/arm.h"
|
|
#include "hw/boards.h"
|
|
#include "exec/address-spaces.h"
|
|
|
|
// Unicorn: Daughterboard member removed, as it's not necessary
|
|
// for Unicorn's purposes.
|
|
typedef struct {
|
|
MachineClass parent;
|
|
} VirtMachineClass;
|
|
|
|
typedef struct {
|
|
MachineState parent;
|
|
bool secure;
|
|
} VirtMachineState;
|
|
|
|
#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
|
|
#define VIRT_MACHINE(uc, obj) \
|
|
OBJECT_CHECK((uc), VirtMachineState, (obj), TYPE_VIRT_MACHINE)
|
|
#define VIRT_MACHINE_GET_CLASS(uc, obj) \
|
|
OBJECT_GET_CLASS(uc, VirtMachineClass, obj, TYPE_VIRT_MACHINE)
|
|
#define VIRT_MACHINE_CLASS(uc, klass) \
|
|
OBJECT_CLASS_CHECK(uc, VirtMachineClass, klass, TYPE_VIRT_MACHINE)
|
|
|
|
static const char *valid_cpus[] = {
|
|
ARM_CPU_TYPE_NAME("cortex-a15"),
|
|
ARM_CPU_TYPE_NAME("cortex-a53"),
|
|
ARM_CPU_TYPE_NAME("cortex-a57"),
|
|
ARM_CPU_TYPE_NAME("host"),
|
|
// Unicorn: added to allow enabling all CPU features
|
|
ARM_CPU_TYPE_NAME("max"),
|
|
};
|
|
|
|
static bool cpu_type_valid(const char *cpu)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(valid_cpus); i++) {
|
|
if (strcmp(cpu, valid_cpus[i]) == 0) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static int machvirt_init(struct uc_struct *uc, MachineState *machine)
|
|
{
|
|
int n;
|
|
|
|
if (!cpu_type_valid(machine->cpu_type)) {
|
|
fprintf(stderr, "mach-virt: CPU type %s not supported", machine->cpu_type);
|
|
return -1;
|
|
}
|
|
|
|
for (n = 0; n < smp_cpus; n++) {
|
|
Object *cpuobj = object_new(uc, machine->cpu_type);
|
|
|
|
uc->cpu = CPU(cpuobj);
|
|
object_property_set_bool(uc, cpuobj, true, "realized", NULL);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static QEMU_UNUSED_FUNC bool virt_get_secure(struct uc_struct *uc, Object *obj, Error **errp)
|
|
{
|
|
VirtMachineState *vms = VIRT_MACHINE(uc, obj);
|
|
|
|
return vms->secure;
|
|
}
|
|
|
|
static QEMU_UNUSED_FUNC int virt_set_secure(struct uc_struct *uc, Object *obj, bool value, Error **errp)
|
|
{
|
|
VirtMachineState *vms = VIRT_MACHINE(uc, obj);
|
|
|
|
vms->secure = value;
|
|
return 0;
|
|
}
|
|
|
|
static void virt_instance_init(struct uc_struct *uc, Object *obj, void *opaque)
|
|
{
|
|
VirtMachineState *vms = VIRT_MACHINE(uc, obj);
|
|
|
|
/* EL3 is enabled by default on virt */
|
|
vms->secure = true;
|
|
|
|
/* Unicorn: should be uncommented, but causes linkage errors :/
|
|
object_property_add_bool(uc, obj, "secure", virt_get_secure,
|
|
virt_set_secure, NULL);
|
|
object_property_set_description(uc, obj, "secure",
|
|
"Set on/off to enable/disable the ARM "
|
|
"Security Extensions (TrustZone)",
|
|
NULL);
|
|
*/
|
|
}
|
|
|
|
static void virt_class_init(struct uc_struct *uc, ObjectClass *oc, void *data)
|
|
{
|
|
MachineClass *mc = MACHINE_CLASS(uc, oc);
|
|
|
|
mc->init = machvirt_init;
|
|
mc->max_cpus = 8;
|
|
mc->is_default = 1;
|
|
mc->arch = UC_ARCH_ARM64;
|
|
// Unicorn: Enable all CPU features
|
|
mc->default_cpu_type = ARM_CPU_TYPE_NAME("max");
|
|
}
|
|
|
|
static const TypeInfo machvirt_info = {
|
|
TYPE_VIRT_MACHINE,
|
|
TYPE_MACHINE,
|
|
|
|
sizeof(VirtMachineClass),
|
|
sizeof(VirtMachineState),
|
|
NULL,
|
|
|
|
virt_instance_init,
|
|
NULL,
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
virt_class_init,
|
|
};
|
|
|
|
void machvirt_machine_init(struct uc_struct *uc)
|
|
{
|
|
type_register_static(uc, &machvirt_info);
|
|
}
|