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