Do not include cpu.h if it's not really necessary
[qemu/ar7.git] / hw / tricore / triboard.c
blob943f706989e34f92e54092995d2ec3a601c9e5fc
1 /*
2 * Infineon TriBoard System emulation.
4 * Copyright (c) 2020 Andreas Konopik <andreas.konopik@efs-auto.de>
5 * Copyright (c) 2020 David Brenken <david.brenken@efs-auto.de>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "qemu/units.h"
23 #include "qapi/error.h"
24 #include "hw/qdev-properties.h"
25 #include "net/net.h"
26 #include "hw/loader.h"
27 #include "exec/address-spaces.h"
28 #include "elf.h"
29 #include "hw/tricore/tricore.h"
30 #include "qemu/error-report.h"
32 #include "hw/tricore/triboard.h"
33 #include "hw/tricore/tc27x_soc.h"
35 static void tricore_load_kernel(const char *kernel_filename)
37 uint64_t entry;
38 long kernel_size;
39 TriCoreCPU *cpu;
40 CPUTriCoreState *env;
42 kernel_size = load_elf(kernel_filename, NULL,
43 NULL, NULL, &entry, NULL,
44 NULL, NULL, 0,
45 EM_TRICORE, 1, 0);
46 if (kernel_size <= 0) {
47 error_report("no kernel file '%s'", kernel_filename);
48 exit(1);
50 cpu = TRICORE_CPU(first_cpu);
51 env = &cpu->env;
52 env->PC = entry;
56 static void triboard_machine_init(MachineState *machine)
58 TriBoardMachineState *ms = TRIBOARD_MACHINE(machine);
59 TriBoardMachineClass *amc = TRIBOARD_MACHINE_GET_CLASS(machine);
61 object_initialize_child(OBJECT(machine), "soc", &ms->tc27x_soc,
62 amc->soc_name);
63 sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
65 if (machine->kernel_filename) {
66 tricore_load_kernel(machine->kernel_filename);
70 static void triboard_machine_tc277d_class_init(ObjectClass *oc,
71 void *data)
73 MachineClass *mc = MACHINE_CLASS(oc);
74 TriBoardMachineClass *amc = TRIBOARD_MACHINE_CLASS(oc);
76 mc->init = triboard_machine_init;
77 mc->desc = "Infineon AURIX TriBoard TC277 (D-Step)";
78 mc->max_cpus = 1;
79 amc->soc_name = "tc277d-soc";
82 static const TypeInfo triboard_machine_types[] = {
84 .name = MACHINE_TYPE_NAME("KIT_AURIX_TC277_TRB"),
85 .parent = TYPE_TRIBOARD_MACHINE,
86 .class_init = triboard_machine_tc277d_class_init,
87 }, {
88 .name = TYPE_TRIBOARD_MACHINE,
89 .parent = TYPE_MACHINE,
90 .instance_size = sizeof(TriBoardMachineState),
91 .class_size = sizeof(TriBoardMachineClass),
92 .abstract = true,
96 DEFINE_TYPES(triboard_machine_types)