diff --git a/addmem/kprintf.i b/addmem/kprintf.i index 3599a33..1b0e9c6 100644 --- a/addmem/kprintf.i +++ b/addmem/kprintf.i @@ -56,6 +56,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -72,10 +74,9 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: movem.l d0-d1/a0-a1/a6,-(sp) - move.l $4.w,a6 +.putch: exg.l a3,a6 jsr -516(a6) ; _LVORawPutChar (execPrivate9) - movem.l (sp)+,d0-d1/a0-a1/a6 + exg.l a6,a3 rts _kprintf_end: ENDC diff --git a/build_rom.sh b/build_rom.sh index 47ba962..157435e 100755 --- a/build_rom.sh +++ b/build_rom.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -romtool -v build -o replay.rom -t ext -s 128 -e f00000 -a f00010 -r 01.10 -f bootrom/bootrom.bin addmem/AddReplayMem poseidon/PoseidonLoader rtc/battclock.resource usb/usb_eth.autoconfig usb/replayusb.device eth/replayeth.device sdcard/replaysd.device rtg/Replay.card xaudio/Devs/AHI/replay.audio +romtool -v build -o replay.rom -t ext -s 128 -e f00000 -a f00010 -r 01.11 -f bootrom/bootrom.bin addmem/AddReplayMem poseidon/PoseidonLoader rtc/battclock.resource usb/usb_eth.autoconfig usb/replayusb.device eth/replayeth.device sdcard/replaysd.device rtg/Replay.card xaudio/Devs/AHI/replay.audio cpufreq/cpufreq.exe printf "000001: 11" | xxd -r - replay.rom romtool copy -c replay.rom replay.rom romtool info replay.rom diff --git a/cpufreq/Makefile b/cpufreq/Makefile new file mode 100644 index 0000000..dbb22e5 --- /dev/null +++ b/cpufreq/Makefile @@ -0,0 +1,42 @@ +AS = $(VASM) +CC = $(VC) +LD = $(VLINK) + +ASFLAGS := -quiet -Fhunk -kick1hunks -nosym -m68000 -no-opt +CFLAGS_CLI := -v -O2 -size -cpu=68060 -c99 -k -sc #-DDEBUG +CFLAGS := -v -O2 -size -cpu=68060 -fastcall -nostdlib -c99 -k -sc #-DDEBUG +LDFLAGS := -sc -Bstatic -Cvbcc -nostdlib -Rshort -b amigahunk -s + +TARGET := cpufreq.exe cpufreq.cli +OBJECTS_CLI := cpufreq.o +OBJECTS := start.o main.o kprintf.o payload.o +INCLUDE := $(wildcard *.h) $(wildcard *.s) + +CRT0 = $(VBCC)/targets/m68k-amigaos/lib/startup.o +LDLIBS = -L$(VBCC)/targets/m68k-amigaos/lib -lvc + +.EXPORT_ALL_VARIABLES: + +.PHONY: clean + +all: $(TARGET) + +clean: + rm -f $(TARGET) $(OBJECTS_CLI) $(OBJECTS_CLI:.o=.asm) $(OBJECTS) $(OBJECTS:.o=.asm) *.txt + +cpufreq.exe : $(OBJECTS) Makefile | buildenv + $(LD) -sc $(OBJECTS) -o $@ -M$@.txt -b amigahunk + +cpufreq.cli : cpufreq.o Makefile | buildenv + $(LD) $(LDFLAGS) $(CRT0) cpufreq.o $(LDLIBS) -o $@ -M$@.txt + +%.o: %.c $(INCLUDE) Makefile | buildenv + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.s Makefile | buildenv + $(AS) $< -o $@ -L $<.txt $(ASFLAGS) -I $(INC_ASM) + +payload.o: cpufreq.cli # payload embeds the cpufreq command +cpufreq.o: CFLAGS=$(CFLAGS_CLI) + +include ../Makefile.build diff --git a/cpufreq/cpufreq.c b/cpufreq/cpufreq.c new file mode 100644 index 0000000..57db829 --- /dev/null +++ b/cpufreq/cpufreq.c @@ -0,0 +1,118 @@ +// +// WWW.FPGAArcade.COM +// +// REPLAY Retro Gaming Platform +// No Emulation No Compromise +// +// cpufreq - CLI tool for updating the 68060 CPU clock frequency +// Copyright (C) Erik Hemming +// +// This software is licensed under LPGLv2.1 ; see LICENSE file +// +// + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define PRODUCTID (32) +#define MANUFACTURER (5060) + +#define TEMPLATE "FREQ/N/A" +#define OPT_FREQ 0 +#define OPT_COUNT 1 + +#define CPU_CLKDIV (0x100) + +int main (void) +{ + uint32_t* result[OPT_COUNT] = { 0 }; + struct RDArgs* args = ReadArgs(TEMPLATE, (LONG *)result, NULL); + + printf(">> FPGAArcade Replay 68060db CPU Frequency Control <<\n\n"); + + struct Library* ExpansionBase = OpenLibrary(EXPANSIONNAME, 0); + if (!ExpansionBase) + { + printf("ERROR: Unable to open '%s'\n", EXPANSIONNAME); + return 1337; + } + + struct ConfigDev* cd = (struct ConfigDev*)FindConfigDev(NULL, MANUFACTURER, PRODUCTID); + if (cd) + { + printf("68060db config device found (%04d/%02d).\n", MANUFACTURER, PRODUCTID); +#ifdef DEBUG + printf(" cd_BoardAddr = %p\n", cd->cd_BoardAddr); + printf(" cd_BoardSize = %lu bytes\n", cd->cd_BoardSize); + printf(" er_Type = $%02x\n", cd->cd_Rom.er_Type); + printf(" er_Flags = $%02x\n", cd->cd_Rom.er_Flags); + printf(" er_SerialNumber = $%08lx\n", cd->cd_Rom.er_SerialNumber); + printf(" er_InitDiagVec = $%04x\n", cd->cd_Rom.er_InitDiagVec); + + struct DiagArea* da = *(struct DiagArea**)&cd->cd_Rom.er_Reserved0c; + printf(" er_DiagArea = %p\n", (APTR)da); + if (da) + { + APTR da_DiagPoint = da->da_DiagPoint ? (APTR)((intptr_t)da + (int16_t)da->da_DiagPoint) : 0; + APTR da_BootPoint = da->da_BootPoint ? (APTR)((intptr_t)da + (int16_t)da->da_BootPoint) : 0; + const char* da_Name = da->da_Name ? (char*)((intptr_t)da + (int16_t)da->da_Name) : 0; + + printf(" da_Config = $%02x\n", da->da_Config); + printf(" da_Flags = $%02x\n", da->da_Flags); + printf(" da_Size = $%04x\n", da->da_Size); + printf(" da_DiagPoint = %p\n", da_DiagPoint); + printf(" da_BootPoint = %p\n", da_BootPoint); + printf(" da_Name = %p (%s)\n", (APTR)da_Name, da_Name ? da_Name : ""); + + } + printf("\n"); +#endif + uint32_t freq_opt = 0; + + if (args != NULL) + { + freq_opt = *result[OPT_FREQ]; + + printf("Setting CPU CLK to %lu MHz\n", freq_opt); + + FreeArgs(args); + } + else + { + printf("usage: cpufreq \n"); + } + + if (freq_opt > 0) + { + uint16_t* cpu_clk = (uint16_t*)((intptr_t)cd->cd_BoardAddr + CPU_CLKDIV); + + uint16_t data = 0x8000 | (freq_opt & 0xff); +#ifdef DEBUG + printf("Writing 0x%x of cpu_clk ( %p )\n", data, (APTR)cpu_clk); +#endif + Disable(); + *cpu_clk = data; + CacheClearU(); + Enable(); +#ifdef DEBUG + printf("\nDONE!\n"); +#endif + } + } + else + { + printf("68060db config device NOT FOUND (%04d/%02d).\n", MANUFACTURER, PRODUCTID); + } + + CloseLibrary(ExpansionBase); + + return 0; +} diff --git a/cpufreq/kprintf.c b/cpufreq/kprintf.c new file mode 100644 index 0000000..288cb88 --- /dev/null +++ b/cpufreq/kprintf.c @@ -0,0 +1,44 @@ +// +// WWW.FPGAArcade.COM +// +// REPLAY Retro Gaming Platform +// No Emulation No Compromise +// +// cpufreq - CLI tool for updating the 68060 CPU clock frequency +// Copyright (C) Erik Hemming +// +// This software is licensed under LPGLv2.1 ; see LICENSE file +// +// + +#include +#include + +#include + +#ifdef DEBUG + +static void set_uart_speed(__reg("d0") uint32_t c) = "\tmove.w\td0,$dff032\n"; +static void RawPutChar(__reg("d0") uint32_t c, __reg("a6") struct ExecBase* SysBase) = "\tjsr\t-516(a6)\n"; + +static void raw_put_char(__reg("d0") uint32_t c, __reg("a3") struct ExecBase* SysBase) +{ + RawPutChar(c, SysBase); +} + +void kprintf(const char *format, ...) +{ + va_list args; + struct ExecBase* SysBase = *((struct ExecBase **) (4L)); + + set_uart_speed(3546895/115200); + + va_start(args, format); + + RawDoFmt((STRPTR) format, (APTR) args, + raw_put_char, (APTR) SysBase); + + va_end(args); +} + +#endif diff --git a/cpufreq/kprintf.h b/cpufreq/kprintf.h new file mode 100644 index 0000000..83b40fb --- /dev/null +++ b/cpufreq/kprintf.h @@ -0,0 +1,11 @@ +#pragma once +#ifndef KPRINTF_H +#define KPRINTF_H + +#ifdef DEBUG +void kprintf(const char* fmt, ...); +#else // DEBUG +#define kprintf(...) do { } while(0) +#endif // DEBUG + +#endif diff --git a/cpufreq/main.c b/cpufreq/main.c new file mode 100644 index 0000000..f829ad8 --- /dev/null +++ b/cpufreq/main.c @@ -0,0 +1,138 @@ +// +// +// tf-rom - resident CLI command test for 'cpufreq' +// Copyright (c) Erik Hemming +// +// This software is licensed under MIT ; see LICENSE file +// +// + +#include + +#include +#include +#include +#include + +#include "kprintf.h" + +void* Init(__reg("d0") APTR libraryBase , __reg("a0") BPTR segList, __reg("a6") struct ExecBase* SysBase); +int Run(__reg("d0") ULONG argc, __reg("a0") APTR argp, __reg("a3") BPTR segList); +int Launch(__reg("d0") ULONG argc, __reg("a0") APTR argp, __reg("a1") APTR entry, __reg("a3") BPTR seglist); + +extern struct Resident romtag; +extern uint8_t cpufreq; +extern int end; + +static __section(CODE) struct SegListTrampoline +{ + ULONG next; + UWORD jmp; + APTR address; +} trampoline = +{ + .next = 0, + .jmp = 0x4ef9, + .address = (APTR)Run +}; + +void* Init( __reg("d0") APTR libraryBase, + __reg("a0") BPTR segList, + __reg("a6") struct ExecBase* SysBase ) +{ + kprintf("Init() => %s", romtag.rt_IdString); + + struct DosLibrary* DOSBase = (struct DosLibrary*)OpenLibrary(DOSNAME, 36); + + if (DOSBase) { + kprintf("AddSegment(segList=%08lx => jumpto=%08lx)\n", MKBADDR(&trampoline), trampoline.address); + int ret = AddSegment("cpufreq", MKBADDR(&trampoline), CMD_INTERNAL); + kprintf(" => success = %08lx\n", ret); + + CloseLibrary((struct Library*)DOSBase); + } + else + { + kprintf("Failed to open dos.library\n"); + } + + return 0; +} + +static uint32_t Copy( __reg("d1") void* readhandle, // Autodocs says D1,A0,D0 + __reg("d2") void* buffer, // but is incorrect! + __reg("d3") uint32_t length, // It matches Read() ... + __reg("a6") struct DosLibrary* DOSBase ) +{ + struct ExecBase * SysBase = *(struct ExecBase **)4; + uint8_t** p = readhandle; + + uint32_t available = (ULONG)&end - (ULONG)*p; + if (available < length) + length = available; + + CopyMem(*p, buffer, length); + *p += length; + + return length; +} + +static void* Alloc( __reg("d0") uint32_t size, + __reg("d1") uint32_t flags, + __reg("a6") struct ExecBase* SysBase ) +{ + return AllocMem(size, flags); +} +static void Free( __reg("a1") void* memory, + __reg("d0") uint32_t size, + __reg("a6") struct ExecBase* SysBase ) +{ + FreeMem(memory, size); +} + +int Run(__reg("d0") ULONG argc, __reg("a0") APTR argp, __reg("a3") BPTR segList) +{ + struct ExecBase* SysBase = *((struct ExecBase **) (4L)); + struct DosLibrary* DOSBase = (struct DosLibrary*)OpenLibrary(DOSNAME, 36); + + if (!DOSBase) { + kprintf("DOS failed\n"); + return 1337; + } + + { + uint8_t* fh = &cpufreq; + LONG funcs[] = { (LONG)Copy, (LONG)Alloc, (LONG)Free }; + LONG stackSize = 0; + kprintf("InternalLoadSeg(%08lx)...\n", fh); + segList = InternalLoadSeg((BPTR)&fh, 0, funcs, &stackSize); + kprintf(" => segList = %08lx (%08lx)\n", segList, BADDR(segList)); + } + + if (!segList) { + kprintf("segList is NULL\n"); + return 1337; + } + + { + kprintf("segTable =\n"); + int hunkNr = 0; + for (BPTR *hunk = BADDR(segList), next; hunk; next = *hunk, hunk = BADDR(next)) + { + kprintf(" [%ld] => %08lx\n", hunkNr++, hunk); + } + } + + kprintf("Launch(argc = %08ld, argp = %08lx, entry=%08lx, segList=%08lx)\n", + argc, argp, BADDR(segList+1), segList); + int ret = Launch(argc, argp, BADDR(segList+1), segList); + kprintf(" => error = %08ld\n", ret); + + { + kprintf("InternalUnLoadSeg(%08lx)\n", segList); + InternalUnLoadSeg(segList, Free); + } + + CloseLibrary((struct Library*)DOSBase); + return ret; +} diff --git a/cpufreq/payload.s b/cpufreq/payload.s new file mode 100644 index 0000000..3161c7e --- /dev/null +++ b/cpufreq/payload.s @@ -0,0 +1,18 @@ + + xdef @Launch + xdef _cpufreq + xdef _end + + section CODE + +@Launch movem.l d2-d7/a2-a6,-(sp) + jsr (a1) + movem.l (sp)+,d2-d7/a2-a6 + rts + + cnop 0,4 + +_cpufreq + incbin cpufreq.cli + +_end: diff --git a/cpufreq/start.c b/cpufreq/start.c new file mode 100644 index 0000000..ae8bd1c --- /dev/null +++ b/cpufreq/start.c @@ -0,0 +1,41 @@ +// +// WWW.FPGAArcade.COM +// +// REPLAY Retro Gaming Platform +// No Emulation No Compromise +// +// cpufreq - CLI tool for updating the 68060 CPU clock frequency +// Copyright (C) Erik Hemming +// +// This software is licensed under LPGLv2.1 ; see LICENSE file +// +// + +#include +#include + +#include +#include + +void* Init(); +int Run(); +extern int end; + +int Start() +{ + return Run(); +} + +__section(CODE) struct Resident romtag = +{ + .rt_MatchWord = RTC_MATCHWORD, + .rt_MatchTag = &romtag, + .rt_EndSkip = &end, + .rt_Flags = RTF_AFTERDOS, + .rt_Version = 1, + .rt_Type = NT_UNKNOWN, + .rt_Pri = 0, + .rt_Name = "cpufreq", + .rt_IdString = "cpufreq 1.0 (8.11.2022)\n\r", + .rt_Init = (APTR)Init +}; diff --git a/eth/Makefile b/eth/Makefile index 640c6d7..3327917 100644 --- a/eth/Makefile +++ b/eth/Makefile @@ -13,6 +13,9 @@ $(TARGET): $(INCLUDES) $(TARGET): $(SOURCE) $(VASM) $< -o $@ -L $(LISTFILE) $(VASM_FLAGS) -I $(INC_ASM) -I $(SANA2)/include +reseteth: reseteth.s + $(VASM) $< -o $@ -L $(LISTFILE) $(VASM_FLAGS) -I $(INC_ASM) -I $(SANA2)/include + clean: rm -rf $(TARGET) $(LISTFILE) diff --git a/eth/kprintf.i b/eth/kprintf.i index 34d5b38..51f8057 100644 --- a/eth/kprintf.i +++ b/eth/kprintf.i @@ -59,6 +59,8 @@ kprintf MACRO _kprintf: movem.l d0-d2/a0-a3/a6,-(sp) movea.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 lea .dos(pc),a1 moveq.l #36,d0 ; fputc is kick 2.x+ diff --git a/eth/reseteth.s b/eth/reseteth.s new file mode 100644 index 0000000..cbf99bc --- /dev/null +++ b/eth/reseteth.s @@ -0,0 +1,277 @@ +ENABLE_KPRINTF + + include "enc624.i" + include "kprintf.i" + +HW_ResetEth: + kprintf "Reset ETH" + lea ($40000000+$00300000),a0 + + kprintf " > Wait EUDAST stable.." + +; 1. Write 1234h to EUDAST. +; 2. Read EUDAST to see if it now equals 1234h. If +; it does not, the SPI/PSP interface may not be +; ready yet, so return to step 1 and try again. + + moveq.l #100,d1 + move.w #$1234,d0 +.notrdy move.w d0,(EUDAST,a0) + cmp.w (EUDAST,a0),d0 + beq.b .psprdy + bsr Wait25us + dbf d1,.notrdy + bra .error + +.psprdy + kprintf " > Write/Readback .." + moveq.l #0,d0 + moveq.l #0,d1 + moveq.l #0,d2 + moveq.l #0,d3 + moveq.l #0,d4 + moveq.l #0,d5 + move.w #32-1,d0 +.rwtest move.w d0,d1 + and.l #%11111,d1 + or.w #$100,d1 ; reserved bit 8, set high + move.w d1,(MIREGADR,a0) + move.w (MIREGADR,a0),d2 + move.w (MIREGADR,a0),d3 + move.w (MIREGADR,a0),d4 + move.w (MIREGADR,a0),d5 + bsr Wait25us + kprintf " > %04lx vs %04lx,%04lx,%04lx,%04lx",d1,d2,d3,d4,d5 +; cmp.w d1,d0 +; bne .error + dbf d0,.rwtest + + kprintf " > Wait CLKRDY .." + +; 3. Poll CLKRDY (ESTAT<12>) and wait for it to +; become set. + + moveq.l #100,d1 +.noclk btst #ESTATB_CLKRDY,(ESTATH,a0) + bne.b .clkrdy + bsr Wait25us + dbf d1,.noclk + bra .error + +.clkrdy + kprintf " > Issue a System Reset .." + +; 4. Issue a System Reset command by setting +; ETHRST (ECON2<4>). +; 5. In software, wait at least 25 s for the Reset to +; take place and the SPI/PSP interface to begin +; operating again. + + moveq.l #100,d1 + move.w #ECON2F_ETHRST,(ECON2SET,a0) +.waitrst bsr Wait25us + btst #ECON2B_ETHRST,(ECON2L,a0) + beq.b .resetok + dbf d1,.waitrst + bra .error + +.resetok + kprintf " > Check EUDAST .." + +; 6. Read EUDAST to confirm that the System Reset +; took place. EUDAST should have reverted back +; to its Reset default of 0000h. + + tst.w (EUDAST,a0) + bne .error + + kprintf " > Wait PHY .." + +; 7. Wait at least 256 s for the PHY registers and +; PHY status bits to become available + + bsr Wait250us + + + kprintf " > Reset PHY .." + +; 7.5 PHY Subsystem Reset +; The PHY module may be reset by setting the PRST bit +; (PHCON1<15>). The PHY register contents all revert +; to their default values. + +; * The POR and System Resets automatically perform a +; * PHY Reset, so this step does not need to be performed +; * after a System or Power-on Reset. + + moveq.l #PHCON1,d0 + move.w #PHCON1F_PRST,d1 + bsr HW_WritePhy + +; It is recom mended that, after issuing a Reset, the host controller +; polls PRST and waits for it to be cleared by hardware +; before using the PHY. + + kprintf " > Wait PHY .." + + moveq.l #100,d7 +.waitphy moveq.l #PHCON1,d0 + bsr HW_ReadPhy + and.w #PHCON1F_PRST,d0 + beq.b .ok + bsr Wait25us + dbf d7,.waitphy + + bra .error + +.ok + ; read PHY regs + + moveq.l #PHCON1,d0 + bsr HW_ReadPhy + kprintf " > PHCON1 = $%04lx ($1000)",d0 + + moveq.l #PHSTAT1,d0 + bsr HW_ReadPhy + kprintf " > PHSTAT1 = $%04lx ($7809)",d0 + + moveq.l #PHANA,d0 + bsr HW_ReadPhy + kprintf " > PHANA = $%04lx ($01e1)",d0 + + moveq.l #PHANLPA,d0 + bsr HW_ReadPhy + kprintf " > PHANLPA = $%04lx ($xxxx)",d0 + + moveq.l #PHANE,d0 + bsr HW_ReadPhy + kprintf " > PHANE = $%04lx ($0000)",d0 + + moveq.l #PHCON2,d0 + bsr HW_ReadPhy + kprintf " > PHCON2 = $%04lx ($0002)",d0 + + moveq.l #PHSTAT2,d0 + bsr HW_ReadPhy + kprintf " > PHSTAT2 = $%04lx ($xx0x)",d0 + + moveq.l #PHSTAT3,d0 + bsr HW_ReadPhy + kprintf " > PHSTAT3 = $%04lx ($0040)",d0 + + ; DONE + + kprintf " > Reset done." + move.l #0,d0 + rts + +.error: kprintf " > Reset failed." + move.l #1337,d0 + rts + +Wait25us: move.l d0,-(sp) + move.w #25,d0 +.wait tst.b $bfe001 ; approx 1us + dbf d0,.wait + move.l (sp)+,d0 + rts + +Wait250us: move.w d0,-(sp) + move.w #250,d0 +.wait tst.b $bfe001 ; approx 1us + dbf d0,.wait + move.w (sp)+,d0 + rts + +HW_ReadPhy: +; To read from a PHY register: +; 1. Write the address of the PHY register to read +; from into the MIREGADR register +; (Register 3-1). Make sure to also set reserved +; bit 8 of this register. +; 2. Set the MIIRD bit (MICMD<0>, Register 3-2). +; The read operation begins and the BUSY bit +; (MISTAT<0>, Register 3-3) is automatically set +; by hardware. +; 3. Wait 25.6 s. Poll the BUSY (MISTAT<0>) bit to +; be certain that the operation is complete. While +; busy, the host controller should not start any +; MIISCAN operations or write to the MIWR +; register. When the MAC has obtained the register +; contents, the BUSY bit will clear itself. +; 4. Clear the MIIRD (MICMD<0>) bit. +; 5. Read the desired data from the MIRD register. +; For 8-bit interfaces, the order that these bytes +; are read is unimportant. + +; move.l g_MachEnc(a6),a0 + + and.l #%11111,d0 +; kprintf "Read PHY reg $%lx",d0 + + or.w #$100,d0 ; reserved bit 8, set high + + moveq.l #10,d1 +.busy move.w d0,(MIREGADR,a0) + bsr Wait25us + bset #MICMDB_MIIRD,(MICMDL,a0) + + bsr Wait25us + + btst #MISTATB_BUSY,(MISTATL,a0) + beq.b .done + + bsr Wait25us + dbf d1,.busy + bra.b .error + +.done + bsr Wait25us + bclr #MICMDB_MIIRD,(MICMDL,a0) + bsr Wait25us + move.w (MIRD,a0),d0 +; kprintf " > $%lx",d0 + rts + +.error: kprintf " > PHY read %lx failed.",d0 + moveq.l #-1,d0 + rts + +HW_WritePhy: +; To write to a PHY register: +; 1. Write the address of the PHY register to write to +; into the MIREGADR register. Make sure to also +; set reserved bit 8 of this register. +; 2. Write the 16 bits of data into the MIWR register. +; The low byte must be written first, followed by +; the high byte. +; 3. Writing to the high byte of MIWR begins the +; MIIM transaction and the BUSY (MISTAT<0>) +; bit is automatically set by hardware. + +; move.l g_MachEnc(a6),a0 + + and.l #%11111,d0 +; kprintf "Write PHY reg $%lx data %lx",d0,d1 + + or.w #$100,d0 ; reserved bit 8, set high + + bsr Wait25us + move.w d0,(MIREGADR,a0) + bsr Wait25us + move.w d1,(MIWR,a0) + bsr Wait25us + + moveq.l #10,d1 +.busy bsr Wait25us + btst #MISTATB_BUSY,(MISTATL,a0) + beq.b .done + dbf d1,.busy + bra.b .error + +.done bsr HW_ReadPhy ; not needed + rts + +.error: kprintf " > PHY write %lx failed.",d0 + moveq.l #-1,d0 + rts diff --git a/oled/kprintf.i b/oled/kprintf.i index 03ab712..7c56f85 100644 --- a/oled/kprintf.i +++ b/oled/kprintf.i @@ -54,6 +54,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -70,8 +72,10 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: move.l a3,a6 - jmp -516(a6) ; _LVORawPutChar (execPrivate9) +.putch: exg.l a3,a6 + jsr -516(a6) ; _LVORawPutChar (execPrivate9) + exg.l a6,a3 + rts _kprintf_end: ENDC diff --git a/oled/oled.exe b/oled/oled.exe index eb13cda..6b24a66 100644 Binary files a/oled/oled.exe and b/oled/oled.exe differ diff --git a/poseidon/PoseidonLoader b/poseidon/PoseidonLoader index 142e9d0..66ae014 100644 Binary files a/poseidon/PoseidonLoader and b/poseidon/PoseidonLoader differ diff --git a/poseidon/kprintf.i b/poseidon/kprintf.i index 05011c1..48dca04 100644 --- a/poseidon/kprintf.i +++ b/poseidon/kprintf.i @@ -54,6 +54,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -70,10 +72,9 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: movem.l d0-d1/a0-a1/a6,-(sp) - move.l $4.w,a6 +.putch: exg.l a3,a6 jsr -516(a6) ; _LVORawPutChar (execPrivate9) - movem.l (sp)+,d0-d1/a0-a1/a6 + exg.l a6,a3 rts _kprintf_end: ENDC diff --git a/poseidon/loader.s b/poseidon/loader.s index 7035011..0b23fc6 100644 --- a/poseidon/loader.s +++ b/poseidon/loader.s @@ -17,15 +17,17 @@ MAX_ROM_TAGS = 32 ;ENABLE_KPRINTF + NOLIST include exec/exec.i include exec/nodes.i include exec/resident.i include exec/libraries.i include lvo/exec_lib.i include kprintf.i + LIST - jmp S + jmp (S)(pc) moveq.l #-1,d0 rts diff --git a/replay.rom b/replay.rom index 7f9a131..37d460a 100644 Binary files a/replay.rom and b/replay.rom differ diff --git a/rtc/battclock.s b/rtc/battclock.s index 2f29edb..b728ad4 100644 --- a/rtc/battclock.s +++ b/rtc/battclock.s @@ -625,6 +625,8 @@ initStruct: DC.L 0 InitResource: + kprintf "INIT: %s",#VERSTRING + movem.l a2/a3/a6,-(sp) move.l #0,a2 ; for no resource case diff --git a/rtc/kprintf.i b/rtc/kprintf.i index e367dd6..168513f 100644 --- a/rtc/kprintf.i +++ b/rtc/kprintf.i @@ -15,8 +15,8 @@ kprintf MACRO IFD ENABLE_KPRINTF - cmp.l #$baadc0de,0.l ; kludge to dynamically enable/disable printf's - bne.b .skip\@ +; cmp.l #$baadc0de,0.l ; kludge to dynamically enable/disable printf's +; bne.b .skip\@ ifnc "","\9" move.l \9,-(sp) @@ -58,6 +58,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -74,8 +76,10 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: move.l a3,a6 - jmp -516(a6) ; _LVORawPutChar (execPrivate9) +.putch: exg.l a3,a6 + jsr -516(a6) ; _LVORawPutChar (execPrivate9) + exg.l a6,a3 + rts _kprintf_end: ENDC diff --git a/rtg/replay.card.asm b/rtg/replay.card.asm index 53d76bf..3c15352 100644 --- a/rtg/replay.card.asm +++ b/rtg/replay.card.asm @@ -139,6 +139,8 @@ MEMF_REPLAY EQU (1<<14) bugprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -155,10 +157,9 @@ bugprintf: movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: move.l a6,-(sp) - move.l a3,a6 +.putch: exg.l a3,a6 jsr -516(a6) ; _LVORawPutChar (execPrivate9) - move.l (sp)+,a6 + exg.l a6,a3 rts _bugprintf_end: rts diff --git a/sdcard/kprintf.i b/sdcard/kprintf.i index a2b3692..0bfad52 100644 --- a/sdcard/kprintf.i +++ b/sdcard/kprintf.i @@ -52,6 +52,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -68,8 +70,10 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: move.l a3,a6 - jmp -516(a6) ; _LVORawPutChar (execPrivate9) +.putch: exg.l a3,a6 + jsr -516(a6) ; _LVORawPutChar (execPrivate9) + exg.l a6,a3 + rts _kprintf_end: ENDC diff --git a/timer/Makefile b/timer/Makefile new file mode 100644 index 0000000..23df207 --- /dev/null +++ b/timer/Makefile @@ -0,0 +1,34 @@ +AS = $(VASM) +CC = $(VC) +LD = $(VLINK) + +ASFLAGS := -quiet -Fhunk -kick1hunks -nosym -m68000 -no-opt +CFLAGS := -v -O2 -size -cpu=68060 -c99 -k -sc -DDEBUG +LDFLAGS := -sc -Bstatic -Cvbcc -nostdlib -Rshort -b amigahunk -s + +TARGET := timer +OBJECTS := main.o timer.o +INCLUDE := $(wildcard *.h) $(wildcard *.s) + +CRT0 = $(VBCC)/targets/m68k-amigaos/lib/startup.o +LDLIBS = -L$(VBCC)/targets/m68k-amigaos/lib -lvc + +.EXPORT_ALL_VARIABLES: + +.PHONY: clean + +all: $(TARGET) + +clean: + rm -f $(TARGET) $(OBJECTS) $(OBJECTS:.o=.asm) *.txt + +$(TARGET) : $(OBJECTS) Makefile | buildenv + $(LD) $(LDFLAGS) $(CRT0) $(OBJECTS) $(LDLIBS) -o $@ -M$@.txt + +%.o: %.c $(INCLUDE) Makefile | buildenv + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.s Makefile | buildenv + $(AS) $< -o $@ -L $<.txt $(ASFLAGS) -I $(INC_ASM) + +include ../Makefile.build diff --git a/timer/main.c b/timer/main.c new file mode 100644 index 0000000..582b280 --- /dev/null +++ b/timer/main.c @@ -0,0 +1,43 @@ +#include +#include + +#include + +#define NUMRUNS (10) +#define NUMITERATIONS (10000) + +uint32_t runAsmCode(__reg("d0") uint32_t iterations); +uint32_t getCpuCycle() = + "\tmoveq.l\t#0,d0\n" + "\trept 100\n" + "\tsub.l\t$40400000,d0\t;read CPU clock\n" + "\tadd.l\t$40400000,d0\n" + "\tendr\n"; + +static uint32_t sample() +{ + return getCpuCycle(); +} + +int main() +{ + uint32_t result[NUMRUNS]; + + // Calibrate the cost of reading the cycle counter + Disable(); + for (int i = 0; i < NUMRUNS; ++i) + result[i] = sample(); + Enable(); + for (int i = 0; i < NUMRUNS; ++i) + printf("REPT 100 took %d cycles\n", (int)result[i]); + + // Measure the 5c/7instr loop + Disable(); + for (int i = 0; i < NUMRUNS; ++i) + result[i] = runAsmCode(NUMITERATIONS); + Enable(); + for (int i = 0; i < NUMRUNS; ++i) + printf("%d iterations took %d cycles\n", NUMITERATIONS, (int)result[i]); + + return 0; +} diff --git a/timer/timer.s b/timer/timer.s new file mode 100644 index 0000000..39c3d2f --- /dev/null +++ b/timer/timer.s @@ -0,0 +1,31 @@ + +; Example program +; This runs a 5-cycle code loop for N iterations (provided in D0), +; and then returns (in D0) the number of CPU cycles used. + + PUBLIC _runAsmCode + +_runAsmCode: + + bset.b #1,$bfe001 ; trigger logic analyzer + tst.b $bfe001 ; delay due to SIO on the 060db + move.l $40400000,a0 ; sample cpu clock counter + +.iter: + addx.l d1,d1 ; pOEP-only + addx.l d1,d1 ; pOEP-only + addx.l d1,d1 ; pOEP-only + addx.l d1,d1 ; pOEP-only + + add.l d1,d1 ; pOEP|sOEP + subq.l #1,d0 ; pOEP|sOEP + bne.s .iter ; is predicted and folded, takes 0 cycles + + sub.l $40400000,a0 ; sample cpu clock counter + bclr.b #1,$bfe001 ; reset logic analyzer + + moveq.l #0,d0 + sub.l a0,d0 + + rts + diff --git a/usb/addconfig.s b/usb/addconfig.s index cad9b35..9c04506 100644 --- a/usb/addconfig.s +++ b/usb/addconfig.s @@ -34,7 +34,7 @@ VERSION = 1 REVISION= 0 -VERSTRING dc.b 'usb_eth.autoconfig 1.1 (15.3.2022) ZorroIII config for Replay USB/Ethernet Card',13,10,0 +VERSTRING dc.b 'usb_eth.autoconfig 1.2 (7.11.2022) ZorroIII config for Replay USB/Ethernet Card',13,10,0 even romtag: dc.w RTC_MATCHWORD @@ -64,7 +64,7 @@ AddBoardConfig: .VENDOR = 5060 ; Replay .PRODUCT = 16 ; usb .SERIAL = $12345678 -.BOARDSIZE = $7 ; %111 = 4MB +.BOARDSIZE = $0 ; %000 = 8MB movem.l d1/a0/a1,-(sp) moveq #0,d0 movea.l 4.w,a6 @@ -99,7 +99,7 @@ AddBoardConfig: movea.l d0,a0 move.l #$40000000,cd_BoardAddr(a0) - move.l #$00400000,cd_BoardSize(a0) + move.l #$00800000,cd_BoardSize(a0) lea cd_Rom(a0),a1 move.b #ERT_ZORROIII+.BOARDSIZE,er_Type(a1) move.b #.PRODUCT,er_Product(a1) diff --git a/usb/kprintf.i b/usb/kprintf.i index 53f9245..84eca9d 100644 --- a/usb/kprintf.i +++ b/usb/kprintf.i @@ -54,6 +54,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -70,10 +72,9 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: movem.l d0-d1/a0-a1/a6,-(sp) - move.l $4.w,a6 +.putch: exg.l a3,a6 jsr -516(a6) ; _LVORawPutChar (execPrivate9) - movem.l (sp)+,d0-d1/a0-a1/a6 + exg.l a6,a3 rts _kprintf_end: ENDC diff --git a/usb/usb_eth.autoconfig b/usb/usb_eth.autoconfig index 0782dba..2bef866 100644 Binary files a/usb/usb_eth.autoconfig and b/usb/usb_eth.autoconfig differ diff --git a/xaudio/Devs/AHI/replay.audio b/xaudio/Devs/AHI/replay.audio index c35b269..52ea0c8 100644 Binary files a/xaudio/Devs/AHI/replay.audio and b/xaudio/Devs/AHI/replay.audio differ diff --git a/xaudio/src/kprintf.i b/xaudio/src/kprintf.i index bf90785..414fc49 100644 --- a/xaudio/src/kprintf.i +++ b/xaudio/src/kprintf.i @@ -52,6 +52,8 @@ kprintf MACRO bra.b _kprintf_end _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) move.l $4.w,a6 +; jsr -504(a6) ; _LVORawIOInit (execPrivate7) + move.w #(3546895/115200),$dff032 move.l 28(sp),a0 lea 32(sp),a1 lea .putch(pc),a2 @@ -68,10 +70,9 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp) movem.l (sp)+,d0-d1/a0-a3/a6 rts -.putch: move.l a6,-(sp) - move.l a3,a6 +.putch: exg.l a3,a6 jsr -516(a6) ; _LVORawPutChar (execPrivate9) - move.l (sp)+,a6 + exg.l a6,a3 rts _kprintf_end: ENDC diff --git a/xaudio/src/replay_audio.s b/xaudio/src/replay_audio.s index ea0656f..f2ca39b 100644 --- a/xaudio/src/replay_audio.s +++ b/xaudio/src/replay_audio.s @@ -106,7 +106,6 @@ VERSTAG MACRO include lvo/exec_lib.i include lvo/expansion_lib.i include lvo/timer_lib.i - LIST ************************************************************************* @@ -189,6 +188,7 @@ FALSE EQU 0 Start: IFD STANDALONE_TESTCODE + LIST move.l 4.w,a6 lea .replayBase(pc),a0 @@ -743,6 +743,7 @@ audio: ; incbin "084_classicbrk-24.aif" ; incbin "Casio-MT-45-16-Beat.wav" ELSE + LIST moveq #-1,d0 rts ENDC ; STANDALONE_TESTCODE @@ -2454,7 +2455,7 @@ ga_Copyright: lea .copyright(pc),a0 move.l a0,d0 rts -.copyright dc.b " 2022 All rights reserved",0 +.copyright dc.b "© 2022 All rights reserved",0 even ga_Version: