Skip to content

Commit

Permalink
[Switch] attempt to make pointer arithmetic 64bit compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Oct 31, 2018
1 parent 6234740 commit 494ea97
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 274 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Expand Up @@ -206,6 +206,7 @@ if(BUILD_NX)
-DGP2X
-DPANDORA
-D__SWITCH__
-D__64BIT__
-DUSE_AUTOCONFIG
-DUSE_ZFILE
-DUSE_FAME_CORE
Expand All @@ -232,19 +233,17 @@ if(BUILD_NX)
-mtune=cortex-a57
-mtp=soft
-fPIE
-fpermissive
-O0
-ffast-math
# -ffast-math
-fno-asynchronous-unwind-tables
-funroll-loops
-fno-unwind-tables
-fno-optimize-sibling-calls
-funsafe-math-optimizations
-mlittle-endian
-ffunction-sections
-fno-rtti
-fno-exceptions
# -mabi=ilp32
# -ffunction-sections
# -fno-rtti
# -fno-exceptions
)

set(LIBS
Expand Down
4 changes: 2 additions & 2 deletions src/audio.cpp
Expand Up @@ -60,10 +60,10 @@ typedef uae_s8 sample8_t;
#define CHECK_SOUND_BUFFERS() \
{ \
if(mainMenu_soundStereo) { \
if ((unsigned)sndbufpt - (unsigned)render_sndbuff >= SNDBUFFER_LEN*2) { \
if ((hostptr)sndbufpt - (hostptr)render_sndbuff >= SNDBUFFER_LEN*2) { \
finish_sound_buffer (); } \
} else { \
if ((unsigned)sndbufpt - (unsigned)render_sndbuff >= SNDBUFFER_LEN) { \
if ((hostptr)sndbufpt - (hostptr)render_sndbuff >= SNDBUFFER_LEN) { \
finish_sound_buffer (); } \
} \
} \
Expand Down
4 changes: 2 additions & 2 deletions src/disk.cpp
Expand Up @@ -1578,7 +1578,7 @@ uae_u8 *restore_disk(int num,uae_u8 *src)
}
}

src = (uae_u8 *)(((unsigned)src)+strlen((char *)src) + 1);
src = (uae_u8 *)(((hostptr)src)+strlen((char *)src) + 1);

return src;
}
Expand Down Expand Up @@ -1613,7 +1613,7 @@ uae_u8 *save_disk(int num,int *len)
dst[0]=dst[1]=0;
}

dst = (uae_u8 *)(((unsigned)dst)+strlen((char *)dst) + 1);
dst = (uae_u8 *)(((hostptr)dst)+strlen((char *)dst) + 1);
*len = dst - dstbak;
return dstbak;
}
Expand Down
10 changes: 7 additions & 3 deletions src/filesys.cpp
Expand Up @@ -444,7 +444,11 @@ struct hardfiledata *get_hardfile_data (int nr)
#define dp_Arg4 32

/* result codes */
#ifdef __64BIT__
#define DOS_TRUE ((unsigned)-1L)
#else
#define DOS_TRUE ((unsigned long)-1L)
#endif
#define DOS_FALSE (0L)

/* Passed as type to Lock() */
Expand Down Expand Up @@ -2106,15 +2110,15 @@ action_read (Unit *unit, dpacket packet)
* If realpt is at odd address, we have to swab the first word.
* That word will be re-swabbed after data has been read.
*/
if (((int)realpt & 1) > 0)
swab_memory ((unsigned char *)((int)realpt & ~1), 2);
if (((hostptr)realpt & 1) > 0)
swab_memory ((unsigned char *)((hostptr)realpt & ~1), 2);

actual = read(k->fd, (char *)realpt, size);

