Statistics
| Branch: | Revision:

root / hw / ppc_chrp.c @ e9df014c

History | View | Annotate | Download (18.6 kB)

1 64201201 bellard
/*
2 64201201 bellard
 * QEMU PPC CHRP/PMAC hardware System Emulator
3 64201201 bellard
 * 
4 47103572 j_mayer
 * Copyright (c) 2004-2007 Fabrice Bellard
5 64201201 bellard
 * 
6 64201201 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 64201201 bellard
 * of this software and associated documentation files (the "Software"), to deal
8 64201201 bellard
 * in the Software without restriction, including without limitation the rights
9 64201201 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 64201201 bellard
 * copies of the Software, and to permit persons to whom the Software is
11 64201201 bellard
 * furnished to do so, subject to the following conditions:
12 64201201 bellard
 *
13 64201201 bellard
 * The above copyright notice and this permission notice shall be included in
14 64201201 bellard
 * all copies or substantial portions of the Software.
15 64201201 bellard
 *
16 64201201 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 64201201 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 64201201 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 64201201 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 64201201 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 64201201 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 64201201 bellard
 * THE SOFTWARE.
23 64201201 bellard
 */
24 64201201 bellard
#include "vl.h"
25 64201201 bellard
26 e9df014c j_mayer
/* SMP is not enabled, for now */
27 e9df014c j_mayer
#define MAX_CPUS 1
28 e9df014c j_mayer
29 64201201 bellard
#define BIOS_FILENAME "ppc_rom.bin"
30 d5295253 bellard
#define VGABIOS_FILENAME "video.x"
31 64201201 bellard
#define NVRAM_SIZE        0x2000
32 64201201 bellard
33 b6b8bd18 bellard
#define KERNEL_LOAD_ADDR 0x01000000
34 b6b8bd18 bellard
#define INITRD_LOAD_ADDR 0x01800000
35 b6b8bd18 bellard
36 267002cd bellard
/* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA,
37 e5733356 bellard
   NVRAM */
