~vcs-imports/qemu/git

719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
1
/*
2
 * QEMU PPC PREP hardware System Emulator
3163 by ths
find -type f | xargs sed -i 's/[\t ]$//g' # on most files
3
 *
2532 by j_mayer
New model for PowerPC CPU hardware interrupt events:
4
 * Copyright (c) 2003-2007 Jocelyn Mayer
3163 by ths
find -type f | xargs sed -i 's/[\t ]$//g' # on most files
5
 *
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
3664 by pbrook
Break up vl.h.
24
#include "hw.h"
25
#include "nvram.h"
26
#include "pc.h"
27
#include "fdc.h"
28
#include "net.h"
29
#include "sysemu.h"
30
#include "isa.h"
31
#include "pci.h"
32
#include "ppc.h"
33
#include "boards.h"
838 by bellard
PowerPC merge: real time TB and decrementer - faster and simpler exception handling (Jocelyn Mayer)
34
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
35
//#define HARD_DEBUG_PPC_IO
36
//#define DEBUG_PPC_IO
37
3307 by j_mayer
Fix PowerPC initialisation and first reset:
38
/* SMP is not enabled, for now */
39
#define MAX_CPUS 1
40
3749 by ths
Add -drive parameter, by Laurent Vivier.
41
#define MAX_IDE_BUS 2
42
954 by bellard
ppc init fixes
43
#define BIOS_FILENAME "ppc_rom.bin"
44
#define KERNEL_LOAD_ADDR 0x01000000
45
#define INITRD_LOAD_ADDR 0x01800000
862 by bellard
PowerPC prep/chrp/pmac support
46
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
47
extern int loglevel;
48
extern FILE *logfile;
49
50
#if defined (HARD_DEBUG_PPC_IO) && !defined (DEBUG_PPC_IO)
51
#define DEBUG_PPC_IO
52
#endif
53
54
#if defined (HARD_DEBUG_PPC_IO)
55
#define PPC_IO_DPRINTF(fmt, args...)                     \
56
do {                                                     \
954 by bellard
ppc init fixes
57
    if (loglevel & CPU_LOG_IOPORT) {                     \
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
58
        fprintf(logfile, "%s: " fmt, __func__ , ##args); \
59
    } else {                                             \
60
        printf("%s : " fmt, __func__ , ##args);          \
61
    }                                                    \
62
} while (0)
63
#elif defined (DEBUG_PPC_IO)
64
#define PPC_IO_DPRINTF(fmt, args...)                     \
65
do {                                                     \
954 by bellard
ppc init fixes
66
    if (loglevel & CPU_LOG_IOPORT) {                     \
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
67
        fprintf(logfile, "%s: " fmt, __func__ , ##args); \
68
    }                                                    \
69
} while (0)
70
#else
71
#define PPC_IO_DPRINTF(fmt, args...) do { } while (0)
72
#endif
73
862 by bellard
PowerPC prep/chrp/pmac support
74
/* Constants for devices init */
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
75
static const int ide_iobase[2] = { 0x1f0, 0x170 };
76
static const int ide_iobase2[2] = { 0x3f6, 0x376 };
77
static const int ide_irq[2] = { 13, 13 };
78
79
#define NE2000_NB_MAX 6
80
81
static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
82
static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
83
862 by bellard
PowerPC prep/chrp/pmac support
84
//static PITState *pit;
85
86
/* ISA IO ports bridge */
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
87
#define PPC_IO_BASE 0x80000000
88
862 by bellard
PowerPC prep/chrp/pmac support
89
/* Speaker port 0x61 */
90
int speaker_data_on;
91
int dummy_refresh_clock;
92
3168 by j_mayer
Coding style fixes in PowerPC related code (no functional change):
93
static void speaker_ioport_write (void *opaque, uint32_t addr, uint32_t val)
862 by bellard
PowerPC prep/chrp/pmac support
94
{
95
#if 0
96
    speaker_data_on = (val >> 1) & 1;
97
    pit_set_gate(pit, 2, val & 1);
98
#endif
99
}
100
2532 by j_mayer
New model for PowerPC CPU hardware interrupt events:
101
static uint32_t speaker_ioport_read (void *opaque, uint32_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
102
{
103
#if 0
104
    int out;
105
    out = pit_get_out(pit, 2, qemu_get_clock(vm_clock));
106
    dummy_refresh_clock ^= 1;
107
    return (speaker_data_on << 1) | pit_get_gate(pit, 2) | (out << 5) |
2532 by j_mayer
New model for PowerPC CPU hardware interrupt events:
108
        (dummy_refresh_clock << 4);
862 by bellard
PowerPC prep/chrp/pmac support
109
#endif
110
    return 0;
111
}
112
113
/* PCI intack register */
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
114
/* Read-only register (?) */
2532 by j_mayer
New model for PowerPC CPU hardware interrupt events:
115
static void _PPC_intack_write (void *opaque,
116
                               target_phys_addr_t addr, uint32_t value)
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
117
{
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
118
//    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
119
}
120
3337 by j_mayer
PowerPC target optimisations: make intensive use of always_inline.
121
static always_inline uint32_t _PPC_intack_read (target_phys_addr_t addr)
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
122
{
123
    uint32_t retval = 0;
124
125
    if (addr == 0xBFFFFFF0)
1481 by bellard
more generic i8259 support
126
        retval = pic_intack_read(isa_pic);
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
127
//   printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
128
129
    return retval;
130
}
131
871 by bellard
support for opaque data on memory I/Os
132
static uint32_t PPC_intack_readb (void *opaque, target_phys_addr_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
133
{
134
    return _PPC_intack_read(addr);
135
}
136
871 by bellard
support for opaque data on memory I/Os
137
static uint32_t PPC_intack_readw (void *opaque, target_phys_addr_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
138
{
139
#ifdef TARGET_WORDS_BIGENDIAN
140
    return bswap16(_PPC_intack_read(addr));
141
#else
142
    return _PPC_intack_read(addr);
143
#endif
144
}
145
871 by bellard
support for opaque data on memory I/Os
146
static uint32_t PPC_intack_readl (void *opaque, target_phys_addr_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
147
{
148
#ifdef TARGET_WORDS_BIGENDIAN
149
    return bswap32(_PPC_intack_read(addr));
150
#else
151
    return _PPC_intack_read(addr);
152
#endif
153
}
154
155
static CPUWriteMemoryFunc *PPC_intack_write[] = {
156
    &_PPC_intack_write,
157
    &_PPC_intack_write,
158
    &_PPC_intack_write,
159
};
160
161
static CPUReadMemoryFunc *PPC_intack_read[] = {
162
    &PPC_intack_readb,
163
    &PPC_intack_readw,
164
    &PPC_intack_readl,
165
};
166
167
/* PowerPC control and status registers */
168
#if 0 // Not used
169
static struct {
170
    /* IDs */
171
    uint32_t veni_devi;
172
    uint32_t revi;
173
    /* Control and status */
174
    uint32_t gcsr;
175
    uint32_t xcfr;
176
    uint32_t ct32;
177
    uint32_t mcsr;
178
    /* General purpose registers */
179
    uint32_t gprg[6];
180
    /* Exceptions */
181
    uint32_t feen;
182
    uint32_t fest;
183
    uint32_t fema;
184
    uint32_t fecl;
185
    uint32_t eeen;
186
    uint32_t eest;
187
    uint32_t eecl;
188
    uint32_t eeint;
189
    uint32_t eemck0;
190
    uint32_t eemck1;
191
    /* Error diagnostic */
192
} XCSR;
193
3168 by j_mayer
Coding style fixes in PowerPC related code (no functional change):
194
static void PPC_XCSR_writeb (void *opaque,
195
                             target_phys_addr_t addr, uint32_t value)
862 by bellard
PowerPC prep/chrp/pmac support
196
{
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
197
    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
862 by bellard
PowerPC prep/chrp/pmac support
198
}
199
3168 by j_mayer
Coding style fixes in PowerPC related code (no functional change):
200
static void PPC_XCSR_writew (void *opaque,
201
                             target_phys_addr_t addr, uint32_t value)
862 by bellard
PowerPC prep/chrp/pmac support
202
{
203
#ifdef TARGET_WORDS_BIGENDIAN
204
    value = bswap16(value);
205
#endif
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
206
    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
862 by bellard
PowerPC prep/chrp/pmac support
207
}
208
3168 by j_mayer
Coding style fixes in PowerPC related code (no functional change):
209
static void PPC_XCSR_writel (void *opaque,
210
                             target_phys_addr_t addr, uint32_t value)
862 by bellard
PowerPC prep/chrp/pmac support
211
{
212
#ifdef TARGET_WORDS_BIGENDIAN
213
    value = bswap32(value);
214
#endif
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
215
    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
862 by bellard
PowerPC prep/chrp/pmac support
216
}
217
871 by bellard
support for opaque data on memory I/Os
218
static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
219
{
220
    uint32_t retval = 0;
221
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
222
    printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
862 by bellard
PowerPC prep/chrp/pmac support
223
224
    return retval;
225
}
226
871 by bellard
support for opaque data on memory I/Os
227
static uint32_t PPC_XCSR_readw (void *opaque, target_phys_addr_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
228
{
229
    uint32_t retval = 0;
230
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
231
    printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
862 by bellard
PowerPC prep/chrp/pmac support
232
#ifdef TARGET_WORDS_BIGENDIAN
233
    retval = bswap16(retval);
234
#endif
235
236
    return retval;
237
}
238
871 by bellard
support for opaque data on memory I/Os
239
static uint32_t PPC_XCSR_readl (void *opaque, target_phys_addr_t addr)
862 by bellard
PowerPC prep/chrp/pmac support
240
{
241
    uint32_t retval = 0;
242
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
243
    printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
862 by bellard
PowerPC prep/chrp/pmac support
244
#ifdef TARGET_WORDS_BIGENDIAN
245
    retval = bswap32(retval);
246
#endif
247
248
    return retval;
249
}
250
251
static CPUWriteMemoryFunc *PPC_XCSR_write[] = {
252
    &PPC_XCSR_writeb,
253
    &PPC_XCSR_writew,
254
    &PPC_XCSR_writel,
255
};
256
257
static CPUReadMemoryFunc *PPC_XCSR_read[] = {
258
    &PPC_XCSR_readb,
259
    &PPC_XCSR_readw,
260
    &PPC_XCSR_readl,
261
};
954 by bellard
ppc init fixes
262
#endif
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
263
264
/* Fake super-io ports for PREP platform (Intel 82378ZB) */
862 by bellard
PowerPC prep/chrp/pmac support
265
typedef struct sysctrl_t {
3471 by j_mayer
Implement PreP reset port.
266
    qemu_irq reset_irq;
862 by bellard
PowerPC prep/chrp/pmac support
267
    m48t59_t *nvram;
268
    uint8_t state;
269
    uint8_t syscontrol;
270
    uint8_t fake_io[2];
1376 by bellard
PREP machines have two IO mappings.
271
    int contiguous_map;
1487 by bellard
endian register support
272
    int endian;
862 by bellard
PowerPC prep/chrp/pmac support
273
} sysctrl_t;
274
275
enum {
276
    STATE_HARDFILE = 0x01,
277
};
278
279
static sysctrl_t *sysctrl;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
280
281
static void PREP_io_write (void *opaque, uint32_t addr, uint32_t val)
282
{
862 by bellard
PowerPC prep/chrp/pmac support
283
    sysctrl_t *sysctrl = opaque;
284
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
285
    PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
286
                   val);
862 by bellard
PowerPC prep/chrp/pmac support
287
    sysctrl->fake_io[addr - 0x0398] = val;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
288
}
289
290
static uint32_t PREP_io_read (void *opaque, uint32_t addr)
291
{
862 by bellard
PowerPC prep/chrp/pmac support
292
    sysctrl_t *sysctrl = opaque;
293
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
294
    PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
862 by bellard
PowerPC prep/chrp/pmac support
295
                   sysctrl->fake_io[addr - 0x0398]);
296
    return sysctrl->fake_io[addr - 0x0398];
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
297
}
298
299
static void PREP_io_800_writeb (void *opaque, uint32_t addr, uint32_t val)
300
{
862 by bellard
PowerPC prep/chrp/pmac support
301
    sysctrl_t *sysctrl = opaque;
302
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
303
    PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n",
304
                   addr - PPC_IO_BASE, val);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
305
    switch (addr) {
306
    case 0x0092:
307
        /* Special port 92 */
308
        /* Check soft reset asked */
862 by bellard
PowerPC prep/chrp/pmac support
309
        if (val & 0x01) {
3471 by j_mayer
Implement PreP reset port.
310
            qemu_irq_raise(sysctrl->reset_irq);
311
        } else {
312
            qemu_irq_lower(sysctrl->reset_irq);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
313
        }
314
        /* Check LE mode */
862 by bellard
PowerPC prep/chrp/pmac support
315
        if (val & 0x02) {
1487 by bellard
endian register support
316
            sysctrl->endian = 1;
317
        } else {
318
            sysctrl->endian = 0;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
319
        }
320
        break;
862 by bellard
PowerPC prep/chrp/pmac support
321
    case 0x0800:
322
        /* Motorola CPU configuration register : read-only */
323
        break;
324
    case 0x0802:
325
        /* Motorola base module feature register : read-only */
326
        break;
327
    case 0x0803:
328
        /* Motorola base module status register : read-only */
329
        break;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
330
    case 0x0808:
862 by bellard
PowerPC prep/chrp/pmac support
331
        /* Hardfile light register */
332
        if (val & 1)
333
            sysctrl->state |= STATE_HARDFILE;
334
        else
335
            sysctrl->state &= ~STATE_HARDFILE;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
336
        break;
337
    case 0x0810:
338
        /* Password protect 1 register */
862 by bellard
PowerPC prep/chrp/pmac support
339
        if (sysctrl->nvram != NULL)
340
            m48t59_toggle_lock(sysctrl->nvram, 1);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
341
        break;
342
    case 0x0812:
343
        /* Password protect 2 register */
862 by bellard
PowerPC prep/chrp/pmac support
344
        if (sysctrl->nvram != NULL)
345
            m48t59_toggle_lock(sysctrl->nvram, 2);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
346
        break;
347
    case 0x0814:
862 by bellard
PowerPC prep/chrp/pmac support
348
        /* L2 invalidate register */
1637 by bellard
cpu_single_env usage fix
349
        //        tlb_flush(first_cpu, 1);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
350
        break;
351
    case 0x081C:
352
        /* system control register */
862 by bellard
PowerPC prep/chrp/pmac support
353
        sysctrl->syscontrol = val & 0x0F;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
354
        break;
355
    case 0x0850:
356
        /* I/O map type register */
1376 by bellard
PREP machines have two IO mappings.
357
        sysctrl->contiguous_map = val & 0x01;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
358
        break;
359
    default:
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
360
        printf("ERROR: unaffected IO port write: %04" PRIx32
361
               " => %02" PRIx32"\n", addr, val);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
362
        break;
363
    }
364
}
365
366
static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr)
367
{
862 by bellard
PowerPC prep/chrp/pmac support
368
    sysctrl_t *sysctrl = opaque;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
369
    uint32_t retval = 0xFF;
370
371
    switch (addr) {
372
    case 0x0092:
373
        /* Special port 92 */
862 by bellard
PowerPC prep/chrp/pmac support
374
        retval = 0x00;
375
        break;
376
    case 0x0800:
377
        /* Motorola CPU configuration register */
378
        retval = 0xEF; /* MPC750 */
379
        break;
380
    case 0x0802:
381
        /* Motorola Base module feature register */
382
        retval = 0xAD; /* No ESCC, PMC slot neither ethernet */
383
        break;
384
    case 0x0803:
385
        /* Motorola base module status register */
386
        retval = 0xE0; /* Standard MPC750 */
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
387
        break;
388
    case 0x080C:
389
        /* Equipment present register:
390
         *  no L2 cache
391
         *  no upgrade processor
392
         *  no cards in PCI slots
393
         *  SCSI fuse is bad
394
         */
862 by bellard
PowerPC prep/chrp/pmac support
395
        retval = 0x3C;
396
        break;
397
    case 0x0810:
398
        /* Motorola base module extended feature register */
399
        retval = 0x39; /* No USB, CF and PCI bridge. NVRAM present */
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
400
        break;
1376 by bellard
PREP machines have two IO mappings.
401
    case 0x0814:
402
        /* L2 invalidate: don't care */
403
        break;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
404
    case 0x0818:
405
        /* Keylock */
406
        retval = 0x00;
407
        break;
408
    case 0x081C:
409
        /* system control register
410
         * 7 - 6 / 1 - 0: L2 cache enable
411
         */
862 by bellard
PowerPC prep/chrp/pmac support
412
        retval = sysctrl->syscontrol;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
413
        break;
414
    case 0x0823:
415
        /* */
416
        retval = 0x03; /* no L2 cache */
417
        break;
418
    case 0x0850:
419
        /* I/O map type register */
1376 by bellard
PREP machines have two IO mappings.
420
        retval = sysctrl->contiguous_map;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
421
        break;
422
    default:
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
423
        printf("ERROR: unaffected IO port: %04" PRIx32 " read\n", addr);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
424
        break;
425
    }
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
426
    PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n",
427
                   addr - PPC_IO_BASE, retval);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
428
429
    return retval;
430
}
431
3337 by j_mayer
PowerPC target optimisations: make intensive use of always_inline.
432
static always_inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl,
433
                                                         target_phys_addr_t
434
                                                         addr)
1376 by bellard
PREP machines have two IO mappings.
435
{
436
    if (sysctrl->contiguous_map == 0) {
437
        /* 64 KB contiguous space for IOs */
438
        addr &= 0xFFFF;
439
    } else {
440
        /* 8 MB non-contiguous space for IOs */
441
        addr = (addr & 0x1F) | ((addr & 0x007FFF000) >> 7);
442
    }
443
444
    return addr;
445
}
446
447
static void PPC_prep_io_writeb (void *opaque, target_phys_addr_t addr,
448
                                uint32_t value)
449
{
450
    sysctrl_t *sysctrl = opaque;
451
452
    addr = prep_IO_address(sysctrl, addr);
453
    cpu_outb(NULL, addr, value);
454
}
455
456
static uint32_t PPC_prep_io_readb (void *opaque, target_phys_addr_t addr)
457
{
458
    sysctrl_t *sysctrl = opaque;
459
    uint32_t ret;
460
461
    addr = prep_IO_address(sysctrl, addr);
462
    ret = cpu_inb(NULL, addr);
463
464
    return ret;
465
}
466
467
static void PPC_prep_io_writew (void *opaque, target_phys_addr_t addr,
468
                                uint32_t value)
469
{
470
    sysctrl_t *sysctrl = opaque;
471
472
    addr = prep_IO_address(sysctrl, addr);
473
#ifdef TARGET_WORDS_BIGENDIAN
474
    value = bswap16(value);
475
#endif
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
476
    PPC_IO_DPRINTF("0x" PADDRX " => 0x%08" PRIx32 "\n", addr, value);
1376 by bellard
PREP machines have two IO mappings.
477
    cpu_outw(NULL, addr, value);
478
}
479
480
static uint32_t PPC_prep_io_readw (void *opaque, target_phys_addr_t addr)
481
{
482
    sysctrl_t *sysctrl = opaque;
483
    uint32_t ret;
484
485
    addr = prep_IO_address(sysctrl, addr);
486
    ret = cpu_inw(NULL, addr);
487
#ifdef TARGET_WORDS_BIGENDIAN
488
    ret = bswap16(ret);
489
#endif
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
490
    PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
1376 by bellard
PREP machines have two IO mappings.
491
492
    return ret;
493
}
494
495
static void PPC_prep_io_writel (void *opaque, target_phys_addr_t addr,
496
                                uint32_t value)
497
{
498
    sysctrl_t *sysctrl = opaque;
499
500
    addr = prep_IO_address(sysctrl, addr);
501
#ifdef TARGET_WORDS_BIGENDIAN
502
    value = bswap32(value);
503
#endif
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
504
    PPC_IO_DPRINTF("0x" PADDRX " => 0x%08" PRIx32 "\n", addr, value);
1376 by bellard
PREP machines have two IO mappings.
505
    cpu_outl(NULL, addr, value);
506
}
507
508
static uint32_t PPC_prep_io_readl (void *opaque, target_phys_addr_t addr)
509
{
510
    sysctrl_t *sysctrl = opaque;
511
    uint32_t ret;
512
513
    addr = prep_IO_address(sysctrl, addr);
514
    ret = cpu_inl(NULL, addr);
515
#ifdef TARGET_WORDS_BIGENDIAN
516
    ret = bswap32(ret);
517
#endif
3716 by j_mayer
More PowerPC debug print fixes - hardware emulation pass.
518
    PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
1376 by bellard
PREP machines have two IO mappings.
519
520
    return ret;
521
}
522
523
CPUWriteMemoryFunc *PPC_prep_io_write[] = {
524
    &PPC_prep_io_writeb,
525
    &PPC_prep_io_writew,
526
    &PPC_prep_io_writel,
527
};
528
529
CPUReadMemoryFunc *PPC_prep_io_read[] = {
530
    &PPC_prep_io_readb,
531
    &PPC_prep_io_readw,
532
    &PPC_prep_io_readl,
533
};
534
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
535
#define NVRAM_SIZE        0x2000
536
770 by bellard
isa memory remapping support (aka PPC PREP VGA support)
537
/* PowerPC PREP hardware initialisation */
3567 by j_mayer
More generic boot devices specification, allowing more devices to be specified
538
static void ppc_prep_init (int ram_size, int vga_ram_size,
3677 by blueswir1
Remove unused parameters from QEMUMachineInitFunc (Laurent Vivier)
539
                           const char *boot_device, DisplayState *ds,
540
                           const char *kernel_filename,
2458 by j_mayer
New -cpu options: choose CPU model for emulated target.
541
                           const char *kernel_cmdline,
542
                           const char *initrd_filename,
543
                           const char *cpu_model)
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
544
{
3576 by j_mayer
Fix PowerPC boot device selection.
545
    CPUState *env = NULL, *envs[MAX_CPUS];
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
546
    char buf[1024];
3465 by j_mayer
* sort the PowerPC target object files
547
    nvram_t nvram;
548
    m48t59_t *m48t59;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
549
    int PPC_io_memory;
1490 by bellard
allow variable bios size
550
    int linux_boot, i, nb_nics1, bios_size;
862 by bellard
PowerPC prep/chrp/pmac support
551
    unsigned long bios_offset;
552
    uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
958 by bellard
added PCI bus
553
    PCIBus *pci_bus;
2625 by pbrook
Unify IRQ handling.
554
    qemu_irq *i8259;
3567 by j_mayer
More generic boot devices specification, allowing more devices to be specified
555
    int ppc_boot_device;
3749 by ths
Add -drive parameter, by Laurent Vivier.
556
    int index;
557
    BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
558
    BlockDriverState *fd[MAX_FD];
862 by bellard
PowerPC prep/chrp/pmac support
559
560
    sysctrl = qemu_mallocz(sizeof(sysctrl_t));
561
    if (sysctrl == NULL)
2672 by j_mayer
Add reset callbacks for PowerPC CPU.
562
        return;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
563
564
    linux_boot = (kernel_filename != NULL);
2672 by j_mayer
Add reset callbacks for PowerPC CPU.
565
1637 by bellard
cpu_single_env usage fix
566
    /* init CPUs */
2458 by j_mayer
New -cpu options: choose CPU model for emulated target.
567
    if (cpu_model == NULL)
3246 by j_mayer
Change POWERPC_PPC_GENERIC to POWERPC_DEFAULT.
568
        cpu_model = "default";
3307 by j_mayer
Fix PowerPC initialisation and first reset:
569
    for (i = 0; i < smp_cpus; i++) {
3552 by bellard
added cpu_model parameter to cpu_init()
570
        env = cpu_init(cpu_model);
571
        if (!env) {
572
            fprintf(stderr, "Unable to find PowerPC CPU definition\n");
573
            exit(1);
574
        }
3691 by j_mayer
New PowerPC CPU flag to define the decrementer and time-base source clock.
575
        if (env->flags & POWERPC_FLAG_RTC_CLK) {
576
            /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
577
            cpu_ppc_tb_init(env, 7812500UL);
578
        } else {
579
            /* Set time-base frequency to 100 Mhz */
580
            cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
581
        }
3307 by j_mayer
Fix PowerPC initialisation and first reset:
582
        qemu_register_reset(&cpu_ppc_reset, env);
583
        register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
584
        envs[i] = env;
585
    }
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
586
587
    /* allocate RAM */
862 by bellard
PowerPC prep/chrp/pmac support
588
    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
589
862 by bellard
PowerPC prep/chrp/pmac support
590
    /* allocate and load BIOS */
591
    bios_offset = ram_size + vga_ram_size;
3321 by j_mayer
New '-bios' option, used to select an alternate BIOS image from bios_dir.
592
    if (bios_name == NULL)
593
        bios_name = BIOS_FILENAME;
594
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1490 by bellard
allow variable bios size
595
    bios_size = load_image(buf, phys_ram_base + bios_offset);
596
    if (bios_size < 0 || bios_size > BIOS_SIZE) {
2696 by j_mayer
No functional changes:
597
        cpu_abort(env, "qemu: could not load PPC PREP bios '%s'\n", buf);
862 by bellard
PowerPC prep/chrp/pmac support
598
        exit(1);
599
    }
3470 by j_mayer
PowerPC 601 / 620 / 970 need a 1MB firmware.
600
    if (env->nip < 0xFFF80000 && bios_size < 0x00100000) {
601
        cpu_abort(env, "PowerPC 601 / 620 / 970 need a 1MB BIOS\n");
602
    }
1490 by bellard
allow variable bios size
603
    bios_size = (bios_size + 0xfff) & ~0xfff;
2696 by j_mayer
No functional changes:
604
    cpu_register_physical_memory((uint32_t)(-bios_size),
1490 by bellard
allow variable bios size
605
                                 bios_size, bios_offset | IO_MEM_ROM);
770 by bellard
isa memory remapping support (aka PPC PREP VGA support)
606
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
607
    if (linux_boot) {
862 by bellard
PowerPC prep/chrp/pmac support
608
        kernel_base = KERNEL_LOAD_ADDR;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
609
        /* now we can load the kernel */
862 by bellard
PowerPC prep/chrp/pmac support
610
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
611
        if (kernel_size < 0) {
2696 by j_mayer
No functional changes:
612
            cpu_abort(env, "qemu: could not load kernel '%s'\n",
613
                      kernel_filename);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
614
            exit(1);
615
        }
616
        /* load initrd */
617
        if (initrd_filename) {
862 by bellard
PowerPC prep/chrp/pmac support
618
            initrd_base = INITRD_LOAD_ADDR;
619
            initrd_size = load_image(initrd_filename,
620
                                     phys_ram_base + initrd_base);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
621
            if (initrd_size < 0) {
2696 by j_mayer
No functional changes:
622
                cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
623
                          initrd_filename);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
624
                exit(1);
625
            }
862 by bellard
PowerPC prep/chrp/pmac support
626
        } else {
627
            initrd_base = 0;
628
            initrd_size = 0;
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
629
        }
3487 by balrog
Set boot sequence from command line (Dan Kenigsberg).
630
        ppc_boot_device = 'm';
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
631
    } else {
862 by bellard
PowerPC prep/chrp/pmac support
632
        kernel_base = 0;
633
        kernel_size = 0;
634
        initrd_base = 0;
635
        initrd_size = 0;
3567 by j_mayer
More generic boot devices specification, allowing more devices to be specified
636
        ppc_boot_device = '\0';
637
        /* For now, OHW cannot boot from the network. */
3576 by j_mayer
Fix PowerPC boot device selection.
638
        for (i = 0; boot_device[i] != '\0'; i++) {
639
            if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
640
                ppc_boot_device = boot_device[i];
3567 by j_mayer
More generic boot devices specification, allowing more devices to be specified
641
                break;
3576 by j_mayer
Fix PowerPC boot device selection.
642
            }
3567 by j_mayer
More generic boot devices specification, allowing more devices to be specified
643
        }
644
        if (ppc_boot_device == '\0') {
645
            fprintf(stderr, "No valid boot device for Mac99 machine\n");
646
            exit(1);
647
        }
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
648
    }
649
862 by bellard
PowerPC prep/chrp/pmac support
650
    isa_mem_base = 0xc0000000;
2671 by j_mayer
PREP and heathrow machines only support PowerPC CPU with a 6xx bus.
651
    if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
652
        cpu_abort(env, "Only 6xx bus is supported on PREP machine\n");
653
        exit(1);
654
    }
