Skip to content

Commit 9ed8972

Browse files
authored
Merge pull request #17 from FPGAArcade/random_stuff
Support for new amiga_db060 core features
2 parents f6f0e7d + 8e425fc commit 9ed8972

31 files changed

+854
-30
lines changed

addmem/kprintf.i

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ kprintf MACRO
5656
bra.b _kprintf_end
5757
_kprintf: movem.l d0-d1/a0-a3/a6,-(sp)
5858
move.l $4.w,a6
59+
; jsr -504(a6) ; _LVORawIOInit (execPrivate7)
60+
move.w #(3546895/115200),$dff032
5961
move.l 28(sp),a0
6062
lea 32(sp),a1
6163
lea .putch(pc),a2
@@ -72,10 +74,9 @@ _kprintf: movem.l d0-d1/a0-a3/a6,-(sp)
7274
movem.l (sp)+,d0-d1/a0-a3/a6
7375
rts
7476

75-
.putch: movem.l d0-d1/a0-a1/a6,-(sp)
76-
move.l $4.w,a6
77+
.putch: exg.l a3,a6
7778
jsr -516(a6) ; _LVORawPutChar (execPrivate9)
78-
movem.l (sp)+,d0-d1/a0-a1/a6
79+
exg.l a6,a3
7980
rts
8081
_kprintf_end:
8182
ENDC

build_rom.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
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
4+
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
55
printf "000001: 11" | xxd -r - replay.rom
66
romtool copy -c replay.rom replay.rom
77
romtool info replay.rom

cpufreq/Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
AS = $(VASM)
2+
CC = $(VC)
3+
LD = $(VLINK)
4+
5+
ASFLAGS := -quiet -Fhunk -kick1hunks -nosym -m68000 -no-opt
6+
CFLAGS_CLI := -v -O2 -size -cpu=68060 -c99 -k -sc #-DDEBUG
7+
CFLAGS := -v -O2 -size -cpu=68060 -fastcall -nostdlib -c99 -k -sc #-DDEBUG
8+
LDFLAGS := -sc -Bstatic -Cvbcc -nostdlib -Rshort -b amigahunk -s
9+
10+
TARGET := cpufreq.exe cpufreq.cli
11+
OBJECTS_CLI := cpufreq.o
12+
OBJECTS := start.o main.o kprintf.o payload.o
13+
INCLUDE := $(wildcard *.h) $(wildcard *.s)
14+
15+
CRT0 = $(VBCC)/targets/m68k-amigaos/lib/startup.o
16+
LDLIBS = -L$(VBCC)/targets/m68k-amigaos/lib -lvc
17+
18+
.EXPORT_ALL_VARIABLES:
19+
20+
.PHONY: clean
21+
22+
all: $(TARGET)
23+
24+
clean:
25+
rm -f $(TARGET) $(OBJECTS_CLI) $(OBJECTS_CLI:.o=.asm) $(OBJECTS) $(OBJECTS:.o=.asm) *.txt
26+
27+
cpufreq.exe : $(OBJECTS) Makefile | buildenv
28+
$(LD) -sc $(OBJECTS) -o $@ -M$@.txt -b amigahunk
29+
30+
cpufreq.cli : cpufreq.o Makefile | buildenv
31+
$(LD) $(LDFLAGS) $(CRT0) cpufreq.o $(LDLIBS) -o $@ -M$@.txt
32+
33+
%.o: %.c $(INCLUDE) Makefile | buildenv
34+
$(CC) $(CFLAGS) -c $< -o $@
35+
36+
%.o: %.s Makefile | buildenv
37+
$(AS) $< -o $@ -L $<.txt $(ASFLAGS) -I $(INC_ASM)
38+
39+
payload.o: cpufreq.cli # payload embeds the cpufreq command
40+
cpufreq.o: CFLAGS=$(CFLAGS_CLI)
41+
42+
include ../Makefile.build