/* If realpt is at odd address, we also have to swab the
* word in which the last byte has been written.
*/
swab_memory((unsigned char *)((int)realpt & ~1), (((actual + 1) & ~1) + ((int)realpt & 1)) & ~1);
swab_memory((unsigned char *)((hostptr)realpt & ~1), (((actual + 1) & ~1) + ((hostptr)realpt & 1)) & ~1);
#else
actual = read(k->fd, (char *) realpt, size);
#endif
Expand Down
5 changes: 5 additions & 0 deletions src/gui.cpp
Expand Up @@ -551,7 +551,12 @@ void getMapping(int customId)

void gui_handle_events (void)
{
#ifdef USE_SDL2
//Uint8 *keystate = (Uint8 *)((hostptr) SDL_GetKeyboardState(NULL));
Uint8 *keystate=const_cast<Uint8*>(SDL_GetKeyboardState(NULL));
#else
Uint8 *keystate = SDL_GetKeyState(NULL);
#endif
#if defined(__PSP2__) || defined(__SWITCH__)
SDL_JoystickUpdate();
SDL_Joystick *currentJoy = uae4all_joy0;
Expand Down
14 changes: 7 additions & 7 deletions src/include/maccess.h
Expand Up @@ -22,7 +22,7 @@ static __inline__ uae_u32 do_get_mem_long(uae_u32 *_GCCRES_ a)
* - read long from 0x00000001 : 0xee110033 (unswabbed data, eg. Amiga register)
*/
b = do_get_mem_word((uae_u16 *)a) << 16;
b |= do_get_mem_word((uae_u16 *)((uae_u32)a + 2));
b |= do_get_mem_word((uae_u16 *)((hostptr)a + 2));
return b;
#else
uae_u8 *b = (uae_u8 *)a;
Expand All @@ -35,13 +35,13 @@ static __inline__ uae_u16 do_get_mem_word(uae_u16 *_GCCRES_ a)
{
#ifdef USE_FAME_CORE
/* ! 68020+ CPUs can read/write words and longs at odd addresses ! */
if ((uae_u32)a & 1) {
if ((hostptr)a & 1) {
/* Example:
* - memory loc. 0x00000000 : 0xeeff0011 (word-swabbed data)
* - read word from 0x00000001 : 0xee11 (unswabbed data)
*/
register uae_u32 b;
b = *((uae_u32 *)((uae_u32)a ^ 1));
b = *((uae_u32 *)((hostptr)a ^ 1));
b = (b << 8) | (b >> 24);
return (uae_u16)b;
}
Expand All @@ -59,7 +59,7 @@ static __inline__ uae_u16 do_get_mem_word(uae_u16 *_GCCRES_ a)
static __inline__ uae_u8 do_get_mem_byte(uae_u8 *_GCCRES_ a)
{
#ifdef USE_FAME_CORE
a= (uae_u8 *)(((unsigned)a)^1);
a= (uae_u8 *)(((hostptr)a)^1);
#endif

return *a;
Expand All @@ -74,7 +74,7 @@ static __inline__ void do_put_mem_long(uae_u32 *_GCCRES_ a, uae_u32 v)
* - write 0x22334455 to 0x00000001 : 0x22ff4433 0xnn55...
*/
do_put_mem_word((uae_u16 *)a, v >> 16);
do_put_mem_word((uae_u16 *)((uae_u32)a + 2), v);
do_put_mem_word((uae_u16 *)((hostptr)a + 2), v);
#else
uae_u8 *b = (uae_u8 *)a;

Expand All @@ -89,7 +89,7 @@ static __inline__ void do_put_mem_word(uae_u16 *_GCCRES_ a, uae_u16 v)
{
#ifdef USE_FAME_CORE
/* ! 68020+ CPUs can read/write words and longs at odd addresses ! */
if ((uae_u32)a & 1) {
if ((hostptr)a & 1) {
/* Example:
* - memory loc. 0x00000000 : 0xeeff0011 (word-swabbed data)
* - write 0x2233 to 0x00000001 : 0x22ff0033
Expand All @@ -111,7 +111,7 @@ static __inline__ void do_put_mem_word(uae_u16 *_GCCRES_ a, uae_u16 v)
static __inline__ void do_put_mem_byte(uae_u8 *_GCCRES_ a, uae_u8 v)
{
#ifdef USE_FAME_CORE
a= (uae_u8 *)(((unsigned)a)^1);
a= (uae_u8 *)(((hostptr)a)^1);
#endif

*a = v;
Expand Down
26 changes: 24 additions & 2 deletions src/include/sysdeps.h
Expand Up @@ -194,6 +194,25 @@ typedef signed char uae_s8;

typedef struct { uae_u8 RGB[3]; } RGB;

#ifdef __64BIT__
typedef uint16_t uae_u16;
typedef int16_t uae_s16;

typedef uint32_t uae_u32;
typedef int32_t uae_s32;

#undef uae_s64
#undef uae_u64

#define uae_s64 int64_t
#define uae_u64 uint64_t
#define VAL64(a) (a)
#define UVAL64(a) (a)

typedef uae_u32 uaecptr;
typedef uae_u64 hostptr;

#else

#if SIZEOF_SHORT == 2
typedef unsigned short uae_u16;
Expand All @@ -215,8 +234,6 @@ typedef long uae_s32;
#error No 4 byte type, you lose.
#endif

typedef uae_u32 uaecptr;

#undef uae_s64
#undef uae_u64

Expand All @@ -237,6 +254,11 @@ typedef uae_u32 uaecptr;
#define UVAL64(a) (a ## ul)
#endif

typedef uae_u32 uaecptr;
typedef uae_u32 hostptr;

#endif

#ifdef HAVE_STRDUP
#define my_strdup strdup
#else
Expand Down
17 changes: 17 additions & 0 deletions src/m68k/fame/fame.h
Expand Up @@ -98,6 +98,21 @@
#undef s32
#endif

#ifdef __64BIT__
#define u8 uint8_t
#define s8 int8_t
#define u16 uint16_t
#define s16 int16_t
#define u32 uint32_t
#define s32 int32_t

#define u64 uint64_t
#define s64 int64_t

#define hostptr u64

#else

#define u8 unsigned char
#define s8 signed char
#define u16 unsigned short
Expand All @@ -108,6 +123,8 @@
#define u64 unsigned long long
#define s64 long long

#define hostptr u32
#endif

/* M68K registers */
typedef enum {
Expand Down
26 changes: 13 additions & 13 deletions src/m68k/fame/famec.cpp
Expand Up @@ -4,7 +4,7 @@
/* Autor: Oscar Orallo Pelaez */
/* Fecha de comienzo: 03-10-2006 */
/* Ultima actualizacion: 08-10-2006 */
/* Based on the excellent FAMEC emulator by Stèphane Dallongueville */
/* Based on the excellent FAMEC emulator by St�phane Dallongueville */
/****************************************************************************/

#include <stdio.h>
Expand Down Expand Up @@ -222,11 +222,11 @@ M68K_CONTEXT m68kcontext;
#define M68K_PPL (m68kcontext.sr >> 8) & 7

#define GET_PC \
(u32)PC - BasePC;
(hostptr)PC - BasePC;

#define SET_PC(A) \
BasePC = Fetch[((A) >> M68K_FETCHSFT) & M68K_FETCHMASK]; \
PC = (u16*)(((A) & M68K_ADR_MASK) + BasePC);
PC = (u16*)((hostptr)(((A) & M68K_ADR_MASK) + BasePC));

#define READ_BYTE_F(A, D) \
D = Read_Byte(A) /*& 0xFF*/;
Expand Down Expand Up @@ -507,7 +507,7 @@ static __attribute__ ((noinline)) u8 Read_Byte(u32 addr)
if (mem_handlerRB[i])
val = ((u8 (*)(s32))mem_handlerRB[i])(addr);
else {
val = *((u8 *)(((u32)mem_data[i]) + (addr^1)));
val = *((u8 *)(((hostptr)mem_data[i]) + (addr^1)));
}

return val;
Expand All @@ -533,14 +533,14 @@ static __attribute__ ((noinline)) u16 Read_Word(u32 addr)
* - read word from 0x00000001 : 0xee11 (unswabbed data)
*/
register u32 b;
b = *((u32 *)(((u32)mem_data[i]) + (addr ^ 1)));
b = *((u32 *)(((hostptr)mem_data[i]) + (addr ^ 1)));
val = (b << 8) | (b >> 24);
// u8 *pdata = (u8 *)((u32)DataWW[i].data + addr);
// val = *(pdata - 1) << 8;
// val |= *(pdata + 2);
}
else {
val = *((u16 *)(((u32)mem_data[i]) + addr));
val = *((u16 *)(((hostptr)mem_data[i]) + addr));
}
}

Expand All @@ -563,7 +563,7 @@ static __attribute__ ((noinline)) void Write_Byte(u32 addr, u8 data)
if (mem_handlerWB[i] != NULL)
((void (*)(s32, s32))mem_handlerWB[i])(addr,data);
else {
*((u8 *)(((u32)mem_data[i]) + (addr^1))) = data;
*((u8 *)(((hostptr)mem_data[i]) + (addr^1))) = data;
}
}

Expand All @@ -581,7 +581,7 @@ static __attribute__ ((noinline)) void Write_Word(u32 addr, u16 data)
}
else {
if (unlikely(addr & 1)) {
u8 *pdata = (u8 *)((u32)mem_data[i] + addr);
u8 *pdata = (u8 *)((hostptr)mem_data[i] + addr);

/* Example:
* - memory loc. 0x00000000 : 0xeeff0011 (word-swabbed data)
Expand All @@ -591,7 +591,7 @@ static __attribute__ ((noinline)) void Write_Word(u32 addr, u16 data)
*(pdata + 2) = data;
}
else {
*((u16 *)(((u32)mem_data[i]) + addr)) = data;
*((u16 *)(((hostptr)mem_data[i]) + addr)) = data;
}
}
}
Expand Down Expand Up @@ -695,7 +695,7 @@ M68K_CONTEXT *m68k_get_context(void)
/****************************************************************************/
u32 m68k_get_pc(void)
{
return (m68kcontext.execinfo & M68K_RUNNING)?(u32)PC-BasePC:m68kcontext.pc;
return (m68kcontext.execinfo & M68K_RUNNING)?(hostptr)PC-BasePC:m68kcontext.pc;
}

/***********************************************************************/
Expand Down Expand Up @@ -777,7 +777,7 @@ s32 m68k_fetch(u32 addr)
u16 *ptr;

Base = Fetch[(addr >> M68K_FETCHSFT) & M68K_FETCHMASK];
ptr = (u16*)((addr & M68K_ADR_MASK) + Base);
ptr = (u16*)((hostptr)((addr & M68K_ADR_MASK) + Base));
val = *ptr;

return val;
Expand Down Expand Up @@ -857,7 +857,7 @@ static FAMEC_EXTRA_INLINE s32 interrupt_chk__(M68K_CONTEXT &m68kcontext)
void process_exception(unsigned int vect)
{
u32 newPC;
u32 oldPC = (u32)(PC) - BasePC;
u32 oldPC = (hostptr)(PC) - BasePC;
u32 oldSR = GET_SR;

// TomB 02.12.2013: 68000 reference manual says, trace-flag is always cleared
Expand Down Expand Up @@ -943,7 +943,7 @@ static FAMEC_EXTRA_INLINE void execute_exception(s32 vect)
{
m68kcontext.sr = GET_SR;
m68kcontext.pc = GET_PC;
icust_handler_func salto=(icust_handler_func)m68kcontext.icust_handler[vect];
icust_handler_func salto=(icust_handler_func)((hostptr)m68kcontext.icust_handler[vect]);
salto(vect);
}
else
Expand Down

0 comments on commit 494ea97

Please sign in to comment.