Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 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 |
Chetan Pant | eb85394 | 2020-10-23 12:21:57 +0000 | [diff] [blame] | 9 | * version 2.1 of the License, or (at your option) any later version. |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 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 | |
Peter Maydell | 61d9f32 | 2016-01-26 18:17:26 +0000 | [diff] [blame] | 21 | #include "qemu/osdep.h" |
Philippe Mathieu-Daudé | b000325 | 2018-06-25 09:42:15 -0300 | [diff] [blame] | 22 | #include "qemu/units.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 23 | #include "qapi/error.h" |
Paolo Bonzini | 4771d75 | 2016-01-19 21:51:44 +0100 | [diff] [blame] | 24 | #include "cpu.h" |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 25 | #include "net/net.h" |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 26 | #include "hw/boards.h" |
| 27 | #include "hw/loader.h" |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 28 | #include "elf.h" |
| 29 | #include "hw/tricore/tricore.h" |
Bastian Koppelmann | 582079c | 2021-05-12 11:20:33 +0100 | [diff] [blame] | 30 | #include "hw/tricore/tricore_testdevice.h" |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 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, |
Liam Merwick | 4366e1d | 2019-01-15 12:18:03 +0000 | [diff] [blame] | 44 | NULL, NULL, &entry, NULL, |
Aleksandar Markovic | 6cdda0f | 2020-01-26 23:55:04 +0100 | [diff] [blame] | 45 | NULL, NULL, 0, |
Peter Crosthwaite | 7ef295e | 2016-03-04 11:30:21 +0000 | [diff] [blame] | 46 | EM_TRICORE, 1, 0); |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 47 | if (kernel_size <= 0) { |
Ishani Chugh | d0e31a1 | 2017-04-13 21:44:39 +0530 | [diff] [blame] | 48 | error_report("no kernel file '%s'", |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 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; |
Bastian Koppelmann | 582079c | 2021-05-12 11:20:33 +0100 | [diff] [blame] | 60 | TriCoreTestDeviceState *test_dev; |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 61 | |
| 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); |
| 69 | |
Igor Mammedov | 0f550c5 | 2017-10-05 15:51:04 +0200 | [diff] [blame] | 70 | cpu = TRICORE_CPU(cpu_create(machine->cpu_type)); |
zhanghailiang | 8ef2b25 | 2014-10-30 10:03:28 +0800 | [diff] [blame] | 71 | env = &cpu->env; |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 72 | memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram", |
Philippe Mathieu-Daudé | b000325 | 2018-06-25 09:42:15 -0300 | [diff] [blame] | 73 | 2 * MiB, &error_fatal); |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 74 | memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram", |
Philippe Mathieu-Daudé | b000325 | 2018-06-25 09:42:15 -0300 | [diff] [blame] | 75 | 4 * MiB, &error_fatal); |
| 76 | memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * KiB, |
Markus Armbruster | f8ed85a | 2015-09-11 16:51:43 +0200 | [diff] [blame] | 77 | &error_fatal); |
Philippe Mathieu-Daudé | b000325 | 2018-06-25 09:42:15 -0300 | [diff] [blame] | 78 | memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * KiB, |
Markus Armbruster | f8ed85a | 2015-09-11 16:51:43 +0200 | [diff] [blame] | 79 | &error_fatal); |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 80 | memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram", |
Philippe Mathieu-Daudé | b000325 | 2018-06-25 09:42:15 -0300 | [diff] [blame] | 81 | 16 * KiB, &error_fatal); |
Peter Maydell | 98a99ce | 2017-07-07 15:42:53 +0100 | [diff] [blame] | 82 | memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram", |
Philippe Mathieu-Daudé | b000325 | 2018-06-25 09:42:15 -0300 | [diff] [blame] | 83 | 32 * KiB, &error_fatal); |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 84 | |
| 85 | memory_region_add_subregion(sysmem, 0x80000000, ext_cram); |
| 86 | memory_region_add_subregion(sysmem, 0xa1000000, ext_dram); |
| 87 | memory_region_add_subregion(sysmem, 0xd4000000, int_cram); |
| 88 | memory_region_add_subregion(sysmem, 0xd0000000, int_dram); |
| 89 | memory_region_add_subregion(sysmem, 0xf0050000, pcp_data); |
| 90 | memory_region_add_subregion(sysmem, 0xf0060000, pcp_text); |
| 91 | |
Philippe Mathieu-Daudé | 61f406f | 2024-02-14 17:44:28 +0100 | [diff] [blame] | 92 | test_dev = TRICORE_TESTDEVICE(qdev_new(TYPE_TRICORE_TESTDEVICE)); |
Bastian Koppelmann | 582079c | 2021-05-12 11:20:33 +0100 | [diff] [blame] | 93 | memory_region_add_subregion(sysmem, 0xf0000000, &test_dev->iomem); |
| 94 | |
| 95 | |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 96 | tricoretb_binfo.ram_size = machine->ram_size; |
| 97 | tricoretb_binfo.kernel_filename = machine->kernel_filename; |
| 98 | |
| 99 | if (machine->kernel_filename) { |
| 100 | tricore_load_kernel(env); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void tricoreboard_init(MachineState *machine) |
| 105 | { |
| 106 | tricore_testboard_init(machine, 0x183); |
| 107 | } |
| 108 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 109 | static void ttb_machine_init(MachineClass *mc) |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 110 | { |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 111 | mc->desc = "a minimal TriCore board"; |
| 112 | mc->init = tricoreboard_init; |
Igor Mammedov | 0f550c5 | 2017-10-05 15:51:04 +0200 | [diff] [blame] | 113 | mc->default_cpu_type = TRICORE_CPU_TYPE_NAME("tc1796"); |
Bastian Koppelmann | e2d0501 | 2014-09-01 12:59:47 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 116 | DEFINE_MACHINE("tricore_testboard", ttb_machine_init) |