cpufreq/cpufreq.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// WWW.FPGAArcade.COM
3+
//
4+
// REPLAY Retro Gaming Platform
5+
// No Emulation No Compromise
6+
//
7+
// cpufreq - CLI tool for updating the 68060 CPU clock frequency
8+
// Copyright (C) Erik Hemming
9+
//
10+
// This software is licensed under LPGLv2.1 ; see LICENSE file
11+
//
12+
//
13+
14+
#include <stdio.h>
15+
#include <stdint.h>
16+
17+
#include <proto/exec.h>
18+
#include <proto/dos.h>
19+
#include <dos/rdargs.h>
20+
#include <libraries/configvars.h>
21+
#include <libraries/configregs.h>
22+
#include <libraries/expansion.h>
23+
#include <proto/expansion.h>
24+
25+
#define PRODUCTID (32)
26+
#define MANUFACTURER (5060)
27+
28+
#define TEMPLATE "FREQ/N/A"
29+
#define OPT_FREQ 0
30+
#define OPT_COUNT 1
31+
32+
#define CPU_CLKDIV (0x100)
33+
34+
int main (void)
35+
{
36+
uint32_t* result[OPT_COUNT] = { 0 };
37+
struct RDArgs* args = ReadArgs(TEMPLATE, (LONG *)result, NULL);
38+
39+
printf(">> FPGAArcade Replay 68060db CPU Frequency Control <<\n\n");
40+
41+
struct Library* ExpansionBase = OpenLibrary(EXPANSIONNAME, 0);
42+
if (!ExpansionBase)
43+
{
44+
printf("ERROR: Unable to open '%s'\n", EXPANSIONNAME);
45+
return 1337;
46+
}
47+
48+
struct ConfigDev* cd = (struct ConfigDev*)FindConfigDev(NULL, MANUFACTURER, PRODUCTID);
49+
if (cd)
50+
{
51+
printf("68060db config device found (%04d/%02d).\n", MANUFACTURER, PRODUCTID);
52+
#ifdef DEBUG
53+
printf(" cd_BoardAddr = %p\n", cd->cd_BoardAddr);
54+
printf(" cd_BoardSize = %lu bytes\n", cd->cd_BoardSize);
55+
printf(" er_Type = $%02x\n", cd->cd_Rom.er_Type);
56+
printf(" er_Flags = $%02x\n", cd->cd_Rom.er_Flags);
57+
printf(" er_SerialNumber = $%08lx\n", cd->cd_Rom.er_SerialNumber);
58+
printf(" er_InitDiagVec = $%04x\n", cd->cd_Rom.er_InitDiagVec);
59+
60+
struct DiagArea* da = *(struct DiagArea**)&cd->cd_Rom.er_Reserved0c;
61+
printf(" er_DiagArea = %p\n", (APTR)da);
62+
if (da)
63+
{
64+
APTR da_DiagPoint = da->da_DiagPoint ? (APTR)((intptr_t)da + (int16_t)da->da_DiagPoint) : 0;
65+
APTR da_BootPoint = da->da_BootPoint ? (APTR)((intptr_t)da + (int16_t)da->da_BootPoint) : 0;
66+
const char* da_Name = da->da_Name ? (char*)((intptr_t)da + (int16_t)da->da_Name) : 0;
67+
68+
printf(" da_Config = $%02x\n", da->da_Config);
69+
printf(" da_Flags = $%02x\n", da->da_Flags);
70+
printf(" da_Size = $%04x\n", da->da_Size);
71+
printf(" da_DiagPoint = %p\n", da_DiagPoint);
72+
printf(" da_BootPoint = %p\n", da_BootPoint);
73+
printf(" da_Name = %p (%s)\n", (APTR)da_Name, da_Name ? da_Name : "<null>");
74+
75+
}
76+
printf("\n");
77+
#endif
78+
uint32_t freq_opt = 0;
79+
80+
if (args != NULL)
81+
{
82+
freq_opt = *result[OPT_FREQ];
83+
84+
printf("Setting CPU CLK to %lu MHz\n", freq_opt);
85+
86+
FreeArgs(args);
87+
}
88+
else
89+
{
90+
printf("usage: cpufreq <cpu freq in megahertz>\n");
91+
}
92+
93+
if (freq_opt > 0)
94+
{
95+
uint16_t* cpu_clk = (uint16_t*)((intptr_t)cd->cd_BoardAddr + CPU_CLKDIV);
96+
97+
uint16_t data = 0x8000 | (freq_opt & 0xff);
98+
#ifdef DEBUG
99+
printf("Writing 0x%x of cpu_clk ( %p )\n", data, (APTR)cpu_clk);
100+
#endif
101+
Disable();
102+
*cpu_clk = data;
103+
CacheClearU();
104+
Enable();
105+
#ifdef DEBUG
106+
printf("\nDONE!\n");
107+
#endif
108+
}
109+
}
110+
else
111+
{
112+
printf("68060db config device NOT FOUND (%04d/%02d).\n", MANUFACTURER, PRODUCTID);
113+
}
114+
115+
CloseLibrary(ExpansionBase);
116+
117+
return 0;
118+
}

