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 "hw/char/escc.h" /* ZILOG 8530 Serial Emulation */
25 #include "hw/block/fdc.h"
26 #include "hw/qdev-properties.h"
27 #include "qapi/error.h"
28 #include "ui/console.h"
29 #include "target/m68k/cpu.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 #define NEXT_MACHINE(obj) OBJECT_CHECK(NeXTState, (obj), TYPE_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
{
92 /* Thanks to NeXT forums for this */
94 static const uint8_t rtc_ram3[32] = {
95 0x94, 0x0f, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x7B, 0x00,
97 0x00, 0x00, 0x65, 0x6e, 0x00, 0x00, 0x00, 0x00,
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x13
101 static const uint8_t rtc_ram2
[32] = {
102 0x94, 0x0f, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0xfb, 0x6d, 0x00, 0x00, 0x4b, 0x00,
104 0x41, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x7e,
108 #define SCR2_RTCLK 0x2
109 #define SCR2_RTDATA 0x4
110 #define SCR2_TOBCD(x) (((x / 10) << 4) + (x % 10))
112 static void nextscr2_write(NeXTState
*s
, uint32_t val
, int size
)
116 static uint8_t old_scr2
;
118 NextRtc
*rtc
= &s
->rtc
;
121 scr2_2
= (val
>> 8) & 0xFF;
130 DPRINTF("LED flashing, possible fault!\n");
136 /* DPRINTF("RTC %x phase %i\n", scr2_2, phase); */
140 /* If we are in going down clock... do something */
141 if (((old_scr2
& SCR2_RTCLK
) != (scr2_2
& SCR2_RTCLK
)) &&
142 ((scr2_2
& SCR2_RTCLK
) == 0)) {
144 rtc
->command
= (rtc
->command
<< 1) |
145 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
147 if (phase
>= 8 && phase
< 16) {
148 rtc
->value
= (rtc
->value
<< 1) |
149 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
151 /* if we read RAM register, output RT_DATA bit */
152 if (rtc
->command
<= 0x1F) {
153 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
154 if (rtc
->ram
[rtc
->command
] & (0x80 >> (phase
- 8))) {
155 scr2_2
|= SCR2_RTDATA
;
158 rtc
->retval
= (rtc
->retval
<< 1) |
159 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
161 /* read the status 0x30 */
162 if (rtc
->command
== 0x30) {
163 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
164 /* for now status = 0x98 (new rtc + FTU) */
165 if (rtc
->status
& (0x80 >> (phase
- 8))) {
166 scr2_2
|= SCR2_RTDATA
;
169 rtc
->retval
= (rtc
->retval
<< 1) |
170 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
172 /* read the status 0x31 */
173 if (rtc
->command
== 0x31) {
174 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
175 if (rtc
->control
& (0x80 >> (phase
- 8))) {
176 scr2_2
|= SCR2_RTDATA
;
178 rtc
->retval
= (rtc
->retval
<< 1) |
179 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
182 if ((rtc
->command
>= 0x20) && (rtc
->command
<= 0x2F)) {
183 scr2_2
= scr2_2
& (~SCR2_RTDATA
);
185 time_t time_h
= time(NULL
);
186 struct tm
*info
= localtime(&time_h
);
189 switch (rtc
->command
) {
191 ret
= SCR2_TOBCD(info
->tm_sec
);
194 ret
= SCR2_TOBCD(info
->tm_min
);
197 ret
= SCR2_TOBCD(info
->tm_hour
);
200 ret
= SCR2_TOBCD(info
->tm_mday
);
203 ret
= SCR2_TOBCD((info
->tm_mon
+ 1));
206 ret
= SCR2_TOBCD((info
->tm_year
- 100));
211 if (ret
& (0x80 >> (phase
- 8))) {
212 scr2_2
|= SCR2_RTDATA
;
214 rtc
->retval
= (rtc
->retval
<< 1) |
215 ((scr2_2
& SCR2_RTDATA
) ? 1 : 0);
222 if (rtc
->command
>= 0x80 && rtc
->command
<= 0x9F) {
223 rtc
->ram
[rtc
->command
- 0x80] = rtc
->value
;
225 /* write to x30 register */
226 if (rtc
->command
== 0xB1) {
228 if (rtc
->value
& 0x04) {
229 rtc
->status
= rtc
->status
& (~0x18);
230 s
->int_status
= s
->int_status
& (~0x04);
236 /* else end or abort */
241 s
->scr2
= val
& 0xFFFF00FF;
242 s
->scr2
|= scr2_2
<< 8;
246 static uint32_t mmio_readb(NeXTState
*s
, hwaddr addr
)
250 return (s
->scr1
>> 24) & 0xFF;
252 return (s
->scr1
>> 16) & 0xFF;
254 return (s
->scr1
>> 8) & 0xFF;
256 return (s
->scr1
>> 0) & 0xFF;
259 return (s
->scr2
>> 24) & 0xFF;
261 return (s
->scr2
>> 16) & 0xFF;
263 return (s
->scr2
>> 8) & 0xFF;
265 return (s
->scr2
>> 0) & 0xFF;
267 DPRINTF("MMIO Read 0x4020\n");
271 DPRINTF("MMIO Read B @ %"HWADDR_PRIx
"\n", addr
);
276 static uint32_t mmio_readw(NeXTState
*s
, hwaddr addr
)
280 DPRINTF("MMIO Read W @ %"HWADDR_PRIx
"\n", addr
);
285 static uint32_t mmio_readl(NeXTState
*s
, hwaddr addr
)
289 /* DPRINTF("Read INT status: %x\n", s->int_status); */
290 return s
->int_status
;
293 DPRINTF("MMIO Read INT mask: %x\n", s
->int_mask
);
303 DPRINTF("MMIO Read L @ %"HWADDR_PRIx
"\n", addr
);
308 static void mmio_writeb(NeXTState
*s
, hwaddr addr
, uint32_t val
)
312 nextscr2_write(s
, val
, 1);
315 DPRINTF("MMIO Write B @ %x with %x\n", (unsigned int)addr
, val
);
320 static void mmio_writew(NeXTState
*s
, hwaddr addr
, uint32_t val
)
322 DPRINTF("MMIO Write W\n");
325 static void mmio_writel(NeXTState
*s
, hwaddr addr
, uint32_t val
)
329 DPRINTF("INT Status old: %x new: %x\n", s
->int_status
, val
);
333 DPRINTF("INT Mask old: %x new: %x\n", s
->int_mask
, val
);
337 DPRINTF("SCR1 Write: %x\n", val
);
340 nextscr2_write(s
, val
, 4);
344 DPRINTF("MMIO Write l @ %x with %x\n", (unsigned int)addr
, val
);
348 static uint64_t mmio_readfn(void *opaque
, hwaddr addr
, unsigned size
)
350 NeXTState
*ns
= NEXT_MACHINE(opaque
);
354 return mmio_readb(ns
, addr
);
356 return mmio_readw(ns
, addr
);
358 return mmio_readl(ns
, addr
);
360 g_assert_not_reached();
364 static void mmio_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
367 NeXTState
*ns
= NEXT_MACHINE(opaque
);
371 mmio_writeb(ns
, addr
, value
);
374 mmio_writew(ns
, addr
, value
);
377 mmio_writel(ns
, addr
, value
);
380 g_assert_not_reached();
384 static const MemoryRegionOps mmio_ops
= {
386 .write
= mmio_writefn
,
387 .valid
.min_access_size
= 1,
388 .valid
.max_access_size
= 4,
389 .endianness
= DEVICE_NATIVE_ENDIAN
,
392 static uint32_t scr_readb(NeXTState
*s
, hwaddr addr
)
396 DPRINTF("FD read @ %x\n", (unsigned int)addr
);
397 return 0x40 | 0x04 | 0x2 | 0x1;
399 DPRINTF("SCSI 4020 STATUS READ %X\n", s
->scsi_csr_1
);
400 return s
->scsi_csr_1
;
403 DPRINTF("SCSI 4021 STATUS READ %X\n", s
->scsi_csr_2
);
407 * These 4 registers are the hardware timer, not sure which register
408 * is the latch instead of data, but no problems so far
411 return 0xff & (clock() >> 24);
413 return 0xff & (clock() >> 16);
415 return 0xff & (clock() >> 8);
417 /* Hack: We need to have this change consistently to make it work */
418 return 0xFF & clock();
421 DPRINTF("BMAP Read B @ %x\n", (unsigned int)addr
);
426 static uint32_t scr_readw(NeXTState
*s
, hwaddr addr
)
428 DPRINTF("BMAP Read W @ %x\n", (unsigned int)addr
);
432 static uint32_t scr_readl(NeXTState
*s
, hwaddr addr
)
434 DPRINTF("BMAP Read L @ %x\n", (unsigned int)addr
);
438 #define SCSICSR_ENABLE 0x01
439 #define SCSICSR_RESET 0x02 /* reset scsi dma */
440 #define SCSICSR_FIFOFL 0x04
441 #define SCSICSR_DMADIR 0x08 /* if set, scsi to mem */
442 #define SCSICSR_CPUDMA 0x10 /* if set, dma enabled */
443 #define SCSICSR_INTMASK 0x20 /* if set, interrupt enabled */
445 static void scr_writeb(NeXTState
*s
, hwaddr addr
, uint32_t value
)
449 DPRINTF("FDCSR Write: %x\n", value
);
452 /* qemu_irq_raise(s->fd_irq[0]); */
455 case 0x14020: /* SCSI Control Register */
456 if (value
& SCSICSR_FIFOFL
) {
457 DPRINTF("SCSICSR FIFO Flush\n");
458 /* will have to add another irq to the esp if this is needed */
459 /* esp_puflush_fifo(esp_g); */
460 /* qemu_irq_pulse(s->scsi_dma); */
463 if (value
& SCSICSR_ENABLE
) {
464 DPRINTF("SCSICSR Enable\n");
466 * qemu_irq_raise(s->scsi_dma);
467 * s->scsi_csr_1 = 0xc0;
468 * s->scsi_csr_1 |= 0x1;
469 * qemu_irq_pulse(s->scsi_dma);
474 * s->scsi_csr_1 &= ~SCSICSR_ENABLE;
477 if (value
& SCSICSR_RESET
) {
478 DPRINTF("SCSICSR Reset\n");
479 /* I think this should set DMADIR. CPUDMA and INTMASK to 0 */
480 /* qemu_irq_raise(s->scsi_reset); */
481 /* s->scsi_csr_1 &= ~(SCSICSR_INTMASK |0x80|0x1); */
484 if (value
& SCSICSR_DMADIR
) {
485 DPRINTF("SCSICSR DMAdir\n");
487 if (value
& SCSICSR_CPUDMA
) {
488 DPRINTF("SCSICSR CPUDMA\n");
489 /* qemu_irq_raise(s->scsi_dma); */
491 s
->int_status
|= 0x4000000;
493 s
->int_status
&= ~(0x4000000);
495 if (value
& SCSICSR_INTMASK
) {
496 DPRINTF("SCSICSR INTMASK\n");
498 * int_mask &= ~0x1000;
499 * s->scsi_csr_1 |= value;
500 * s->scsi_csr_1 &= ~SCSICSR_INTMASK;
501 * if (s->scsi_queued) {
502 * s->scsi_queued = 0;
503 * next_irq(s, NEXT_SCSI_I, level);
507 /* int_mask |= 0x1000; */
510 /* int_mask |= 0x1000; */
511 /* s->scsi_csr_1 |= 0x80; */
513 DPRINTF("SCSICSR Write: %x\n", value
);
514 /* s->scsi_csr_1 = value; */
516 /* Hardware timer latch - not implemented yet */
519 DPRINTF("BMAP Write B @ %x with %x\n", (unsigned int)addr
, value
);
523 static void scr_writew(NeXTState
*s
, hwaddr addr
, uint32_t value
)
525 DPRINTF("BMAP Write W @ %x with %x\n", (unsigned int)addr
, value
);
528 static void scr_writel(NeXTState
*s
, hwaddr addr
, uint32_t value
)
530 DPRINTF("BMAP Write L @ %x with %x\n", (unsigned int)addr
, value
);
533 static uint64_t scr_readfn(void *opaque
, hwaddr addr
, unsigned size
)
535 NeXTState
*ns
= NEXT_MACHINE(opaque
);
539 return scr_readb(ns
, addr
);
541 return scr_readw(ns
, addr
);
543 return scr_readl(ns
, addr
);
545 g_assert_not_reached();
549 static void scr_writefn(void *opaque
, hwaddr addr
, uint64_t value
,
552 NeXTState
*ns
= NEXT_MACHINE(opaque
);
556 scr_writeb(ns
, addr
, value
);
559 scr_writew(ns
, addr
, value
);
562 scr_writel(ns
, addr
, value
);
565 g_assert_not_reached();
569 static const MemoryRegionOps scr_ops
= {
571 .write
= scr_writefn
,
572 .valid
.min_access_size
= 1,
573 .valid
.max_access_size
= 4,
574 .endianness
= DEVICE_NATIVE_ENDIAN
,
577 #define NEXTDMA_SCSI(x) (0x10 + x)
578 #define NEXTDMA_FD(x) (0x10 + x)
579 #define NEXTDMA_ENTX(x) (0x110 + x)
580 #define NEXTDMA_ENRX(x) (0x150 + x)
581 #define NEXTDMA_CSR 0x0
582 #define NEXTDMA_NEXT 0x4000
583 #define NEXTDMA_LIMIT 0x4004
584 #define NEXTDMA_START 0x4008
585 #define NEXTDMA_STOP 0x400c
586 #define NEXTDMA_NEXT_INIT 0x4200
587 #define NEXTDMA_SIZE 0x4204
589 static void dma_writel(void *opaque
, hwaddr addr
, uint64_t value
,
592 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
595 case NEXTDMA_ENRX(NEXTDMA_CSR
):
596 if (value
& DMA_DEV2M
) {
597 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_DEV2M
;
600 if (value
& DMA_SETENABLE
) {
601 /* DPRINTF("SCSI DMA ENABLE\n"); */
602 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_ENABLE
;
604 if (value
& DMA_SETSUPDATE
) {
605 next_state
->dma
[NEXTDMA_ENRX
].csr
|= DMA_SUPDATE
;
607 if (value
& DMA_CLRCOMPLETE
) {
608 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~DMA_COMPLETE
;
611 if (value
& DMA_RESET
) {
612 next_state
->dma
[NEXTDMA_ENRX
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
613 DMA_ENABLE
| DMA_DEV2M
);
615 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
617 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
618 next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
= value
;
620 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
621 next_state
->dma
[NEXTDMA_ENRX
].next
= value
;
623 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
624 next_state
->dma
[NEXTDMA_ENRX
].limit
= value
;
626 case NEXTDMA_SCSI(NEXTDMA_CSR
):
627 if (value
& DMA_DEV2M
) {
628 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_DEV2M
;
630 if (value
& DMA_SETENABLE
) {
631 /* DPRINTF("SCSI DMA ENABLE\n"); */
632 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_ENABLE
;
634 if (value
& DMA_SETSUPDATE
) {
635 next_state
->dma
[NEXTDMA_SCSI
].csr
|= DMA_SUPDATE
;
637 if (value
& DMA_CLRCOMPLETE
) {
638 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~DMA_COMPLETE
;
641 if (value
& DMA_RESET
) {
642 next_state
->dma
[NEXTDMA_SCSI
].csr
&= ~(DMA_COMPLETE
| DMA_SUPDATE
|
643 DMA_ENABLE
| DMA_DEV2M
);
644 /* DPRINTF("SCSI DMA RESET\n"); */
646 /* DPRINTF("RXCSR \tWrite: %x\n",value); */
649 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
650 next_state
->dma
[NEXTDMA_SCSI
].next
= value
;
653 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
654 next_state
->dma
[NEXTDMA_SCSI
].limit
= value
;
657 case NEXTDMA_SCSI(NEXTDMA_START
):
658 next_state
->dma
[NEXTDMA_SCSI
].start
= value
;
661 case NEXTDMA_SCSI(NEXTDMA_STOP
):
662 next_state
->dma
[NEXTDMA_SCSI
].stop
= value
;
665 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
666 next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
= value
;
670 DPRINTF("DMA write @ %x w/ %x\n", (unsigned)addr
, (unsigned)value
);
674 static uint64_t dma_readl(void *opaque
, hwaddr addr
, unsigned int size
)
676 NeXTState
*next_state
= NEXT_MACHINE(opaque
);
679 case NEXTDMA_SCSI(NEXTDMA_CSR
):
680 DPRINTF("SCSI DMA CSR READ\n");
681 return next_state
->dma
[NEXTDMA_SCSI
].csr
;
682 case NEXTDMA_ENRX(NEXTDMA_CSR
):
683 return next_state
->dma
[NEXTDMA_ENRX
].csr
;
684 case NEXTDMA_ENRX(NEXTDMA_NEXT_INIT
):
685 return next_state
->dma
[NEXTDMA_ENRX
].next_initbuf
;
686 case NEXTDMA_ENRX(NEXTDMA_NEXT
):
687 return next_state
->dma
[NEXTDMA_ENRX
].next
;
688 case NEXTDMA_ENRX(NEXTDMA_LIMIT
):
689 return next_state
->dma
[NEXTDMA_ENRX
].limit
;
691 case NEXTDMA_SCSI(NEXTDMA_NEXT
):
692 return next_state
->dma
[NEXTDMA_SCSI
].next
;
693 case NEXTDMA_SCSI(NEXTDMA_NEXT_INIT
):
694 return next_state
->dma
[NEXTDMA_SCSI
].next_initbuf
;
695 case NEXTDMA_SCSI(NEXTDMA_LIMIT
):
696 return next_state
->dma
[NEXTDMA_SCSI
].limit
;
697 case NEXTDMA_SCSI(NEXTDMA_START
):
698 return next_state
->dma
[NEXTDMA_SCSI
].start
;
699 case NEXTDMA_SCSI(NEXTDMA_STOP
):
700 return next_state
->dma
[NEXTDMA_SCSI
].stop
;
703 DPRINTF("DMA read @ %x\n", (unsigned int)addr
);
708 * once the csr's are done, subtract 0x3FEC from the addr, and that will
709 * normalize the upper registers
713 static const MemoryRegionOps dma_ops
= {
716 .impl
.min_access_size
= 4,
717 .valid
.min_access_size
= 4,
718 .valid
.max_access_size
= 4,
719 .endianness
= DEVICE_NATIVE_ENDIAN
,
723 * TODO: set the shift numbers as values in the enum, so the first switch
726 void next_irq(void *opaque
, int number
, int level
)
728 M68kCPU
*cpu
= opaque
;
730 NeXTState
*ns
= NEXT_MACHINE(qdev_get_machine());
732 /* first switch sets interupt status */
733 /* DPRINTF("IRQ %i\n",number); */
735 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
758 /* level 5 - scc (serial) */
763 /* level 6 - audio etherrx/tx dma */
764 case NEXT_ENTX_DMA_I
:
767 case NEXT_ENRX_DMA_I
:
770 case NEXT_SCSI_DMA_I
:
782 * this HAS to be wrong, the interrupt handlers in mach and together
783 * int_status and int_mask and return if there is a hit
785 if (ns
->int_mask
& (1 << shift
)) {
786 DPRINTF("%x interrupt masked @ %x\n", 1 << shift
, cpu
->env
.pc
);
790 /* second switch triggers the correct interrupt */
792 ns
->int_status
|= 1 << shift
;
795 /* level 3 - floppy, kbd/mouse, power, ether rx/tx, scsi, clock */
803 m68k_set_irq_level(cpu
, 3, 27);
806 /* level 5 - scc (serial) */
808 m68k_set_irq_level(cpu
, 5, 29);
811 /* level 6 - audio etherrx/tx dma */
812 case NEXT_ENTX_DMA_I
:
813 case NEXT_ENRX_DMA_I
:
814 case NEXT_SCSI_DMA_I
:
817 m68k_set_irq_level(cpu
, 6, 30);
821 ns
->int_status
&= ~(1 << shift
);
822 cpu_reset_interrupt(CPU(cpu
), CPU_INTERRUPT_HARD
);
826 static void next_serial_irq(void *opaque
, int n
, int level
)
828 /* DPRINTF("SCC IRQ NUM %i\n",n); */
830 next_irq(opaque
, NEXT_SCC_DMA_I
, level
);
832 next_irq(opaque
, NEXT_SCC_I
, level
);
836 static void next_escc_init(M68kCPU
*cpu
)
838 qemu_irq
*ser_irq
= qemu_allocate_irqs(next_serial_irq
, cpu
, 2);
842 dev
= qdev_new(TYPE_ESCC
);
843 qdev_prop_set_uint32(dev
, "disabled", 0);
844 qdev_prop_set_uint32(dev
, "frequency", 9600 * 384);
845 qdev_prop_set_uint32(dev
, "it_shift", 0);
846 qdev_prop_set_bit(dev
, "bit_swap", true);
847 qdev_prop_set_chr(dev
, "chrB", serial_hd(1));
848 qdev_prop_set_chr(dev
, "chrA", serial_hd(0));
849 qdev_prop_set_uint32(dev
, "chnBtype", escc_serial
);
850 qdev_prop_set_uint32(dev
, "chnAtype", escc_serial
);
852 s
= SYS_BUS_DEVICE(dev
);
853 sysbus_realize_and_unref(s
, &error_fatal
);
854 sysbus_connect_irq(s
, 0, ser_irq
[0]);
855 sysbus_connect_irq(s
, 1, ser_irq
[1]);
856 sysbus_mmio_map(s
, 0, 0x2118000);
859 static void next_cube_init(MachineState
*machine
)
863 MemoryRegion
*rom
= g_new(MemoryRegion
, 1);
864 MemoryRegion
*mmiomem
= g_new(MemoryRegion
, 1);
865 MemoryRegion
*scrmem
= g_new(MemoryRegion
, 1);
866 MemoryRegion
*dmamem
= g_new(MemoryRegion
, 1);
867 MemoryRegion
*bmapm1
= g_new(MemoryRegion
, 1);
868 MemoryRegion
*bmapm2
= g_new(MemoryRegion
, 1);
869 MemoryRegion
*sysmem
= get_system_memory();
870 NeXTState
*ns
= NEXT_MACHINE(machine
);
873 /* Initialize the cpu core */
874 cpu
= M68K_CPU(cpu_create(machine
->cpu_type
));
876 error_report("Unable to find m68k CPU definition");
881 /* Initialize CPU registers. */
885 /* Set internal registers to initial values */
886 /* 0x0000XX00 << vital bits */
887 ns
->scr1
= 0x00011102;
888 ns
->scr2
= 0x00ff0c80;
889 ns
->rtc
.status
= 0x90;
891 /* Load RTC RAM - TODO: provide possibility to load contents from file */
892 memcpy(ns
->rtc
.ram
, rtc_ram2
, 32);
894 /* 64MB RAM starting at 0x04000000 */
895 memory_region_add_subregion(sysmem
, 0x04000000, machine
->ram
);
898 dev
= qdev_new(TYPE_NEXTFB
);
899 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
900 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0B000000);
903 memory_region_init_io(mmiomem
, NULL
, &mmio_ops
, machine
, "next.mmio",
905 memory_region_add_subregion(sysmem
, 0x02000000, mmiomem
);
908 memory_region_init_ram_shared_nomigrate(bmapm1
, NULL
, "next.bmapmem", 64,
910 memory_region_add_subregion(sysmem
, 0x020c0000, bmapm1
);
911 /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */
912 memory_region_init_alias(bmapm2
, NULL
, "next.bmapmem2", bmapm1
, 0x0, 64);
913 memory_region_add_subregion(sysmem
, 0x820c0000, bmapm2
);
915 /* BMAP IO - acts as a catch-all for now */
916 memory_region_init_io(scrmem
, NULL
, &scr_ops
, machine
, "next.scr",
918 memory_region_add_subregion(sysmem
, 0x02100000, scrmem
);
921 dev
= qdev_new(TYPE_NEXTKBD
);
922 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
923 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, 0x0200e000);
926 if (bios_name
== NULL
) {
927 bios_name
= ROM_FILE
;
929 /* still not sure if the rom should also be mapped at 0x0*/
930 memory_region_init_rom(rom
, NULL
, "next.rom", 0x20000, &error_fatal
);
931 memory_region_add_subregion(sysmem
, 0x01000000, rom
);
932 if (load_image_targphys(bios_name
, 0x01000000, 0x20000) < 8) {
933 if (!qtest_enabled()) {
934 error_report("Failed to load firmware '%s'.", bios_name
);
938 /* Initial PC is always at offset 4 in firmware binaries */
939 ptr
= rom_ptr(0x01000004, 4);
940 g_assert(ptr
!= NULL
);
941 env
->pc
= ldl_p(ptr
);
942 if (env
->pc
>= 0x01020000) {
943 error_report("'%s' does not seem to be a valid firmware image.",
957 memory_region_init_io(dmamem
, NULL
, &dma_ops
, machine
, "next.dma", 0x5000);
958 memory_region_add_subregion(sysmem
, 0x02000000, dmamem
);
961 static void next_machine_class_init(ObjectClass
*oc
, void *data
)
963 MachineClass
*mc
= MACHINE_CLASS(oc
);
965 mc
->desc
= "NeXT Cube";
966 mc
->init
= next_cube_init
;
967 mc
->default_ram_size
= RAM_SIZE
;
968 mc
->default_ram_id
= "next.ram";
969 mc
->default_cpu_type
= M68K_CPU_TYPE_NAME("m68040");
972 static const TypeInfo next_typeinfo
= {
973 .name
= TYPE_NEXT_MACHINE
,
974 .parent
= TYPE_MACHINE
,
975 .class_init
= next_machine_class_init
,
976 .instance_size
= sizeof(NeXTState
),
979 static void next_register_type(void)
981 type_register_static(&next_typeinfo
);
984 type_init(next_register_type
)