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 "sysemu/block-backend.h"
32#include "exec/address-spaces.h"
33#include "hw/block/flash.h"
34#include "elf.h"
35#include "hw/tricore/tricore.h"
36#include "qemu/error-report.h"
37
38
39
40
41static struct tricore_boot_info tricoretb_binfo;
42
43static void tricore_load_kernel(CPUTriCoreState *env)
44{
45 uint64_t entry;
46 long kernel_size;
47
48 kernel_size = load_elf(tricoretb_binfo.kernel_filename, NULL,
49 NULL, &entry, NULL,
50 NULL, 0,
51 EM_TRICORE, 1, 0);
52 if (kernel_size <= 0) {
53 error_report("no kernel file '%s'",
54 tricoretb_binfo.kernel_filename);
55 exit(1);
56 }
57 env->PC = entry;
58
59}
60
61static void tricore_testboard_init(MachineState *machine, int board_id)
62{
63 TriCoreCPU *cpu;
64 CPUTriCoreState *env;
65
66 MemoryRegion *sysmem = get_system_memory();
67 MemoryRegion *ext_cram = g_new(MemoryRegion, 1);
68 MemoryRegion *ext_dram = g_new(MemoryRegion, 1);
69 MemoryRegion *int_cram = g_new(MemoryRegion, 1);
70 MemoryRegion *int_dram = g_new(MemoryRegion, 1);
71 MemoryRegion *pcp_data = g_new(MemoryRegion, 1);
72 MemoryRegion *pcp_text = g_new(MemoryRegion, 1);
73
74 if (!machine->cpu_model) {
75 machine->cpu_model = "tc1796";
76 }
77 cpu = cpu_tricore_init(machine->cpu_model);
78 if (!cpu) {
79 error_report("Unable to find CPU definition");
80 exit(1);
81 }
82 env = &cpu->env;
83 memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
84 2 * 1024 * 1024, &error_fatal);
85 memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram",
86 4 * 1024 * 1024, &error_fatal);
87 memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * 1024,
88 &error_fatal);
89 memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * 1024,
90 &error_fatal);
91 memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram",
92 16 * 1024, &error_fatal);
93 memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram",
94 32 * 1024, &error_fatal);
95
96 memory_region_add_subregion(sysmem, 0x80000000, ext_cram);
97 memory_region_add_subregion(sysmem, 0xa1000000, ext_dram);
98 memory_region_add_subregion(sysmem, 0xd4000000, int_cram);
99 memory_region_add_subregion(sysmem, 0xd0000000, int_dram);
100 memory_region_add_subregion(sysmem, 0xf0050000, pcp_data);
101 memory_region_add_subregion(sysmem, 0xf0060000, pcp_text);
102
103 tricoretb_binfo.ram_size = machine->ram_size;
104 tricoretb_binfo.kernel_filename = machine->kernel_filename;
105
106 if (machine->kernel_filename) {
107 tricore_load_kernel(env);
108 }
109}
110
111static void tricoreboard_init(MachineState *machine)
112{
113 tricore_testboard_init(machine, 0x183);
114}
115
116static void ttb_machine_init(MachineClass *mc)
117{
118 mc->desc = "a minimal TriCore board";
119 mc->init = tricoreboard_init;
120 mc->is_default = 0;
121}
122
123DEFINE_MACHINE("tricore_testboard", ttb_machine_init)
124