xref: /qemu/hw/tricore/triboard.c (revision dc293f60)
1 /*
2  * Infineon TriBoard System emulation.
3  *
4  * Copyright (c) 2020 Andreas Konopik <andreas.konopik@efs-auto.de>
5  * Copyright (c) 2020 David Brenken <david.brenken@efs-auto.de>
6  *
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.
11  *
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.
16  *
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/>.
19  */
20 
21 #include "qemu/osdep.h"
22 #include "qemu/units.h"
23 #include "qapi/error.h"
24 #include "hw/qdev-properties.h"
25 #include "cpu.h"
26 #include "net/net.h"
27 #include "hw/boards.h"
28 #include "hw/loader.h"
29 #include "exec/address-spaces.h"
30 #include "elf.h"
31 #include "hw/tricore/tricore.h"
32 #include "qemu/error-report.h"
33 
34 #include "hw/tricore/triboard.h"
35 #include "hw/tricore/tc27x_soc.h"
36 
37 static void tricore_load_kernel(const char *kernel_filename)
38 {
39     uint64_t entry;
40     long kernel_size;
41     TriCoreCPU *cpu;
42     CPUTriCoreState *env;
43 
44     kernel_size = load_elf(kernel_filename, NULL,
45                            NULL, NULL, &entry, NULL,
46                            NULL, NULL, 0,
47                            EM_TRICORE, 1, 0);
48     if (kernel_size <= 0) {
49         error_report("no kernel file '%s'", kernel_filename);
50         exit(1);
51     }
52     cpu = TRICORE_CPU(first_cpu);
53     env = &cpu->env;
54     env->PC = entry;
55 }
56 
57 
58 static void triboard_machine_init(MachineState *machine)
59 {
60     TriBoardMachineState *ms = TRIBOARD_MACHINE(machine);
61     TriBoardMachineClass *amc = TRIBOARD_MACHINE_GET_CLASS(machine);
62 
63     object_initialize_child(OBJECT(machine), "soc", &ms->tc27x_soc,
64             amc->soc_name);
65     sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
66 
67     if (machine->kernel_filename) {
68         tricore_load_kernel(machine->kernel_filename);
69     }
70 }
71 
72 static void triboard_machine_tc277d_class_init(ObjectClass *oc,
73         void *data)
74 {
75     MachineClass *mc = MACHINE_CLASS(oc);
76     TriBoardMachineClass *amc = TRIBOARD_MACHINE_CLASS(oc);
77 
78     mc->init        = triboard_machine_init;
79     mc->desc        = "Infineon AURIX TriBoard TC277 (D-Step)";
80     mc->max_cpus    = 1;
81     amc->soc_name   = "tc277d-soc";
82 };
83 
84 static const TypeInfo triboard_machine_types[] = {
85     {
86         .name           = MACHINE_TYPE_NAME("KIT_AURIX_TC277_TRB"),
87         .parent         = TYPE_TRIBOARD_MACHINE,
88         .class_init     = triboard_machine_tc277d_class_init,
89     }, {
90         .name           = TYPE_TRIBOARD_MACHINE,
91         .parent         = TYPE_MACHINE,
92         .instance_size  = sizeof(TriBoardMachineState),
93         .class_size     = sizeof(TriBoardMachineClass),
94         .abstract       = true,
95     },
96 };
97 
98 DEFINE_TYPES(triboard_machine_types)
99