38 267002cd bellard
39 267002cd bellard
static int dbdma_mem_index;
40 267002cd bellard
static int cuda_mem_index;
41 0aa6a4a2 bellard
static int ide0_mem_index = -1;
42 0aa6a4a2 bellard
static int ide1_mem_index = -1;
43 0aa6a4a2 bellard
static int openpic_mem_index = -1;
44 0aa6a4a2 bellard
static int heathrow_pic_mem_index = -1;
45 e5733356 bellard
static int macio_nvram_mem_index = -1;
46 267002cd bellard
47 267002cd bellard
/* DBDMA: currently no op - should suffice right now */
48 267002cd bellard
49 267002cd bellard
static void dbdma_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
50 267002cd bellard
{
51 b6b8bd18 bellard
    printf("%s: 0x%08x <= 0x%08x\n", __func__, addr, value);
52 267002cd bellard
}
53 267002cd bellard
54 267002cd bellard
static void dbdma_writew (void *opaque, target_phys_addr_t addr, uint32_t value)
55 267002cd bellard
{
56 267002cd bellard
}
57 267002cd bellard
58 267002cd bellard
static void dbdma_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
59 267002cd bellard
{
60 267002cd bellard
}
61 267002cd bellard
62 267002cd bellard
static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr)
63 267002cd bellard
{
64 b6b8bd18 bellard
    printf("%s: 0x%08x => 0x00000000\n", __func__, addr);
65 267002cd bellard
    return 0;
66 267002cd bellard
}
67 267002cd bellard
68 267002cd bellard
static uint32_t dbdma_readw (void *opaque, target_phys_addr_t addr)
69 267002cd bellard
{
70 267002cd bellard
    return 0;
71 267002cd bellard
}
72 267002cd bellard
73 267002cd bellard
static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr)
74 267002cd bellard
{
75 267002cd bellard
    return 0;
76 267002cd bellard
}
77 267002cd bellard
78 267002cd bellard
static CPUWriteMemoryFunc *dbdma_write[] = {
79 267002cd bellard
    &dbdma_writeb,
80 267002cd bellard
    &dbdma_writew,
81 267002cd bellard
    &dbdma_writel,
82 267002cd bellard
};
83 267002cd bellard
84 267002cd bellard
static CPUReadMemoryFunc *dbdma_read[] = {
85 267002cd bellard
    &dbdma_readb,
86 267002cd bellard
    &dbdma_readw,
87 267002cd bellard
    &dbdma_readl,
88 267002cd bellard
};
89 267002cd bellard
90 e5733356 bellard
/* macio style NVRAM device */
91 e5733356 bellard
typedef struct MacIONVRAMState {
92 e5733356 bellard
    uint8_t data[0x2000];
93 e5733356 bellard
} MacIONVRAMState;
94 e5733356 bellard
95 e5733356 bellard
static void macio_nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t value)
96 e5733356 bellard
{
97 e5733356 bellard
    MacIONVRAMState *s = opaque;
98 e5733356 bellard
    addr = (addr >> 4) & 0x1fff;
99 e5733356 bellard
    s->data[addr] = value;
100 e5733356 bellard
    //    printf("macio_nvram_writeb %04x = %02x\n", addr, value);
101 e5733356 bellard
}
102 e5733356 bellard
103 e5733356 bellard
static uint32_t macio_nvram_readb (void *opaque, target_phys_addr_t addr)
104 e5733356 bellard
{
105 e5733356 bellard
    MacIONVRAMState *s = opaque;
106 e5733356 bellard
    uint32_t value;
107 e5733356 bellard
108 e5733356 bellard
    addr = (addr >> 4) & 0x1fff;
109 e5733356 bellard
    value = s->data[addr];
110 e5733356 bellard
    //    printf("macio_nvram_readb %04x = %02x\n", addr, value);
111 e5733356 bellard
    return value;
112 e5733356 bellard
}
113 e5733356 bellard
114 e5733356 bellard
static CPUWriteMemoryFunc *macio_nvram_write[] = {
115 e5733356 bellard
    &macio_nvram_writeb,
116 e5733356 bellard
    &macio_nvram_writeb,
117 e5733356 bellard
    &macio_nvram_writeb,
118 e5733356 bellard
};
119 e5733356 bellard
120 e5733356 bellard
static CPUReadMemoryFunc *macio_nvram_read[] = {
121 e5733356 bellard
    &macio_nvram_readb,
122 e5733356 bellard
    &macio_nvram_readb,
123 e5733356 bellard
    &macio_nvram_readb,
124 e5733356 bellard
};
125 e5733356 bellard
126 e5733356 bellard
static MacIONVRAMState *macio_nvram_init(void)
127 e5733356 bellard
{
128 e5733356 bellard
    MacIONVRAMState *s;
129 e5733356 bellard
    s = qemu_mallocz(sizeof(MacIONVRAMState));
130 e5733356 bellard
    if (!s)
131 e5733356 bellard
        return NULL;
132 e5733356 bellard
    macio_nvram_mem_index = cpu_register_io_memory(0, macio_nvram_read, 
133 e5733356 bellard
                                                   macio_nvram_write, s);
134 e5733356 bellard
    return s;
135 e5733356 bellard
}
136 e5733356 bellard
137 267002cd bellard
static void macio_map(PCIDevice *pci_dev, int region_num, 
138 267002cd bellard
                      uint32_t addr, uint32_t size, int type)
139 267002cd bellard
{
140 0aa6a4a2 bellard
    if (heathrow_pic_mem_index >= 0) {
141 0aa6a4a2 bellard
        cpu_register_physical_memory(addr + 0x00000, 0x1000, 
142 0aa6a4a2 bellard
                                     heathrow_pic_mem_index);
143 0aa6a4a2 bellard
    }
144 267002cd bellard
    cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index);
145 267002cd bellard
    cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index);
146 0aa6a4a2 bellard
    if (ide0_mem_index >= 0)
147 0aa6a4a2 bellard
        cpu_register_physical_memory(addr + 0x1f000, 0x1000, ide0_mem_index);
148 0aa6a4a2 bellard
    if (ide1_mem_index >= 0)
149 0aa6a4a2 bellard
        cpu_register_physical_memory(addr + 0x20000, 0x1000, ide1_mem_index);
150 0aa6a4a2 bellard
    if (openpic_mem_index >= 0) {
151 0aa6a4a2 bellard
        cpu_register_physical_memory(addr + 0x40000, 0x40000, 
152 0aa6a4a2 bellard
                                     openpic_mem_index);
153 0aa6a4a2 bellard
    }
154 e5733356 bellard
    if (macio_nvram_mem_index >= 0)
155 e5733356 bellard
        cpu_register_physical_memory(addr + 0x60000, 0x20000, macio_nvram_mem_index);
