134602f99SAndreas Konopik /*
234602f99SAndreas Konopik * Infineon TriBoard System emulation.
334602f99SAndreas Konopik *
434602f99SAndreas Konopik * Copyright (c) 2020 Andreas Konopik <andreas.konopik@efs-auto.de>
534602f99SAndreas Konopik * Copyright (c) 2020 David Brenken <david.brenken@efs-auto.de>
634602f99SAndreas Konopik *
734602f99SAndreas Konopik * This library is free software; you can redistribute it and/or
834602f99SAndreas Konopik * modify it under the terms of the GNU Lesser General Public
934602f99SAndreas Konopik * License as published by the Free Software Foundation; either
1034602f99SAndreas Konopik * version 2 of the License, or (at your option) any later version.
1134602f99SAndreas Konopik *
1234602f99SAndreas Konopik * This library is distributed in the hope that it will be useful,
1334602f99SAndreas Konopik * but WITHOUT ANY WARRANTY; without even the implied warranty of
1434602f99SAndreas Konopik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1534602f99SAndreas Konopik * Lesser General Public License for more details.
1634602f99SAndreas Konopik *
1734602f99SAndreas Konopik * You should have received a copy of the GNU Lesser General Public
1834602f99SAndreas Konopik * License along with this library; if not, see <http://www.gnu.org/licenses/>.
1934602f99SAndreas Konopik */
2034602f99SAndreas Konopik
2134602f99SAndreas Konopik #include "qemu/osdep.h"
2234602f99SAndreas Konopik #include "qemu/units.h"
2334602f99SAndreas Konopik #include "qapi/error.h"
2434602f99SAndreas Konopik #include "hw/qdev-properties.h"
2534602f99SAndreas Konopik #include "net/net.h"
2634602f99SAndreas Konopik #include "hw/loader.h"
2734602f99SAndreas Konopik #include "elf.h"
2834602f99SAndreas Konopik #include "hw/tricore/tricore.h"
2934602f99SAndreas Konopik #include "qemu/error-report.h"
3034602f99SAndreas Konopik
3134602f99SAndreas Konopik #include "hw/tricore/triboard.h"
3234602f99SAndreas Konopik #include "hw/tricore/tc27x_soc.h"
3334602f99SAndreas Konopik
tricore_load_kernel(TriCoreCPU * cpu,const char * kernel_filename)34e555abceSPhilippe Mathieu-Daudé static void tricore_load_kernel(TriCoreCPU *cpu, const char *kernel_filename)
3534602f99SAndreas Konopik {
3634602f99SAndreas Konopik uint64_t entry;
3734602f99SAndreas Konopik long kernel_size;
3834602f99SAndreas Konopik CPUTriCoreState *env;
3934602f99SAndreas Konopik
4034602f99SAndreas Konopik kernel_size = load_elf(kernel_filename, NULL,
4134602f99SAndreas Konopik NULL, NULL, &entry, NULL,
42adc1a4a2SPhilippe Mathieu-Daudé NULL, NULL, ELFDATA2LSB,
4334602f99SAndreas Konopik EM_TRICORE, 1, 0);
4434602f99SAndreas Konopik if (kernel_size <= 0) {
4534602f99SAndreas Konopik error_report("no kernel file '%s'", kernel_filename);
4634602f99SAndreas Konopik exit(1);
4734602f99SAndreas Konopik }
4834602f99SAndreas Konopik env = &cpu->env;
4934602f99SAndreas Konopik env->PC = entry;
5034602f99SAndreas Konopik }
5134602f99SAndreas Konopik
5234602f99SAndreas Konopik
triboard_machine_init(MachineState * machine)5334602f99SAndreas Konopik static void triboard_machine_init(MachineState *machine)
5434602f99SAndreas Konopik {
5534602f99SAndreas Konopik TriBoardMachineState *ms = TRIBOARD_MACHINE(machine);
5634602f99SAndreas Konopik TriBoardMachineClass *amc = TRIBOARD_MACHINE_GET_CLASS(machine);
5734602f99SAndreas Konopik
5834602f99SAndreas Konopik object_initialize_child(OBJECT(machine), "soc", &ms->tc27x_soc,
5934602f99SAndreas Konopik amc->soc_name);
6034602f99SAndreas Konopik sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
6134602f99SAndreas Konopik
6234602f99SAndreas Konopik if (machine->kernel_filename) {
63e555abceSPhilippe Mathieu-Daudé tricore_load_kernel(&ms->tc27x_soc.cpu, machine->kernel_filename);
6434602f99SAndreas Konopik }
6534602f99SAndreas Konopik }
6634602f99SAndreas Konopik
triboard_machine_tc277d_class_init(ObjectClass * oc,const void * data)6734602f99SAndreas Konopik static void triboard_machine_tc277d_class_init(ObjectClass *oc,
68*12d1a768SPhilippe Mathieu-Daudé const void *data)
6934602f99SAndreas Konopik {
7034602f99SAndreas Konopik MachineClass *mc = MACHINE_CLASS(oc);
7134602f99SAndreas Konopik TriBoardMachineClass *amc = TRIBOARD_MACHINE_CLASS(oc);
7234602f99SAndreas Konopik
7334602f99SAndreas Konopik mc->init = triboard_machine_init;
7434602f99SAndreas Konopik mc->desc = "Infineon AURIX TriBoard TC277 (D-Step)";
7534602f99SAndreas Konopik mc->max_cpus = 1;
7634602f99SAndreas Konopik amc->soc_name = "tc277d-soc";
7734602f99SAndreas Konopik };
7834602f99SAndreas Konopik
7934602f99SAndreas Konopik static const TypeInfo triboard_machine_types[] = {
8034602f99SAndreas Konopik {
8134602f99SAndreas Konopik .name = MACHINE_TYPE_NAME("KIT_AURIX_TC277_TRB"),
8234602f99SAndreas Konopik .parent = TYPE_TRIBOARD_MACHINE,
8334602f99SAndreas Konopik .class_init = triboard_machine_tc277d_class_init,
8434602f99SAndreas Konopik }, {
8534602f99SAndreas Konopik .name = TYPE_TRIBOARD_MACHINE,
8634602f99SAndreas Konopik .parent = TYPE_MACHINE,
8734602f99SAndreas Konopik .instance_size = sizeof(TriBoardMachineState),
8834602f99SAndreas Konopik .class_size = sizeof(TriBoardMachineClass),
8934602f99SAndreas Konopik .abstract = true,
9034602f99SAndreas Konopik },
9134602f99SAndreas Konopik };
9234602f99SAndreas Konopik
9334602f99SAndreas Konopik DEFINE_TYPES(triboard_machine_types)
94