-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from FPGAArcade/random_stuff
Support for new amiga_db060 core features
- Loading branch information
Showing
31 changed files
with
854 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <stdio.h> | ||
#include <stdint.h> | ||
|
||
#include <proto/exec.h> | ||
#include <proto/dos.h> | ||
#include <dos/rdargs.h> | ||
#include <libraries/configvars.h> | ||
#include <libraries/configregs.h> | ||
#include <libraries/expansion.h> | ||
#include <proto/expansion.h> | ||
|
||
#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 : "<null>"); | ||
|
||
} | ||
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 <cpu freq in megahertz>\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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <stdint.h> | ||
#include <stdarg.h> | ||
|
||
#include <proto/exec.h> | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <stdint.h> | ||
|
||
#include <proto/dos.h> | ||
#include <proto/exec.h> | ||
#include <exec/nodes.h> | ||
#include <exec/resident.h> | ||
|
||
#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; | ||
} |
Oops, something went wrong.