156 267002cd bellard
}
157 267002cd bellard
158 e5733356 bellard
static void macio_init(PCIBus *bus, int device_id)
159 267002cd bellard
{
160 267002cd bellard
    PCIDevice *d;
161 267002cd bellard
162 46e50e9d bellard
    d = pci_register_device(bus, "macio", sizeof(PCIDevice),
163 46e50e9d bellard
                            -1, NULL, NULL);
164 267002cd bellard
    /* Note: this code is strongly inspirated from the corresponding code
165 267002cd bellard
       in PearPC */
166 267002cd bellard
    d->config[0x00] = 0x6b; // vendor_id
167 267002cd bellard
    d->config[0x01] = 0x10;
168 e5733356 bellard
    d->config[0x02] = device_id;
169 e5733356 bellard
    d->config[0x03] = device_id >> 8;
170 267002cd bellard
171 267002cd bellard
    d->config[0x0a] = 0x00; // class_sub = pci2pci
172 267002cd bellard
    d->config[0x0b] = 0xff; // class_base = bridge
173 267002cd bellard
    d->config[0x0e] = 0x00; // header_type
174 267002cd bellard
175 267002cd bellard
    d->config[0x3d] = 0x01; // interrupt on pin 1
176 267002cd bellard
    
177 267002cd bellard
    dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL);
178 267002cd bellard
179 267002cd bellard
    pci_register_io_region(d, 0, 0x80000, 
180 267002cd bellard
                           PCI_ADDRESS_SPACE_MEM, macio_map);
181 267002cd bellard
}
182 267002cd bellard
183 0aa6a4a2 bellard
/* UniN device */
184 0aa6a4a2 bellard
static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
185 0aa6a4a2 bellard
{
186 0aa6a4a2 bellard
}
187 0aa6a4a2 bellard
188 0aa6a4a2 bellard
static uint32_t unin_readl (void *opaque, target_phys_addr_t addr)
189 0aa6a4a2 bellard
{
190 0aa6a4a2 bellard
    return 0;
191 0aa6a4a2 bellard
}
192 0aa6a4a2 bellard
193 0aa6a4a2 bellard
static CPUWriteMemoryFunc *unin_write[] = {
194 0aa6a4a2 bellard
    &unin_writel,
195 0aa6a4a2 bellard
    &unin_writel,
196 0aa6a4a2 bellard
    &unin_writel,
197 0aa6a4a2 bellard
};
198 0aa6a4a2 bellard
199 0aa6a4a2 bellard
static CPUReadMemoryFunc *unin_read[] = {
200 0aa6a4a2 bellard
    &unin_readl,
201 0aa6a4a2 bellard
    &unin_readl,
202 0aa6a4a2 bellard
    &unin_readl,
203 0aa6a4a2 bellard
};
204 0aa6a4a2 bellard
205 0aa6a4a2 bellard
/* temporary frame buffer OSI calls for the video.x driver. The right
206 0aa6a4a2 bellard
   solution is to modify the driver to use VGA PCI I/Os */