2644 by j_mayer
Add PowerPC 405 input pins (IRQ, resets, ...) model.
655
    i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
2625 by pbrook
Unify IRQ handling.
656
    pci_bus = pci_prep_init(i8259);
1376 by bellard
PREP machines have two IO mappings.
657
    //    pci_bus = i440fx_init();
658
    /* Register 8 MB of ISA IO space (needed for non-contiguous map) */
659
    PPC_io_memory = cpu_register_io_memory(0, PPC_prep_io_read,
660
                                           PPC_prep_io_write, sysctrl);
661
    cpu_register_physical_memory(0x80000000, 0x00800000, PPC_io_memory);
862 by bellard
PowerPC prep/chrp/pmac support
662
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
663
    /* init basic PC hardware */
3163 by ths
find -type f | xargs sed -i 's/[\t ]$//g' # on most files
664
    pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, ram_size,
2105 by bellard
vga init changes
665
                 vga_ram_size, 0, 0);
862 by bellard
PowerPC prep/chrp/pmac support
666
    //    openpic = openpic_init(0x00000000, 0xF0000000, 1);
2625 by pbrook
Unify IRQ handling.
667
    //    pit = pit_init(0x40, i8259[0]);
668
    rtc_init(0x70, i8259[8]);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
669
2625 by pbrook
Unify IRQ handling.
670
    serial_init(0x3f8, i8259[4], serial_hds[0]);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
