qemu/hw/m68k/an5206.c
<<
>>
Prefs
   1/*
   2 * Arnewsh 5206 ColdFire system emulation.
   3 *
   4 * Copyright (c) 2007 CodeSourcery.
   5 *
   6 * This code is licensed under the GPL
   7 */
   8
   9#include "qemu/osdep.h"
  10#include "qapi/error.h"
  11#include "cpu.h"
  12#include "hw/m68k/mcf.h"
  13#include "hw/boards.h"
  14#include "hw/loader.h"
  15#include "elf.h"
  16#include "qemu/error-report.h"
  17#include "sysemu/qtest.h"
  18
  19#define KERNEL_LOAD_ADDR 0x10000
  20#define AN5206_MBAR_ADDR 0x10000000
  21#define AN5206_RAMBAR_ADDR 0x20000000
  22
  23static void mcf5206_init(MemoryRegion *sysmem, uint32_t base)
  24{
  25    DeviceState *dev;
  26    SysBusDevice *s;
  27
  28    dev = qdev_new(TYPE_MCF5206_MBAR);
  29    s = SYS_BUS_DEVICE(dev);
  30    sysbus_realize_and_unref(s, &error_fatal);
  31
  32    memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(s, 0));
  33}
  34
  35static void an5206_init(MachineState *machine)
  36{
  37    ram_addr_t ram_size = machine->ram_size;
  38    const char *kernel_filename = machine->kernel_filename;
  39    M68kCPU *cpu;
  40    CPUM68KState *env;
  41    int kernel_size;
  42    uint64_t elf_entry;
  43    hwaddr entry;
  44    MemoryRegion *address_space_mem = get_system_memory();
  45    MemoryRegion *sram = g_new(MemoryRegion, 1);
  46
  47    cpu = M68K_CPU(cpu_create(machine->cpu_type));
  48    env = &cpu->env;
  49
  50    /* Initialize CPU registers.  */
  51    env->vbr = 0;
  52    /* TODO: allow changing MBAR and RAMBAR.  */
  53    env->mbar = AN5206_MBAR_ADDR | 1;
  54    env->rambar0 = AN5206_RAMBAR_ADDR | 1;
  55
  56    /* DRAM at address zero */
  57    memory_region_add_subregion(address_space_mem, 0, machine->ram);
  58
  59    /* Internal SRAM.  */
  60    memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
  61    memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
  62
  63    mcf5206_init(address_space_mem, AN5206_MBAR_ADDR);
  64
  65    /* Load kernel.  */
  66    if (!kernel_filename) {
  67        if (qtest_enabled()) {
  68            return;
  69        }
  70        error_report("Kernel image must be specified");
  71        exit(1);
  72    }
  73
  74    kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, &elf_entry,
  75                           NULL, NULL, NULL, 1, EM_68K, 0, 0);
  76    entry = elf_entry;
  77    if (kernel_size < 0) {
  78        kernel_size = load_uimage(kernel_filename, &entry, NULL, NULL,
  79                                  NULL, NULL);
  80    }
  81    if (kernel_size < 0) {
  82        kernel_size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
  83                                          ram_size - KERNEL_LOAD_ADDR);
  84        entry = KERNEL_LOAD_ADDR;
  85    }
  86    if (kernel_size < 0) {
  87        error_report("Could not load kernel '%s'", kernel_filename);
  88        exit(1);
  89    }
  90
  91    env->pc = entry;
  92}
  93
  94static void an5206_machine_init(MachineClass *mc)
  95{
  96    mc->desc = "Arnewsh 5206";
  97    mc->init = an5206_init;
  98    mc->default_cpu_type = M68K_CPU_TYPE_NAME("m5206");
  99    mc->default_ram_id = "an5206.ram";
 100}
 101
 102DEFINE_MACHINE("an5206", an5206_machine_init)
 103