Skip to content
Open
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
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,22 @@ else ifneq (,$(findstring RK,$(platform)))
else ifneq (,$(findstring osx,$(platform)))
TARGET := $(TARGET_NAME)_libretro.dylib
LDFLAGS += -dynamiclib
SYSTEM_ZLIB = 1
OSXVER = `sw_vers -productVersion | cut -d. -f 2`
OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"`
LDFLAGS += -mmacosx-version-min=10.7
LDFLAGS += -stdlib=libc++

PLATCFLAGS += -D__MACOSX__ -DOSX -DOS_MAC_OS_X -DHAVE_UNISTD_H=1 -DHAVE_POSIX_MEMALIGN -DNO_ASM -DGL_SILENCE_DEPRECATION=1
PLATCFLAGS += -D__MACOSX__ -DOSX -DOS_MAC_OS_X -DHAVE_UNISTD_H=1 -DHAVE_POSIX_MEMALIGN -DGL_SILENCE_DEPRECATION=1
GL_LIB := -framework OpenGL
LDFLAGS += -framework AudioToolbox

# Target Dynarec
WITH_DYNAREC =
ifeq ($(ARCH), $(filter $(ARCH), arm64 aarch64))
WITH_DYNAREC = aarch64
else
WITH_DYNAREC =
endif

HAVE_PARALLEL_RSP = 1
HAVE_PARALLEL_RDP = 1
Expand Down
4 changes: 3 additions & 1 deletion custom/dependencies/libpng/pngpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@
*/
# include <float.h>

# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
# if defined(__APPLE__)
# include <math.h>
# elif (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
/* We need to check that <math.h> hasn't already been included earlier
* as it seems it doesn't agree with <fp.h>, yet we should really use
Expand Down
46 changes: 32 additions & 14 deletions mupen64plus-core/src/device/r4300/new_dynarec/arm64/assem_arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static const uintptr_t jump_vaddr_reg[32] = {
(intptr_t)jump_vaddr_x15,
(intptr_t)jump_vaddr_x16,
(intptr_t)jump_vaddr_x17,
(intptr_t)breakpoint, /*trampoline jumps uses x18*/
(intptr_t)breakpoint, /*x18 is platform-reserved (no jump_vaddr_x18 thunk)*/
(intptr_t)jump_vaddr_x19,
(intptr_t)breakpoint, /*cycle count*/
(intptr_t)jump_vaddr_x21,
Expand Down Expand Up @@ -263,7 +263,17 @@ static uintptr_t jump_table_symbols[] = {

static void cache_flush(char* start, char* end)
{
#ifndef WIN32
#if defined(__APPLE__) && defined(__aarch64__)
// Apple-documented MAP_JIT pattern: switch to executable, then invalidate icache.
jit_write_disable();
sys_icache_invalidate(start, end - start);
jit_write_enable();
#elif defined(__APPLE__)
__builtin___clear_cache(start, end);
#elif defined(__APPLE__)
sys_dcache_flush(start, end - start);
sys_icache_invalidate(start, end - start);
#elif !defined(WIN32)
// Don't rely on GCC's __clear_cache implementation, as it caches
// icache/dcache cache line sizes, that can vary between cores on
// big.LITTLE architectures.
Expand Down Expand Up @@ -356,7 +366,7 @@ static void *kill_pointer(void *stub)
int *i_ptr=(int*)((intptr_t)ptr+offset);
assert((*i_ptr&0xfc000000)==0x14000000); //b
set_jump_target((intptr_t)i_ptr,(intptr_t)stub);

intptr_t ptr_rx=((intptr_t)i_ptr-(intptr_t)base_addr)+(intptr_t)base_addr_rx;
cache_flush((void*)ptr_rx, (void*)(ptr_rx+4));
return i_ptr;
Expand Down Expand Up @@ -439,7 +449,7 @@ static void alloc_reg(struct regstat *cur,int i,signed char tr)
// registers that have not been used recently.
if(i>0) {
for(hr=0;hr<HOST_REGS;hr++) {
if(hr!=EXCLUDE_REG&&cur->regmap[hr]==-1) {
if(!IS_REG_EXCLUDED(hr)&&cur->regmap[hr]==-1) {
if(regs[i-1].regmap[hr]!=rs1[i-1]&&regs[i-1].regmap[hr]!=rs2[i-1]&&regs[i-1].regmap[hr]!=rt1[i-1]&&regs[i-1].regmap[hr]!=rt2[i-1]) {
cur->regmap[hr]=tr;
cur->dirty&=~(1<<hr);
Expand All @@ -451,7 +461,7 @@ static void alloc_reg(struct regstat *cur,int i,signed char tr)
}
// Try to allocate any available register
for(hr=0;hr<HOST_REGS;hr++) {
if(hr!=EXCLUDE_REG&&cur->regmap[hr]==-1) {
if(!IS_REG_EXCLUDED(hr)&&cur->regmap[hr]==-1) {
cur->regmap[hr]=tr;
cur->dirty&=~(1<<hr);
cur->isconst&=~(1<<hr);
Expand Down Expand Up @@ -603,7 +613,7 @@ static void alloc_reg64(struct regstat *cur,int i,signed char tr)
// registers that have not been used recently.
if(i>0) {
for(hr=0;hr<HOST_REGS;hr++) {
if(hr!=EXCLUDE_REG&&cur->regmap[hr]==-1) {
if(!IS_REG_EXCLUDED(hr)&&cur->regmap[hr]==-1) {
if(regs[i-1].regmap[hr]!=rs1[i-1]&&regs[i-1].regmap[hr]!=rs2[i-1]&&regs[i-1].regmap[hr]!=rt1[i-1]&&regs[i-1].regmap[hr]!=rt2[i-1]) {
cur->regmap[hr]=tr|64;
cur->dirty&=~(1<<hr);
Expand All @@ -615,7 +625,7 @@ static void alloc_reg64(struct regstat *cur,int i,signed char tr)
}
// Try to allocate any available register
for(hr=0;hr<HOST_REGS;hr++) {
if(hr!=EXCLUDE_REG&&cur->regmap[hr]==-1) {
if(!IS_REG_EXCLUDED(hr)&&cur->regmap[hr]==-1) {
cur->regmap[hr]=tr|64;
cur->dirty&=~(1<<hr);
cur->isconst&=~(1<<hr);
Expand Down Expand Up @@ -714,12 +724,12 @@ static void alloc_reg_temp(struct regstat *cur,int i,signed char tr)
// see if it's already allocated
for(hr=0;hr<HOST_REGS;hr++)
{
if(hr!=EXCLUDE_REG&&cur->regmap[hr]==tr) return;
if(!IS_REG_EXCLUDED(hr)&&cur->regmap[hr]==tr) return;
}

// Try to allocate any available register
for(hr=HOST_REGS-1;hr>=0;hr--) {
if(hr!=EXCLUDE_REG&&cur->regmap[hr]==-1) {
if(!IS_REG_EXCLUDED(hr)&&cur->regmap[hr]==-1) {
cur->regmap[hr]=tr;
cur->dirty&=~(1<<hr);
cur->isconst&=~(1<<hr);
Expand Down Expand Up @@ -833,7 +843,7 @@ static void alloc_arm64_reg(struct regstat *cur,int i,signed char tr,int hr)
// see if it's already allocated (and dealloc it)
for(n=0;n<HOST_REGS;n++)
{
if(n!=EXCLUDE_REG&&cur->regmap[n]==tr) {
if(!IS_REG_EXCLUDED(n)&&cur->regmap[n]==tr) {
dirty=(cur->dirty>>n)&1;
cur->regmap[n]=-1;
}
Expand Down Expand Up @@ -4522,7 +4532,7 @@ static void do_miniht_jump(int rs,int rh,int ht) {
intptr_t jaddr=(intptr_t)out;
emit_jeq(0);
if(rs==18) {
// x18 is used for trampoline jumps, move it to another register (x0)
// x18 has no jump_vaddr_x18 thunk; move it to x0 for dispatch.
emit_mov(rs,0);
rs=0;
}
Expand Down Expand Up @@ -4608,22 +4618,30 @@ static void arch_init(void) {
ptr=(intptr_t *)jump_table_symbols;
ptr2=(intptr_t *)((char *)base_addr+(1<<TARGET_SIZE_2)-JUMP_TABLE_SIZE);
ptr3=(intptr_t *)((char *)base_addr_rx+(1<<TARGET_SIZE_2)-JUMP_TABLE_SIZE);
jit_write_enable();
while((char *)ptr<(char *)jump_table_symbols+sizeof(jump_table_symbols))
{
int *ptr4=(int*)ptr2;
intptr_t target = *ptr;
/* x18 is platform-reserved on Apple arm64.
Default to x17 for trampolines, but preserve x17 when the target
itself is jump_vaddr_x17 (it consumes w17 as input). */
int tramp_reg = (target == (intptr_t)jump_vaddr_x17) ? 16 : 17;
intptr_t offset=*ptr-(intptr_t)ptr3;
if(offset>=-134217728LL&&offset<134217728LL) {
*ptr4=0x14000000|((offset>>2)&0x3ffffff); // direct branch
}else{
*ptr4=0x58000000|((8>>2)<<5)|18; // ldr x18,[pc,#8]
*(ptr4+1)=0xd61f0000|(18<<5);
*ptr4=0x58000000|((8>>2)<<5)|tramp_reg; // ldr xN,[pc,#8]
*(ptr4+1)=0xd61f0000|(tramp_reg<<5); // br xN
}
ptr2++;
*ptr2=*ptr;
ptr++;
ptr2++;
ptr3+=2;
}
jit_write_disable();

__clear_cache((char *)base_addr+(1<<TARGET_SIZE_2)-JUMP_TABLE_SIZE,(char *)base_addr+(1<<TARGET_SIZE_2));
// Flush icache for the RX mapping where code will actually execute
__clear_cache((char *)base_addr_rx+(1<<TARGET_SIZE_2)-JUMP_TABLE_SIZE,(char *)base_addr_rx+(1<<TARGET_SIZE_2));
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#define HOST_CCREG 20 /* callee-save */
#define HOST_BTREG 19 /* callee-save */
#define EXCLUDE_REG 29 /* FP */
#if defined(__APPLE__)
/* x18 is the platform-reserved register on Apple arm64; the OS may
modify it at any time (thread-local storage, signal handlers, etc.).
The JIT must never allocate it for guest registers. */
#define IS_REG_EXCLUDED(hr) ((hr)==EXCLUDE_REG||(hr)==18)
#else
#define IS_REG_EXCLUDED(hr) ((hr)==EXCLUDE_REG)
#endif

//#define DISABLE_BLOCK_LINKING 1
#define NATIVE_64 1
Expand Down
Loading