]> git.proxmox.com Git - qemu.git/blame - hw/ppc_oldworld.c
Add support for -prom-env command line options
[qemu.git] / hw / ppc_oldworld.c
CommitLineData
3cbee15b
JM
1/*
2 * QEMU OldWorld PowerMac (currently ~G3 B&W) hardware System Emulator
3 *
4 * Copyright (c) 2004-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
87ecb68b
PB
25#include "hw.h"
26#include "ppc.h"
3cbee15b 27#include "ppc_mac.h"
87ecb68b
PB
28#include "nvram.h"
29#include "pc.h"
30#include "sysemu.h"
31#include "net.h"
32#include "isa.h"
33#include "pci.h"
34#include "boards.h"
3cbee15b 35
e4bcb14c 36#define MAX_IDE_BUS 2
a748ab6d 37#define VGA_BIOS_SIZE 65536
e4bcb14c 38
3cbee15b
JM
39/* temporary frame buffer OSI calls for the video.x driver. The right
40 solution is to modify the driver to use VGA PCI I/Os */
41/* XXX: to be removed. This is no way related to emulation */
42static int vga_osi_call (CPUState *env)
43{
44 static int vga_vbl_enabled;
45 int linesize;
46
aae9366a 47 // printf("osi_call R5=" REGX "\n", ppc_dump_gpr(env, 5));
3cbee15b
JM
48
49 /* same handler as PearPC, coming from the original MOL video
50 driver. */
51 switch(env->gpr[5]) {
52 case 4:
53 break;
54 case 28: /* set_vmode */
55 if (env->gpr[6] != 1 || env->gpr[7] != 0)
56 env->gpr[3] = 1;
57 else
58 env->gpr[3] = 0;
59 break;
60 case 29: /* get_vmode_info */
61 if (env->gpr[6] != 0) {
62 if (env->gpr[6] != 1 || env->gpr[7] != 0) {
63 env->gpr[3] = 1;
64 break;
65 }
66 }
67 env->gpr[3] = 0;
68 env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */
69 env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */
70 env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */
71 env->gpr[7] = 85 << 16; /* refresh rate */
72 env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */
73 linesize = ((graphic_depth + 7) >> 3) * graphic_width;
74 linesize = (linesize + 3) & ~3;
75 env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */
76 break;
77 case 31: /* set_video power */
78 env->gpr[3] = 0;
79 break;
80 case 39: /* video_ctrl */
81 if (env->gpr[6] == 0 || env->gpr[6] == 1)
82 vga_vbl_enabled = env->gpr[6];
83 env->gpr[3] = 0;
84 break;
85 case 47:
86 break;
87 case 59: /* set_color */
88 /* R6 = index, R7 = RGB */
89 env->gpr[3] = 0;
90 break;
91 case 64: /* get color */
92 /* R6 = index */
93 env->gpr[3] = 0;
94 break;
95 case 116: /* set hwcursor */
96 /* R6 = x, R7 = y, R8 = visible, R9 = data */
97 break;
98 default:
aae9366a
JM
99 fprintf(stderr, "unsupported OSI call R5=" REGX "\n",
100 ppc_dump_gpr(env, 5));
3cbee15b
JM
101 break;
102 }
103
104 return 1; /* osi_call handled */
105}
106
00f82b8a 107static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size,
6ac0e82d 108 const char *boot_device, DisplayState *ds,
3cbee15b
JM
109 const char *kernel_filename,
110 const char *kernel_cmdline,
111 const char *initrd_filename,
112 const char *cpu_model)
113{
aaed909a 114 CPUState *env = NULL, *envs[MAX_CPUS];
3cbee15b
JM
115 char buf[1024];
116 qemu_irq *pic, **heathrow_irqs;
117 nvram_t nvram;
118 m48t59_t *m48t59;
119 int linux_boot, i;
a748ab6d 120 ram_addr_t ram_offset, vga_ram_offset, bios_offset, vga_bios_offset;
3cbee15b 121 uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
3cbee15b
JM
122 PCIBus *pci_bus;
123 MacIONVRAMState *nvr;
124 int vga_bios_size, bios_size;
125 qemu_irq *dummy_irq;
126 int pic_mem_index, nvram_mem_index, dbdma_mem_index, cuda_mem_index;
0d913fdb 127 int ide_mem_index[2];
28c5af54 128 int ppc_boot_device;
e4bcb14c
TS
129 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
130 int index;
3cbee15b
JM
131
132 linux_boot = (kernel_filename != NULL);
133
134 /* init CPUs */
3cbee15b 135 if (cpu_model == NULL)
f2fde45a 136 cpu_model = "G3";
3cbee15b 137 for (i = 0; i < smp_cpus; i++) {
aaed909a
FB
138 env = cpu_init(cpu_model);
139 if (!env) {
140 fprintf(stderr, "Unable to find PowerPC CPU definition\n");
141 exit(1);
142 }
3cbee15b
JM
143 /* Set time-base frequency to 100 Mhz */
144 cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
145 env->osi_call = vga_osi_call;
146 qemu_register_reset(&cpu_ppc_reset, env);
3cbee15b
JM
147 envs[i] = env;
148 }
4c823cff
JM
149 if (env->nip < 0xFFF80000) {
150 /* Special test for PowerPC 601:
151 * the boot vector is at 0xFFF00100, then we need a 1MB BIOS.
152 * But the NVRAM is located at 0xFFF04000...
153 */
154 cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n");
155 }
3cbee15b
JM
156
157 /* allocate RAM */
a748ab6d
AJ
158 ram_offset = qemu_ram_alloc(ram_size);
159 cpu_register_physical_memory(0, ram_size, ram_offset);
160
161 /* allocate VGA RAM */
162 vga_ram_offset = qemu_ram_alloc(vga_ram_size);
3cbee15b
JM
163
164 /* allocate and load BIOS */
a748ab6d 165 bios_offset = qemu_ram_alloc(BIOS_SIZE);
3cbee15b 166 if (bios_name == NULL)
992e5acd 167 bios_name = PROM_FILENAME;
3cbee15b 168 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
992e5acd
BS
169 cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | IO_MEM_ROM);
170
171 /* Load OpenBIOS (ELF) */
172 bios_size = load_elf(buf, 0, NULL, NULL, NULL);
3cbee15b
JM
173 if (bios_size < 0 || bios_size > BIOS_SIZE) {
174 cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
175 exit(1);
176 }
3cbee15b
JM
177
178 /* allocate and load VGA BIOS */
a748ab6d 179 vga_bios_offset = qemu_ram_alloc(VGA_BIOS_SIZE);
3cbee15b
JM
180 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
181 vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
182 if (vga_bios_size < 0) {
183 /* if no bios is present, we can still work */
184 fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
185 vga_bios_size = 0;
186 } else {
187 /* set a specific header (XXX: find real Apple format for NDRV
188 drivers) */
189 phys_ram_base[vga_bios_offset] = 'N';
190 phys_ram_base[vga_bios_offset + 1] = 'D';
191 phys_ram_base[vga_bios_offset + 2] = 'R';
192 phys_ram_base[vga_bios_offset + 3] = 'V';
193 cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4),
194 vga_bios_size);
195 vga_bios_size += 8;
196 }
3cbee15b
JM
197
198 if (linux_boot) {
199 kernel_base = KERNEL_LOAD_ADDR;
200 /* now we can load the kernel */
201 kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
202 if (kernel_size < 0) {
203 cpu_abort(env, "qemu: could not load kernel '%s'\n",
204 kernel_filename);
205 exit(1);
206 }
207 /* load initrd */
208 if (initrd_filename) {
209 initrd_base = INITRD_LOAD_ADDR;
210 initrd_size = load_image(initrd_filename,
211 phys_ram_base + initrd_base);
212 if (initrd_size < 0) {
213 cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
214 initrd_filename);
215 exit(1);
216 }
217 } else {
218 initrd_base = 0;
219 initrd_size = 0;
220 }
6ac0e82d 221 ppc_boot_device = 'm';
3cbee15b
JM
222 } else {
223 kernel_base = 0;
224 kernel_size = 0;
225 initrd_base = 0;
226 initrd_size = 0;
28c5af54 227 ppc_boot_device = '\0';
0d913fdb 228 for (i = 0; boot_device[i] != '\0'; i++) {
28c5af54 229 /* TOFIX: for now, the second IDE channel is not properly
0d913fdb 230 * used by OHW. The Mac floppy disk are not emulated.
28c5af54
JM
231 * For now, OHW cannot boot from the network.
232 */
233#if 0
0d913fdb
JM
234 if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
235 ppc_boot_device = boot_device[i];
28c5af54 236 break;
0d913fdb 237 }
28c5af54 238#else
0d913fdb
JM
239 if (boot_device[i] >= 'c' && boot_device[i] <= 'd') {
240 ppc_boot_device = boot_device[i];
28c5af54 241 break;
0d913fdb 242 }
28c5af54
JM
243#endif
244 }
245 if (ppc_boot_device == '\0') {
246 fprintf(stderr, "No valid boot device for Mac99 machine\n");
247 exit(1);
248 }
3cbee15b
JM
249 }
250
251 isa_mem_base = 0x80000000;
aae9366a 252
3cbee15b
JM
253 /* Register 2 MB of ISA IO space */
254 isa_mmio_init(0xfe000000, 0x00200000);
255
256 /* XXX: we register only 1 output pin for heathrow PIC */
257 heathrow_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
258 heathrow_irqs[0] =
259 qemu_mallocz(smp_cpus * sizeof(qemu_irq) * 1);
260 /* Connect the heathrow PIC outputs to the 6xx bus */
261 for (i = 0; i < smp_cpus; i++) {
262 switch (PPC_INPUT(env)) {
263 case PPC_FLAGS_INPUT_6xx:
264 heathrow_irqs[i] = heathrow_irqs[0] + (i * 1);
265 heathrow_irqs[i][0] =
266 ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
267 break;
268 default:
269 cpu_abort(env, "Bus model not supported on OldWorld Mac machine\n");
270 exit(1);
271 }
272 }
273
274 /* init basic PC hardware */
275 if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
276 cpu_abort(env, "Only 6xx bus is supported on heathrow machine\n");
277 exit(1);
278 }
279 pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs);
280 pci_bus = pci_grackle_init(0xfec00000, pic);
a748ab6d
AJ
281 pci_vga_init(pci_bus, ds, phys_ram_base + vga_ram_offset,
282 vga_ram_offset, vga_ram_size,
3cbee15b 283 vga_bios_offset, vga_bios_size);
aae9366a 284
3cbee15b
JM
285 /* XXX: suppress that */
286 dummy_irq = i8259_init(NULL);
287
288 /* XXX: use Mac Serial port */
b6cd0ea1 289 serial_init(0x3f8, dummy_irq[4], 115200, serial_hds[0]);
aae9366a 290
3cbee15b
JM
291 for(i = 0; i < nb_nics; i++) {
292 if (!nd_table[i].model)
293 nd_table[i].model = "ne2k_pci";
294 pci_nic_init(pci_bus, &nd_table[i], -1);
295 }
0d913fdb
JM
296
297 /* First IDE channel is a CMD646 on the PCI bus */
e4bcb14c
TS
298
299 if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
300 fprintf(stderr, "qemu: too many IDE bus\n");
301 exit(1);
302 }
303 index = drive_get_index(IF_IDE, 0, 0);
304 if (index == -1)
305 hd[0] = NULL;
306 else
307 hd[0] = drives_table[index].bdrv;
308 index = drive_get_index(IF_IDE, 0, 1);
309 if (index == -1)
310 hd[1] = NULL;
311 else
312 hd[1] = drives_table[index].bdrv;
313 hd[3] = hd[2] = NULL;
314 pci_cmd646_ide_init(pci_bus, hd, 0);
315
0d913fdb 316 /* Second IDE channel is a MAC IDE on the MacIO bus */
e4bcb14c
TS
317 index = drive_get_index(IF_IDE, 1, 0);
318 if (index == -1)
319 hd[0] = NULL;
320 else
321 hd[0] = drives_table[index].bdrv;
322 index = drive_get_index(IF_IDE, 1, 1);
323 if (index == -1)
324 hd[1] = NULL;
325 else
326 hd[1] = drives_table[index].bdrv;
0d913fdb 327 ide_mem_index[0] = -1;
e4bcb14c 328 ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D]);
3cbee15b
JM
329
330 /* cuda also initialize ADB */
331 cuda_init(&cuda_mem_index, pic[0x12]);
332
333 adb_kbd_init(&adb_bus);
334 adb_mouse_init(&adb_bus);
aae9366a 335
74e91155 336 nvr = macio_nvram_init(&nvram_mem_index, 0x2000);
3cbee15b
JM
337 pmac_format_nvram_partition(nvr, 0x2000);
338
339 dbdma_init(&dbdma_mem_index);
28c5af54 340
3cbee15b 341 macio_init(pci_bus, 0x0017, 1, pic_mem_index, dbdma_mem_index,
0d913fdb 342 cuda_mem_index, nvr, 2, ide_mem_index);
3cbee15b
JM
343
344 if (usb_enabled) {
345 usb_ohci_init_pci(pci_bus, 3, -1);
346 }
347
348 if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
349 graphic_depth = 15;
350
351 m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
352 nvram.opaque = m48t59;
353 nvram.read_fn = &m48t59_read;
354 nvram.write_fn = &m48t59_write;
6ac0e82d
AZ
355 PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "HEATHROW", ram_size,
356 ppc_boot_device, kernel_base, kernel_size,
3cbee15b
JM
357 kernel_cmdline,
358 initrd_base, initrd_size,
359 /* XXX: need an option to load a NVRAM image */
360 0,
361 graphic_width, graphic_height, graphic_depth);
362 /* No PCI init: the BIOS will do it */
363
364 /* Special port to get debug messages from Open-Firmware */
365 register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
366}
367
368QEMUMachine heathrow_machine = {
4b32e168
AL
369 .name = "g3bw",
370 .desc = "Heathrow based PowerMAC",
371 .init = ppc_heathrow_init,
a748ab6d 372 .ram_require = BIOS_SIZE + VGA_BIOS_SIZE + VGA_RAM_SIZE,
3d878caa 373 .max_cpus = MAX_CPUS,
3cbee15b 374};