target-tricore: check return value before using it
[qemu/ar7.git] / hw / tricore / tricore_testboard.c
bloba059a20a30f634701eb67c86e2813a50608f906f
1 /*
2 * TriCore Baseboard System emulation.
4 * Copyright (c) 2013-2014 Bastian Koppelmann C-Lab/University Paderborn
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "hw/hw.h"
22 #include "hw/devices.h"
23 #include "net/net.h"
24 #include "sysemu/sysemu.h"
25 #include "hw/boards.h"
26 #include "hw/loader.h"
27 #include "sysemu/block-backend.h"
28 #include "exec/address-spaces.h"
29 #include "hw/block/flash.h"
30 #include "elf.h"
31 #include "hw/tricore/tricore.h"
32 #include "qemu/error-report.h"
35 /* Board init. */
37 static struct tricore_boot_info tricoretb_binfo;
39 static void tricore_load_kernel(CPUTriCoreState *env)
41 uint64_t entry;
42 long kernel_size;
44 kernel_size = load_elf(tricoretb_binfo.kernel_filename, NULL,
45 NULL, (uint64_t *)&entry, NULL,
46 NULL, 0,
47 ELF_MACHINE, 1);
48 if (kernel_size <= 0) {
49 error_report("qemu: no kernel file '%s'",
50 tricoretb_binfo.kernel_filename);
51 exit(1);
53 env->PC = entry;
57 static void tricore_testboard_init(MachineState *machine, int board_id)
59 TriCoreCPU *cpu;
60 CPUTriCoreState *env;
62 MemoryRegion *sysmem = get_system_memory();
63 MemoryRegion *ext_cram = g_new(MemoryRegion, 1);
64 MemoryRegion *ext_dram = g_new(MemoryRegion, 1);
65 MemoryRegion *int_cram = g_new(MemoryRegion, 1);
66 MemoryRegion *int_dram = g_new(MemoryRegion, 1);
67 MemoryRegion *pcp_data = g_new(MemoryRegion, 1);
68 MemoryRegion *pcp_text = g_new(MemoryRegion, 1);
70 if (!machine->cpu_model) {
71 machine->cpu_model = "tc1796";
73 cpu = cpu_tricore_init(machine->cpu_model);
74 if (!cpu) {
75 error_report("Unable to find CPU definition");
76 exit(1);
78 env = &cpu->env;
79 memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram", 2*1024*1024, &error_abort);
80 vmstate_register_ram_global(ext_cram);
81 memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram", 4*1024*1024, &error_abort);
82 vmstate_register_ram_global(ext_dram);
83 memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48*1024, &error_abort);
84 vmstate_register_ram_global(int_cram);
85 memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48*1024, &error_abort);
86 vmstate_register_ram_global(int_dram);
87 memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram", 16*1024, &error_abort);
88 vmstate_register_ram_global(pcp_data);
89 memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram", 32*1024, &error_abort);
90 vmstate_register_ram_global(pcp_text);
92 memory_region_add_subregion(sysmem, 0x80000000, ext_cram);
93 memory_region_add_subregion(sysmem, 0xa1000000, ext_dram);
94 memory_region_add_subregion(sysmem, 0xd4000000, int_cram);
95 memory_region_add_subregion(sysmem, 0xd0000000, int_dram);
96 memory_region_add_subregion(sysmem, 0xf0050000, pcp_data);
97 memory_region_add_subregion(sysmem, 0xf0060000, pcp_text);
99 tricoretb_binfo.ram_size = machine->ram_size;
100 tricoretb_binfo.kernel_filename = machine->kernel_filename;
102 if (machine->kernel_filename) {
103 tricore_load_kernel(env);
107 static void tricoreboard_init(MachineState *machine)
109 tricore_testboard_init(machine, 0x183);
112 static QEMUMachine ttb_machine = {
113 .name = "tricore_testboard",
114 .desc = "a minimal TriCore board",
115 .init = tricoreboard_init,
116 .is_default = 0,
119 static void tricore_testboard_machine_init(void)
121 qemu_register_machine(&ttb_machine);
124 machine_init(tricore_testboard_machine_init);