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