671
    nb_nics1 = nb_nics;
672
    if (nb_nics1 > NE2000_NB_MAX)
673
        nb_nics1 = NE2000_NB_MAX;
674
    for(i = 0; i < nb_nics1; i++) {
3414 by j_mayer
Bugfix: now PCI NICs really work on PowerPC PreP platform.
675
        if (nd_table[i].model == NULL
676
            || strcmp(nd_table[i].model, "ne2k_isa") == 0) {
2625 by pbrook
Unify IRQ handling.
677
            isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
1738 by pbrook
Allow selection of emulated network card.
678
        } else {
3413 by j_mayer
Allow use of PCI NICs on PowerPC PreP platform.
679
            pci_nic_init(pci_bus, &nd_table[i], -1);
1738 by pbrook
Allow selection of emulated network card.
680
        }
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
681
    }
682
3749 by ths
Add -drive parameter, by Laurent Vivier.
683
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
684
        fprintf(stderr, "qemu: too many IDE bus\n");
685
        exit(1);
686
    }
687
688
    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
689
        index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
690
        if (index != -1)
691
            hd[i] = drives_table[index].bdrv;
692
        else
693
            hd[i] = NULL;
694
    }
695
696
    for(i = 0; i < MAX_IDE_BUS; i++) {
2625 by pbrook
Unify IRQ handling.
697
        isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
3749 by ths
Add -drive parameter, by Laurent Vivier.
698
                     hd[2 * i],
699
		     hd[2 * i + 1]);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
