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