1
2
3
4
5
6
7
8
9
10
11
12#include "qemu/osdep.h"
13#include "qapi/error.h"
14#include "qemu-common.h"
15#include "cpu.h"
16#include "ui/console.h"
17#include "elf.h"
18#include "exec/address-spaces.h"
19#include "hw/sysbus.h"
20#include "hw/boards.h"
21#include "hw/loader.h"
22#include "hw/i386/pc.h"
23#include "qemu/error-report.h"
24#include "sysemu/qtest.h"
25
26#undef DEBUG_PUV3
27#include "hw/unicore32/puv3.h"
28
29#define KERNEL_LOAD_ADDR 0x03000000
30#define KERNEL_MAX_SIZE 0x00800000
31
32static void puv3_intc_cpu_handler(void *opaque, int irq, int level)
33{
34 UniCore32CPU *cpu = opaque;
35 CPUState *cs = CPU(cpu);
36
37 assert(irq == 0);
38 if (level) {
39 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
40 } else {
41 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
42 }
43}
44
45static void puv3_soc_init(CPUUniCore32State *env)
46{
47 qemu_irq cpu_intc, irqs[PUV3_IRQS_NR];
48 DeviceState *dev;
49 MemoryRegion *i8042 = g_new(MemoryRegion, 1);
50 int i;
51
52
53 cpu_intc = qemu_allocate_irq(puv3_intc_cpu_handler,
54 uc32_env_get_cpu(env), 0);
55 dev = sysbus_create_simple("puv3_intc", PUV3_INTC_BASE, cpu_intc);
56 for (i = 0; i < PUV3_IRQS_NR; i++) {
57 irqs[i] = qdev_get_gpio_in(dev, i);
58 }
59
60
61 sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL);
62 sysbus_create_simple("puv3_dma", PUV3_DMA_BASE, NULL);
63 sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
64 sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE,
65 irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
66 irqs[PUV3_IRQS_GPIOLOW2], irqs[PUV3_IRQS_GPIOLOW3],
67 irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5],
68 irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7],
69 irqs[PUV3_IRQS_GPIOHIGH], NULL);
70
71
72 i8042_mm_init(irqs[PUV3_IRQS_PS2_KBD], NULL, i8042, PUV3_REGS_OFFSET, 4);
73 memory_region_add_subregion(get_system_memory(), PUV3_PS2_BASE, i8042);
74}
75
76static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
77{
78 MemoryRegion *ram_memory = g_new(MemoryRegion, 1);
79
80
81 memory_region_init_ram(ram_memory, NULL, "puv3.ram", ram_size,
82 &error_fatal);
83 vmstate_register_ram_global(ram_memory);
84 memory_region_add_subregion(get_system_memory(), 0, ram_memory);
85}
86
87static const GraphicHwOps no_ops;
88
89static void puv3_load_kernel(const char *kernel_filename)
90{
91 int size;
92
93 if (kernel_filename == NULL && qtest_enabled()) {
94 return;
95 }
96 assert(kernel_filename != NULL);
97
98
99 size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
100 KERNEL_MAX_SIZE);
101 if (size < 0) {
102 error_report("Load kernel error: '%s'", kernel_filename);
103 exit(1);
104 }
105
106
107 graphic_console_init(NULL, 0, &no_ops, NULL);
108}
109
110static void puv3_init(MachineState *machine)
111{
112 ram_addr_t ram_size = machine->ram_size;
113 const char *cpu_model = machine->cpu_model;
114 const char *kernel_filename = machine->kernel_filename;
115 const char *initrd_filename = machine->initrd_filename;
116 CPUUniCore32State *env;
117 UniCore32CPU *cpu;
118
119 if (initrd_filename) {
120 error_report("Please use kernel built-in initramdisk");
121 exit(1);
122 }
123
124 if (!cpu_model) {
125 cpu_model = "UniCore-II";
126 }
127
128 cpu = uc32_cpu_init(cpu_model);
129 if (!cpu) {
130 error_report("Unable to find CPU definition");
131 exit(1);
132 }
133 env = &cpu->env;
134
135 puv3_soc_init(env);
136 puv3_board_init(env, ram_size);
137 puv3_load_kernel(kernel_filename);
138}
139
140static void puv3_machine_init(MachineClass *mc)
141{
142 mc->desc = "PKUnity Version-3 based on UniCore32";
143 mc->init = puv3_init;
144 mc->is_default = 1;
145}
146
147DEFINE_MACHINE("puv3", puv3_machine_init)
148