cpufreq/kprintf.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// WWW.FPGAArcade.COM
3+
//
4+
// REPLAY Retro Gaming Platform
5+
// No Emulation No Compromise
6+
//
7+
// cpufreq - CLI tool for updating the 68060 CPU clock frequency
8+
// Copyright (C) Erik Hemming
9+
//
10+
// This software is licensed under LPGLv2.1 ; see LICENSE file
11+
//
12+
//
13+
14+
#include <stdint.h>
15+
#include <stdarg.h>
16+
17+
#include <proto/exec.h>
18+
19+
#ifdef DEBUG
20+
21+
static void set_uart_speed(__reg("d0") uint32_t c) = "\tmove.w\td0,$dff032\n";
22+
static void RawPutChar(__reg("d0") uint32_t c, __reg("a6") struct ExecBase* SysBase) = "\tjsr\t-516(a6)\n";
23+
24+
static void raw_put_char(__reg("d0") uint32_t c, __reg("a3") struct ExecBase* SysBase)
25+
{
26+
RawPutChar(c, SysBase);
27+
}
28+
29+
void kprintf(const char *format, ...)
30+
{
31+
va_list args;
32+
struct ExecBase* SysBase = *((struct ExecBase **) (4L));
33+
34+
set_uart_speed(3546895/115200);
35+
36+
va_start(args, format);
37+
38+
RawDoFmt((STRPTR) format, (APTR) args,
39+
raw_put_char, (APTR) SysBase);
40+
41+
va_end(args);
42+
}
43+
44+
#endif

cpufreq/kprintf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#ifndef KPRINTF_H
3+
#define KPRINTF_H
4+
5+
#ifdef DEBUG
6+
void kprintf(const char* fmt, ...);
7+
#else // DEBUG
8+
#define kprintf(...) do { } while(0)
9+
#endif // DEBUG
10+
11+
#endif