700
    }
2625 by pbrook
Unify IRQ handling.
701
    i8042_init(i8259[1], i8259[12], 0x60);
954 by bellard
ppc init fixes
702
    DMA_init(1);
862 by bellard
PowerPC prep/chrp/pmac support
703
    //    AUD_init();
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
704
    //    SB16_init();
705
3749 by ths
Add -drive parameter, by Laurent Vivier.
706
    for(i = 0; i < MAX_FD; i++) {
707
        index = drive_get_index(IF_FLOPPY, 0, i);
708
        if (index != -1)
709
            fd[i] = drives_table[index].bdrv;
710
        else
711
            fd[i] = NULL;
712
    }
713
    fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
714
862 by bellard
PowerPC prep/chrp/pmac support
715
    /* Register speaker port */
716
    register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL);
717
    register_ioport_write(0x61, 1, 1, speaker_ioport_write, NULL);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
718
    /* Register fake IO ports for PREP */
3471 by j_mayer
Implement PreP reset port.
719
    sysctrl->reset_irq = first_cpu->irq_inputs[PPC6xx_INPUT_HRESET];
862 by bellard
PowerPC prep/chrp/pmac support
720
    register_ioport_read(0x398, 2, 1, &PREP_io_read, sysctrl);
721
    register_ioport_write(0x398, 2, 1, &PREP_io_write, sysctrl);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
