2011-03-08 01:32:44 +03:00
|
|
|
/*
|
|
|
|
* QEMU model for the Milkymist board.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:16:57 +03:00
|
|
|
#include "qemu/osdep.h"
|
2018-06-25 15:42:19 +03:00
|
|
|
#include "qemu/units.h"
|
hw/lm32: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines where then manually tweaked to pass checkpatch.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: Michael Walle <michael@walle.cc>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Michael Walle <michael@walle.cc>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-5-armbru@redhat.com>
2018-02-03 11:43:05 +03:00
|
|
|
#include "qemu/error-report.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "qemu-common.h"
|
|
|
|
#include "cpu.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "hw/hw.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/block/flash.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2013-08-04 18:49:28 +04:00
|
|
|
#include "sysemu/qtest.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/boards.h"
|
|
|
|
#include "hw/loader.h"
|
2011-03-08 01:32:44 +03:00
|
|
|
#include "elf.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "milkymist-hw.h"
|
2019-01-30 15:00:05 +03:00
|
|
|
#include "hw/display/milkymist_tmu2.h"
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "lm32.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
#define BIOS_FILENAME "mmone-bios.bin"
|
|
|
|
#define BIOS_OFFSET 0x00860000
|
2018-06-25 15:42:19 +03:00
|
|
|
#define BIOS_SIZE (512 * KiB)
|
2011-03-08 01:32:44 +03:00
|
|
|
#define KERNEL_LOAD_ADDR 0x40000000
|
|
|
|
|
|
|
|
typedef struct {
|
2012-05-04 21:05:02 +04:00
|
|
|
LM32CPU *cpu;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr bootstrap_pc;
|
|
|
|
hwaddr flash_base;
|
|
|
|
hwaddr initrd_base;
|
2011-03-08 01:32:44 +03:00
|
|
|
size_t initrd_size;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr cmdline_base;
|
2011-03-08 01:32:44 +03:00
|
|
|
} ResetInfo;
|
|
|
|
|
|
|
|
static void cpu_irq_handler(void *opaque, int irq, int level)
|
|
|
|
{
|
2013-01-18 01:30:20 +04:00
|
|
|
LM32CPU *cpu = opaque;
|
|
|
|
CPUState *cs = CPU(cpu);
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
if (level) {
|
2013-01-18 18:03:43 +04:00
|
|
|
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
|
2011-03-08 01:32:44 +03:00
|
|
|
} else {
|
2013-01-18 01:30:20 +04:00
|
|
|
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
|
2011-03-08 01:32:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void main_cpu_reset(void *opaque)
|
|
|
|
{
|
|
|
|
ResetInfo *reset_info = opaque;
|
2012-05-04 21:05:02 +04:00
|
|
|
CPULM32State *env = &reset_info->cpu->env;
|
2011-03-08 01:32:44 +03:00
|
|
|
|
2012-05-04 21:05:02 +04:00
|
|
|
cpu_reset(CPU(reset_info->cpu));
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
/* init defaults */
|
|
|
|
env->pc = reset_info->bootstrap_pc;
|
|
|
|
env->regs[R_R1] = reset_info->cmdline_base;
|
|
|
|
env->regs[R_R2] = reset_info->initrd_base;
|
|
|
|
env->regs[R_R3] = reset_info->initrd_base + reset_info->initrd_size;
|
|
|
|
env->eba = reset_info->flash_base;
|
|
|
|
env->deba = reset_info->flash_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-07 18:42:57 +04:00
|
|
|
milkymist_init(MachineState *machine)
|
2011-03-08 01:32:44 +03:00
|
|
|
{
|
2014-05-07 18:42:57 +04:00
|
|
|
const char *kernel_filename = machine->kernel_filename;
|
|
|
|
const char *kernel_cmdline = machine->kernel_cmdline;
|
|
|
|
const char *initrd_filename = machine->initrd_filename;
|
2012-05-04 21:03:24 +04:00
|
|
|
LM32CPU *cpu;
|
2012-03-14 04:38:23 +04:00
|
|
|
CPULM32State *env;
|
2011-03-08 01:32:44 +03:00
|
|
|
int kernel_size;
|
|
|
|
DriveInfo *dinfo;
|
2011-08-08 22:42:57 +04:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
|
|
|
MemoryRegion *phys_sdram = g_new(MemoryRegion, 1);
|
2015-05-29 08:27:07 +03:00
|
|
|
qemu_irq irq[32];
|
2011-03-08 01:32:44 +03:00
|
|
|
int i;
|
|
|
|
char *bios_filename;
|
|
|
|
ResetInfo *reset_info;
|
|
|
|
|
|
|
|
/* memory map */
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr flash_base = 0x00000000;
|
2018-06-25 15:42:19 +03:00
|
|
|
size_t flash_sector_size = 128 * KiB;
|
|
|
|
size_t flash_size = 32 * MiB;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr sdram_base = 0x40000000;
|
2018-06-25 15:42:19 +03:00
|
|
|
size_t sdram_size = 128 * MiB;
|
2011-03-08 01:32:44 +03:00
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr initrd_base = sdram_base + 0x1002000;
|
|
|
|
hwaddr cmdline_base = sdram_base + 0x1000000;
|
2011-03-08 01:32:44 +03:00
|
|
|
size_t initrd_max = sdram_size - 0x1002000;
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
reset_info = g_malloc0(sizeof(ResetInfo));
|
2011-03-08 01:32:44 +03:00
|
|
|
|
2017-10-05 16:50:43 +03:00
|
|
|
cpu = LM32_CPU(cpu_create(machine->cpu_type));
|
2013-11-28 22:09:33 +04:00
|
|
|
|
2012-05-04 21:03:24 +04:00
|
|
|
env = &cpu->env;
|
2012-05-04 21:05:02 +04:00
|
|
|
reset_info->cpu = cpu;
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
cpu_lm32_set_phys_msb_ignore(env, 1);
|
|
|
|
|
2015-04-04 15:16:18 +03:00
|
|
|
memory_region_allocate_system_memory(phys_sdram, NULL, "milkymist.sdram",
|
|
|
|
sdram_size);
|
2011-08-08 22:42:57 +04:00
|
|
|
memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram);
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
dinfo = drive_get(IF_PFLASH, 0, 0);
|
|
|
|
/* Numonyx JS28F256J3F105 */
|
2019-03-08 12:46:09 +03:00
|
|
|
pflash_cfi01_register(flash_base, "milkymist.flash", flash_size,
|
2014-10-07 15:59:18 +04:00
|
|
|
dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
|
2019-03-08 12:46:10 +03:00
|
|
|
flash_sector_size, 2, 0x00, 0x89, 0x00, 0x1d, 1);
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
/* create irq lines */
|
2015-05-29 08:27:07 +03:00
|
|
|
env->pic_state = lm32_pic_init(qemu_allocate_irq(cpu_irq_handler, cpu, 0));
|
2011-03-08 01:32:44 +03:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
irq[i] = qdev_get_gpio_in(env->pic_state, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load bios rom */
|
|
|
|
if (bios_name == NULL) {
|
|
|
|
bios_name = BIOS_FILENAME;
|
|
|
|
}
|
|
|
|
bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
|
|
|
|
|
|
|
|
if (bios_filename) {
|
2018-11-06 14:32:14 +03:00
|
|
|
if (load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE) < 0) {
|
|
|
|
error_report("could not load bios '%s'", bios_filename);
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-03-08 01:32:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
reset_info->bootstrap_pc = BIOS_OFFSET;
|
|
|
|
|
|
|
|
/* if no kernel is given no valid bios rom is a fatal error */
|
2013-08-04 18:49:28 +04:00
|
|
|
if (!kernel_filename && !dinfo && !bios_filename && !qtest_enabled()) {
|
hw/lm32: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines where then manually tweaked to pass checkpatch.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: Michael Walle <michael@walle.cc>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Michael Walle <michael@walle.cc>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-5-armbru@redhat.com>
2018-02-03 11:43:05 +03:00
|
|
|
error_report("could not load Milkymist One bios '%s'", bios_name);
|
2011-03-08 01:32:44 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
2015-02-27 10:50:17 +03:00
|
|
|
g_free(bios_filename);
|
2011-03-08 01:32:44 +03:00
|
|
|
|
2018-04-20 17:52:43 +03:00
|
|
|
milkymist_uart_create(0x60000000, irq[0], serial_hd(0));
|
2011-09-16 02:48:34 +04:00
|
|
|
milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3],
|
2011-03-08 01:32:44 +03:00
|
|
|
80000000, 0x10014d31, 0x0000041f, 0x00000001);
|
|
|
|
milkymist_hpdmc_create(0x60002000);
|
|
|
|
milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff);
|
|
|
|
milkymist_memcard_create(0x60004000);
|
2011-09-16 02:48:34 +04:00
|
|
|
milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]);
|
|
|
|
milkymist_pfpu_create(0x60006000, irq[8]);
|
2016-04-19 22:55:25 +03:00
|
|
|
if (machine->enable_graphics) {
|
2016-04-19 22:55:24 +03:00
|
|
|
milkymist_tmu2_create(0x60007000, irq[9]);
|
|
|
|
}
|
2011-09-16 02:48:34 +04:00
|
|
|
milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]);
|
|
|
|
milkymist_softusb_create(0x6000f000, irq[15],
|
2011-03-08 01:32:44 +03:00
|
|
|
0x20000000, 0x1000, 0x20020000, 0x2000);
|
|
|
|
|
|
|
|
/* make sure juart isn't the first chardev */
|
2018-04-20 17:52:43 +03:00
|
|
|
env->juart_state = lm32_juart_init(serial_hd(1));
|
2011-03-08 01:32:44 +03:00
|
|
|
|
|
|
|
if (kernel_filename) {
|
|
|
|
uint64_t entry;
|
|
|
|
|
|
|
|
/* Boots a kernel elf binary. */
|
2019-01-15 15:18:03 +03:00
|
|
|
kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
|
|
|
|
&entry, NULL, NULL,
|
2016-03-04 14:30:21 +03:00
|
|
|
1, EM_LATTICEMICO32, 0, 0);
|
2011-03-08 01:32:44 +03:00
|
|
|
reset_info->bootstrap_pc = entry;
|
|
|
|
|
|
|
|
if (kernel_size < 0) {
|
|
|
|
kernel_size = load_image_targphys(kernel_filename, sdram_base,
|
|
|
|
sdram_size);
|
|
|
|
reset_info->bootstrap_pc = sdram_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel_size < 0) {
|
hw/lm32: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
find ./* -type f -exec sed -i \
'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
{} +
Some lines where then manually tweaked to pass checkpatch.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: Michael Walle <michael@walle.cc>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Michael Walle <michael@walle.cc>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-5-armbru@redhat.com>
2018-02-03 11:43:05 +03:00
|
|
|
error_report("could not load kernel '%s'", kernel_filename);
|
2011-03-08 01:32:44 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel_cmdline && strlen(kernel_cmdline)) {
|
|
|
|
pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
|
|
|
|
kernel_cmdline);
|
|
|
|
reset_info->cmdline_base = (uint32_t)cmdline_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initrd_filename) {
|
|
|
|
size_t initrd_size;
|
|
|
|
initrd_size = load_image_targphys(initrd_filename, initrd_base,
|
|
|
|
initrd_max);
|
|
|
|
reset_info->initrd_base = (uint32_t)initrd_base;
|
|
|
|
reset_info->initrd_size = (uint32_t)initrd_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_register_reset(main_cpu_reset, reset_info);
|
|
|
|
}
|
|
|
|
|
2015-09-04 21:37:08 +03:00
|
|
|
static void milkymist_machine_init(MachineClass *mc)
|
2011-03-08 01:32:44 +03:00
|
|
|
{
|
2015-09-04 21:37:08 +03:00
|
|
|
mc->desc = "Milkymist One";
|
|
|
|
mc->init = milkymist_init;
|
|
|
|
mc->is_default = 0;
|
2017-10-05 16:50:43 +03:00
|
|
|
mc->default_cpu_type = LM32_CPU_TYPE_NAME("lm32-full");
|
2011-03-08 01:32:44 +03:00
|
|
|
}
|
|
|
|
|
2015-09-04 21:37:08 +03:00
|
|
|
DEFINE_MACHINE("milkymist", milkymist_machine_init)
|