Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / hw / tricore / triboard.c
blob4dba0259cd338d964d2342267a5c5c51f16aa08a
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 "elf.h"
28 #include "hw/tricore/tricore.h"
29 #include "qemu/error-report.h"
31 #include "hw/tricore/triboard.h"
32 #include "hw/tricore/tc27x_soc.h"
34 static void tricore_load_kernel(const char *kernel_filename)
36 uint64_t entry;
37 long kernel_size;
38 TriCoreCPU *cpu;
39 CPUTriCoreState *env;
41 kernel_size = load_elf(kernel_filename, NULL,
42 NULL, NULL, &entry, NULL,
43 NULL, NULL, 0,
44 EM_TRICORE, 1, 0);
45 if (kernel_size <= 0) {
46 error_report("no kernel file '%s'", kernel_filename);
47 exit(1);
49 cpu = TRICORE_CPU(first_cpu);
50 env = &cpu->env;
51 env->PC = entry;
55 static void triboard_machine_init(MachineState *machine)
57 TriBoardMachineState *ms = TRIBOARD_MACHINE(machine);
58 TriBoardMachineClass *amc = TRIBOARD_MACHINE_GET_CLASS(machine);
60 object_initialize_child(OBJECT(machine), "soc", &ms->tc27x_soc,
61 amc->soc_name);
62 sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
64 if (machine->kernel_filename) {
65 tricore_load_kernel(machine->kernel_filename);
69 static void triboard_machine_tc277d_class_init(ObjectClass *oc,
70 void *data)
72 MachineClass *mc = MACHINE_CLASS(oc);
73 TriBoardMachineClass *amc = TRIBOARD_MACHINE_CLASS(oc);
75 mc->init = triboard_machine_init;
76 mc->desc = "Infineon AURIX TriBoard TC277 (D-Step)";
77 mc->max_cpus = 1;
78 amc->soc_name = "tc277d-soc";
81 static const TypeInfo triboard_machine_types[] = {
83 .name = MACHINE_TYPE_NAME("KIT_AURIX_TC277_TRB"),
84 .parent = TYPE_TRIBOARD_MACHINE,
85 .class_init = triboard_machine_tc277d_class_init,
86 }, {
87 .name = TYPE_TRIBOARD_MACHINE,
88 .parent = TYPE_MACHINE,
89 .instance_size = sizeof(TriBoardMachineState),
90 .class_size = sizeof(TriBoardMachineClass),
91 .abstract = true,
95 DEFINE_TYPES(triboard_machine_types)