207 0aa6a4a2 bellard
static int vga_osi_call(CPUState *env)
208 0aa6a4a2 bellard
{
209 0aa6a4a2 bellard
    static int vga_vbl_enabled;
210 0aa6a4a2 bellard
    int linesize;
211 0aa6a4a2 bellard
    
212 0aa6a4a2 bellard
    //    printf("osi_call R5=%d\n", env->gpr[5]);
213 0aa6a4a2 bellard
214 0aa6a4a2 bellard
    /* same handler as PearPC, coming from the original MOL video
215 0aa6a4a2 bellard
       driver. */
216 0aa6a4a2 bellard
    switch(env->gpr[5]) {
217 0aa6a4a2 bellard
    case 4:
218 0aa6a4a2 bellard
        break;
219 0aa6a4a2 bellard
    case 28: /* set_vmode */
220 0aa6a4a2 bellard
        if (env->gpr[6] != 1 || env->gpr[7] != 0)
221 0aa6a4a2 bellard
            env->gpr[3] = 1;
222 0aa6a4a2 bellard
        else
223 0aa6a4a2 bellard
            env->gpr[3] = 0;
224 0aa6a4a2 bellard
        break;
225 0aa6a4a2 bellard
    case 29: /* get_vmode_info */
226 0aa6a4a2 bellard
        if (env->gpr[6] != 0) {
227 0aa6a4a2 bellard
            if (env->gpr[6] != 1 || env->gpr[7] != 0) {
228 0aa6a4a2 bellard
                env->gpr[3] = 1;
229 0aa6a4a2 bellard
                break;
230 0aa6a4a2 bellard
            }
231 0aa6a4a2 bellard
        }
232 0aa6a4a2 bellard
        env->gpr[3] = 0; 
233 0aa6a4a2 bellard
        env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */
234 0aa6a4a2 bellard
        env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */
235 0aa6a4a2 bellard
        env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */
236 0aa6a4a2 bellard
        env->gpr[7] = 85 << 16; /* refresh rate */
237 0aa6a4a2 bellard
        env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */
238 0aa6a4a2 bellard
        linesize = ((graphic_depth + 7) >> 3) * graphic_width;
239 0aa6a4a2 bellard
        linesize = (linesize + 3) & ~3;
240 0aa6a4a2 bellard
        env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */
241 0aa6a4a2 bellard
        break;
242 0aa6a4a2 bellard
    case 31: /* set_video power */
243 0aa6a4a2 bellard
        env->gpr[3] = 0;
244 0aa6a4a2 bellard
        break;
245 0aa6a4a2 bellard
    case 39: /* video_ctrl */
246 0aa6a4a2 bellard
        if (env->gpr[6] == 0 || env->gpr[6] == 1)
247 0aa6a4a2 bellard
            vga_vbl_enabled = env->gpr[6];
248 0aa6a4a2 bellard
        env->gpr[3] = 0;
249 0aa6a4a2 bellard
        break;
250 0aa6a4a2 bellard
    case 47:
251 0aa6a4a2 bellard
        break;
252 0aa6a4a2 bellard
    case 59: /* set_color */
253 0aa6a4a2 bellard
        /* R6 = index, R7 = RGB */
254 0aa6a4a2 bellard
        env->gpr[3] = 0;
255 0aa6a4a2 bellard
        break;
256 0aa6a4a2 bellard
    case 64: /* get color */
257 0aa6a4a2 bellard
        /* R6 = index */
258 0aa6a4a2 bellard
        env->gpr[3] = 0; 
259 0aa6a4a2 bellard
        break;
260 0aa6a4a2 bellard
    case 116: /* set hwcursor */
261 0aa6a4a2 bellard
        /* R6 = x, R7 = y, R8 = visible, R9 = data */
262 0aa6a4a2 bellard
        break;
263 0aa6a4a2 bellard
    default:
264 0aa6a4a2 bellard
        fprintf(stderr, "unsupported OSI call R5=%08x\n", env->gpr[5]);
265 0aa6a4a2 bellard
        break;
266 0aa6a4a2 bellard
    }
267 0aa6a4a2 bellard
    return 1; /* osi_call handled */
268 0aa6a4a2 bellard
}
269 0aa6a4a2 bellard
270 e5733356 bellard
static uint8_t nvram_chksum(const uint8_t *buf, int n)
271 e5733356 bellard
{
272 e5733356 bellard
    int sum, i;
273 e5733356 bellard
    sum = 0;
274 e5733356 bellard
    for(i = 0; i < n; i++)
275 e5733356 bellard
        sum += buf[i];
276 e5733356 bellard
    return (sum & 0xff) + (sum >> 8);
277 e5733356 bellard
}
278 e5733356 bellard
279 e5733356 bellard
/* set a free Mac OS NVRAM partition */
280 e5733356 bellard
void pmac_format_nvram_partition(uint8_t *buf, int len)
281 e5733356 bellard
{
282 e5733356 bellard
    char partition_name[12] = "wwwwwwwwwwww";
283 e5733356 bellard
    
284 e5733356 bellard
    buf[0] = 0x7f; /* free partition magic */
285 e5733356 bellard
    buf[1] = 0; /* checksum */
286 e5733356 bellard
    buf[2] = len >> 8;
287 e5733356 bellard
    buf[3] = len;
288 e5733356 bellard
    memcpy(buf + 4, partition_name, 12);
289 e5733356 bellard
    buf[1] = nvram_chksum(buf, 16);
290 e5733356 bellard
}    
291 e5733356 bellard
292 0aa6a4a2 bellard
/* PowerPC CHRP hardware initialisation */
293 94fc95cd j_mayer
static void ppc_chrp_init (int ram_size, int vga_ram_size, int boot_device,
294 94fc95cd j_mayer
                           DisplayState *ds, const char **fd_filename,
295 94fc95cd j_mayer
                           int snapshot,
296 94fc95cd j_mayer
                           const char *kernel_filename,
297 94fc95cd j_mayer
                           const char *kernel_cmdline,
298 94fc95cd j_mayer
                           const char *initrd_filename,
299 94fc95cd j_mayer
                           const char *cpu_model,
300 94fc95cd j_mayer
                           int is_heathrow)