cpufreq/main.c

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//
2+
//
3+
// tf-rom - resident CLI command test for 'cpufreq'
4+
// Copyright (c) Erik Hemming
5+
//
6+
// This software is licensed under MIT ; see LICENSE file
7+
//
8+
//
9+
10+
#include <stdint.h>
11+
12+
#include <proto/dos.h>
13+
#include <proto/exec.h>
14+
#include <exec/nodes.h>
15+
#include <exec/resident.h>
16+
17+
#include "kprintf.h"
18+
19+
void* Init(__reg("d0") APTR libraryBase , __reg("a0") BPTR segList, __reg("a6") struct ExecBase* SysBase);
20+
int Run(__reg("d0") ULONG argc, __reg("a0") APTR argp, __reg("a3") BPTR segList);
21+
int Launch(__reg("d0") ULONG argc, __reg("a0") APTR argp, __reg("a1") APTR entry, __reg("a3") BPTR seglist);
22+
23+
extern struct Resident romtag;
24+
extern uint8_t cpufreq;
25+
extern int end;
26+
27+
static __section(CODE) struct SegListTrampoline
28+
{
29+
ULONG next;
30+
UWORD jmp;
31+
APTR address;
32+
} trampoline =
33+
{
34+
.next = 0,
35+
.jmp = 0x4ef9,
36+
.address = (APTR)Run
37+
};
38+
39+
void* Init( __reg("d0") APTR libraryBase,
40+
__reg("a0") BPTR segList,
41+
__reg("a6") struct ExecBase* SysBase )
42+
{
43+
kprintf("Init() => %s", romtag.rt_IdString);
44+
45+
struct DosLibrary* DOSBase = (struct DosLibrary*)OpenLibrary(DOSNAME, 36);
46+
47+
if (DOSBase) {
48+
kprintf("AddSegment(segList=%08lx => jumpto=%08lx)\n", MKBADDR(&trampoline), trampoline.address);
49+
int ret = AddSegment("cpufreq", MKBADDR(&trampoline), CMD_INTERNAL);
50+
kprintf(" => success = %08lx\n", ret);
51+
52+
CloseLibrary((struct Library*)DOSBase);
53+
}
54+
else
55+
{
56+
kprintf("Failed to open dos.library\n");
57+
}
58+
59+
return 0;
60+
}
61+
62+
static uint32_t Copy( __reg("d1") void* readhandle, // Autodocs says D1,A0,D0
63+
__reg("d2") void* buffer, // but is incorrect!
64+
__reg("d3") uint32_t length, // It matches Read() ...
65+
__reg("a6") struct DosLibrary* DOSBase )
66+
{
67+
struct ExecBase * SysBase = *(struct ExecBase **)4;
68+
uint8_t** p = readhandle;
69+
70+
uint32_t available = (ULONG)&end - (ULONG)*p;
71+
if (available < length)
72+
length = available;
73+
74+
CopyMem(*p, buffer, length);
75+
*p += length;
76+
77+
return length;
78+
}
79+
80+
static void* Alloc( __reg("d0") uint32_t size,
81+
__reg("d1") uint32_t flags,
82+
__reg("a6") struct ExecBase* SysBase )
83+
{
84+
return AllocMem(size, flags);
85+
}
86+
static void Free( __reg("a1") void* memory,
87+
__reg("d0") uint32_t size,
88+
__reg("a6") struct ExecBase* SysBase )
89+
{
90+
FreeMem(memory, size);
91+
}
92+
93+
int Run(__reg("d0") ULONG argc, __reg("a0") APTR argp, __reg("a3") BPTR segList)
94+
{
95+
struct ExecBase* SysBase = *((struct ExecBase **) (4L));
96+
struct DosLibrary* DOSBase = (struct DosLibrary*)OpenLibrary(DOSNAME, 36);
97+
98+
if (!DOSBase) {
99+
kprintf("DOS failed\n");
100+
return 1337;
101+
}
102+
103+
{
104+
uint8_t* fh = &cpufreq;
105+
LONG funcs[] = { (LONG)Copy, (LONG)Alloc, (LONG)Free };
106+
LONG stackSize = 0;
107+
kprintf("InternalLoadSeg(%08lx)...\n", fh);
108+
segList = InternalLoadSeg((BPTR)&fh, 0, funcs, &stackSize);
109+
kprintf(" => segList = %08lx (%08lx)\n", segList, BADDR(segList));
110+
}
111+
112+
if (!segList) {
113+
kprintf("segList is NULL\n");
114+
return 1337;
115+
}
116+
117+
{
118+
kprintf("segTable =\n");
119+
int hunkNr = 0;
120+
for (BPTR *hunk = BADDR(segList), next; hunk; next = *hunk, hunk = BADDR(next))
121+
{
122+
kprintf(" [%ld] => %08lx\n", hunkNr++, hunk);
123+
}
124+
}
125+
126+
kprintf("Launch(argc = %08ld, argp = %08lx, entry=%08lx, segList=%08lx)\n",
127+
argc, argp, BADDR(segList+1), segList);
128+
int ret = Launch(argc, argp, BADDR(segList+1), segList);
129+
kprintf(" => error = %08ld\n", ret);
130+
131+
{
132+
kprintf("InternalUnLoadSeg(%08lx)\n", segList);
133+
InternalUnLoadSeg(segList, Free);
134+
}
135+
136+
CloseLibrary((struct Library*)DOSBase);
137+
return ret;
138+
}

0 commit comments

Comments
 (0)