722
    /* System control ports */
862 by bellard
PowerPC prep/chrp/pmac support
723
    register_ioport_read(0x0092, 0x01, 1, &PREP_io_800_readb, sysctrl);
724
    register_ioport_write(0x0092, 0x01, 1, &PREP_io_800_writeb, sysctrl);
725
    register_ioport_read(0x0800, 0x52, 1, &PREP_io_800_readb, sysctrl);
726
    register_ioport_write(0x0800, 0x52, 1, &PREP_io_800_writeb, sysctrl);
727
    /* PCI intack location */
728
    PPC_io_memory = cpu_register_io_memory(0, PPC_intack_read,
871 by bellard
support for opaque data on memory I/Os
729
                                           PPC_intack_write, NULL);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
730
    cpu_register_physical_memory(0xBFFFFFF0, 0x4, PPC_io_memory);
862 by bellard
PowerPC prep/chrp/pmac support
731
    /* PowerPC control and status register group */
954 by bellard
ppc init fixes
732
#if 0
3168 by j_mayer
Coding style fixes in PowerPC related code (no functional change):
733
    PPC_io_memory = cpu_register_io_memory(0, PPC_XCSR_read, PPC_XCSR_write,
734
                                           NULL);
862 by bellard
PowerPC prep/chrp/pmac support
735
    cpu_register_physical_memory(0xFEFF0000, 0x1000, PPC_io_memory);
