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 "ui/console.h"
28 #include "target/m68k/cpu.h"
29 #include "migration/vmstate.h"
31 /* #define DEBUG_NEXT */
33 #define DPRINTF(fmt, ...) \
34 do { printf("NeXT: " fmt , ## __VA_ARGS__); } while (0)
36 #define DPRINTF(fmt, ...) do { } while (0)
39 #define TYPE_NEXT_MACHINE MACHINE_TYPE_NAME("next-cube")
40 OBJECT_DECLARE_SIMPLE_TYPE(NeXTState
, NEXT_MACHINE
)
42 #define ENTRY 0x0100001e
43 #define RAM_SIZE 0x4000000
44 #define ROM_FILE "Rev_2.5_v66.bin"
46 typedef struct next_dma
{
59 uint32_t next_initbuf
;
63 typedef struct NextRtc
{
78 #define TYPE_NEXT_PC "next-pc"
79 OBJECT_DECLARE_SIMPLE_TYPE(NeXTPC
, NEXT_PC
)
81 /* NeXT Peripheral Controller */
83 SysBusDevice parent_obj
;
100 /* Thanks to NeXT forums for this */
102 static const uint8_t rtc_ram3[32] = {
103 0x94, 0x0f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
104 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x7B, 0x00,
105 0x00, 0x00, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x13
109 static const uint8_t rtc_ram2
[32] = {
110 0x94, 0x0f, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00,
111 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x4b, 0x00,
112 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x7e,
116 #define SCR2_RTCLK 0x2
117 #define SCR2_RTDATA 0x4
118 #define SCR2_TOBCD(x) (((x / 10) << 4) + (x % 10))
120 static void nextscr2_write(NeXTPC
*s
, uint32_t val
, int size
)
124 static uint8_t old_scr2
;
126 NextRtc
*rtc
= &s
->rtc
;
129 scr2_2
= (val
>> 8) & 0xFF;
138 DPRINTF("LED flashing, possible fault!\n");
144 /* DPRINTF("RTC %x phase %i\n", scr2_2, phase); */
148 /* If we are in going down clock... do something */
149 if (((old_scr2
& SCR2_RTCLK
) != (scr2_2
& SCR2_RTCLK
)) &&
150 ((scr2_2
& SCR2_RTCLK
) == 0)) {
152 rtc
->command
= (rtc
->command
<< 1) |
153 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
155 if (phase
>= 8 && phase
< 16) {
156 rtc
->value
= (rtc
->value
<< 1) |
157 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
159 /* if we read RAM register, output RT_DATA bit */
160 if (rtc
->command
<= 0x1F) {
161 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
162 if (rtc
->ram
[rtc
->command
] & (0x80 >> (phase
- 8))) {
163 scr2_2
|= SCR2_RTDATA
;
166 rtc
->retval
= (rtc
->retval
<< 1) |
167 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
169 /* read the status 0x30 */
170 if (rtc
->command
== 0x30) {
171 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
172 /* for now status = 0x98 (new rtc + FTU) */
173 if (rtc
->status
& (0x80 >> (phase
- 8))) {
174 scr2_2
|= SCR2_RTDATA
;
177 rtc
->retval
= (rtc
->retval
<< 1) |
178 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
180 /* read the status 0x31 */
181 if (rtc
->command
== 0x31) {
182 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
183 if (rtc
->control
& (0x80 >> (phase
- 8))) {
184 scr2_2
|= SCR2_RTDATA
;
186 rtc
->retval
= (rtc
->retval
<< 1) |
187 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
190 if ((rtc
->command
>= 0x20) && (rtc
->command
<= 0x2F)) {
191 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
193 time_t time_h
= time(NULL
);
194 struct tm
*info
= localtime(&time_h
);
197 switch (rtc
->command
) {
199 ret
= SCR2_TOBCD(info
->tm_sec
);
202 ret
= SCR2_TOBCD(info
->tm_min
);
205 ret
= SCR2_TOBCD(info
->tm_hour
);
208 ret
= SCR2_TOBCD(info
->tm_mday
);
211 ret
= SCR2_TOBCD((info
->tm_mon
+ 1));
214 ret
= SCR2_TOBCD((info
->tm_year
- 100));
219 if (ret
& (0x80 >> (phase
- 8))) {
220 scr2_2
|= SCR2_RTDATA
;
222 rtc
->retval
= (rtc
->retval
<< 1) |
223 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
230 if (rtc
->command
>= 0x80 && rtc
->command
<= 0x9F) {
231 rtc
->ram
[rtc
->command
- 0x80] = rtc
->value
;
233 /* write to x30 register */
234 if (rtc
->command
== 0xB1) {
236 if (rtc
->value
& 0x04) {
237 rtc
->status
= rtc
->status
& (~0x18);
238 s
->int_status
= s
->int_status
& (~0x04);
244 /* else end or abort */
249 s
->scr2
= val
& 0xFFFF00FF;
250 s
->scr2
|= scr2_2
<< 8;
254 static uint32_t mmio_readb(NeXTPC
*s
, hwaddr addr
)
258 return (s
->scr1
>> 24) & 0xFF;
260 return (s
->scr1
>> 16) & 0xFF;
262 return (s
->scr1
>> 8) & 0xFF;
264 return (s
->scr1
>> 0) & 0xFF;
267 return (s
->scr2
>> 24) & 0xFF;
269 return (s
->scr2
>> 16) & 0xFF;
271 return (s
->scr2
>> 8) & 0xFF;
273 return (s
->scr2
>> 0) & 0xFF;
275 DPRINTF("MMIO Read 0x4020\n");
279 DPRINTF("MMIO Read B @ %"HWADDR_PRIx
"\n", addr
);
284 static uint32_t mmio_readw(NeXTPC
*s
, hwaddr addr
)
288 DPRINTF("MMIO Read W @ %"HWADDR_PRIx
"\n", addr
);
293 static uint32_t mmio_readl(NeXTPC
*s
, hwaddr addr
)
297 /* DPRINTF("Read INT status: %x\n", s->int_status); */
298 return s
->int_status
;
301 DPRINTF("MMIO Read INT mask: %x\n", s
->int_mask
);
311 DPRINTF("MMIO Read L @ %"HWADDR_PRIx
"\n", addr
);
316 static void mmio_writeb(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
320 nextscr2_write(s
, val
, 1);
323 DPRINTF("MMIO Write B @ %x with %x\n", (unsigned int)addr
, val
);
328 static void mmio_writew(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
330 DPRINTF("MMIO Write W\n");
333 static void mmio_writel(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
337 DPRINTF("INT Status old: %x new: %x\n", s
->int_status
, val
);
341 DPRINTF("INT Mask old: %x new: %x\n", s
->int_mask
, val
);
345 DPRINTF("SCR1 Write: %x\n", val
);
348 nextscr2_write(s
, val
, 4);
352 DPRINTF("MMIO Write l @ %x with %x\n", (unsigned int)addr
, val
);
356 static uint64_t mmio_readfn(void *opaque
, hwaddr addr
, unsigned size
)
358 NeXTPC
*s
= NEXT_PC(opaque
);
362 return mmio_readb(s
, addr
);
364 return mmio_readw(s
, addr
);
366 return mmio_readl(s
, addr
);
368 g_assert_not_reached();
372 static void mmio_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
375 NeXTPC
*s
= NEXT_PC(opaque
);
379 mmio_writeb(s
, addr
, value
);
382 mmio_writew(s
, addr
, value
);
385 mmio_writel(s
, addr
, value
);
388 g_assert_not_reached();
392 static const MemoryRegionOps mmio_ops
= {
394 .write
= mmio_writefn
,
395 .valid
.min_access_size
= 1,
396 .valid
.max_access_size
= 4,
397 .endianness
= DEVICE_NATIVE_ENDIAN
,
400 static uint32_t scr_readb(NeXTPC
*s
, hwaddr addr
)
404 DPRINTF("FD read @ %x\n", (unsigned int)addr
);
405 return 0x40 | 0x04 | 0x2 | 0x1;
407 DPRINTF("SCSI 4020 STATUS READ %X\n", s
->scsi_csr_1
);
408 return s
->scsi_csr_1
;
411 DPRINTF("SCSI 4021 STATUS READ %X\n", s
->scsi_csr_2
);
415 * These 4 registers are the hardware timer, not sure which register
416 * is the latch instead of data, but no problems so far
419 return 0xff & (clock() >> 24);
421 return 0xff & (clock() >> 16);
423 return 0xff & (clock() >> 8);
425 /* Hack: We need to have this change consistently to make it work */
426 return 0xFF & clock();
429 DPRINTF("BMAP Read B @ %x\n", (unsigned int)addr
);
434 static uint32_t scr_readw(NeXTPC
*s
, hwaddr addr
)
436 DPRINTF("BMAP Read W @ %x\n", (unsigned int)addr
);
440 static uint32_t scr_readl(NeXTPC
*s
, hwaddr addr
)
442 DPRINTF("BMAP Read L @ %x\n", (unsigned int)addr
);
446 #define SCSICSR_ENABLE 0x01
447 #define SCSICSR_RESET 0x02 /* reset scsi dma */
448 #define SCSICSR_FIFOFL 0x04
449 #define SCSICSR_DMADIR 0x08 /* if set, scsi to mem */
450 #define SCSICSR_CPUDMA 0x10 /* if set, dma enabled */
451 #define SCSICSR_INTMASK 0x20 /* if set, interrupt enabled */
453 static void scr_writeb(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
457 DPRINTF("FDCSR Write: %x\n", value
);
460 /* qemu_irq_raise(s->fd_irq[0]); */
463 case 0x14020: /* SCSI Control Register */
464 if (value
& SCSICSR_FIFOFL
) {
465 DPRINTF("SCSICSR FIFO Flush\n");
466 /* will have to add another irq to the esp if this is needed */
467 /* esp_puflush_fifo(esp_g); */
468 /* qemu_irq_pulse(s->scsi_dma); */
471 if (value
& SCSICSR_ENABLE
) {
472 DPRINTF("SCSICSR Enable\n");
474 * qemu_irq_raise(s->scsi_dma);
475 * s->scsi_csr_1 = 0xc0;
476 * s->scsi_csr_1 |= 0x1;
477 * qemu_irq_pulse(s->scsi_dma);
482 * s->scsi_csr_1 &= ~SCSICSR_ENABLE;
485 if (value
& SCSICSR_RESET
) {
486 DPRINTF("SCSICSR Reset\n");
487 /* I think this should set DMADIR. CPUDMA and INTMASK to 0 */
488 /* qemu_irq_raise(s->scsi_reset); */
489 /* s->scsi_csr_1 &= ~(SCSICSR_INTMASK |0x80|0x1); */
492 if (value
& SCSICSR_DMADIR
) {
493 DPRINTF("SCSICSR DMAdir\n");
495 if (value
& SCSICSR_CPUDMA
) {
496 DPRINTF("SCSICSR CPUDMA\n");
497 /* qemu_irq_raise(s->scsi_dma); */
499 s
->int_status
|= 0x4000000;
501 s
->int_status
&= ~(0x4000000);
503 if (value
& SCSICSR_INTMASK
) {
504 DPRINTF("SCSICSR INTMASK\n");
506 * int_mask &= ~0x1000;
507 * s->scsi_csr_1 |= value;
508 * s->scsi_csr_1 &= ~SCSICSR_INTMASK;
509 * if (s->scsi_queued) {
510 * s->scsi_queued = 0;
511 * next_irq(s, NEXT_SCSI_I, level);
515 /* int_mask |= 0x1000; */
518 /* int_mask |= 0x1000; */
519 /* s->scsi_csr_1 |= 0x80; */
521 DPRINTF("SCSICSR Write: %x\n", value
);
522 /* s->scsi_csr_1 = value; */
524 /* Hardware timer latch - not implemented yet */
527 DPRINTF("BMAP Write B @ %x with %x\n", (unsigned int)addr
, value
);
531 static void scr_writew(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
533 DPRINTF("BMAP Write W @ %x with %x\n", (unsigned int)addr
, value
);
536 static void scr_writel(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
538 DPRINTF("BMAP Write L @ %x with %x\n", (unsigned int)addr
, value
);
541 static uint64_t scr_readfn(void *opaque
, hwaddr addr
, unsigned size
)
543 NeXTPC
*s
= NEXT_PC(opaque
);
547 return scr_readb(s
, addr
);
549 return scr_readw(s
, addr
);
551 return scr_readl(s
, addr
);
553 g_assert_not_reached();
557 static void scr_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
560 NeXTPC
*s
= NEXT_PC(opaque
);
564 scr_writeb(s
, addr
, value
);
567 scr_writew(s
, addr
, value
);
570 scr_writel(s
, addr
, value
);
573 g_assert_not_reached();
577 static const MemoryRegionOps scr_ops
= {
579 .write
= scr_writefn
,
580 .valid
.min_access_size
= 1,
581 .valid
.max_access_size
= 4,
582 .endianness
= DEVICE_NATIVE_ENDIAN
,
585 #define NEXTDMA_SCSI(x) (0x10 + x)
586 #define NEXTDMA_FD(x) (0x10 + x)
587 #define NEXTDMA_ENTX(x) (0x110 + x)
588 #define NEXTDMA_ENRX(x) (0x150 + x)
589 #define NEXTDMA_CSR 0x0
590 #define NEXTDMA_NEXT 0x4000
591 #define NEXTDMA_LIMIT 0x4004
592 #define NEXTDMA_START 0x4008
593 #define NEXTDMA_STOP 0x400c
594 #define NEXTDMA_NEXT_INIT 0x4200
595 #define NEXTDMA_SIZE 0x4204
597 static void dma_writel(void *opaque
, hwaddr addr
, uint64_t value
,
600 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
603 case NEXTDMA_ENRX(NEXTDMA_CSR
):
604 if (value
& DMA_DEV2M
) {
605 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_DEV2M
;
608 if (value
& DMA_SETENABLE
) {
609 /* DPRINTF("SCSI DMA ENABLE\n"); */
610 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_ENABLE
;
612 if (value
& DMA_SETSUPDATE
) {
613 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_SUPDATE
;
615 if (value
& DMA_CLRCOMPLETE
) {
616 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~DMA_COMPLETE
;
619 if (value
& DMA_RESET
) {
620 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
621 DMA_ENABLE
| DMA_DEV2M
);
623 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
625 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
626 next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
= value
;
628 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
629 next_state
->dma
[NEXTDMA_ENRX
].next
= value
;
631 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
632 next_state
->dma
[NEXTDMA_ENRX
].limit
= value
;
634 case NEXTDMA_SCSI(NEXTDMA_CSR
):
635 if (value
& DMA_DEV2M
) {
636 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_DEV2M
;
638 if (value
& DMA_SETENABLE
) {
639 /* DPRINTF("SCSI DMA ENABLE\n"); */
640 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_ENABLE
;
642 if (value
& DMA_SETSUPDATE
) {
643 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_SUPDATE
;
645 if (value
& DMA_CLRCOMPLETE
) {
646 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~DMA_COMPLETE
;
649 if (value
& DMA_RESET
) {
650 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
651 DMA_ENABLE
| DMA_DEV2M
);
652 /* DPRINTF("SCSI DMA RESET\n"); */
654 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
657 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
658 next_state
->dma
[NEXTDMA_SCSI
].next
= value
;
661 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
662 next_state
->dma
[NEXTDMA_SCSI
].limit
= value
;
665 case NEXTDMA_SCSI(NEXTDMA_START
):
666 next_state
->dma
[NEXTDMA_SCSI
].start
= value
;
669 case NEXTDMA_SCSI(NEXTDMA_STOP
):
670 next_state
->dma
[NEXTDMA_SCSI
].stop
= value
;
673 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
674 next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
= value
;
678 DPRINTF("DMA write @ %x w/ %x\n", (unsigned)addr
, (unsigned)value
);
682 static uint64_t dma_readl(void *opaque
, hwaddr addr
, unsigned int size
)
684 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
687 case NEXTDMA_SCSI(NEXTDMA_CSR
):
688 DPRINTF("SCSI DMA CSR READ\n");
689 return next_state
->dma
[NEXTDMA_SCSI
].csr
;
690 case NEXTDMA_ENRX(NEXTDMA_CSR
):
691 return next_state
->dma
[NEXTDMA_ENRX
].csr
;
692 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
693 return next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
;
694 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
695 return next_state
->dma
[NEXTDMA_ENRX
].next
;
696 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
697 return next_state
->dma
[NEXTDMA_ENRX
].limit
;
699 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
700 return next_state
->dma
[NEXTDMA_SCSI
].next
;
701 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
702 return next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
;
703 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
704 return next_state
->dma
[NEXTDMA_SCSI
].limit
;
705 case NEXTDMA_SCSI(NEXTDMA_START
):
706 return next_state
->dma
[NEXTDMA_SCSI
].start
;
707 case NEXTDMA_SCSI(NEXTDMA_STOP
):
708 return next_state
->dma
[NEXTDMA_SCSI
].stop
;
711 DPRINTF("DMA read @ %x\n", (unsigned int)addr
);
716 * once the csr's are done, subtract 0x3FEC from the addr, and that will
717 * normalize the upper registers
721 static const MemoryRegionOps dma_ops
= {
724 .impl
.min_access_size
= 4,
725 .valid
.min_access_size
= 4,
726 .valid
.max_access_size
= 4,
727 .endianness
= DEVICE_NATIVE_ENDIAN
,
730 static void next_irq(void *opaque
, int number
, int level
)
732 NeXTPC
*s
= NEXT_PC(opaque
);
733 M68kCPU
*cpu
= s
->cpu
;
736 /* first switch sets interupt status */
737 /* DPRINTF("IRQ %i\n",number); */
739 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
762 /* level 5 - scc (serial) */
767 /* level 6 - audio etherrx/tx dma */
768 case NEXT_ENTX_DMA_I
:
771 case NEXT_ENRX_DMA_I
:
774 case NEXT_SCSI_DMA_I
:
786 * this HAS to be wrong, the interrupt handlers in mach and together
787 * int_status and int_mask and return if there is a hit
789 if (s
->int_mask
& (1 << shift
)) {
790 DPRINTF("%x interrupt masked @ %x\n", 1 << shift
, cpu
->env
.pc
);
794 /* second switch triggers the correct interrupt */
796 s
->int_status
|= 1 << shift
;
799 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
807 m68k_set_irq_level(cpu
, 3, 27);
810 /* level 5 - scc (serial) */
812 m68k_set_irq_level(cpu
, 5, 29);
815 /* level 6 - audio etherrx/tx dma */
816 case NEXT_ENTX_DMA_I
:
817 case NEXT_ENRX_DMA_I
:
818 case NEXT_SCSI_DMA_I
:
821 m68k_set_irq_level(cpu
, 6, 30);
825 s
->int_status
&= ~(1 << shift
);
826 cpu_reset_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
830 static void next_escc_init(DeviceState
*pcdev
)
835 dev
= qdev_new(TYPE_ESCC
);
836 qdev_prop_set_uint32(dev
, "disabled", 0);
837 qdev_prop_set_uint32(dev
, "frequency", 9600 * 384);
838 qdev_prop_set_uint32(dev
, "it_shift", 0);
839 qdev_prop_set_bit(dev
, "bit_swap", true);
840 qdev_prop_set_chr(dev
, "chrB", serial_hd(1));
841 qdev_prop_set_chr(dev
, "chrA", serial_hd(0));
842 qdev_prop_set_uint32(dev
, "chnBtype", escc_serial
);
843 qdev_prop_set_uint32(dev
, "chnAtype", escc_serial
);
845 s
= SYS_BUS_DEVICE(dev
);
846 sysbus_realize_and_unref(s
, &error_fatal
);
847 sysbus_connect_irq(s
, 0, qdev_get_gpio_in(pcdev
, NEXT_SCC_I
));
848 sysbus_connect_irq(s
, 1, qdev_get_gpio_in(pcdev
, NEXT_SCC_DMA_I
));
849 sysbus_mmio_map(s
, 0, 0x2118000);
852 static void next_pc_reset(DeviceState
*dev
)
854 NeXTPC
*s
= NEXT_PC(dev
);
856 /* Set internal registers to initial values */
857 /* 0x0000XX00 << vital bits */
858 s
->scr1
= 0x00011102;
859 s
->scr2
= 0x00ff0c80;
861 s
->rtc
.status
= 0x90;
863 /* Load RTC RAM - TODO: provide possibility to load contents from file */
864 memcpy(s
->rtc
.ram
, rtc_ram2
, 32);
867 static void next_pc_realize(DeviceState
*dev
, Error
**errp
)
869 NeXTPC
*s
= NEXT_PC(dev
);
870 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
872 qdev_init_gpio_in(dev
, next_irq
, NEXT_NUM_IRQS
);
874 memory_region_init_io(&s
->mmiomem
, OBJECT(s
), &mmio_ops
, s
,
875 "next.mmio", 0xD0000);
876 memory_region_init_io(&s
->scrmem
, OBJECT(s
), &scr_ops
, s
,
877 "next.scr", 0x20000);
878 sysbus_init_mmio(sbd
, &s
->mmiomem
);
879 sysbus_init_mmio(sbd
, &s
->scrmem
);
883 * If the m68k CPU implemented its inbound irq lines as GPIO lines
884 * rather than via the m68k_set_irq_level() function we would not need
885 * this cpu link property and could instead provide outbound IRQ lines
886 * that the board could wire up to the CPU.
888 static Property next_pc_properties
[] = {
889 DEFINE_PROP_LINK("cpu", NeXTPC
, cpu
, TYPE_M68K_CPU
, M68kCPU
*),
890 DEFINE_PROP_END_OF_LIST(),
893 static const VMStateDescription next_rtc_vmstate
= {
896 .minimum_version_id
= 1,
897 .fields
= (VMStateField
[]) {
898 VMSTATE_UINT8_ARRAY(ram
, NextRtc
, 32),
899 VMSTATE_UINT8(command
, NextRtc
),
900 VMSTATE_UINT8(value
, NextRtc
),
901 VMSTATE_UINT8(status
, NextRtc
),
902 VMSTATE_UINT8(control
, NextRtc
),
903 VMSTATE_UINT8(retval
, NextRtc
),
904 VMSTATE_END_OF_LIST()
908 static const VMStateDescription next_pc_vmstate
= {
911 .minimum_version_id
= 1,
912 .fields
= (VMStateField
[]) {
913 VMSTATE_UINT32(scr1
, NeXTPC
),
914 VMSTATE_UINT32(scr2
, NeXTPC
),
915 VMSTATE_UINT32(int_mask
, NeXTPC
),
916 VMSTATE_UINT32(int_status
, NeXTPC
),
917 VMSTATE_UINT8(scsi_csr_1
, NeXTPC
),
918 VMSTATE_UINT8(scsi_csr_2
, NeXTPC
),
919 VMSTATE_STRUCT(rtc
, NeXTPC
, 0, next_rtc_vmstate
, NextRtc
),
920 VMSTATE_END_OF_LIST()
924 static void next_pc_class_init(ObjectClass
*klass
, void *data
)
926 DeviceClass
*dc
= DEVICE_CLASS(klass
);
928 dc
->desc
= "NeXT Peripheral Controller";
929 dc
->realize
= next_pc_realize
;
930 dc
->reset
= next_pc_reset
;
931 device_class_set_props(dc
, next_pc_properties
);
932 dc
->vmsd
= &next_pc_vmstate
;
935 static const TypeInfo next_pc_info
= {
936 .name
= TYPE_NEXT_PC
,
937 .parent
= TYPE_SYS_BUS_DEVICE
,
938 .instance_size
= sizeof(NeXTPC
),
939 .class_init
= next_pc_class_init
,
942 static void next_cube_init(MachineState
*machine
)
946 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
947 MemoryRegion
*dmamem
= g_new(MemoryRegion
, 1);
948 MemoryRegion
*bmapm1
= g_new(MemoryRegion
, 1);
949 MemoryRegion
*bmapm2
= g_new(MemoryRegion
, 1);
950 MemoryRegion
*sysmem
= get_system_memory();
951 const char *bios_name
= machine
->firmware
?: ROM_FILE
;
955 /* Initialize the cpu core */
956 cpu
= M68K_CPU(cpu_create(machine
->cpu_type
));
958 error_report("Unable to find m68k CPU definition");
963 /* Initialize CPU registers. */
967 /* Peripheral Controller */
968 pcdev
= qdev_new(TYPE_NEXT_PC
);
969 object_property_set_link(OBJECT(pcdev
), "cpu", OBJECT(cpu
), &error_abort
);
970 sysbus_realize_and_unref(SYS_BUS_DEVICE(pcdev
), &error_fatal
);
972 /* 64MB RAM starting at 0x04000000 */
973 memory_region_add_subregion(sysmem
, 0x04000000, machine
->ram
);
976 dev
= qdev_new(TYPE_NEXTFB
);
977 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
978 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0B000000);
981 sysbus_mmio_map(SYS_BUS_DEVICE(pcdev
), 0, 0x02000000);
983 /* BMAP IO - acts as a catch-all for now */
984 sysbus_mmio_map(SYS_BUS_DEVICE(pcdev
), 1, 0x02100000);
987 memory_region_init_ram_flags_nomigrate(bmapm1
, NULL
, "next.bmapmem", 64,
988 RAM_SHARED
, &error_fatal
);
989 memory_region_add_subregion(sysmem
, 0x020c0000, bmapm1
);
990 /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */
991 memory_region_init_alias(bmapm2
, NULL
, "next.bmapmem2", bmapm1
, 0x0, 64);
992 memory_region_add_subregion(sysmem
, 0x820c0000, bmapm2
);
995 dev
= qdev_new(TYPE_NEXTKBD
);
996 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
997 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0200e000);
1000 /* still not sure if the rom should also be mapped at 0x0*/
1001 memory_region_init_rom(rom
, NULL
, "next.rom", 0x20000, &error_fatal
);
1002 memory_region_add_subregion(sysmem
, 0x01000000, rom
);
1003 if (load_image_targphys(bios_name
, 0x01000000, 0x20000) < 8) {
1004 if (!qtest_enabled()) {
1005 error_report("Failed to load firmware '%s'.", bios_name
);
1009 /* Initial PC is always at offset 4 in firmware binaries */
1010 ptr
= rom_ptr(0x01000004, 4);
1011 g_assert(ptr
!= NULL
);
1012 env
->pc
= ldl_p(ptr
);
1013 if (env
->pc
>= 0x01020000) {
1014 error_report("'%s' does not seem to be a valid firmware image.",
1021 next_escc_init(pcdev
);
1028 memory_region_init_io(dmamem
, NULL
, &dma_ops
, machine
, "next.dma", 0x5000);
1029 memory_region_add_subregion(sysmem
, 0x02000000, dmamem
);
1032 static void next_machine_class_init(ObjectClass
*oc
, void *data
)
1034 MachineClass
*mc
= MACHINE_CLASS(oc
);
1036 mc
->desc
= "NeXT Cube";
1037 mc
->init
= next_cube_init
;
1038 mc
->default_ram_size
= RAM_SIZE
;
1039 mc
->default_ram_id
= "next.ram";
1040 mc
->default_cpu_type
= M68K_CPU_TYPE_NAME("m68040");
1043 static const TypeInfo next_typeinfo
= {
1044 .name
= TYPE_NEXT_MACHINE
,
1045 .parent
= TYPE_MACHINE
,
1046 .class_init
= next_machine_class_init
,
1047 .instance_size
= sizeof(NeXTState
),
1050 static void next_register_type(void)
1052 type_register_static(&next_typeinfo
);
1053 type_register_static(&next_pc_info
);
1056 type_init(next_register_type
)