301 64201201 bellard
{
302 e9df014c j_mayer
    CPUState *env, *envs[MAX_CPUS];
303 64201201 bellard
    char buf[1024];
304 e9df014c j_mayer
    qemu_irq *pic, **openpic_irqs;
305 64201201 bellard
    m48t59_t *nvram;
306 aef445bd pbrook
    int unin_memory;
307 d5295253 bellard
    int linux_boot, i;
308 d5295253 bellard
    unsigned long bios_offset, vga_bios_offset;
309 b6b8bd18 bellard
    uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
310 3fc6c082 bellard
    ppc_def_t *def;
311 46e50e9d bellard
    PCIBus *pci_bus;
312 0aa6a4a2 bellard
    const char *arch_name;
313 d5295253 bellard
    int vga_bios_size, bios_size;
314 d537cf6c pbrook
    qemu_irq *dummy_irq;
315 46e50e9d bellard
316 64201201 bellard
    linux_boot = (kernel_filename != NULL);
317 64201201 bellard
318 c68ea704 bellard
    /* init CPUs */
319 c68ea704 bellard
    env = cpu_init();
320 c68ea704 bellard
    register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
321 c68ea704 bellard
322 94fc95cd j_mayer
    /* Default CPU is a generic 74x/75x */
323 94fc95cd j_mayer
    if (cpu_model == NULL)
324 94fc95cd j_mayer
        cpu_model = "750";
325 c68ea704 bellard
    /* XXX: CPU model (or PVR) should be provided on command line */
326 c68ea704 bellard
    //    ppc_find_by_name("750gx", &def); // Linux boot OK
327 c68ea704 bellard
    //    ppc_find_by_name("750fx", &def); // Linux boot OK
328 c68ea704 bellard
    /* Linux does not boot on 750cxe (and probably other 750cx based)
329 c68ea704 bellard
     * because it assumes it has 8 IBAT & DBAT pairs as it only have 4.
330 c68ea704 bellard
     */
331 94fc95cd j_mayer
    ppc_find_by_name(cpu_model, &def);
332 c68ea704 bellard
    if (def == NULL) {
333 c68ea704 bellard
        cpu_abort(env, "Unable to find PowerPC CPU definition\n");
334 c68ea704 bellard
    }
335 e9df014c j_mayer
    for (i = 0; i < smp_cpus; i++) {
336 e9df014c j_mayer
        cpu_ppc_register(env, def);
337 e9df014c j_mayer
        /* Set time-base frequency to 100 Mhz */
338 e9df014c j_mayer
        cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
339 e9df014c j_mayer
        env->osi_call = vga_osi_call;
340 e9df014c j_mayer
        envs[i] = env;
341 e9df014c j_mayer
    }
342 c68ea704 bellard
343 64201201 bellard
    /* allocate RAM */
344 64201201 bellard
    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
345 64201201 bellard
346 64201201 bellard
    /* allocate and load BIOS */
347 64201201 bellard
    bios_offset = ram_size + vga_ram_size;
348 64201201 bellard
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
349 d5295253 bellard
    bios_size = load_image(buf, phys_ram_base + bios_offset);
350 d5295253 bellard
    if (bios_size < 0 || bios_size > BIOS_SIZE) {
351 d5295253 bellard
        fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
352 64201201 bellard
        exit(1);
353 64201201 bellard
    }
354 d5295253 bellard
    bios_size = (bios_size + 0xfff) & ~0xfff;
355 d5295253 bellard
    cpu_register_physical_memory((uint32_t)(-bios_size), 
356 d5295253 bellard
                                 bios_size, bios_offset | IO_MEM_ROM);
357 d5295253 bellard
    
358 d5295253 bellard
    /* allocate and load VGA BIOS */
359 d5295253 bellard
    vga_bios_offset = bios_offset + bios_size;
360 d5295253 bellard
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
361 d5295253 bellard
    vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
362 d5295253 bellard
    if (vga_bios_size < 0) {
363 d5295253 bellard
        /* if no bios is present, we can still work */
364 d5295253 bellard
        fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
365 d5295253 bellard
        vga_bios_size = 0;
366 d5295253 bellard
    } else {
367 d5295253 bellard
        /* set a specific header (XXX: find real Apple format for NDRV
368 d5295253 bellard
           drivers) */
369 d5295253 bellard
        phys_ram_base[vga_bios_offset] = 'N';
370 d5295253 bellard
        phys_ram_base[vga_bios_offset + 1] = 'D';
371 d5295253 bellard
        phys_ram_base[vga_bios_offset + 2] = 'R';
372 d5295253 bellard
        phys_ram_base[vga_bios_offset + 3] = 'V';
373 d5295253 bellard
        cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4), 
374 d5295253 bellard
                     vga_bios_size);
