diff --git a/nubus-to-ztex-gateware/DeclROM/Makefile b/nubus-to-ztex-gateware/DeclROM/Makefile index 7b1518a..77845ef 100644 --- a/nubus-to-ztex-gateware/DeclROM/Makefile +++ b/nubus-to-ztex-gateware/DeclROM/Makefile @@ -1,6 +1,7 @@ AS=/home/dolbeau/Retro68/build/toolchain/bin/m68k-apple-macos-as CC=/home/dolbeau/Retro68/build/toolchain/bin/m68k-apple-macos-gcc OBJCOPY=/home/dolbeau/Retro68/build/toolchain/bin/m68k-apple-macos-objcopy +HOSTCC=gcc NS816DECLROMDIR=/home/dolbeau/ns816-declrom NUBUS_CHECKSUM=${NS816DECLROMDIR}/nubus_checksum @@ -11,12 +12,12 @@ APPLEINCS=${NS816DECLROMDIR}/atrap.inc ${NS816DECLROMDIR}/declrom.inc ${NS816DEC HRES=1920 VRES=1080 -CSRC=NuBusFPGADrvr_OpenClose.c NuBusFPGADrvr_Ctrl.c NuBusFPGADrvr_Status.c NuBusFPGAPrimaryInit_Primary.c +CSRC=NuBusFPGADrvr_OpenClose.c NuBusFPGADrvr_Ctrl.c NuBusFPGADrvr_Status.c NuBusFPGAPrimaryInit_Primary.c NuBusFPGASecondaryInit_Secondary.c CSRC_ASM=${CSRC:.c=.s} all: vid_decl_rom.bin vid_decl_rom.srec -vid_decl_rom.o: vid_decl_rom.s NuBusFPGAPrimaryInit.s NuBusFPGAPrimaryInit_Primary.s NuBusFPGASecondaryInit.s NuBusFPGADrvr.s ${APPLEINCS} ${CSRC_ASM} DepVideo.inc +vid_decl_rom.o: vid_decl_rom.s NuBusFPGAPrimaryInit.s NuBusFPGAPrimaryInit_Primary.s NuBusFPGASecondaryInit.s NuBusFPGASecondaryInit_Secondary.s NuBusFPGADrvr.s ${APPLEINCS} ${CSRC_ASM} DepVideo.inc rm -f res.inc echo -e "HRES=${HRES}\nVRES=${VRES}\n" | tee res.inc ${AS} -march=68020 -mcpu=68020 -I${NS816DECLROMDIR} $< -o $@ -a > vid_decl_rom.l @@ -41,15 +42,27 @@ NuBusFPGAPrimaryInit_Primary.s: NuBusFPGAPrimaryInit_Primary.c NuBusFPGADrvr.h sed -i -e 's/^\([^a-zA-Z0-9_]*\.globl.*\)/# --- \1/' $@ sed -i -e 's/\.\(L[0-9][0-9]*\)/.PIPrimary_\1/g' $@ +NuBusFPGASecondaryInit_Secondary.s: NuBusFPGASecondaryInit_Secondary.c NuBusFPGADrvr.h + ${CC} -march=68020 -mcpu=68020 -O2 $< -S -o $@ -DHRES=${HRES} -DVRES=${VRES} + sed -i -e 's/^\([^a-zA-Z0-9_]*\.globl.*\)/# --- \1/' $@ + sed -i -e 's/\.\(L[0-9][0-9]*\)/.PISecondary_\1/g' $@ + vid_decl_rom.srec: vid_decl_rom.o ${OBJCOPY} $^ $@ --input-target=elf32-m68k --output-target=srec vid_decl_rom.raw: vid_decl_rom.o ${OBJCOPY} $^ $@ --input-target=elf32-m68k --output-target=binary -vid_decl_rom.bin: vid_decl_rom.raw +vid_decl_rom.dir: vid_decl_rom.raw append_romdir + cp $< $@ + ./append_romdir $@ + +vid_decl_rom.bin: vid_decl_rom.dir ${NUBUS_CHECKSUM} --input_file $< --output_file $@ --output_size 32768 clean: - rm -f res.inc ${CSRC_ASM} *.o vid_decl_rom.srec vid_decl_rom.raw vid_decl_rom.l + rm -f res.inc ${CSRC_ASM} *.o vid_decl_rom.srec vid_decl_rom.raw vid_decl_rom.dir vid_decl_rom.l + +append_romdir: append_romdir.c + ${HOSTCC} $< -o $@ diff --git a/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr.s b/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr.s index d27a8ae..1add7f2 100644 --- a/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr.s +++ b/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr.s @@ -88,6 +88,5 @@ interruptRoutine: jsr (%a0) moveq #1,%d0 rts - - - ALIGN 2 + + ALIGN 2 diff --git a/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Ctrl.c b/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Ctrl.c index c4ef2ae..34ce2c2 100644 --- a/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Ctrl.c +++ b/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Ctrl.c @@ -104,8 +104,8 @@ OSErr cNuBusFPGACtl(CntrlParamPtr pb, /* DCtlPtr */ AuxDCEPtr dce) short ret = -1; char busMode = 1; - write_reg(dce, GOBOFB_DEBUG, 0xBEEF0001); - write_reg(dce, GOBOFB_DEBUG, pb->csCode); + /* write_reg(dce, GOBOFB_DEBUG, 0xBEEF0001); */ + /* write_reg(dce, GOBOFB_DEBUG, pb->csCode); */ #if 1 switch (pb->csCode) diff --git a/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Status.c b/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Status.c index 654dc80..bee43d2 100644 --- a/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Status.c +++ b/nubus-to-ztex-gateware/DeclROM/NuBusFPGADrvr_Status.c @@ -39,8 +39,8 @@ OSErr cNuBusFPGAStatus(CntrlParamPtr pb, /* DCtlPtr */ AuxDCEPtr dce) NuBusFPGADriverGlobalsPtr dStore = *dStoreHdl; short ret = -1; - write_reg(dce, GOBOFB_DEBUG, 0xBEEF0002); - write_reg(dce, GOBOFB_DEBUG, pb->csCode); + /* write_reg(dce, GOBOFB_DEBUG, 0xBEEF0002); */ + /* write_reg(dce, GOBOFB_DEBUG, pb->csCode); */ #if 1 switch (pb->csCode) diff --git a/nubus-to-ztex-gateware/DeclROM/NuBusFPGAPrimaryInit_Primary.c b/nubus-to-ztex-gateware/DeclROM/NuBusFPGAPrimaryInit_Primary.c index 5a7ad6a..5299d3e 100644 --- a/nubus-to-ztex-gateware/DeclROM/NuBusFPGAPrimaryInit_Primary.c +++ b/nubus-to-ztex-gateware/DeclROM/NuBusFPGAPrimaryInit_Primary.c @@ -40,6 +40,8 @@ UInt32 Primary(SEBlock* seblock) { } SwapMMUMode ( &busMode ); // restore + +#if 0 /* call SVersion to figure out if we have a recent SlotManager */ //spblock.spSlot = seblock->seSlot; @@ -98,7 +100,8 @@ UInt32 Primary(SEBlock* seblock) { /* PRIM_WRITEREG(GOBOFB_DEBUG, pram[i]);*/ } SwapMMUMode ( &busMode ); // restore - + +#endif seblock->seStatus = 1; diff --git a/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit.s b/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit.s index 2200cc8..c0384d5 100644 --- a/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit.s +++ b/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit.s @@ -4,35 +4,10 @@ .short 0 /* Reserved */ .long BeginSecondary-. /* Offset to code. */ -BeginSecondary: - movew #1,%A0@(seStatus) /* VendorStatus <- 1 {Code was executed} */ - movel %A0,%A3 /* save param block */ - /* Set up a slot parameter block in %A0 */ - SUBA #smParamBlockSize,%SP /* make an SDM parameter block on stack */ - movel %SP,%A0 /* get pointer to parm block now */ - MOVE.B seSlot(%A3),spSlot(%A0) /* put slot in pBlock */ - CLR.B spExtDev(%A0) /* external device = 0 */ - - moveq #8,%D0 /* _sVersion ; find the Slot Manager version */ - .word 0xA06E /* _sVersion ; find the Slot Manager version */ - - MOVEL spResult(%A0),%D1 /* recover result */ - ADDA #smParamBlockSize,%SP /* drop the slot Parameter block */ - - moveq #0,%D0 /* D0 <- 00000000 */ - MOVEB %A3@(seSlot),%D0 /* D0 <- 0000000s */ - LSLW #4,%D0 /* D0 <- 000000s0 */ - /* OR.B %A3@(seSlot),%D0 /* D0 <- 000000ss */ - OR.W #0xF00,%D0 /* D0 <- 00000Fs0 */ - SWAP %D0 /* D0 <- 0Fs00000 */ - LSLL #4,%D0 /* D0 <- Fs000000 */ - MOVEAL %D0,%A1 - - /* param block in %A3, our HW (32-bits mode) in %A1 */ - addl #0x00900000, %A1 - movel #0x0f0f0f0f,%A1@(0x1c) /* marker to qemu */ - movel %D1,%A1@(0x1c) /*_sVersion spResult to Qemu */ - -ExitSecondary: - RTS /* Return */ - +BeginSecondary: + MOVE.L %A0, -(%A7) + JSR Secondary + MOVE.L (%A7)+, %a0 + rts + .include "NuBusFPGASecondaryInit_Secondary.s" + .text diff --git a/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit_Secondary.c b/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit_Secondary.c new file mode 100644 index 0000000..d1677a1 --- /dev/null +++ b/nubus-to-ztex-gateware/DeclROM/NuBusFPGASecondaryInit_Secondary.c @@ -0,0 +1,133 @@ +#include "NuBusFPGADrvr.h" + +#include + +#define SECO_WRITEREG(reg, val) \ + *((volatile UInt32*)(a32+GOBOFB_BASE+reg)) = (UInt32)val; + +UniversalProcPtr toto; + +void local_BitBlt(void); +asm(" .ALIGN 2\n" +" .type local_BitBlt, @function\n" +"local_BitBlt:\n" +" move.l %a0,-(%sp)\n" +" move.l #0xfc90001c, %a0\n" +" move.l #0xDEADBEEF, (%a0)\n" +" /* move.l %pc@(orig_BitBlt), (%a0) */\n" +" move.l %sp@(4), (%a0)\n" +" move.l %a1, (%a0)\n" +" move.l %a2, (%a0)\n" +" move.l %a3, (%a0)\n" +" move.l %a4, (%a0)\n" +" move.l %a5, (%a0)\n" +" move.l %a6, (%a0)\n" +" move.l %a2@(0),(%a0)\n" +" move.l %a2@(4),(%a0)\n" +" move.l %a3@(0),(%a0)\n" +" move.l %a3@(4),(%a0)\n" +" move.l (%sp)+,%a0\n" +" move.l %pc@(toto),(%a0)\n" +" move.l %pc@(toto),-(%sp)\n" +" rts\n" +".size local_BitBlt, .-local_BitBlt\n" + ); + +UInt32 Secondary(SEBlock* seblock) { + UInt32 a32 = 0xF0000000 | ((UInt32)seblock->seSlot << 24); + UInt32 a32_l0, a32_l1; + UInt32 a32_4p0, a32_4p1; + SpBlock spblock; + UInt8 pram[8]; + OSErr err; + UInt16 i,j; + char busMode; + UniversalProcPtr qd32ptr, unimpptr; + + busMode = 1; + + /* call SVersion to figure out if we have a recent SlotManager */ +#if 0 + //spblock.spSlot = seblock->seSlot; + //spblock.spExtDev = 0; + err = SVersion(&spblock); + + busMode = 1; + SwapMMUMode ( &busMode ); // to32 + if (err) { + /* DCDMF3 p178: if error, old slot manager*/ + /* SECO_WRITEREG(GOBOFB_DEBUG, 0xFFFFFFFF);*/ + /* SECO_WRITEREG(GOBOFB_DEBUG, err);*/ + } else { + /* DCDMF3 p178: new slot manager */ + /* SECO_WRITEREG(GOBOFB_DEBUG, 0);*/ + /* SECO_WRITEREG(GOBOFB_DEBUG, spblock.spResult);*/ + } + SwapMMUMode ( &busMode ); // restore +#endif + +#if 1 + /* check for 32-bits QuickDraw */ + qd32ptr = GetTrapAddress(Check32QDTrap); + unimpptr = GetTrapAddress(_Unimplemented); + + busMode = 1; + SwapMMUMode ( &busMode ); // to32 + if (qd32ptr == unimpptr) { + /* no 32QD */ + SECO_WRITEREG(GOBOFB_DEBUG, 0xFFFFFFFF); + SECO_WRITEREG(GOBOFB_DEBUG, unimpptr); + } else { + /* yes 32QD */ + SECO_WRITEREG(GOBOFB_DEBUG, 0x00C0FFEE); + } + SwapMMUMode ( &busMode ); // restore +#endif + + +#if 0 + /* check the content of the PRAM */ + spblock.spSlot = seblock->seSlot; + spblock.spResult = (UInt32)pram; + err = SReadPRAMRec(&spblock); + +#if 0 + SECO_WRITEREG(GOBOFB_DEBUG, 0x88888888); + for (j = 0 ; j < 8 ; j++) + SECO_WRITEREG(GOBOFB_DEBUG, (uint32_t)pram[j]); + SECO_WRITEREG(GOBOFB_DEBUG, 0x88888888); +#endif +#endif + +#if 0 + busMode = 1; + SwapMMUMode ( &busMode ); // to32 + if (err) { + /* SECO_WRITEREG(GOBOFB_DEBUG, 0xFFFFFFFF);*/ + /* SECO_WRITEREG(GOBOFB_DEBUG, err);*/ + } else { + /* SECO_WRITEREG(GOBOFB_DEBUG, 0xC0FFEE00);*/ + /* for (i = 0 ; i < 8 ; i++) */ + /* SECO_WRITEREG(GOBOFB_DEBUG, pram[i]);*/ + } + SwapMMUMode ( &busMode ); // restore +#endif + +#if 0 + // patch some traps + UniversalProcPtr orig_BitBlt = GetToolTrapAddress(0xAB00); // BitBlt + SECO_WRITEREG(GOBOFB_DEBUG, orig_BitBlt); + SECO_WRITEREG(GOBOFB_DEBUG, unimpptr); + toto = orig_BitBlt; + SECO_WRITEREG(GOBOFB_DEBUG, toto); + UniversalProcPtr tutu; + asm("lea %%pc@(local_BitBlt),%0\n" : "=a"(tutu)); + SECO_WRITEREG(GOBOFB_DEBUG, tutu); + SetToolTrapAddress(orig_BitBlt, 0xAB00); +#endif + + seblock->seStatus = 1; + + return 0; +} + diff --git a/nubus-to-ztex-gateware/DeclROM/append_romdir.c b/nubus-to-ztex-gateware/DeclROM/append_romdir.c new file mode 100644 index 0000000..566eb64 --- /dev/null +++ b/nubus-to-ztex-gateware/DeclROM/append_romdir.c @@ -0,0 +1,83 @@ +// 00 00 10 0a 00 00 00 00 01 01 5a 93 2b c7 00 0f + + + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +struct dir { + uint32_t oslt; + uint32_t length; + uint32_t crc; + uint8_t one; + uint8_t appleformat; + uint8_t tp0; + uint8_t tp1; + uint8_t tp2; + uint8_t tp3; + uint8_t zero; + uint8_t bytelane; +}; + +int main(int argc, char **argv) { + struct dir data; + struct stat buf; + int fd; + + if (argc < 2) { + fprintf(stderr, "no I/O file\n"); + exit(-1); + } + + + data.oslt = 0; + data.length = 0; + data.crc = 0; + data.one = 1; + data.appleformat = 1; + data.tp0 = 0x5a; + data.tp1 = 0x93; + data.tp2 = 0x2b; + data.tp3 = 0xc7; + data.zero = 0; + data.bytelane = 0x0F; + + if (stat(argv[1], &buf)) { + fprintf(stderr, "stat: %d -> %s\n", errno, strerror(errno)); + exit(-2); + } + + data.length = sizeof(data) + buf.st_size; + + printf("size is %u\n", data.length); + + //.long (\entry_type<<24) + ((\label-.) & 0xffffff) + data.oslt = 0x00 << 24 | (-buf.st_size) & 0xFFFFFF; + + printf("entry is 0x%08x\n", data.oslt); + + data.length = __builtin_bswap32(data.length); + data.oslt = __builtin_bswap32(data.oslt); + + if ((fd = open(argv[1], O_WRONLY | O_APPEND)) == -1) { + fprintf(stderr, "open: %d -> %s\n", errno, strerror(errno)); + exit(-3); + } + + write(fd, &data, sizeof(data)); + + close(fd); + + return 0; +} diff --git a/nubus-to-ztex-gateware/DeclROM/vid_decl_rom.s b/nubus-to-ztex-gateware/DeclROM/vid_decl_rom.s index 1ef9270..756cf1e 100644 --- a/nubus-to-ztex-gateware/DeclROM/vid_decl_rom.s +++ b/nubus-to-ztex-gateware/DeclROM/vid_decl_rom.s @@ -272,18 +272,3 @@ _HRV24Parms: .long defmPlaneBytes /* bmPlaneBytes */ _EndHRV24Parms: - /* Declaration ROM directory at end */ - ALIGN 2 -DeclROMDir: - OSLstEntry 0, _sRsrcDir - .long DeclRomEnd-_sRsrcDir /* Length should be 0x824 */ -DeclROMCRC: - .long 0x0 /* TODO: calculate this */ - .byte 1 /* Revision Level */ - .byte appleFormat /* Apple Format */ - .long testPattern /* magic TestPattern */ - .byte 0 /* reserved */ - .byte 0x0F /* byte lane marker */ -DeclRomEnd: - .end -