Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MISCFILES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file gets included by the Makefile in this directory to determine
# the files that should go both into source and binary distributions.

MISCFILES = gem.h gemx.h mt_gem.h mt_gemx.h
MISCFILES = gem.h gemx.h mt_gem.h mt_gemx.h include/arm/compiler.h
41 changes: 39 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@ top_builddir = .

default: all

ARCH ?= m68k

ifeq ($(ARCH),arm)
CROSS_TOOL ?= arm-none-eabi
endif

include $(top_srcdir)/CONFIGVARS
include $(top_srcdir)/RULES
include $(top_srcdir)/PHONY
include $(srcdir)/VERSION

ifeq ($(ARCH),arm)
CFLAGS_arm = -mfloat-abi=hard -mfpu=vfp -mword-relocations
ARCH_INCLUDES = -I$(srcdir)/include/arm
ALL_LIBS = arm
else

CFLAGS_68000 = -m68000
CFLAGS_68000.short = -m68000 -mshort
CFLAGS_68020-60 = -m68020-60
Expand All @@ -36,7 +48,9 @@ CFLAGS_5475.short.fastcall = -mcpu=5475 -mshort -mfastcall
ALL_LIBS = 68000 68020-60 68000.short 68020-60.short 5475 5475.short
BUILD_FAST=$(shell if $(CC) -mfastcall -E - < /dev/null >/dev/null 2>&1; then echo Y; else echo N; fi)
ifeq ($(BUILD_FAST), Y)
ALL_LIBS += 68000.fastcall 68020-60.fastcall 68000.short.fastcall 68020-60.short.fastcall 5475.fastcall 5475.short.fastcall
ALL_LIBS += 68000.fastcall 68020-60.fastcall 68000.short.fastcall 68020-60.short.fastcall 5475.fastcall 5475.short.fastcall
endif

endif

all-here: $(foreach LIB, $(ALL_LIBS), .lib$(LIB)/libgem.a)
Expand All @@ -63,7 +77,7 @@ OBJS_$(1) = $(foreach FILE, $(COBJS) $(SOBJS), .lib$(1)/$(notdir $(basename $(FI
endef
define CC_TEMPLATE
.lib$(1)/$(notdir $(basename $(2))).o: $(2) mt_gem.h Makefile
$$(AM_V_CC)$$(CC) $$(CFLAGS_$(1)) $$(CFLAGS) -I$$(srcdir) -c -o $$@ $$<
$$(AM_V_CC)$$(CC) $$(CFLAGS_$(1)) $$(CFLAGS) $$(ARCH_INCLUDES) -I$$(srcdir) -c -o $$@ $$<
endef

$(foreach DIR,$(ALL_LIBS),$(eval $(call LIB_TEMPLATE,$(DIR))))
Expand Down Expand Up @@ -166,6 +180,27 @@ mt_gem.h: mt_gem.h.in VERSION
mv $(srcdir)/mt_gem.tmp $(srcdir)/mt_gem.h
# $(MOVEIFCHANGE) $(srcdir)/mt_gem.tmp $(srcdir)/mt_gem.h

ifeq ($(ARCH),arm)
install:
install -m 755 -d $(DESTDIR)$(PREFIX)/lib
install -m 644 .libarm/libgem.a $(DESTDIR)$(PREFIX)/lib/libgem.a
install -m 755 -d $(DESTDIR)$(PREFIX)/include
install -m 644 gem.h $(DESTDIR)$(PREFIX)/include
install -m 644 gemx.h $(DESTDIR)$(PREFIX)/include
install -m 644 mt_gem.h $(DESTDIR)$(PREFIX)/include
install -m 644 mt_gemx.h $(DESTDIR)$(PREFIX)/include
install -m 644 include/arm/compiler.h $(DESTDIR)$(PREFIX)/include

uninstall:
rm -f $(DESTDIR)$(PREFIX)/lib/libgem.a
rm -f $(DESTDIR)$(PREFIX)/include/gem.h
rm -f $(DESTDIR)$(PREFIX)/include/gemx.h
rm -f $(DESTDIR)$(PREFIX)/include/mt_gem.h
rm -f $(DESTDIR)$(PREFIX)/include/mt_gemx.h
rm -f $(DESTDIR)$(PREFIX)/include/compiler.h

else

install:
@for i in $(ALL_LIBS); do \
cpu=`echo $$i | cut -d . -f 1`; \
Expand Down Expand Up @@ -197,6 +232,8 @@ uninstall:
rm -f $(DESTDIR)$(PREFIX)/include/mt_gem.h
rm -f $(DESTDIR)$(PREFIX)/include/mt_gemx.h

endif


ifneq (clean,$(findstring clean,$(MAKECMDGOALS)))
DEPS_MAGIC := $(shell mkdir -p $(foreach LIB, $(ALL_LIBS), .lib$(LIB))) > /dev/null 2>&1 || :)
Expand Down
1 change: 1 addition & 0 deletions RULES
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ distdir: $(DISTFILES) distdir-local
mkdir -p $(distdir)
@for file in $(DISTFILES); do \
d=$(srcdir); \
mkdir -p `dirname $(distdir)/$$file` || exit 1; \
test -d $$d/$$file \
|| test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2>/dev/null \
Expand Down
12 changes: 12 additions & 0 deletions _gc_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
#ifdef __GNUC__
void aes(AESPB *pb)
{
#if defined(__arm__)
register long r0 __asm__("r0") = 200;
register AESPB *r1 __asm__("r1") = pb;

__asm__ __volatile__ (
"svc #2"
: "+r"(r0), "+r"(r1)
:
: "r2", "r3", "r7", "r12", "lr", "memory", "cc"
);
#else
register long d1 __asm__("d1") = (long)pb;

__asm__ __volatile__ (
Expand All @@ -12,5 +23,6 @@ void aes(AESPB *pb)
: "r"(d1)
: "d0", "d2", "a0", "a1", "a2", "memory", "cc"
);
#endif
}
#endif
42 changes: 42 additions & 0 deletions _gc_vdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@
#ifdef __GNUC__
void vdi(VDIPB *pb)
{
#if defined(__arm__)
typedef struct
{
short code, nptsin, nptsout, nintin, nintout, subcode, handle, pad;
void *ptr1, *ptr2;
} ARM_VDICONTROL;
ARM_VDICONTROL control;
VDIPB arm_pb;

control.code = pb->control[0];
control.nptsin = pb->control[1];
control.nptsout = pb->control[2];
control.nintin = pb->control[3];
control.nintout = pb->control[4];
control.subcode = pb->control[5];
control.handle = pb->control[6];
control.pad = 0;
control.ptr1 = vdi_control_get_ptr(pb->control, 0);
control.ptr2 = vdi_control_get_ptr(pb->control, 1);

arm_pb.control = (short *)&control;
arm_pb.intin = pb->intin;
arm_pb.ptsin = pb->ptsin;
arm_pb.intout = pb->intout;
arm_pb.ptsout = pb->ptsout;

__asm__ __volatile__ (
"mov r0, #0x73\n\t"
"mov r1, %0\n\t"
"svc #2"
:
: "r"(&arm_pb)
: "r0", "r1", "r2", "r3", "r7", "r12", "lr", "memory", "cc"
);

pb->control[2] = control.nptsout;
pb->control[4] = control.nintout;
pb->control[6] = control.handle;
vdi_control_set_ptr(pb->control, 0, control.ptr1);
vdi_control_set_ptr(pb->control, 1, control.ptr2);
#else
register long d1 __asm__("d1") = (long)pb;

__asm__ __volatile__ (
Expand All @@ -12,5 +53,6 @@ void vdi(VDIPB *pb)
: "r"(d1)
: "d0", "d2", "a0", "a1", "a2", "memory", "cc"
);
#endif
}
#endif
12 changes: 12 additions & 0 deletions _gc_vq_gdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
#ifdef __GNUC__
short vq_gdos(void)
{
#if defined(__arm__)
register long ret __asm__("r0") = -2;

__asm__ __volatile__ (
"svc #2"
: "+r"(ret)
:
: "r1", "r2", "r3", "r7", "r12", "lr", "memory", "cc"
);
return ret == -2 ? 0 : 1;
#else
register long ret __asm__("d0");

__asm__ __volatile__ (
Expand All @@ -19,5 +30,6 @@ short vq_gdos(void)
: "d1", "d2", "a0", "a1", "a2", "memory", "cc"
);
return ret;
#endif
}
#endif
12 changes: 12 additions & 0 deletions _gc_vq_vgdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
#ifdef __GNUC__
long vq_vgdos(void)
{
#if defined(__arm__)
register long ret __asm__("r0") = -2;

__asm__ __volatile__ (
"svc #2"
: "+r"(ret)
:
: "r1", "r2", "r3", "r7", "r12", "lr", "memory", "cc"
);
return ret;
#else
register long ret __asm__("d0");

__asm__ __volatile__ (
Expand All @@ -13,5 +24,6 @@ long vq_vgdos(void)
: "d1", "d2", "a0", "a1", "a2", "memory", "cc"
);
return (short)ret == -2 ? (short)ret : ret;
#endif
}
#endif
11 changes: 11 additions & 0 deletions a__appl_yield.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@
#ifdef __GNUC__
void _appl_yield(void)
{
#if defined(__arm__)
register long r0 __asm__("r0") = 201;

__asm__ volatile (
"svc #2"
: "+r"(r0)
:
: "r1", "r2", "r3", "r7", "r12", "lr", "memory", "cc"
);
#else
__asm__ volatile (
"move.w #201,%%d0\n\t"
"trap #2"
:
:
: "d0","d1","d2","a0","a1","a2","memory","cc"
);
#endif
}
#endif

Expand Down
15 changes: 15 additions & 0 deletions gem_aesP.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@

#if defined(__GNUC__) && !defined(__NO_INLINE__)

#if defined(__arm__)

static inline void
_aes_trap(AESPB *aespb)
{
/* pTOS ARM passes the AES opcode in r0 and the parameter block in r1. */
aes(aespb);
}

#define AES_TRAP(aespb) _aes_trap(&aespb)

#else

static inline void
_aes_trap (AESPB * aespb)
{
Expand All @@ -35,6 +48,8 @@ _aes_trap (AESPB * aespb)
}
#define AES_TRAP(aespb) _aes_trap(&aespb)

#endif

#else

#if defined(__VBCC__)
Expand Down
57 changes: 57 additions & 0 deletions gem_vdiP.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@

#if defined(__GNUC__) && !defined(__NO_INLINE__)

#if defined(__arm__)

static inline void
_vdi_trap_esc(VDIPB *vdipb, long cntrl_0_1, long cntrl_2_3,
long cntrl_4_5, short handle)
{
short *control = vdipb->control;

control[0] = (short)(cntrl_0_1 >> 16);
control[1] = (short)cntrl_0_1;
control[2] = (short)(cntrl_2_3 >> 16);
control[3] = (short)cntrl_2_3;
control[4] = (short)(cntrl_4_5 >> 16);
control[5] = (short)cntrl_4_5;
control[6] = handle;
vdi(vdipb);
}

#define VDI_TRAP_ESC(vdipb, handle, opcode, subop, nptsin, nintin) \
_vdi_trap_esc(&vdipb, (opcode##uL << 16) | nptsin, nintin, subop, handle)

static inline void
_vdi_trap_00(VDIPB *vdipb, long cntrl_0_1, short handle)
{
_vdi_trap_esc(vdipb, cntrl_0_1, 0, 0, handle);
}

#define VDI_TRAP_00(vdipb, handle, opcode) \
_vdi_trap_00(&vdipb, (opcode##uL << 16), handle)

#else

static inline void
_vdi_trap_esc (VDIPB * vdipb,
long cntrl_0_1, long cntrl_2_3, long cntrl_4_5, short handle)
Expand Down Expand Up @@ -64,6 +96,7 @@ _vdi_trap_00 (VDIPB * vdipb, long cntrl_0_1, short handle)
#define VDI_TRAP_00(vdipb, handle, opcode) \
_vdi_trap_00 (&vdipb, (opcode##uL<<16), handle)

#endif

#else

Expand Down Expand Up @@ -155,6 +188,30 @@ __regsused("d0/d1/a0/a1") void _vdi_trap_00(

#define N_PTRINTS (sizeof(void *) / sizeof(short))

/* Avoid unaligned control[7..] pointer access. */
static __inline void
vdi_control_set_ptr(short *control, short n, const void *value)
{
unsigned char *dest = (unsigned char *)control + (7 + n * N_PTRINTS) * sizeof(*control);
const unsigned char *source = (const unsigned char *)&value;
unsigned long i;

for (i = 0; i < sizeof(value); i++)
dest[i] = source[i];
}

static __inline void *
vdi_control_get_ptr(const short *control, short n)
{
void *value;
const unsigned char *source = (const unsigned char *)control + (7 + n * N_PTRINTS) * sizeof(*control);
unsigned char *dest = (unsigned char *)&value;
unsigned long i;

for (i = 0; i < sizeof(value); i++)
dest[i] = source[i];
return value;
}
#ifdef __GNUC__

/* to avoid "dereferencing type-punned pointer" */
Expand Down
14 changes: 14 additions & 0 deletions include/arm/compiler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef _GEMLIB_ARM_COMPILER_H
#define _GEMLIB_ARM_COMPILER_H

#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
#else
#define __BEGIN_DECLS
#define __END_DECLS
#endif

#define __CDECL

#endif
10 changes: 10 additions & 0 deletions mt_gem.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -2050,13 +2050,23 @@ typedef struct cicon_blk
/** Bit Field OBject SPECification */
typedef struct
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
unsigned interiorcol : 4; /**< color of interior */
unsigned fillpattern : 3; /**< fill pattern index */
unsigned textmode : 1; /**< transparent or replace */
unsigned textcol : 4; /**< color of text */
unsigned framecol : 4; /**< color of frame */
signed framesize : 8; /**< size of frame */
unsigned character : 8; /**< character to display (BOXCHAR) */
#else
unsigned character : 8; /**< character to display (BOXCHAR) */
signed framesize : 8; /**< size of frame */
unsigned framecol : 4; /**< color of frame */
unsigned textcol : 4; /**< color of text */
unsigned textmode : 1; /**< transparent or replace */
unsigned fillpattern : 3; /**< fill pattern index */
unsigned interiorcol : 4; /**< color of interior */
#endif
} BFOBSPEC;

/** User block */
Expand Down
Loading