tricore_testboard.c 3.7 KB

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