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"
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
{
93 /* Thanks to NeXT forums for this */
95 static const uint8_t rtc_ram3[32] = {
96 0x94, 0x0f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
97 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x7B, 0x00,
98 0x00, 0x00, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00,
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x13
102 static const uint8_t rtc_ram2
[32] = {
103 0x94, 0x0f, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00,
104 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x4b, 0x00,
105 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x7e,
109 #define SCR2_RTCLK 0x2
110 #define SCR2_RTDATA 0x4
111 #define SCR2_TOBCD(x) (((x / 10) << 4) + (x % 10))
113 static void nextscr2_write(NeXTState
*s
, uint32_t val
, int size
)
117 static uint8_t old_scr2
;
119 NextRtc
*rtc
= &s
->rtc
;
122 scr2_2
= (val
>> 8) & 0xFF;
131 DPRINTF("LED flashing, possible fault!\n");
137 /* DPRINTF("RTC %x phase %i\n", scr2_2, phase); */
141 /* If we are in going down clock... do something */
142 if (((old_scr2
& SCR2_RTCLK
) != (scr2_2
& SCR2_RTCLK
)) &&
143 ((scr2_2
& SCR2_RTCLK
) == 0)) {
145 rtc
->command
= (rtc
->command
<< 1) |
146 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
148 if (phase
>= 8 && phase
< 16) {
149 rtc
->value
= (rtc
->value
<< 1) |
150 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
152 /* if we read RAM register, output RT_DATA bit */
153 if (rtc
->command
<= 0x1F) {
154 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
155 if (rtc
->ram
[rtc
->command
] & (0x80 >> (phase
- 8))) {
156 scr2_2
|= SCR2_RTDATA
;
159 rtc
->retval
= (rtc
->retval
<< 1) |
160 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
162 /* read the status 0x30 */
163 if (rtc
->command
== 0x30) {
164 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
165 /* for now status = 0x98 (new rtc + FTU) */
166 if (rtc
->status
& (0x80 >> (phase
- 8))) {
167 scr2_2
|= SCR2_RTDATA
;
170 rtc
->retval
= (rtc
->retval
<< 1) |
171 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
173 /* read the status 0x31 */
174 if (rtc
->command
== 0x31) {
175 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
176 if (rtc
->control
& (0x80 >> (phase
- 8))) {
177 scr2_2
|= SCR2_RTDATA
;
179 rtc
->retval
= (rtc
->retval
<< 1) |
180 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
183 if ((rtc
->command
>= 0x20) && (rtc
->command
<= 0x2F)) {
184 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
186 time_t time_h
= time(NULL
);
187 struct tm
*info
= localtime(&time_h
);
190 switch (rtc
->command
) {
192 ret
= SCR2_TOBCD(info
->tm_sec
);
195 ret
= SCR2_TOBCD(info
->tm_min
);
198 ret
= SCR2_TOBCD(info
->tm_hour
);
201 ret
= SCR2_TOBCD(info
->tm_mday
);
204 ret
= SCR2_TOBCD((info
->tm_mon
+ 1));
207 ret
= SCR2_TOBCD((info
->tm_year
- 100));
212 if (ret
& (0x80 >> (phase
- 8))) {
213 scr2_2
|= SCR2_RTDATA
;
215 rtc
->retval
= (rtc
->retval
<< 1) |
216 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
223 if (rtc
->command
>= 0x80 && rtc
->command
<= 0x9F) {
224 rtc
->ram
[rtc
->command
- 0x80] = rtc
->value
;
226 /* write to x30 register */
227 if (rtc
->command
== 0xB1) {
229 if (rtc
->value
& 0x04) {
230 rtc
->status
= rtc
->status
& (~0x18);
231 s
->int_status
= s
->int_status
& (~0x04);
237 /* else end or abort */
242 s
->scr2
= val
& 0xFFFF00FF;
243 s
->scr2
|= scr2_2
<< 8;
247 static uint32_t mmio_readb(NeXTState
*s
, hwaddr addr
)
251 return (s
->scr1
>> 24) & 0xFF;
253 return (s
->scr1
>> 16) & 0xFF;
255 return (s
->scr1
>> 8) & 0xFF;
257 return (s
->scr1
>> 0) & 0xFF;
260 return (s
->scr2
>> 24) & 0xFF;
262 return (s
->scr2
>> 16) & 0xFF;
264 return (s
->scr2
>> 8) & 0xFF;
266 return (s
->scr2
>> 0) & 0xFF;
268 DPRINTF("MMIO Read 0x4020\n");
272 DPRINTF("MMIO Read B @ %"HWADDR_PRIx
"\n", addr
);
277 static uint32_t mmio_readw(NeXTState
*s
, hwaddr addr
)
281 DPRINTF("MMIO Read W @ %"HWADDR_PRIx
"\n", addr
);
286 static uint32_t mmio_readl(NeXTState
*s
, hwaddr addr
)
290 /* DPRINTF("Read INT status: %x\n", s->int_status); */
291 return s
->int_status
;
294 DPRINTF("MMIO Read INT mask: %x\n", s
->int_mask
);
304 DPRINTF("MMIO Read L @ %"HWADDR_PRIx
"\n", addr
);
309 static void mmio_writeb(NeXTState
*s
, hwaddr addr
, uint32_t val
)
313 nextscr2_write(s
, val
, 1);
316 DPRINTF("MMIO Write B @ %x with %x\n", (unsigned int)addr
, val
);
321 static void mmio_writew(NeXTState
*s
, hwaddr addr
, uint32_t val
)
323 DPRINTF("MMIO Write W\n");
326 static void mmio_writel(NeXTState
*s
, hwaddr addr
, uint32_t val
)
330 DPRINTF("INT Status old: %x new: %x\n", s
->int_status
, val
);
334 DPRINTF("INT Mask old: %x new: %x\n", s
->int_mask
, val
);
338 DPRINTF("SCR1 Write: %x\n", val
);
341 nextscr2_write(s
, val
, 4);
345 DPRINTF("MMIO Write l @ %x with %x\n", (unsigned int)addr
, val
);
349 static uint64_t mmio_readfn(void *opaque
, hwaddr addr
, unsigned size
)
351 NeXTState
*ns
= NEXT_MACHINE(opaque
);
355 return mmio_readb(ns
, addr
);
357 return mmio_readw(ns
, addr
);
359 return mmio_readl(ns
, addr
);
361 g_assert_not_reached();
365 static void mmio_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
368 NeXTState
*ns
= NEXT_MACHINE(opaque
);
372 mmio_writeb(ns
, addr
, value
);
375 mmio_writew(ns
, addr
, value
);
378 mmio_writel(ns
, addr
, value
);
381 g_assert_not_reached();
385 static const MemoryRegionOps mmio_ops
= {
387 .write
= mmio_writefn
,
388 .valid
.min_access_size
= 1,
389 .valid
.max_access_size
= 4,
390 .endianness
= DEVICE_NATIVE_ENDIAN
,
393 static uint32_t scr_readb(NeXTState
*s
, hwaddr addr
)
397 DPRINTF("FD read @ %x\n", (unsigned int)addr
);
398 return 0x40 | 0x04 | 0x2 | 0x1;
400 DPRINTF("SCSI 4020 STATUS READ %X\n", s
->scsi_csr_1
);
401 return s
->scsi_csr_1
;
404 DPRINTF("SCSI 4021 STATUS READ %X\n", s
->scsi_csr_2
);
408 * These 4 registers are the hardware timer, not sure which register
409 * is the latch instead of data, but no problems so far
412 return 0xff & (clock() >> 24);
414 return 0xff & (clock() >> 16);
416 return 0xff & (clock() >> 8);
418 /* Hack: We need to have this change consistently to make it work */
419 return 0xFF & clock();
422 DPRINTF("BMAP Read B @ %x\n", (unsigned int)addr
);
427 static uint32_t scr_readw(NeXTState
*s
, hwaddr addr
)
429 DPRINTF("BMAP Read W @ %x\n", (unsigned int)addr
);
433 static uint32_t scr_readl(NeXTState
*s
, hwaddr addr
)
435 DPRINTF("BMAP Read L @ %x\n", (unsigned int)addr
);
439 #define SCSICSR_ENABLE 0x01
440 #define SCSICSR_RESET 0x02 /* reset scsi dma */
441 #define SCSICSR_FIFOFL 0x04
442 #define SCSICSR_DMADIR 0x08 /* if set, scsi to mem */
443 #define SCSICSR_CPUDMA 0x10 /* if set, dma enabled */
444 #define SCSICSR_INTMASK 0x20 /* if set, interrupt enabled */
446 static void scr_writeb(NeXTState
*s
, hwaddr addr
, uint32_t value
)
450 DPRINTF("FDCSR Write: %x\n", value
);
453 /* qemu_irq_raise(s->fd_irq[0]); */
456 case 0x14020: /* SCSI Control Register */
457 if (value
& SCSICSR_FIFOFL
) {
458 DPRINTF("SCSICSR FIFO Flush\n");
459 /* will have to add another irq to the esp if this is needed */
460 /* esp_puflush_fifo(esp_g); */
461 /* qemu_irq_pulse(s->scsi_dma); */
464 if (value
& SCSICSR_ENABLE
) {
465 DPRINTF("SCSICSR Enable\n");
467 * qemu_irq_raise(s->scsi_dma);
468 * s->scsi_csr_1 = 0xc0;
469 * s->scsi_csr_1 |= 0x1;
470 * qemu_irq_pulse(s->scsi_dma);
475 * s->scsi_csr_1 &= ~SCSICSR_ENABLE;
478 if (value
& SCSICSR_RESET
) {
479 DPRINTF("SCSICSR Reset\n");
480 /* I think this should set DMADIR. CPUDMA and INTMASK to 0 */
481 /* qemu_irq_raise(s->scsi_reset); */
482 /* s->scsi_csr_1 &= ~(SCSICSR_INTMASK |0x80|0x1); */
485 if (value
& SCSICSR_DMADIR
) {
486 DPRINTF("SCSICSR DMAdir\n");
488 if (value
& SCSICSR_CPUDMA
) {
489 DPRINTF("SCSICSR CPUDMA\n");
490 /* qemu_irq_raise(s->scsi_dma); */
492 s
->int_status
|= 0x4000000;
494 s
->int_status
&= ~(0x4000000);
496 if (value
& SCSICSR_INTMASK
) {
497 DPRINTF("SCSICSR INTMASK\n");
499 * int_mask &= ~0x1000;
500 * s->scsi_csr_1 |= value;
501 * s->scsi_csr_1 &= ~SCSICSR_INTMASK;
502 * if (s->scsi_queued) {
503 * s->scsi_queued = 0;
504 * next_irq(s, NEXT_SCSI_I, level);
508 /* int_mask |= 0x1000; */
511 /* int_mask |= 0x1000; */
512 /* s->scsi_csr_1 |= 0x80; */
514 DPRINTF("SCSICSR Write: %x\n", value
);
515 /* s->scsi_csr_1 = value; */
517 /* Hardware timer latch - not implemented yet */
520 DPRINTF("BMAP Write B @ %x with %x\n", (unsigned int)addr
, value
);
524 static void scr_writew(NeXTState
*s
, hwaddr addr
, uint32_t value
)
526 DPRINTF("BMAP Write W @ %x with %x\n", (unsigned int)addr
, value
);
529 static void scr_writel(NeXTState
*s
, hwaddr addr
, uint32_t value
)
531 DPRINTF("BMAP Write L @ %x with %x\n", (unsigned int)addr
, value
);
534 static uint64_t scr_readfn(void *opaque
, hwaddr addr
, unsigned size
)
536 NeXTState
*ns
= NEXT_MACHINE(opaque
);
540 return scr_readb(ns
, addr
);
542 return scr_readw(ns
, addr
);
544 return scr_readl(ns
, addr
);
546 g_assert_not_reached();
550 static void scr_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
553 NeXTState
*ns
= NEXT_MACHINE(opaque
);
557 scr_writeb(ns
, addr
, value
);
560 scr_writew(ns
, addr
, value
);
563 scr_writel(ns
, addr
, value
);
566 g_assert_not_reached();
570 static const MemoryRegionOps scr_ops
= {
572 .write
= scr_writefn
,
573 .valid
.min_access_size
= 1,
574 .valid
.max_access_size
= 4,
575 .endianness
= DEVICE_NATIVE_ENDIAN
,
578 #define NEXTDMA_SCSI(x) (0x10 + x)
579 #define NEXTDMA_FD(x) (0x10 + x)
580 #define NEXTDMA_ENTX(x) (0x110 + x)
581 #define NEXTDMA_ENRX(x) (0x150 + x)
582 #define NEXTDMA_CSR 0x0
583 #define NEXTDMA_NEXT 0x4000
584 #define NEXTDMA_LIMIT 0x4004
585 #define NEXTDMA_START 0x4008
586 #define NEXTDMA_STOP 0x400c
587 #define NEXTDMA_NEXT_INIT 0x4200
588 #define NEXTDMA_SIZE 0x4204
590 static void dma_writel(void *opaque
, hwaddr addr
, uint64_t value
,
593 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
596 case NEXTDMA_ENRX(NEXTDMA_CSR
):
597 if (value
& DMA_DEV2M
) {
598 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_DEV2M
;
601 if (value
& DMA_SETENABLE
) {
602 /* DPRINTF("SCSI DMA ENABLE\n"); */
603 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_ENABLE
;
605 if (value
& DMA_SETSUPDATE
) {
606 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_SUPDATE
;
608 if (value
& DMA_CLRCOMPLETE
) {
609 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~DMA_COMPLETE
;
612 if (value
& DMA_RESET
) {
613 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
614 DMA_ENABLE
| DMA_DEV2M
);
616 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
618 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
619 next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
= value
;
621 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
622 next_state
->dma
[NEXTDMA_ENRX
].next
= value
;
624 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
625 next_state
->dma
[NEXTDMA_ENRX
].limit
= value
;
627 case NEXTDMA_SCSI(NEXTDMA_CSR
):
628 if (value
& DMA_DEV2M
) {
629 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_DEV2M
;
631 if (value
& DMA_SETENABLE
) {
632 /* DPRINTF("SCSI DMA ENABLE\n"); */
633 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_ENABLE
;
635 if (value
& DMA_SETSUPDATE
) {
636 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_SUPDATE
;
638 if (value
& DMA_CLRCOMPLETE
) {
639 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~DMA_COMPLETE
;
642 if (value
& DMA_RESET
) {
643 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
644 DMA_ENABLE
| DMA_DEV2M
);
645 /* DPRINTF("SCSI DMA RESET\n"); */
647 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
650 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
651 next_state
->dma
[NEXTDMA_SCSI
].next
= value
;
654 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
655 next_state
->dma
[NEXTDMA_SCSI
].limit
= value
;
658 case NEXTDMA_SCSI(NEXTDMA_START
):
659 next_state
->dma
[NEXTDMA_SCSI
].start
= value
;
662 case NEXTDMA_SCSI(NEXTDMA_STOP
):
663 next_state
->dma
[NEXTDMA_SCSI
].stop
= value
;
666 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
667 next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
= value
;
671 DPRINTF("DMA write @ %x w/ %x\n", (unsigned)addr
, (unsigned)value
);
675 static uint64_t dma_readl(void *opaque
, hwaddr addr
, unsigned int size
)
677 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
680 case NEXTDMA_SCSI(NEXTDMA_CSR
):
681 DPRINTF("SCSI DMA CSR READ\n");
682 return next_state
->dma
[NEXTDMA_SCSI
].csr
;
683 case NEXTDMA_ENRX(NEXTDMA_CSR
):
684 return next_state
->dma
[NEXTDMA_ENRX
].csr
;
685 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
686 return next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
;
687 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
688 return next_state
->dma
[NEXTDMA_ENRX
].next
;
689 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
690 return next_state
->dma
[NEXTDMA_ENRX
].limit
;
692 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
693 return next_state
->dma
[NEXTDMA_SCSI
].next
;
694 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
695 return next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
;
696 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
697 return next_state
->dma
[NEXTDMA_SCSI
].limit
;
698 case NEXTDMA_SCSI(NEXTDMA_START
):
699 return next_state
->dma
[NEXTDMA_SCSI
].start
;
700 case NEXTDMA_SCSI(NEXTDMA_STOP
):
701 return next_state
->dma
[NEXTDMA_SCSI
].stop
;
704 DPRINTF("DMA read @ %x\n", (unsigned int)addr
);
709 * once the csr's are done, subtract 0x3FEC from the addr, and that will
710 * normalize the upper registers
714 static const MemoryRegionOps dma_ops
= {
717 .impl
.min_access_size
= 4,
718 .valid
.min_access_size
= 4,
719 .valid
.max_access_size
= 4,
720 .endianness
= DEVICE_NATIVE_ENDIAN
,
724 * TODO: set the shift numbers as values in the enum, so the first switch
727 void next_irq(void *opaque
, int number
, int level
)
729 M68kCPU
*cpu
= opaque
;
731 NeXTState
*ns
= NEXT_MACHINE(qdev_get_machine());
733 /* first switch sets interupt status */
734 /* DPRINTF("IRQ %i\n",number); */
736 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
759 /* level 5 - scc (serial) */
764 /* level 6 - audio etherrx/tx dma */
765 case NEXT_ENTX_DMA_I
:
768 case NEXT_ENRX_DMA_I
:
771 case NEXT_SCSI_DMA_I
:
783 * this HAS to be wrong, the interrupt handlers in mach and together
784 * int_status and int_mask and return if there is a hit
786 if (ns
->int_mask
& (1 << shift
)) {
787 DPRINTF("%x interrupt masked @ %x\n", 1 << shift
, cpu
->env
.pc
);
791 /* second switch triggers the correct interrupt */
793 ns
->int_status
|= 1 << shift
;
796 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
804 m68k_set_irq_level(cpu
, 3, 27);
807 /* level 5 - scc (serial) */
809 m68k_set_irq_level(cpu
, 5, 29);
812 /* level 6 - audio etherrx/tx dma */
813 case NEXT_ENTX_DMA_I
:
814 case NEXT_ENRX_DMA_I
:
815 case NEXT_SCSI_DMA_I
:
818 m68k_set_irq_level(cpu
, 6, 30);
822 ns
->int_status
&= ~(1 << shift
);
823 cpu_reset_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
827 static void next_serial_irq(void *opaque
, int n
, int level
)
829 /* DPRINTF("SCC IRQ NUM %i\n",n); */
831 next_irq(opaque
, NEXT_SCC_DMA_I
, level
);
833 next_irq(opaque
, NEXT_SCC_I
, level
);
837 static void next_escc_init(M68kCPU
*cpu
)
839 qemu_irq
*ser_irq
= qemu_allocate_irqs(next_serial_irq
, cpu
, 2);
843 dev
= qdev_new(TYPE_ESCC
);
844 qdev_prop_set_uint32(dev
, "disabled", 0);
845 qdev_prop_set_uint32(dev
, "frequency", 9600 * 384);
846 qdev_prop_set_uint32(dev
, "it_shift", 0);
847 qdev_prop_set_bit(dev
, "bit_swap", true);
848 qdev_prop_set_chr(dev
, "chrB", serial_hd(1));
849 qdev_prop_set_chr(dev
, "chrA", serial_hd(0));
850 qdev_prop_set_uint32(dev
, "chnBtype", escc_serial
);
851 qdev_prop_set_uint32(dev
, "chnAtype", escc_serial
);
853 s
= SYS_BUS_DEVICE(dev
);
854 sysbus_realize_and_unref(s
, &error_fatal
);
855 sysbus_connect_irq(s
, 0, ser_irq
[0]);
856 sysbus_connect_irq(s
, 1, ser_irq
[1]);
857 sysbus_mmio_map(s
, 0, 0x2118000);
860 static void next_cube_init(MachineState
*machine
)
864 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
865 MemoryRegion
*mmiomem
= g_new(MemoryRegion
, 1);
866 MemoryRegion
*scrmem
= g_new(MemoryRegion
, 1);
867 MemoryRegion
*dmamem
= g_new(MemoryRegion
, 1);
868 MemoryRegion
*bmapm1
= g_new(MemoryRegion
, 1);
869 MemoryRegion
*bmapm2
= g_new(MemoryRegion
, 1);
870 MemoryRegion
*sysmem
= get_system_memory();
871 const char *bios_name
= machine
->firmware
?: ROM_FILE
;
872 NeXTState
*ns
= NEXT_MACHINE(machine
);
875 /* Initialize the cpu core */
876 cpu
= M68K_CPU(cpu_create(machine
->cpu_type
));
878 error_report("Unable to find m68k CPU definition");
883 /* Initialize CPU registers. */
887 /* Set internal registers to initial values */
888 /* 0x0000XX00 << vital bits */
889 ns
->scr1
= 0x00011102;
890 ns
->scr2
= 0x00ff0c80;
891 ns
->rtc
.status
= 0x90;
893 /* Load RTC RAM - TODO: provide possibility to load contents from file */
894 memcpy(ns
->rtc
.ram
, rtc_ram2
, 32);
896 /* 64MB RAM starting at 0x04000000 */
897 memory_region_add_subregion(sysmem
, 0x04000000, machine
->ram
);
900 dev
= qdev_new(TYPE_NEXTFB
);
901 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
902 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0B000000);
905 memory_region_init_io(mmiomem
, NULL
, &mmio_ops
, machine
, "next.mmio",
907 memory_region_add_subregion(sysmem
, 0x02000000, mmiomem
);
910 memory_region_init_ram_shared_nomigrate(bmapm1
, NULL
, "next.bmapmem", 64,
912 memory_region_add_subregion(sysmem
, 0x020c0000, bmapm1
);
913 /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */
914 memory_region_init_alias(bmapm2
, NULL
, "next.bmapmem2", bmapm1
, 0x0, 64);
915 memory_region_add_subregion(sysmem
, 0x820c0000, bmapm2
);
917 /* BMAP IO - acts as a catch-all for now */
918 memory_region_init_io(scrmem
, NULL
, &scr_ops
, machine
, "next.scr",
920 memory_region_add_subregion(sysmem
, 0x02100000, scrmem
);
923 dev
= qdev_new(TYPE_NEXTKBD
);
924 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
925 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0200e000);
928 /* still not sure if the rom should also be mapped at 0x0*/
929 memory_region_init_rom(rom
, NULL
, "next.rom", 0x20000, &error_fatal
);
930 memory_region_add_subregion(sysmem
, 0x01000000, rom
);
931 if (load_image_targphys(bios_name
, 0x01000000, 0x20000) < 8) {
932 if (!qtest_enabled()) {
933 error_report("Failed to load firmware '%s'.", bios_name
);
937 /* Initial PC is always at offset 4 in firmware binaries */
938 ptr
= rom_ptr(0x01000004, 4);
939 g_assert(ptr
!= NULL
);
940 env
->pc
= ldl_p(ptr
);
941 if (env
->pc
>= 0x01020000) {
942 error_report("'%s' does not seem to be a valid firmware image.",
956 memory_region_init_io(dmamem
, NULL
, &dma_ops
, machine
, "next.dma", 0x5000);
957 memory_region_add_subregion(sysmem
, 0x02000000, dmamem
);
960 static void next_machine_class_init(ObjectClass
*oc
, void *data
)
962 MachineClass
*mc
= MACHINE_CLASS(oc
);
964 mc
->desc
= "NeXT Cube";
965 mc
->init
= next_cube_init
;
966 mc
->default_ram_size
= RAM_SIZE
;
967 mc
->default_ram_id
= "next.ram";
968 mc
->default_cpu_type
= M68K_CPU_TYPE_NAME("m68040");
971 static const TypeInfo next_typeinfo
= {
972 .name
= TYPE_NEXT_MACHINE
,
973 .parent
= TYPE_MACHINE
,
974 .class_init
= next_machine_class_init
,
975 .instance_size
= sizeof(NeXTState
),
978 static void next_register_type(void)
980 type_register_static(&next_typeinfo
);
983 type_init(next_register_type
)