375 d5295253 bellard
        vga_bios_size += 8;
376 d5295253 bellard
    }
377 d5295253 bellard
    vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff;
378 d5295253 bellard
    
379 b6b8bd18 bellard
    if (linux_boot) {
380 b6b8bd18 bellard
        kernel_base = KERNEL_LOAD_ADDR;
381 b6b8bd18 bellard
        /* now we can load the kernel */
382 b6b8bd18 bellard
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
383 b6b8bd18 bellard
        if (kernel_size < 0) {
384 b6b8bd18 bellard
            fprintf(stderr, "qemu: could not load kernel '%s'\n", 
385 b6b8bd18 bellard
                    kernel_filename);
386 b6b8bd18 bellard
            exit(1);
387 b6b8bd18 bellard
        }
388 b6b8bd18 bellard
        /* load initrd */
389 b6b8bd18 bellard
        if (initrd_filename) {
390 b6b8bd18 bellard
            initrd_base = INITRD_LOAD_ADDR;
391 b6b8bd18 bellard
            initrd_size = load_image(initrd_filename,
392 b6b8bd18 bellard
                                     phys_ram_base + initrd_base);
393 b6b8bd18 bellard
            if (initrd_size < 0) {
394 b6b8bd18 bellard
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", 
395 b6b8bd18 bellard
                        initrd_filename);
396 b6b8bd18 bellard
                exit(1);
397 b6b8bd18 bellard
            }
398 b6b8bd18 bellard
        } else {
399 b6b8bd18 bellard
            initrd_base = 0;
400 b6b8bd18 bellard
            initrd_size = 0;
401 b6b8bd18 bellard
        }
402 b6b8bd18 bellard
        boot_device = 'm';
403 b6b8bd18 bellard
    } else {
404 b6b8bd18 bellard
        kernel_base = 0;
405 b6b8bd18 bellard
        kernel_size = 0;
406 b6b8bd18 bellard
        initrd_base = 0;
407 b6b8bd18 bellard
        initrd_size = 0;
408 b6b8bd18 bellard
    }
409 0aa6a4a2 bellard
410 0aa6a4a2 bellard
    if (is_heathrow) {
411 0aa6a4a2 bellard
        isa_mem_base = 0x80000000;
412 0aa6a4a2 bellard
        
413 0aa6a4a2 bellard
        /* Register 2 MB of ISA IO space */
414 aef445bd pbrook
        isa_mmio_init(0xfe000000, 0x00200000);
415 aef445bd pbrook
416 0aa6a4a2 bellard
        /* init basic PC hardware */
417 502a5395 pbrook
        pic = heathrow_pic_init(&heathrow_pic_mem_index);
418 502a5395 pbrook
        pci_bus = pci_grackle_init(0xfec00000, pic);
419 89b6b508 bellard
        pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, 
420 89b6b508 bellard
                     ram_size, vga_ram_size,
421 89b6b508 bellard
                     vga_bios_offset, vga_bios_size);
422 0aa6a4a2 bellard
423 0aa6a4a2 bellard
        /* XXX: suppress that */
424 d537cf6c pbrook
        dummy_irq = i8259_init(NULL);
425 0aa6a4a2 bellard
        
426 0aa6a4a2 bellard
        /* XXX: use Mac Serial port */
427 d537cf6c pbrook
        serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
428 0aa6a4a2 bellard
        
429 0aa6a4a2 bellard
        for(i = 0; i < nb_nics; i++) {
430 a41b2ff2 pbrook
            if (!nd_table[i].model)
431 a41b2ff2 pbrook
                nd_table[i].model = "ne2k_pci";
432 abcebc7e ths
            pci_nic_init(pci_bus, &nd_table[i], -1);
433 0aa6a4a2 bellard
        }
434 0aa6a4a2 bellard
        
435 0aa6a4a2 bellard
        pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
436 0aa6a4a2 bellard
437 0aa6a4a2 bellard
        /* cuda also initialize ADB */
