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"
14 #include "exec/hwaddr.h"
15 #include "exec/address-spaces.h"
16 #include "sysemu/sysemu.h"
17 #include "sysemu/qtest.h"
19 #include "hw/m68k/next-cube.h"
20 #include "hw/boards.h"
21 #include "hw/loader.h"
22 #include "hw/scsi/esp.h"
23 #include "hw/sysbus.h"
24 #include "qom/object.h"
25 #include "hw/char/escc.h" /* ZILOG 8530 Serial Emulation */
26 #include "hw/block/fdc.h"
27 #include "hw/qdev-properties.h"
28 #include "qapi/error.h"
29 #include "ui/console.h"
30 #include "target/m68k/cpu.h"
31 #include "migration/vmstate.h"
33 /* #define DEBUG_NEXT */
35 #define DPRINTF(fmt, ...) \
36 do { printf("NeXT: " fmt , ## __VA_ARGS__); } while (0)
38 #define DPRINTF(fmt, ...) do { } while (0)
41 #define TYPE_NEXT_MACHINE MACHINE_TYPE_NAME("next-cube")
42 OBJECT_DECLARE_SIMPLE_TYPE(NeXTState
, NEXT_MACHINE
)
44 #define ENTRY 0x0100001e
45 #define RAM_SIZE 0x4000000
46 #define ROM_FILE "Rev_2.5_v66.bin"
48 typedef struct next_dma
{
61 uint32_t next_initbuf
;
65 typedef struct NextRtc
{
80 #define TYPE_NEXT_PC "next-pc"
81 OBJECT_DECLARE_SIMPLE_TYPE(NeXTPC
, NEXT_PC
)
83 /* NeXT Peripheral Controller */
85 SysBusDevice parent_obj
;
102 /* Thanks to NeXT forums for this */
104 static const uint8_t rtc_ram3[32] = {
105 0x94, 0x0f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x7B, 0x00,
107 0x00, 0x00, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x13
111 static const uint8_t rtc_ram2
[32] = {
112 0x94, 0x0f, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00,
113 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x4b, 0x00,
114 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x7e,
118 #define SCR2_RTCLK 0x2
119 #define SCR2_RTDATA 0x4
120 #define SCR2_TOBCD(x) (((x / 10) << 4) + (x % 10))
122 static void nextscr2_write(NeXTPC
*s
, uint32_t val
, int size
)
126 static uint8_t old_scr2
;
128 NextRtc
*rtc
= &s
->rtc
;
131 scr2_2
= (val
>> 8) & 0xFF;
140 DPRINTF("LED flashing, possible fault!\n");
146 /* DPRINTF("RTC %x phase %i\n", scr2_2, phase); */
150 /* If we are in going down clock... do something */
151 if (((old_scr2
& SCR2_RTCLK
) != (scr2_2
& SCR2_RTCLK
)) &&
152 ((scr2_2
& SCR2_RTCLK
) == 0)) {
154 rtc
->command
= (rtc
->command
<< 1) |
155 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
157 if (phase
>= 8 && phase
< 16) {
158 rtc
->value
= (rtc
->value
<< 1) |
159 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
161 /* if we read RAM register, output RT_DATA bit */
162 if (rtc
->command
<= 0x1F) {
163 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
164 if (rtc
->ram
[rtc
->command
] & (0x80 >> (phase
- 8))) {
165 scr2_2
|= SCR2_RTDATA
;
168 rtc
->retval
= (rtc
->retval
<< 1) |
169 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
171 /* read the status 0x30 */
172 if (rtc
->command
== 0x30) {
173 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
174 /* for now status = 0x98 (new rtc + FTU) */
175 if (rtc
->status
& (0x80 >> (phase
- 8))) {
176 scr2_2
|= SCR2_RTDATA
;
179 rtc
->retval
= (rtc
->retval
<< 1) |
180 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
182 /* read the status 0x31 */
183 if (rtc
->command
== 0x31) {
184 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
185 if (rtc
->control
& (0x80 >> (phase
- 8))) {
186 scr2_2
|= SCR2_RTDATA
;
188 rtc
->retval
= (rtc
->retval
<< 1) |
189 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
192 if ((rtc
->command
>= 0x20) && (rtc
->command
<= 0x2F)) {
193 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
195 time_t time_h
= time(NULL
);
196 struct tm
*info
= localtime(&time_h
);
199 switch (rtc
->command
) {
201 ret
= SCR2_TOBCD(info
->tm_sec
);
204 ret
= SCR2_TOBCD(info
->tm_min
);
207 ret
= SCR2_TOBCD(info
->tm_hour
);
210 ret
= SCR2_TOBCD(info
->tm_mday
);
213 ret
= SCR2_TOBCD((info
->tm_mon
+ 1));
216 ret
= SCR2_TOBCD((info
->tm_year
- 100));
221 if (ret
& (0x80 >> (phase
- 8))) {
222 scr2_2
|= SCR2_RTDATA
;
224 rtc
->retval
= (rtc
->retval
<< 1) |
225 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
232 if (rtc
->command
>= 0x80 && rtc
->command
<= 0x9F) {
233 rtc
->ram
[rtc
->command
- 0x80] = rtc
->value
;
235 /* write to x30 register */
236 if (rtc
->command
== 0xB1) {
238 if (rtc
->value
& 0x04) {
239 rtc
->status
= rtc
->status
& (~0x18);
240 s
->int_status
= s
->int_status
& (~0x04);
246 /* else end or abort */
251 s
->scr2
= val
& 0xFFFF00FF;
252 s
->scr2
|= scr2_2
<< 8;
256 static uint32_t mmio_readb(NeXTPC
*s
, hwaddr addr
)
260 return (s
->scr1
>> 24) & 0xFF;
262 return (s
->scr1
>> 16) & 0xFF;
264 return (s
->scr1
>> 8) & 0xFF;
266 return (s
->scr1
>> 0) & 0xFF;
269 return (s
->scr2
>> 24) & 0xFF;
271 return (s
->scr2
>> 16) & 0xFF;
273 return (s
->scr2
>> 8) & 0xFF;
275 return (s
->scr2
>> 0) & 0xFF;
277 DPRINTF("MMIO Read 0x4020\n");
281 DPRINTF("MMIO Read B @ %"HWADDR_PRIx
"\n", addr
);
286 static uint32_t mmio_readw(NeXTPC
*s
, hwaddr addr
)
290 DPRINTF("MMIO Read W @ %"HWADDR_PRIx
"\n", addr
);
295 static uint32_t mmio_readl(NeXTPC
*s
, hwaddr addr
)
299 /* DPRINTF("Read INT status: %x\n", s->int_status); */
300 return s
->int_status
;
303 DPRINTF("MMIO Read INT mask: %x\n", s
->int_mask
);
313 DPRINTF("MMIO Read L @ %"HWADDR_PRIx
"\n", addr
);
318 static void mmio_writeb(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
322 nextscr2_write(s
, val
, 1);
325 DPRINTF("MMIO Write B @ %x with %x\n", (unsigned int)addr
, val
);
330 static void mmio_writew(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
332 DPRINTF("MMIO Write W\n");
335 static void mmio_writel(NeXTPC
*s
, hwaddr addr
, uint32_t val
)
339 DPRINTF("INT Status old: %x new: %x\n", s
->int_status
, val
);
343 DPRINTF("INT Mask old: %x new: %x\n", s
->int_mask
, val
);
347 DPRINTF("SCR1 Write: %x\n", val
);
350 nextscr2_write(s
, val
, 4);
354 DPRINTF("MMIO Write l @ %x with %x\n", (unsigned int)addr
, val
);
358 static uint64_t mmio_readfn(void *opaque
, hwaddr addr
, unsigned size
)
360 NeXTPC
*s
= NEXT_PC(opaque
);
364 return mmio_readb(s
, addr
);
366 return mmio_readw(s
, addr
);
368 return mmio_readl(s
, addr
);
370 g_assert_not_reached();
374 static void mmio_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
377 NeXTPC
*s
= NEXT_PC(opaque
);
381 mmio_writeb(s
, addr
, value
);
384 mmio_writew(s
, addr
, value
);
387 mmio_writel(s
, addr
, value
);
390 g_assert_not_reached();
394 static const MemoryRegionOps mmio_ops
= {
396 .write
= mmio_writefn
,
397 .valid
.min_access_size
= 1,
398 .valid
.max_access_size
= 4,
399 .endianness
= DEVICE_NATIVE_ENDIAN
,
402 static uint32_t scr_readb(NeXTPC
*s
, hwaddr addr
)
406 DPRINTF("FD read @ %x\n", (unsigned int)addr
);
407 return 0x40 | 0x04 | 0x2 | 0x1;
409 DPRINTF("SCSI 4020 STATUS READ %X\n", s
->scsi_csr_1
);
410 return s
->scsi_csr_1
;
413 DPRINTF("SCSI 4021 STATUS READ %X\n", s
->scsi_csr_2
);
417 * These 4 registers are the hardware timer, not sure which register
418 * is the latch instead of data, but no problems so far
421 return 0xff & (clock() >> 24);
423 return 0xff & (clock() >> 16);
425 return 0xff & (clock() >> 8);
427 /* Hack: We need to have this change consistently to make it work */
428 return 0xFF & clock();
431 DPRINTF("BMAP Read B @ %x\n", (unsigned int)addr
);
436 static uint32_t scr_readw(NeXTPC
*s
, hwaddr addr
)
438 DPRINTF("BMAP Read W @ %x\n", (unsigned int)addr
);
442 static uint32_t scr_readl(NeXTPC
*s
, hwaddr addr
)
444 DPRINTF("BMAP Read L @ %x\n", (unsigned int)addr
);
448 #define SCSICSR_ENABLE 0x01
449 #define SCSICSR_RESET 0x02 /* reset scsi dma */
450 #define SCSICSR_FIFOFL 0x04
451 #define SCSICSR_DMADIR 0x08 /* if set, scsi to mem */
452 #define SCSICSR_CPUDMA 0x10 /* if set, dma enabled */
453 #define SCSICSR_INTMASK 0x20 /* if set, interrupt enabled */
455 static void scr_writeb(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
459 DPRINTF("FDCSR Write: %x\n", value
);
462 /* qemu_irq_raise(s->fd_irq[0]); */
465 case 0x14020: /* SCSI Control Register */
466 if (value
& SCSICSR_FIFOFL
) {
467 DPRINTF("SCSICSR FIFO Flush\n");
468 /* will have to add another irq to the esp if this is needed */
469 /* esp_puflush_fifo(esp_g); */
470 /* qemu_irq_pulse(s->scsi_dma); */
473 if (value
& SCSICSR_ENABLE
) {
474 DPRINTF("SCSICSR Enable\n");
476 * qemu_irq_raise(s->scsi_dma);
477 * s->scsi_csr_1 = 0xc0;
478 * s->scsi_csr_1 |= 0x1;
479 * qemu_irq_pulse(s->scsi_dma);
484 * s->scsi_csr_1 &= ~SCSICSR_ENABLE;
487 if (value
& SCSICSR_RESET
) {
488 DPRINTF("SCSICSR Reset\n");
489 /* I think this should set DMADIR. CPUDMA and INTMASK to 0 */
490 /* qemu_irq_raise(s->scsi_reset); */
491 /* s->scsi_csr_1 &= ~(SCSICSR_INTMASK |0x80|0x1); */
494 if (value
& SCSICSR_DMADIR
) {
495 DPRINTF("SCSICSR DMAdir\n");
497 if (value
& SCSICSR_CPUDMA
) {
498 DPRINTF("SCSICSR CPUDMA\n");
499 /* qemu_irq_raise(s->scsi_dma); */
501 s
->int_status
|= 0x4000000;
503 s
->int_status
&= ~(0x4000000);
505 if (value
& SCSICSR_INTMASK
) {
506 DPRINTF("SCSICSR INTMASK\n");
508 * int_mask &= ~0x1000;
509 * s->scsi_csr_1 |= value;
510 * s->scsi_csr_1 &= ~SCSICSR_INTMASK;
511 * if (s->scsi_queued) {
512 * s->scsi_queued = 0;
513 * next_irq(s, NEXT_SCSI_I, level);
517 /* int_mask |= 0x1000; */
520 /* int_mask |= 0x1000; */
521 /* s->scsi_csr_1 |= 0x80; */
523 DPRINTF("SCSICSR Write: %x\n", value
);
524 /* s->scsi_csr_1 = value; */
526 /* Hardware timer latch - not implemented yet */
529 DPRINTF("BMAP Write B @ %x with %x\n", (unsigned int)addr
, value
);
533 static void scr_writew(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
535 DPRINTF("BMAP Write W @ %x with %x\n", (unsigned int)addr
, value
);
538 static void scr_writel(NeXTPC
*s
, hwaddr addr
, uint32_t value
)
540 DPRINTF("BMAP Write L @ %x with %x\n", (unsigned int)addr
, value
);
543 static uint64_t scr_readfn(void *opaque
, hwaddr addr
, unsigned size
)
545 NeXTPC
*s
= NEXT_PC(opaque
);
549 return scr_readb(s
, addr
);
551 return scr_readw(s
, addr
);
553 return scr_readl(s
, addr
);
555 g_assert_not_reached();
559 static void scr_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
562 NeXTPC
*s
= NEXT_PC(opaque
);
566 scr_writeb(s
, addr
, value
);
569 scr_writew(s
, addr
, value
);
572 scr_writel(s
, addr
, value
);
575 g_assert_not_reached();
579 static const MemoryRegionOps scr_ops
= {
581 .write
= scr_writefn
,
582 .valid
.min_access_size
= 1,
583 .valid
.max_access_size
= 4,
584 .endianness
= DEVICE_NATIVE_ENDIAN
,
587 #define NEXTDMA_SCSI(x) (0x10 + x)
588 #define NEXTDMA_FD(x) (0x10 + x)
589 #define NEXTDMA_ENTX(x) (0x110 + x)
590 #define NEXTDMA_ENRX(x) (0x150 + x)
591 #define NEXTDMA_CSR 0x0
592 #define NEXTDMA_NEXT 0x4000
593 #define NEXTDMA_LIMIT 0x4004
594 #define NEXTDMA_START 0x4008
595 #define NEXTDMA_STOP 0x400c
596 #define NEXTDMA_NEXT_INIT 0x4200
597 #define NEXTDMA_SIZE 0x4204
599 static void dma_writel(void *opaque
, hwaddr addr
, uint64_t value
,
602 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
605 case NEXTDMA_ENRX(NEXTDMA_CSR
):
606 if (value
& DMA_DEV2M
) {
607 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_DEV2M
;
610 if (value
& DMA_SETENABLE
) {
611 /* DPRINTF("SCSI DMA ENABLE\n"); */
612 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_ENABLE
;
614 if (value
& DMA_SETSUPDATE
) {
615 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_SUPDATE
;
617 if (value
& DMA_CLRCOMPLETE
) {
618 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~DMA_COMPLETE
;
621 if (value
& DMA_RESET
) {
622 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
623 DMA_ENABLE
| DMA_DEV2M
);
625 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
627 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
628 next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
= value
;
630 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
631 next_state
->dma
[NEXTDMA_ENRX
].next
= value
;
633 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
634 next_state
->dma
[NEXTDMA_ENRX
].limit
= value
;
636 case NEXTDMA_SCSI(NEXTDMA_CSR
):
637 if (value
& DMA_DEV2M
) {
638 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_DEV2M
;
640 if (value
& DMA_SETENABLE
) {
641 /* DPRINTF("SCSI DMA ENABLE\n"); */
642 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_ENABLE
;
644 if (value
& DMA_SETSUPDATE
) {
645 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_SUPDATE
;
647 if (value
& DMA_CLRCOMPLETE
) {
648 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~DMA_COMPLETE
;
651 if (value
& DMA_RESET
) {
652 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
653 DMA_ENABLE
| DMA_DEV2M
);
654 /* DPRINTF("SCSI DMA RESET\n"); */
656 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
659 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
660 next_state
->dma
[NEXTDMA_SCSI
].next
= value
;
663 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
664 next_state
->dma
[NEXTDMA_SCSI
].limit
= value
;
667 case NEXTDMA_SCSI(NEXTDMA_START
):
668 next_state
->dma
[NEXTDMA_SCSI
].start
= value
;
671 case NEXTDMA_SCSI(NEXTDMA_STOP
):
672 next_state
->dma
[NEXTDMA_SCSI
].stop
= value
;
675 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
676 next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
= value
;
680 DPRINTF("DMA write @ %x w/ %x\n", (unsigned)addr
, (unsigned)value
);
684 static uint64_t dma_readl(void *opaque
, hwaddr addr
, unsigned int size
)
686 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
689 case NEXTDMA_SCSI(NEXTDMA_CSR
):
690 DPRINTF("SCSI DMA CSR READ\n");
691 return next_state
->dma
[NEXTDMA_SCSI
].csr
;
692 case NEXTDMA_ENRX(NEXTDMA_CSR
):
693 return next_state
->dma
[NEXTDMA_ENRX
].csr
;
694 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
695 return next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
;
696 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
697 return next_state
->dma
[NEXTDMA_ENRX
].next
;
698 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
699 return next_state
->dma
[NEXTDMA_ENRX
].limit
;
701 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
702 return next_state
->dma
[NEXTDMA_SCSI
].next
;
703 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
704 return next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
;
705 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
706 return next_state
->dma
[NEXTDMA_SCSI
].limit
;
707 case NEXTDMA_SCSI(NEXTDMA_START
):
708 return next_state
->dma
[NEXTDMA_SCSI
].start
;
709 case NEXTDMA_SCSI(NEXTDMA_STOP
):
710 return next_state
->dma
[NEXTDMA_SCSI
].stop
;
713 DPRINTF("DMA read @ %x\n", (unsigned int)addr
);
718 * once the csr's are done, subtract 0x3FEC from the addr, and that will
719 * normalize the upper registers
723 static const MemoryRegionOps dma_ops
= {
726 .impl
.min_access_size
= 4,
727 .valid
.min_access_size
= 4,
728 .valid
.max_access_size
= 4,
729 .endianness
= DEVICE_NATIVE_ENDIAN
,
732 static void next_irq(void *opaque
, int number
, int level
)
734 NeXTPC
*s
= NEXT_PC(opaque
);
735 M68kCPU
*cpu
= s
->cpu
;
738 /* first switch sets interupt status */
739 /* DPRINTF("IRQ %i\n",number); */
741 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
764 /* level 5 - scc (serial) */
769 /* level 6 - audio etherrx/tx dma */
770 case NEXT_ENTX_DMA_I
:
773 case NEXT_ENRX_DMA_I
:
776 case NEXT_SCSI_DMA_I
:
788 * this HAS to be wrong, the interrupt handlers in mach and together
789 * int_status and int_mask and return if there is a hit
791 if (s
->int_mask
& (1 << shift
)) {
792 DPRINTF("%x interrupt masked @ %x\n", 1 << shift
, cpu
->env
.pc
);
796 /* second switch triggers the correct interrupt */
798 s
->int_status
|= 1 << shift
;
801 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
809 m68k_set_irq_level(cpu
, 3, 27);
812 /* level 5 - scc (serial) */
814 m68k_set_irq_level(cpu
, 5, 29);
817 /* level 6 - audio etherrx/tx dma */
818 case NEXT_ENTX_DMA_I
:
819 case NEXT_ENRX_DMA_I
:
820 case NEXT_SCSI_DMA_I
:
823 m68k_set_irq_level(cpu
, 6, 30);
827 s
->int_status
&= ~(1 << shift
);
828 cpu_reset_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
832 static void next_escc_init(DeviceState
*pcdev
)
837 dev
= qdev_new(TYPE_ESCC
);
838 qdev_prop_set_uint32(dev
, "disabled", 0);
839 qdev_prop_set_uint32(dev
, "frequency", 9600 * 384);
840 qdev_prop_set_uint32(dev
, "it_shift", 0);
841 qdev_prop_set_bit(dev
, "bit_swap", true);
842 qdev_prop_set_chr(dev
, "chrB", serial_hd(1));
843 qdev_prop_set_chr(dev
, "chrA", serial_hd(0));
844 qdev_prop_set_uint32(dev
, "chnBtype", escc_serial
);
845 qdev_prop_set_uint32(dev
, "chnAtype", escc_serial
);
847 s
= SYS_BUS_DEVICE(dev
);
848 sysbus_realize_and_unref(s
, &error_fatal
);
849 sysbus_connect_irq(s
, 0, qdev_get_gpio_in(pcdev
, NEXT_SCC_I
));
850 sysbus_connect_irq(s
, 1, qdev_get_gpio_in(pcdev
, NEXT_SCC_DMA_I
));
851 sysbus_mmio_map(s
, 0, 0x2118000);
854 static void next_pc_reset(DeviceState
*dev
)
856 NeXTPC
*s
= NEXT_PC(dev
);
858 /* Set internal registers to initial values */
859 /* 0x0000XX00 << vital bits */
860 s
->scr1
= 0x00011102;
861 s
->scr2
= 0x00ff0c80;
863 s
->rtc
.status
= 0x90;
865 /* Load RTC RAM - TODO: provide possibility to load contents from file */
866 memcpy(s
->rtc
.ram
, rtc_ram2
, 32);
869 static void next_pc_realize(DeviceState
*dev
, Error
**errp
)
871 NeXTPC
*s
= NEXT_PC(dev
);
872 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
874 qdev_init_gpio_in(dev
, next_irq
, NEXT_NUM_IRQS
);
876 memory_region_init_io(&s
->mmiomem
, OBJECT(s
), &mmio_ops
, s
,
877 "next.mmio", 0xD0000);
878 memory_region_init_io(&s
->scrmem
, OBJECT(s
), &scr_ops
, s
,
879 "next.scr", 0x20000);
880 sysbus_init_mmio(sbd
, &s
->mmiomem
);
881 sysbus_init_mmio(sbd
, &s
->scrmem
);
885 * If the m68k CPU implemented its inbound irq lines as GPIO lines
886 * rather than via the m68k_set_irq_level() function we would not need
887 * this cpu link property and could instead provide outbound IRQ lines
888 * that the board could wire up to the CPU.
890 static Property next_pc_properties
[] = {
891 DEFINE_PROP_LINK("cpu", NeXTPC
, cpu
, TYPE_M68K_CPU
, M68kCPU
*),
892 DEFINE_PROP_END_OF_LIST(),
895 static const VMStateDescription next_rtc_vmstate
= {
898 .minimum_version_id
= 1,
899 .fields
= (VMStateField
[]) {
900 VMSTATE_UINT8_ARRAY(ram
, NextRtc
, 32),
901 VMSTATE_UINT8(command
, NextRtc
),
902 VMSTATE_UINT8(value
, NextRtc
),
903 VMSTATE_UINT8(status
, NextRtc
),
904 VMSTATE_UINT8(control
, NextRtc
),
905 VMSTATE_UINT8(retval
, NextRtc
),
906 VMSTATE_END_OF_LIST()
910 static const VMStateDescription next_pc_vmstate
= {
913 .minimum_version_id
= 1,
914 .fields
= (VMStateField
[]) {
915 VMSTATE_UINT32(scr1
, NeXTPC
),
916 VMSTATE_UINT32(scr2
, NeXTPC
),
917 VMSTATE_UINT32(int_mask
, NeXTPC
),
918 VMSTATE_UINT32(int_status
, NeXTPC
),
919 VMSTATE_UINT8(scsi_csr_1
, NeXTPC
),
920 VMSTATE_UINT8(scsi_csr_2
, NeXTPC
),
921 VMSTATE_STRUCT(rtc
, NeXTPC
, 0, next_rtc_vmstate
, NextRtc
),
922 VMSTATE_END_OF_LIST()
926 static void next_pc_class_init(ObjectClass
*klass
, void *data
)
928 DeviceClass
*dc
= DEVICE_CLASS(klass
);
930 dc
->desc
= "NeXT Peripheral Controller";
931 dc
->realize
= next_pc_realize
;
932 dc
->reset
= next_pc_reset
;
933 device_class_set_props(dc
, next_pc_properties
);
934 dc
->vmsd
= &next_pc_vmstate
;
937 static const TypeInfo next_pc_info
= {
938 .name
= TYPE_NEXT_PC
,
939 .parent
= TYPE_SYS_BUS_DEVICE
,
940 .instance_size
= sizeof(NeXTPC
),
941 .class_init
= next_pc_class_init
,
944 static void next_cube_init(MachineState
*machine
)
948 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
949 MemoryRegion
*dmamem
= g_new(MemoryRegion
, 1);
950 MemoryRegion
*bmapm1
= g_new(MemoryRegion
, 1);
951 MemoryRegion
*bmapm2
= g_new(MemoryRegion
, 1);
952 MemoryRegion
*sysmem
= get_system_memory();
953 const char *bios_name
= machine
->firmware
?: ROM_FILE
;
957 /* Initialize the cpu core */
958 cpu
= M68K_CPU(cpu_create(machine
->cpu_type
));
960 error_report("Unable to find m68k CPU definition");
965 /* Initialize CPU registers. */
969 /* Peripheral Controller */
970 pcdev
= qdev_new(TYPE_NEXT_PC
);
971 object_property_set_link(OBJECT(pcdev
), "cpu", OBJECT(cpu
), &error_abort
);
972 sysbus_realize_and_unref(SYS_BUS_DEVICE(pcdev
), &error_fatal
);
974 /* 64MB RAM starting at 0x04000000 */
975 memory_region_add_subregion(sysmem
, 0x04000000, machine
->ram
);
978 dev
= qdev_new(TYPE_NEXTFB
);
979 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
980 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0B000000);
983 sysbus_mmio_map(SYS_BUS_DEVICE(pcdev
), 0, 0x02000000);
985 /* BMAP IO - acts as a catch-all for now */
986 sysbus_mmio_map(SYS_BUS_DEVICE(pcdev
), 1, 0x02100000);
989 memory_region_init_ram_shared_nomigrate(bmapm1
, NULL
, "next.bmapmem", 64,
991 memory_region_add_subregion(sysmem
, 0x020c0000, bmapm1
);
992 /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */
993 memory_region_init_alias(bmapm2
, NULL
, "next.bmapmem2", bmapm1
, 0x0, 64);
994 memory_region_add_subregion(sysmem
, 0x820c0000, bmapm2
);
997 dev
= qdev_new(TYPE_NEXTKBD
);
998 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
999 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0200e000);
1002 /* still not sure if the rom should also be mapped at 0x0*/
1003 memory_region_init_rom(rom
, NULL
, "next.rom", 0x20000, &error_fatal
);
1004 memory_region_add_subregion(sysmem
, 0x01000000, rom
);
1005 if (load_image_targphys(bios_name
, 0x01000000, 0x20000) < 8) {
1006 if (!qtest_enabled()) {
1007 error_report("Failed to load firmware '%s'.", bios_name
);
1011 /* Initial PC is always at offset 4 in firmware binaries */
1012 ptr
= rom_ptr(0x01000004, 4);
1013 g_assert(ptr
!= NULL
);
1014 env
->pc
= ldl_p(ptr
);
1015 if (env
->pc
>= 0x01020000) {
1016 error_report("'%s' does not seem to be a valid firmware image.",
1023 next_escc_init(pcdev
);
1030 memory_region_init_io(dmamem
, NULL
, &dma_ops
, machine
, "next.dma", 0x5000);
1031 memory_region_add_subregion(sysmem
, 0x02000000, dmamem
);
1034 static void next_machine_class_init(ObjectClass
*oc
, void *data
)
1036 MachineClass
*mc
= MACHINE_CLASS(oc
);
1038 mc
->desc
= "NeXT Cube";
1039 mc
->init
= next_cube_init
;
1040 mc
->default_ram_size
= RAM_SIZE
;
1041 mc
->default_ram_id
= "next.ram";
1042 mc
->default_cpu_type
= M68K_CPU_TYPE_NAME("m68040");
1045 static const TypeInfo next_typeinfo
= {
1046 .name
= TYPE_NEXT_MACHINE
,
1047 .parent
= TYPE_MACHINE
,
1048 .class_init
= next_machine_class_init
,
1049 .instance_size
= sizeof(NeXTState
),
1052 static void next_register_type(void)
1054 type_register_static(&next_typeinfo
);
1055 type_register_static(&next_pc_info
);
1058 type_init(next_register_type
)