xref: /openbmc/qemu/hw/tricore/tricore_testboard.c (revision f7160f32)
1 /*
2  * TriCore Baseboard System emulation.
3  *
4  * Copyright (c) 2013-2014 Bastian Koppelmann C-Lab/University Paderborn
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 
20 
21 #include "qemu/osdep.h"
22 #include "qemu/units.h"
23 #include "qapi/error.h"
24 #include "cpu.h"
25 #include "net/net.h"
26 #include "hw/boards.h"
27 #include "hw/loader.h"
28 #include "exec/address-spaces.h"
29 #include "elf.h"
30 #include "hw/tricore/tricore.h"
31 #include "qemu/error-report.h"
32 
33 
34 /* Board init.  */
35 
36 static struct tricore_boot_info tricoretb_binfo;
37 
38 static void tricore_load_kernel(CPUTriCoreState *env)
39 {
40     uint64_t entry;
41     long kernel_size;
42 
43     kernel_size = load_elf(tricoretb_binfo.kernel_filename, NULL,
44                            NULL, NULL, &entry, NULL,
45                            NULL, NULL, 0,
46                            EM_TRICORE, 1, 0);
47     if (kernel_size <= 0) {
48         error_report("no kernel file '%s'",
49                 tricoretb_binfo.kernel_filename);
50         exit(1);
51     }
52     env->PC = entry;
53 
54 }
55 
56 static void tricore_testboard_init(MachineState *machine, int board_id)
57 {
58     TriCoreCPU *cpu;
59     CPUTriCoreState *env;
60 
61     MemoryRegion *sysmem = get_system_memory();
62     MemoryRegion *ext_cram = g_new(MemoryRegion, 1);
63     MemoryRegion *ext_dram = g_new(MemoryRegion, 1);
64     MemoryRegion *int_cram = g_new(MemoryRegion, 1);
65     MemoryRegion *int_dram = g_new(MemoryRegion, 1);
66     MemoryRegion *pcp_data = g_new(MemoryRegion, 1);
67     MemoryRegion *pcp_text = g_new(MemoryRegion, 1);
68 
69     cpu = TRICORE_CPU(cpu_create(machine->cpu_type));
70     env = &cpu->env;
71     memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
72                            2 * MiB, &error_fatal);
73     memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram",
74                            4 * MiB, &error_fatal);
75     memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * KiB,
76                            &error_fatal);
77     memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * KiB,
78                            &error_fatal);
79     memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram",
80                            16 * KiB, &error_fatal);
81     memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram",
82                            32 * KiB, &error_fatal);
83 
84     memory_region_add_subregion(sysmem, 0x80000000, ext_cram);
85     memory_region_add_subregion(sysmem, 0xa1000000, ext_dram);
86     memory_region_add_subregion(sysmem, 0xd4000000, int_cram);
87     memory_region_add_subregion(sysmem, 0xd0000000, int_dram);
88     memory_region_add_subregion(sysmem, 0xf0050000, pcp_data);
89     memory_region_add_subregion(sysmem, 0xf0060000, pcp_text);
90 
91     tricoretb_binfo.ram_size = machine->ram_size;
92     tricoretb_binfo.kernel_filename = machine->kernel_filename;
93 
94     if (machine->kernel_filename) {
95         tricore_load_kernel(env);
96     }
97 }
98 
99 static void tricoreboard_init(MachineState *machine)
100 {
101     tricore_testboard_init(machine, 0x183);
102 }
103 
104 static void ttb_machine_init(MachineClass *mc)
105 {
106     mc->desc = "a minimal TriCore board";
107     mc->init = tricoreboard_init;
108     mc->default_cpu_type = TRICORE_CPU_TYPE_NAME("tc1796");
109 }
110 
111 DEFINE_MACHINE("tricore_testboard", ttb_machine_init)
112