438 d537cf6c pbrook
        cuda_mem_index = cuda_init(pic[0x12]);
439 0aa6a4a2 bellard
        
440 0aa6a4a2 bellard
        adb_kbd_init(&adb_bus);
441 0aa6a4a2 bellard
        adb_mouse_init(&adb_bus);
442 0aa6a4a2 bellard
        
443 e5733356 bellard
        {
444 e5733356 bellard
            MacIONVRAMState *nvr;
445 e5733356 bellard
            nvr = macio_nvram_init();
446 e5733356 bellard
            pmac_format_nvram_partition(nvr->data, 0x2000);
447 e5733356 bellard
        }
448 e5733356 bellard
449 e5733356 bellard
        macio_init(pci_bus, 0x0017);
450 47103572 j_mayer
451 d537cf6c pbrook
        nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
452 47103572 j_mayer
453 0aa6a4a2 bellard
        arch_name = "HEATHROW";
454 0aa6a4a2 bellard
    } else {
455 0aa6a4a2 bellard
        isa_mem_base = 0x80000000;
456 47103572 j_mayer
457 0aa6a4a2 bellard
        /* Register 8 MB of ISA IO space */
458 aef445bd pbrook
        isa_mmio_init(0xf2000000, 0x00800000);
459 47103572 j_mayer
460 0aa6a4a2 bellard
        /* UniN init */
461 0aa6a4a2 bellard
        unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL);
462 0aa6a4a2 bellard
        cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory);
463 0aa6a4a2 bellard
464 e9df014c j_mayer
        openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
465 e9df014c j_mayer
        openpic_irqs[0] =
466 e9df014c j_mayer
            qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
467 e9df014c j_mayer
        for (i = 0; i < smp_cpus; i++) {
468 e9df014c j_mayer
            /* Mac99 IRQ connection between OpenPIC outputs pins
469 e9df014c j_mayer
             * and PowerPC input pins
470 e9df014c j_mayer
             */
471 e9df014c j_mayer
            openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
472 e9df014c j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_INT] =
473 e9df014c j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC_INPUT_INT];
474 e9df014c j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
475 e9df014c j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC_INPUT_INT];
476 e9df014c j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
477 e9df014c j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC_INPUT_MCP];
478 e9df014c j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL; /* Not connected ? */
479 e9df014c j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
480 e9df014c j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC_INPUT_HRESET]; /* Check this */
481 e9df014c j_mayer
        }
482 e9df014c j_mayer
        pic = openpic_init(NULL, &openpic_mem_index, smp_cpus,
483 e9df014c j_mayer
                           openpic_irqs, NULL);
484 502a5395 pbrook
        pci_bus = pci_pmac_init(pic);
485 0aa6a4a2 bellard
        /* init basic PC hardware */
486 89b6b508 bellard
        pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
487 89b6b508 bellard
                     ram_size, vga_ram_size,
488 89b6b508 bellard
                     vga_bios_offset, vga_bios_size);
489 0aa6a4a2 bellard
490 0aa6a4a2 bellard
        /* XXX: suppress that */
491 d537cf6c pbrook
        dummy_irq = i8259_init(NULL);
492 3079c59a j_mayer
493 0aa6a4a2 bellard
        /* XXX: use Mac Serial port */
494 d537cf6c pbrook
        serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
495 0aa6a4a2 bellard
        for(i = 0; i < nb_nics; i++) {
496 3079c59a j_mayer
            if (!nd_table[i].model)
497 3079c59a j_mayer
                nd_table[i].model = "ne2k_pci";
498 3079c59a j_mayer
            pci_nic_init(pci_bus, &nd_table[i], -1);
499 0aa6a4a2 bellard
        }
500 0aa6a4a2 bellard
#if 1
501 d537cf6c pbrook
        ide0_mem_index = pmac_ide_init(&bs_table[0], pic[0x13]);
502 d537cf6c pbrook
        ide1_mem_index = pmac_ide_init(&bs_table[2], pic[0x14]);
503 0aa6a4a2 bellard
#else
504 0aa6a4a2 bellard
        pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
505 0aa6a4a2 bellard
#endif
506 0aa6a4a2 bellard
        /* cuda also initialize ADB */
507 d537cf6c pbrook
        cuda_mem_index = cuda_init(pic[0x19]);
508 0aa6a4a2 bellard
        
509 0aa6a4a2 bellard
        adb_kbd_init(&adb_bus);