954 by bellard
ppc init fixes
736
#endif
862 by bellard
PowerPC prep/chrp/pmac support
737
1920 by pbrook
OHCI USB host emulation.
738
    if (usb_enabled) {
2480 by pbrook
OHCI USB PXA support (Andrzej Zaborowski).
739
        usb_ohci_init_pci(pci_bus, 3, -1);
1920 by pbrook
OHCI USB host emulation.
740
    }
741
3465 by j_mayer
* sort the PowerPC target object files
742
    m48t59 = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
743
    if (m48t59 == NULL)
862 by bellard
PowerPC prep/chrp/pmac support
744
        return;
3465 by j_mayer
* sort the PowerPC target object files
745
    sysctrl->nvram = m48t59;
862 by bellard
PowerPC prep/chrp/pmac support
746
747
    /* Initialise NVRAM */
3465 by j_mayer
* sort the PowerPC target object files
748
    nvram.opaque = m48t59;
749
    nvram.read_fn = &m48t59_read;
750
    nvram.write_fn = &m48t59_write;
3487 by balrog
Set boot sequence from command line (Dan Kenigsberg).
751
    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
862 by bellard
PowerPC prep/chrp/pmac support
752
                         kernel_base, kernel_size,
954 by bellard
ppc init fixes
753
                         kernel_cmdline,
862 by bellard
PowerPC prep/chrp/pmac support
754
                         initrd_base, initrd_size,
755
                         /* XXX: need an option to load a NVRAM image */
954 by bellard
ppc init fixes
756
                         0,
757
                         graphic_width, graphic_height, graphic_depth);
1445 by bellard
use new machine API
758
759
    /* Special port to get debug messages from Open-Firmware */
760
    register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
719 by bellard
PowerPC system emulation fixes (Jocelyn Mayer)
761
}
1445 by bellard
use new machine API
762
763
QEMUMachine prep_machine = {
764
    "prep",
765
    "PowerPC PREP platform",
766
    ppc_prep_init,
767
};