2 * NeXT Cube System Driver
4 * Copyright (c) 2011 Bryce Lanham
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License,
9 * or (at your option) any later version.
12 #include "qemu/osdep.h"
13 #include "exec/hwaddr.h"
14 #include "sysemu/sysemu.h"
15 #include "sysemu/qtest.h"
17 #include "hw/m68k/next-cube.h"
18 #include "hw/boards.h"
19 #include "hw/loader.h"
20 #include "hw/scsi/esp.h"
21 #include "hw/sysbus.h"
22 #include "qom/object.h"
23 #include "hw/char/escc.h" /* ZILOG 8530 Serial Emulation */
24 #include "hw/block/fdc.h"
25 #include "hw/qdev-properties.h"
26 #include "qapi/error.h"
27 #include "qemu/error-report.h"
28 #include "ui/console.h"
29 #include "target/m68k/cpu.h"
30 #include "migration/vmstate.h"
32 /* #define DEBUG_NEXT */
34 #define DPRINTF(fmt, ...) \
35 do { printf("NeXT: " fmt , ## __VA_ARGS__); } while (0)
37 #define DPRINTF(fmt, ...) do { } while (0)
40 #define TYPE_NEXT_MACHINE MACHINE_TYPE_NAME("next-cube")
41 OBJECT_DECLARE_SIMPLE_TYPE(NeXTState
, NEXT_MACHINE
)
43 #define ENTRY 0x0100001e
44 #define RAM_SIZE 0x4000000
45 #define ROM_FILE "Rev_2.5_v66.bin"
47 typedef struct next_dma
{
60 uint32_t next_initbuf
;
64 typedef struct NextRtc
{
79 #define TYPE_NEXT_PC "next-pc"
80 OBJECT_DECLARE_SIMPLE_TYPE(NeXTPC
, NEXT_PC
)
82 /* NeXT Peripheral Controller */
84 SysBusDevice parent_obj
;
101 /* Thanks to NeXT forums for this */
103 static const uint8_t rtc_ram3[32] = {
104 0x94, 0x0f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
105 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x7B, 0x00,
106 0x00, 0x00, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x13
110 static const uint8_t rtc_ram2
[32] = {
111 0x94, 0x0f, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x4b, 0x00,
113 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x7e,
117 #define SCR2_RTCLK 0x2
118 #define SCR2_RTDATA 0x4
119 #define SCR2_TOBCD(x) (((x / 10) << 4) + (x % 10))
121 static void nextscr2_write(NeXTPC
*s
, uint32_t val
, int size
)
125 static uint8_t old_scr2
;
127 NextRtc
*rtc
= &s
->rtc
;
130 scr2_2
= (val
>> 8) & 0xFF;
139 DPRINTF("LED flashing, possible fault!\n");
145 /* DPRINTF("RTC %x phase %i\n", scr2_2, phase); */
149 /* If we are in going down clock... do something */
150 if (((old_scr2
& SCR2_RTCLK
) != (scr2_2
& SCR2_RTCLK
)) &&
151 ((scr2_2
& SCR2_RTCLK
) == 0)) {
153 rtc
->command
= (rtc
->command
<< 1) |
154 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
156 if (phase
>= 8 && phase
< 16) {
157 rtc
->value
= (rtc
->value
<< 1) |
158 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
160 /* if we read RAM register, output RT_DATA bit */
161 if (rtc
->command
<= 0x1F) {
162 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
163 if (rtc
->ram
[rtc
->command
] & (0x80 >> (phase
- 8))) {
164 scr2_2
|= SCR2_RTDATA
;
167 rtc
->retval
= (rtc
->retval
<< 1) |
168 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
170 /* read the status 0x30 */
171 if (rtc
->command
== 0x30) {
172 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
173 /* for now status = 0x98 (new rtc + FTU) */
174 if (rtc
->status
& (0x80 >> (phase
- 8))) {
175 scr2_2
|= SCR2_RTDATA
;
178 rtc
->retval
= (rtc
->retval
<< 1) |
179 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
181 /* read the status 0x31 */
182 if (rtc
->command
== 0x31) {
183 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
184 if (rtc
->control
& (0x80 >> (phase
- 8))) {
185 scr2_2
|= SCR2_RTDATA
;
187 rtc
->retval
= (rtc
->retval
<< 1) |
188 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
191 if ((rtc
->command
>= 0x20) && (rtc
->command
<= 0x2F)) {
192 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
194 time_t time_h
= time(NULL
);
195 struct tm
*info
= localtime(&time_h
);
198 switch (rtc
->command
) {
200 ret
= SCR2_TOBCD(info
->tm_sec
);
203 ret
= SCR2_TOBCD(info
->tm_min
);
206 ret
= SCR2_TOBCD(info
->tm_hour
);
209 ret
= SCR2_TOBCD(info
->tm_mday
);
212 ret
= SCR2_TOBCD((info
->tm_mon
+ 1));
215 ret
= SCR2_TOBCD((info
->tm_year
- 100));
220 if (ret
& (0x80 >> (phase
- 8))) {
221 scr2_2
|= SCR2_RTDATA
;
223 rtc
->retval
= (rtc
->retval
<< 1) |
224 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
231 if (rtc
->command
>= 0x80 && rtc
->command
<= 0x9F) {
232 rtc
->ram
[rtc
->command
- 0x80] = rtc
->value
;
234 /* write to x30 register */
235 if (rtc
->command
== 0xB1) {
237 if (rtc
->value
& 0x04) {
238 rtc
->status
= rtc
->status
& (~0x18);
239 s
->int_status
= s
->int_status
& (~0x04);
245 /* else end or abort */
250 s
->scr2
= val
& 0xFFFF00FF;
251 s
->scr2
|= scr2_2
<< 8;
255 static uint32_t mmio_readb(NeXTPC
*s
, hwaddr addr
)
259 return (s
->scr1
>> 24) & 0xFF;
261 return (s
->scr1
>> 16) & 0xFF;
263 return (s
->scr1
>> 8) & 0xFF;
265 return (s
->scr1
>> 0) & 0xFF;
268 return (s
->scr2
>> 24) & 0xFF;
270 return (s
->scr2
>> 16) & 0xFF;
272 return (s
->scr2
>> 8) & 0xFF;
274 return (s
->scr2
>> 0) & 0xFF;
276 DPRINTF("MMIO Read 0x4020\n");
280 DPRINTF("MMIO Read B @ %"HWADDR_PRIx
"\n", addr
);
285 static uint32_t mmio_readw(NeXTPC
*s
, hwaddr addr
)
289 DPRINTF("MMIO Read W @ %"HWADDR_PRIx
"\n", addr
);
294 static uint32_t mmio_readl(NeXTPC
*s
, hwaddr addr
)
298 /* DPRINTF("Read INT status: %x\n", s->int_status); */
299 return s
->int_status
;
302 DPRINTF("MMIO Read INT mask: %x\n", s
->int_mask
);
312 DPRINTF("MMIO Read L @ %"HWADDR_PRIx
"\n", addr
);
317 static void mmio_writeb(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
321 nextscr2_write(s
, val
, 1);
324 DPRINTF("MMIO Write B @ %x with %x\n", (unsigned int)addr
, val
);
329 static void mmio_writew(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
331 DPRINTF("MMIO Write W\n");
334 static void mmio_writel(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
338 DPRINTF("INT Status old: %x new: %x\n", s
->int_status
, val
);
342 DPRINTF("INT Mask old: %x new: %x\n", s
->int_mask
, val
);
346 DPRINTF("SCR1 Write: %x\n", val
);
349 nextscr2_write(s
, val
, 4);
353 DPRINTF("MMIO Write l @ %x with %x\n", (unsigned int)addr
, val
);
357 static uint64_t mmio_readfn(void *opaque
, hwaddr addr
, unsigned size
)
359 NeXTPC
*s
= NEXT_PC(opaque
);
363 return mmio_readb(s
, addr
);
365 return mmio_readw(s
, addr
);
367 return mmio_readl(s
, addr
);
369 g_assert_not_reached();
373 static void mmio_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
376 NeXTPC
*s
= NEXT_PC(opaque
);
380 mmio_writeb(s
, addr
, value
);
383 mmio_writew(s
, addr
, value
);
386 mmio_writel(s
, addr
, value
);
389 g_assert_not_reached();
393 static const MemoryRegionOps mmio_ops
= {
395 .write
= mmio_writefn
,
396 .valid
.min_access_size
= 1,
397 .valid
.max_access_size
= 4,
398 .endianness
= DEVICE_NATIVE_ENDIAN
,
401 static uint32_t scr_readb(NeXTPC
*s
, hwaddr addr
)
405 DPRINTF("FD read @ %x\n", (unsigned int)addr
);
406 return 0x40 | 0x04 | 0x2 | 0x1;
408 DPRINTF("SCSI 4020 STATUS READ %X\n", s
->scsi_csr_1
);
409 return s
->scsi_csr_1
;
412 DPRINTF("SCSI 4021 STATUS READ %X\n", s
->scsi_csr_2
);
416 * These 4 registers are the hardware timer, not sure which register
417 * is the latch instead of data, but no problems so far
420 return 0xff & (clock() >> 24);
422 return 0xff & (clock() >> 16);
424 return 0xff & (clock() >> 8);
426 /* Hack: We need to have this change consistently to make it work */
427 return 0xFF & clock();
430 DPRINTF("BMAP Read B @ %x\n", (unsigned int)addr
);
435 static uint32_t scr_readw(NeXTPC
*s
, hwaddr addr
)
437 DPRINTF("BMAP Read W @ %x\n", (unsigned int)addr
);
441 static uint32_t scr_readl(NeXTPC
*s
, hwaddr addr
)
443 DPRINTF("BMAP Read L @ %x\n", (unsigned int)addr
);
447 #define SCSICSR_ENABLE 0x01
448 #define SCSICSR_RESET 0x02 /* reset scsi dma */
449 #define SCSICSR_FIFOFL 0x04
450 #define SCSICSR_DMADIR 0x08 /* if set, scsi to mem */
451 #define SCSICSR_CPUDMA 0x10 /* if set, dma enabled */
452 #define SCSICSR_INTMASK 0x20 /* if set, interrupt enabled */
454 static void scr_writeb(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
458 DPRINTF("FDCSR Write: %x\n", value
);
461 /* qemu_irq_raise(s->fd_irq[0]); */
464 case 0x14020: /* SCSI Control Register */
465 if (value
& SCSICSR_FIFOFL
) {
466 DPRINTF("SCSICSR FIFO Flush\n");
467 /* will have to add another irq to the esp if this is needed */
468 /* esp_puflush_fifo(esp_g); */
469 /* qemu_irq_pulse(s->scsi_dma); */
472 if (value
& SCSICSR_ENABLE
) {
473 DPRINTF("SCSICSR Enable\n");
475 * qemu_irq_raise(s->scsi_dma);
476 * s->scsi_csr_1 = 0xc0;
477 * s->scsi_csr_1 |= 0x1;
478 * qemu_irq_pulse(s->scsi_dma);
483 * s->scsi_csr_1 &= ~SCSICSR_ENABLE;
486 if (value
& SCSICSR_RESET
) {
487 DPRINTF("SCSICSR Reset\n");
488 /* I think this should set DMADIR. CPUDMA and INTMASK to 0 */
489 /* qemu_irq_raise(s->scsi_reset); */
490 /* s->scsi_csr_1 &= ~(SCSICSR_INTMASK |0x80|0x1); */
493 if (value
& SCSICSR_DMADIR
) {
494 DPRINTF("SCSICSR DMAdir\n");
496 if (value
& SCSICSR_CPUDMA
) {
497 DPRINTF("SCSICSR CPUDMA\n");
498 /* qemu_irq_raise(s->scsi_dma); */
500 s
->int_status
|= 0x4000000;
502 s
->int_status
&= ~(0x4000000);
504 if (value
& SCSICSR_INTMASK
) {
505 DPRINTF("SCSICSR INTMASK\n");
507 * int_mask &= ~0x1000;
508 * s->scsi_csr_1 |= value;
509 * s->scsi_csr_1 &= ~SCSICSR_INTMASK;
510 * if (s->scsi_queued) {
511 * s->scsi_queued = 0;
512 * next_irq(s, NEXT_SCSI_I, level);
516 /* int_mask |= 0x1000; */
519 /* int_mask |= 0x1000; */
520 /* s->scsi_csr_1 |= 0x80; */
522 DPRINTF("SCSICSR Write: %x\n", value
);
523 /* s->scsi_csr_1 = value; */
525 /* Hardware timer latch - not implemented yet */
528 DPRINTF("BMAP Write B @ %x with %x\n", (unsigned int)addr
, value
);
532 static void scr_writew(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
534 DPRINTF("BMAP Write W @ %x with %x\n", (unsigned int)addr
, value
);
537 static void scr_writel(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
539 DPRINTF("BMAP Write L @ %x with %x\n", (unsigned int)addr
, value
);
542 static uint64_t scr_readfn(void *opaque
, hwaddr addr
, unsigned size
)
544 NeXTPC
*s
= NEXT_PC(opaque
);
548 return scr_readb(s
, addr
);
550 return scr_readw(s
, addr
);
552 return scr_readl(s
, addr
);
554 g_assert_not_reached();
558 static void scr_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
561 NeXTPC
*s
= NEXT_PC(opaque
);
565 scr_writeb(s
, addr
, value
);
568 scr_writew(s
, addr
, value
);
571 scr_writel(s
, addr
, value
);
574 g_assert_not_reached();
578 static const MemoryRegionOps scr_ops
= {
580 .write
= scr_writefn
,
581 .valid
.min_access_size
= 1,
582 .valid
.max_access_size
= 4,
583 .endianness
= DEVICE_NATIVE_ENDIAN
,
586 #define NEXTDMA_SCSI(x) (0x10 + x)
587 #define NEXTDMA_FD(x) (0x10 + x)
588 #define NEXTDMA_ENTX(x) (0x110 + x)
589 #define NEXTDMA_ENRX(x) (0x150 + x)
590 #define NEXTDMA_CSR 0x0
591 #define NEXTDMA_NEXT 0x4000
592 #define NEXTDMA_LIMIT 0x4004
593 #define NEXTDMA_START 0x4008
594 #define NEXTDMA_STOP 0x400c
595 #define NEXTDMA_NEXT_INIT 0x4200
596 #define NEXTDMA_SIZE 0x4204
598 static void dma_writel(void *opaque
, hwaddr addr
, uint64_t value
,
601 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
604 case NEXTDMA_ENRX(NEXTDMA_CSR
):
605 if (value
& DMA_DEV2M
) {
606 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_DEV2M
;
609 if (value
& DMA_SETENABLE
) {
610 /* DPRINTF("SCSI DMA ENABLE\n"); */
611 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_ENABLE
;
613 if (value
& DMA_SETSUPDATE
) {
614 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_SUPDATE
;
616 if (value
& DMA_CLRCOMPLETE
) {
617 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~DMA_COMPLETE
;
620 if (value
& DMA_RESET
) {
621 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
622 DMA_ENABLE
| DMA_DEV2M
);
624 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
626 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
627 next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
= value
;
629 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
630 next_state
->dma
[NEXTDMA_ENRX
].next
= value
;
632 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
633 next_state
->dma
[NEXTDMA_ENRX
].limit
= value
;
635 case NEXTDMA_SCSI(NEXTDMA_CSR
):
636 if (value
& DMA_DEV2M
) {
637 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_DEV2M
;
639 if (value
& DMA_SETENABLE
) {
640 /* DPRINTF("SCSI DMA ENABLE\n"); */
641 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_ENABLE
;
643 if (value
& DMA_SETSUPDATE
) {
644 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_SUPDATE
;
646 if (value
& DMA_CLRCOMPLETE
) {
647 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~DMA_COMPLETE
;
650 if (value
& DMA_RESET
) {
651 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
652 DMA_ENABLE
| DMA_DEV2M
);
653 /* DPRINTF("SCSI DMA RESET\n"); */
655 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
658 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
659 next_state
->dma
[NEXTDMA_SCSI
].next
= value
;
662 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
663 next_state
->dma
[NEXTDMA_SCSI
].limit
= value
;
666 case NEXTDMA_SCSI(NEXTDMA_START
):
667 next_state
->dma
[NEXTDMA_SCSI
].start
= value
;
670 case NEXTDMA_SCSI(NEXTDMA_STOP
):
671 next_state
->dma
[NEXTDMA_SCSI
].stop
= value
;
674 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
675 next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
= value
;
679 DPRINTF("DMA write @ %x w/ %x\n", (unsigned)addr
, (unsigned)value
);
683 static uint64_t dma_readl(void *opaque
, hwaddr addr
, unsigned int size
)
685 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
688 case NEXTDMA_SCSI(NEXTDMA_CSR
):
689 DPRINTF("SCSI DMA CSR READ\n");
690 return next_state
->dma
[NEXTDMA_SCSI
].csr
;
691 case NEXTDMA_ENRX(NEXTDMA_CSR
):
692 return next_state
->dma
[NEXTDMA_ENRX
].csr
;
693 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
694 return next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
;
695 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
696 return next_state
->dma
[NEXTDMA_ENRX
].next
;
697 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
698 return next_state
->dma
[NEXTDMA_ENRX
].limit
;
700 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
701 return next_state
->dma
[NEXTDMA_SCSI
].next
;
702 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
703 return next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
;
704 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
705 return next_state
->dma
[NEXTDMA_SCSI
].limit
;
706 case NEXTDMA_SCSI(NEXTDMA_START
):
707 return next_state
->dma
[NEXTDMA_SCSI
].start
;
708 case NEXTDMA_SCSI(NEXTDMA_STOP
):
709 return next_state
->dma
[NEXTDMA_SCSI
].stop
;
712 DPRINTF("DMA read @ %x\n", (unsigned int)addr
);
717 * once the csr's are done, subtract 0x3FEC from the addr, and that will
718 * normalize the upper registers
722 static const MemoryRegionOps dma_ops
= {
725 .impl
.min_access_size
= 4,
726 .valid
.min_access_size
= 4,
727 .valid
.max_access_size
= 4,
728 .endianness
= DEVICE_NATIVE_ENDIAN
,
731 static void next_irq(void *opaque
, int number
, int level
)
733 NeXTPC
*s
= NEXT_PC(opaque
);
734 M68kCPU
*cpu
= s
->cpu
;
737 /* first switch sets interupt status */
738 /* DPRINTF("IRQ %i\n",number); */
740 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
763 /* level 5 - scc (serial) */
768 /* level 6 - audio etherrx/tx dma */
769 case NEXT_ENTX_DMA_I
:
772 case NEXT_ENRX_DMA_I
:
775 case NEXT_SCSI_DMA_I
:
787 * this HAS to be wrong, the interrupt handlers in mach and together
788 * int_status and int_mask and return if there is a hit
790 if (s
->int_mask
& (1 << shift
)) {
791 DPRINTF("%x interrupt masked @ %x\n", 1 << shift
, cpu
->env
.pc
);
795 /* second switch triggers the correct interrupt */
797 s
->int_status
|= 1 << shift
;
800 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
808 m68k_set_irq_level(cpu
, 3, 27);
811 /* level 5 - scc (serial) */
813 m68k_set_irq_level(cpu
, 5, 29);
816 /* level 6 - audio etherrx/tx dma */
817 case NEXT_ENTX_DMA_I
:
818 case NEXT_ENRX_DMA_I
:
819 case NEXT_SCSI_DMA_I
:
822 m68k_set_irq_level(cpu
, 6, 30);
826 s
->int_status
&= ~(1 << shift
);
827 cpu_reset_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
831 static void next_escc_init(DeviceState
*pcdev
)
836 dev
= qdev_new(TYPE_ESCC
);
837 qdev_prop_set_uint32(dev
, "disabled", 0);
838 qdev_prop_set_uint32(dev
, "frequency", 9600 * 384);
839 qdev_prop_set_uint32(dev
, "it_shift", 0);
840 qdev_prop_set_bit(dev
, "bit_swap", true);
841 qdev_prop_set_chr(dev
, "chrB", serial_hd(1));
842 qdev_prop_set_chr(dev
, "chrA", serial_hd(0));
843 qdev_prop_set_uint32(dev
, "chnBtype", escc_serial
);
844 qdev_prop_set_uint32(dev
, "chnAtype", escc_serial
);
846 s
= SYS_BUS_DEVICE(dev
);
847 sysbus_realize_and_unref(s
, &error_fatal
);
848 sysbus_connect_irq(s
, 0, qdev_get_gpio_in(pcdev
, NEXT_SCC_I
));
849 sysbus_connect_irq(s
, 1, qdev_get_gpio_in(pcdev
, NEXT_SCC_DMA_I
));
850 sysbus_mmio_map(s
, 0, 0x2118000);
853 static void next_pc_reset(DeviceState
*dev
)
855 NeXTPC
*s
= NEXT_PC(dev
);
857 /* Set internal registers to initial values */
858 /* 0x0000XX00 << vital bits */
859 s
->scr1
= 0x00011102;
860 s
->scr2
= 0x00ff0c80;
862 s
->rtc
.status
= 0x90;
864 /* Load RTC RAM - TODO: provide possibility to load contents from file */
865 memcpy(s
->rtc
.ram
, rtc_ram2
, 32);
868 static void next_pc_realize(DeviceState
*dev
, Error
**errp
)
870 NeXTPC
*s
= NEXT_PC(dev
);
871 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
873 qdev_init_gpio_in(dev
, next_irq
, NEXT_NUM_IRQS
);
875 memory_region_init_io(&s
->mmiomem
, OBJECT(s
), &mmio_ops
, s
,
876 "next.mmio", 0xD0000);
877 memory_region_init_io(&s
->scrmem
, OBJECT(s
), &scr_ops
, s
,
878 "next.scr", 0x20000);
879 sysbus_init_mmio(sbd
, &s
->mmiomem
);
880 sysbus_init_mmio(sbd
, &s
->scrmem
);
884 * If the m68k CPU implemented its inbound irq lines as GPIO lines
885 * rather than via the m68k_set_irq_level() function we would not need
886 * this cpu link property and could instead provide outbound IRQ lines
887 * that the board could wire up to the CPU.
889 static Property next_pc_properties
[] = {
890 DEFINE_PROP_LINK("cpu", NeXTPC
, cpu
, TYPE_M68K_CPU
, M68kCPU
*),
891 DEFINE_PROP_END_OF_LIST(),
894 static const VMStateDescription next_rtc_vmstate
= {
897 .minimum_version_id
= 1,
898 .fields
= (VMStateField
[]) {
899 VMSTATE_UINT8_ARRAY(ram
, NextRtc
, 32),
900 VMSTATE_UINT8(command
, NextRtc
),
901 VMSTATE_UINT8(value
, NextRtc
),
902 VMSTATE_UINT8(status
, NextRtc
),
903 VMSTATE_UINT8(control
, NextRtc
),
904 VMSTATE_UINT8(retval
, NextRtc
),
905 VMSTATE_END_OF_LIST()
909 static const VMStateDescription next_pc_vmstate
= {
912 .minimum_version_id
= 1,
913 .fields
= (VMStateField
[]) {
914 VMSTATE_UINT32(scr1
, NeXTPC
),
915 VMSTATE_UINT32(scr2
, NeXTPC
),
916 VMSTATE_UINT32(int_mask
, NeXTPC
),
917 VMSTATE_UINT32(int_status
, NeXTPC
),
918 VMSTATE_UINT8(scsi_csr_1
, NeXTPC
),
919 VMSTATE_UINT8(scsi_csr_2
, NeXTPC
),
920 VMSTATE_STRUCT(rtc
, NeXTPC
, 0, next_rtc_vmstate
, NextRtc
),
921 VMSTATE_END_OF_LIST()
925 static void next_pc_class_init(ObjectClass
*klass
, void *data
)
927 DeviceClass
*dc
= DEVICE_CLASS(klass
);
929 dc
->desc
= "NeXT Peripheral Controller";
930 dc
->realize
= next_pc_realize
;
931 dc
->reset
= next_pc_reset
;
932 device_class_set_props(dc
, next_pc_properties
);
933 dc
->vmsd
= &next_pc_vmstate
;
936 static const TypeInfo next_pc_info
= {
937 .name
= TYPE_NEXT_PC
,
938 .parent
= TYPE_SYS_BUS_DEVICE
,
939 .instance_size
= sizeof(NeXTPC
),
940 .class_init
= next_pc_class_init
,
943 static void next_cube_init(MachineState
*machine
)
947 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
948 MemoryRegion
*dmamem
= g_new(MemoryRegion
, 1);
949 MemoryRegion
*bmapm1
= g_new(MemoryRegion
, 1);
950 MemoryRegion
*bmapm2
= g_new(MemoryRegion
, 1);
951 MemoryRegion
*sysmem
= get_system_memory();
952 const char *bios_name
= machine
->firmware
?: ROM_FILE
;
956 /* Initialize the cpu core */
957 cpu
= M68K_CPU(cpu_create(machine
->cpu_type
));
959 error_report("Unable to find m68k CPU definition");
964 /* Initialize CPU registers. */
968 /* Peripheral Controller */
969 pcdev
= qdev_new(TYPE_NEXT_PC
);
970 object_property_set_link(OBJECT(pcdev
), "cpu", OBJECT(cpu
), &error_abort
);
971 sysbus_realize_and_unref(SYS_BUS_DEVICE(pcdev
), &error_fatal
);
973 /* 64MB RAM starting at 0x04000000 */
974 memory_region_add_subregion(sysmem
, 0x04000000, machine
->ram
);
977 dev
= qdev_new(TYPE_NEXTFB
);
978 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
979 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0B000000);
982 sysbus_mmio_map(SYS_BUS_DEVICE(pcdev
), 0, 0x02000000);
984 /* BMAP IO - acts as a catch-all for now */
985 sysbus_mmio_map(SYS_BUS_DEVICE(pcdev
), 1, 0x02100000);
988 memory_region_init_ram_flags_nomigrate(bmapm1
, NULL
, "next.bmapmem", 64,
989 RAM_SHARED
, &error_fatal
);
990 memory_region_add_subregion(sysmem
, 0x020c0000, bmapm1
);
991 /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */
992 memory_region_init_alias(bmapm2
, NULL
, "next.bmapmem2", bmapm1
, 0x0, 64);
993 memory_region_add_subregion(sysmem
, 0x820c0000, bmapm2
);
996 dev
= qdev_new(TYPE_NEXTKBD
);
997 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
998 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0200e000);
1001 /* still not sure if the rom should also be mapped at 0x0*/
1002 memory_region_init_rom(rom
, NULL
, "next.rom", 0x20000, &error_fatal
);
1003 memory_region_add_subregion(sysmem
, 0x01000000, rom
);
1004 if (load_image_targphys(bios_name
, 0x01000000, 0x20000) < 8) {
1005 if (!qtest_enabled()) {
1006 error_report("Failed to load firmware '%s'.", bios_name
);
1010 /* Initial PC is always at offset 4 in firmware binaries */
1011 ptr
= rom_ptr(0x01000004, 4);
1012 g_assert(ptr
!= NULL
);
1013 env
->pc
= ldl_p(ptr
);
1014 if (env
->pc
>= 0x01020000) {
1015 error_report("'%s' does not seem to be a valid firmware image.",
1022 next_escc_init(pcdev
);
1029 memory_region_init_io(dmamem
, NULL
, &dma_ops
, machine
, "next.dma", 0x5000);
1030 memory_region_add_subregion(sysmem
, 0x02000000, dmamem
);
1033 static void next_machine_class_init(ObjectClass
*oc
, void *data
)
1035 MachineClass
*mc
= MACHINE_CLASS(oc
);
1037 mc
->desc
= "NeXT Cube";
1038 mc
->init
= next_cube_init
;
1039 mc
->default_ram_size
= RAM_SIZE
;
1040 mc
->default_ram_id
= "next.ram";
1041 mc
->default_cpu_type
= M68K_CPU_TYPE_NAME("m68040");
1044 static const TypeInfo next_typeinfo
= {
1045 .name
= TYPE_NEXT_MACHINE
,
1046 .parent
= TYPE_MACHINE
,
1047 .class_init
= next_machine_class_init
,
1048 .instance_size
= sizeof(NeXTState
),
1051 static void next_register_type(void)
1053 type_register_static(&next_typeinfo
);
1054 type_register_static(&next_pc_info
);
1057 type_init(next_register_type
)