510 0aa6a4a2 bellard
        adb_mouse_init(&adb_bus);
511 0aa6a4a2 bellard
        
512 e5733356 bellard
        macio_init(pci_bus, 0x0022);
513 0aa6a4a2 bellard
        
514 d537cf6c pbrook
        nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
515 0aa6a4a2 bellard
        
516 0aa6a4a2 bellard
        arch_name = "MAC99";
517 64201201 bellard
    }
518 0d92ed30 pbrook
519 0d92ed30 pbrook
    if (usb_enabled) {
520 e24ad6f1 pbrook
        usb_ohci_init_pci(pci_bus, 3, -1);
521 0d92ed30 pbrook
    }
522 0d92ed30 pbrook
523 b6b8bd18 bellard
    if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
524 b6b8bd18 bellard
        graphic_depth = 15;
525 64201201 bellard
526 0aa6a4a2 bellard
    PPC_NVRAM_set_params(nvram, NVRAM_SIZE, arch_name, ram_size, boot_device,
527 b6b8bd18 bellard
                         kernel_base, kernel_size,
528 b6b8bd18 bellard
                         kernel_cmdline,
529 b6b8bd18 bellard
                         initrd_base, initrd_size,
530 64201201 bellard
                         /* XXX: need an option to load a NVRAM image */
531 b6b8bd18 bellard
                         0,
532 b6b8bd18 bellard
                         graphic_width, graphic_height, graphic_depth);
533 b6b8bd18 bellard
    /* No PCI init: the BIOS will do it */
534 0aa6a4a2 bellard
535 0aa6a4a2 bellard
    /* Special port to get debug messages from Open-Firmware */
536 0aa6a4a2 bellard
    register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
537 0aa6a4a2 bellard
}
538 0aa6a4a2 bellard
539 94fc95cd j_mayer
static void ppc_core99_init (int ram_size, int vga_ram_size, int boot_device,
540 94fc95cd j_mayer
                             DisplayState *ds, const char **fd_filename,
541 94fc95cd j_mayer
                             int snapshot,
542 94fc95cd j_mayer
                             const char *kernel_filename,
543 94fc95cd j_mayer
                             const char *kernel_cmdline,
544 94fc95cd j_mayer
                             const char *initrd_filename,
545 94fc95cd j_mayer
                             const char *cpu_model)
546 0aa6a4a2 bellard
{
547 0aa6a4a2 bellard
    ppc_chrp_init(ram_size, vga_ram_size, boot_device,
548 0aa6a4a2 bellard
                  ds, fd_filename, snapshot,
549 0aa6a4a2 bellard
                  kernel_filename, kernel_cmdline,
550 94fc95cd j_mayer
                  initrd_filename, cpu_model, 0);
551 64201201 bellard
}
552 0aa6a4a2 bellard
    
553 94fc95cd j_mayer
static void ppc_heathrow_init (int ram_size, int vga_ram_size, int boot_device,
554 94fc95cd j_mayer
                               DisplayState *ds, const char **fd_filename,
555 94fc95cd j_mayer
                               int snapshot,
556 94fc95cd j_mayer
                               const char *kernel_filename,
557 94fc95cd j_mayer
                               const char *kernel_cmdline,
558 94fc95cd j_mayer
                               const char *initrd_filename,
559 94fc95cd j_mayer
                               const char *cpu_model)
560 0aa6a4a2 bellard
{
561 0aa6a4a2 bellard
    ppc_chrp_init(ram_size, vga_ram_size, boot_device,
562 0aa6a4a2 bellard
                  ds, fd_filename, snapshot,
563 0aa6a4a2 bellard
                  kernel_filename, kernel_cmdline,
564 94fc95cd j_mayer
                  initrd_filename, cpu_model, 1);
565 0aa6a4a2 bellard
}
566 0aa6a4a2 bellard
567 0aa6a4a2 bellard
QEMUMachine core99_machine = {
568 0289b2c1 bellard
    "mac99",
569 0289b2c1 bellard
    "Mac99 based PowerMAC",
570 0aa6a4a2 bellard
    ppc_core99_init,
571 0aa6a4a2 bellard
};
572 0aa6a4a2 bellard
573 0aa6a4a2 bellard
QEMUMachine heathrow_machine = {
574 0289b2c1 bellard
    "g3bw",
575 0aa6a4a2 bellard
    "Heathrow based PowerMAC",
576 0aa6a4a2 bellard
    ppc_heathrow_init,
577 0aa6a4a2 bellard
};