an5206.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Arnewsh 5206 ColdFire system emulation.
  3. *
  4. * Copyright (c) 2007 CodeSourcery.
  5. *
  6. * This code is licensed under the GPL
  7. */
  8. #include "hw.h"
  9. #include "mcf.h"
  10. #include "boards.h"
  11. #include "loader.h"
  12. #include "elf.h"
  13. #include "exec-memory.h"
  14. #define KERNEL_LOAD_ADDR 0x10000
  15. #define AN5206_MBAR_ADDR 0x10000000
  16. #define AN5206_RAMBAR_ADDR 0x20000000
  17. /* Board init. */
  18. static void an5206_init(ram_addr_t ram_size,
  19. const char *boot_device,
  20. const char *kernel_filename, const char *kernel_cmdline,
  21. const char *initrd_filename, const char *cpu_model)
  22. {
  23. CPUM68KState *env;
  24. int kernel_size;
  25. uint64_t elf_entry;
  26. target_phys_addr_t entry;
  27. MemoryRegion *address_space_mem = get_system_memory();
  28. MemoryRegion *ram = g_new(MemoryRegion, 1);
  29. MemoryRegion *sram = g_new(MemoryRegion, 1);
  30. if (!cpu_model)
  31. cpu_model = "m5206";
  32. env = cpu_init(cpu_model);
  33. if (!env) {
  34. hw_error("Unable to find m68k CPU definition\n");
  35. }
  36. /* Initialize CPU registers. */
  37. env->vbr = 0;
  38. /* TODO: allow changing MBAR and RAMBAR. */
  39. env->mbar = AN5206_MBAR_ADDR | 1;
  40. env->rambar0 = AN5206_RAMBAR_ADDR | 1;
  41. /* DRAM at address zero */
  42. memory_region_init_ram(ram, "an5206.ram", ram_size);
  43. vmstate_register_ram_global(ram);
  44. memory_region_add_subregion(address_space_mem, 0, ram);
  45. /* Internal SRAM. */
  46. memory_region_init_ram(sram, "an5206.sram", 512);
  47. vmstate_register_ram_global(sram);
  48. memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
  49. mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, env);
  50. /* Load kernel. */
  51. if (!kernel_filename) {
  52. fprintf(stderr, "Kernel image must be specified\n");
  53. exit(1);
  54. }
  55. kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
  56. NULL, NULL, 1, ELF_MACHINE, 0);
  57. entry = elf_entry;
  58. if (kernel_size < 0) {
  59. kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL);
  60. }
  61. if (kernel_size < 0) {
  62. kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
  63. ram_size - KERNEL_LOAD_ADDR);
  64. entry = KERNEL_LOAD_ADDR;
  65. }
  66. if (kernel_size < 0) {
  67. fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
  68. exit(1);
  69. }
  70. env->pc = entry;
  71. }
  72. static QEMUMachine an5206_machine = {
  73. .name = "an5206",
  74. .desc = "Arnewsh 5206",
  75. .init = an5206_init,
  76. };
  77. static void an5206_machine_init(void)
  78. {
  79. qemu_register_machine(&an5206_machine);
  80. }
  81. machine_init(an5206_machine_init);