Work on 64-bit support

parent ab673449
......@@ -31,6 +31,7 @@
#define __I_PROCDEF_ST_H
#include "instance_st.h"
#include <stdint.h>
/* Process definitions, more simple than in the compiler */
......@@ -54,7 +55,7 @@ typedef struct _procdef {
int string_count;
int pubstring_count;
int params;
intptr_t params;
int id;
int type;
int flags;
......@@ -70,13 +71,13 @@ typedef struct _procdef {
/* System functions */
typedef int SYSFUNC(INSTANCE *, int *);
typedef int SYSFUNC(INSTANCE *, intptr_t *);
typedef struct _sysproc {
int code;
char *name;
char *paramtypes;
int type;
int params;
intptr_t params;
SYSFUNC *func;
int id;
} SYSPROC;
......
......@@ -37,6 +37,8 @@
#define STACK_SIZE_MASK 0x7FFF
#define STACK_SIZE 2048
#include <stdint.h>
/* Instancias. Una instancia se crea a partir de un proceso, pero en
* realidad es independiente del proceso original */
......@@ -88,8 +90,8 @@ typedef struct _instance {
/* The first integer at the stack is the stack size,
with optional NO_RETURN_VALUE mask. The stack contents follows */
int *stack;
int *stack_ptr;
intptr_t *stack;
intptr_t *stack_ptr;
/* For debugging */
......
......@@ -37,6 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>
......@@ -195,21 +196,21 @@ static int copytype(void *dst, void *src, DCB_TYPEDEF *var) {
* Copy struct data from src to dst, using the information varspace given
**/
int pxt_copy_struct(INSTANCE *my, int *params) {
int pxt_copy_struct(INSTANCE *my, intptr_t *params) {
return copytypes((void *)params[0], (void *)params[1], (DCB_TYPEDEF *)params[2], params[3],
params[4]);
}
int pxt_internal_memcopy(INSTANCE *my, int *params) {
memmove((void *)params[0], (void *)params[1], params[2]);
int pxt_internal_memcopy(INSTANCE *my, intptr_t *params) {
memmove((void *)params[0], (void *)params[1], (size_t)params[2]);
return 1;
}
int pxt_internal_copy_string_array(INSTANCE *my, int *params) {
int n = params[2];
int pxt_internal_copy_string_array(INSTANCE *my, intptr_t *params) {
intptr_t n = params[2];
while (n--) {
((int *)(params[0]))[n] = ((int *)(params[1]))[n];
string_use(((int *)(params[0]))[n]);
((intptr_t *)(params[0]))[n] = ((intptr_t *)(params[1]))[n];
string_use( ((int *)(params[0]))[n] );
}
return 1;
......
......@@ -196,8 +196,9 @@ int instance_go_all() {
/* ---------------------------------------------------------------------- */
int instance_go(INSTANCE *r) {
if (!r)
if (!r) {
return 0;
}
register int *ptr = r->codeptr;
......@@ -256,10 +257,12 @@ int instance_go(INSTANCE *r) {
if (debug_DCB > 0) {
if (debug_DCB > 2) {
int c = 45 - stack_dump(r) * 9;
if (debug_DCB > 1)
if (debug_DCB > 1) {
PXTRTM_LOG("%*.*s[%4u] ", c, c, "", (ptr - r->code));
} else if (debug_DCB > 1)
}
} else if (debug_DCB > 1) {
PXTRTM_LOG("[%4u] ", (ptr - r->code));
}
mnemonic_dump(*ptr, ptr[1]);
}
......@@ -323,8 +326,9 @@ int instance_go(INSTANCE *r) {
assert(i);
for (n = 0; n < proc->params; n++)
for (n = 0; n < proc->params; n++) {
PRIDWORD(i, 4 * n) = r->stack_ptr[-proc->params + n];
}
r->stack_ptr -= proc->params;
......@@ -360,10 +364,11 @@ int instance_go(INSTANCE *r) {
r->codeptr = ptr;
/* If it don't was a CALL, then I set a flag in "len" for no return value */
if (ptr[-2] == MN_CALL)
if (ptr[-2] == MN_CALL) {
r->stack[0] |= STACK_RETURN_VALUE;
else
} else {
r->stack[0] &= ~STACK_RETURN_VALUE;
}
if (debug_next && trace_sentence != -1) {
force_debug = 1;
......@@ -374,8 +379,9 @@ int instance_go(INSTANCE *r) {
/* Wake up! */
LOCDWORD(r, STATUS) &= ~STATUS_WAITING_MASK;
if (child_is_alive)
if (child_is_alive) {
i->called_by = NULL;
}
break;
}
......
......@@ -27,8 +27,9 @@
*
*/
#include <loadlib.h> /* Must be fist include */
#include <loadlib.h> /* Must be first include */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -42,9 +43,9 @@
/* ---------------------------------------------------------------------- */
extern int pxt_copy_struct(INSTANCE *my, int *params);
extern int pxt_internal_memcopy(INSTANCE *my, int *params);
extern int pxt_internal_copy_string_array(INSTANCE *my, int *params);
extern int pxt_copy_struct(INSTANCE *my, intptr_t *params);
extern int pxt_internal_memcopy(INSTANCE *my, intptr_t *params);
extern int pxt_internal_copy_string_array(INSTANCE *my, intptr_t *params);
#include "sysprocs.h"
#include "sysprocs_p.h"
......
......@@ -120,7 +120,7 @@ static int kernel_version_type(void) {
* and may or may not be an approximation.
*/
int modmem_memory_free(INSTANCE *my, int *params) {
int modmem_memory_free(INSTANCE *my, intptr_t *params) {
#ifdef WIN32
MEMORYSTATUS mem;
GlobalMemoryStatus(&mem);
......@@ -154,7 +154,7 @@ int modmem_memory_free(INSTANCE *my, int *params) {
* Return total number of bytes of physical memory
*/
int modmem_memory_total(INSTANCE *my, int *params) {
int modmem_memory_total(INSTANCE *my, intptr_t *params) {
#ifdef WIN32
MEMORYSTATUS mem;
GlobalMemoryStatus(&mem);
......@@ -200,36 +200,37 @@ int modmem_memory_total(INSTANCE *my, int *params) {
#endif
}
int modmem_memcmp(INSTANCE *my, int *params) {
return (memcmp((void *)params[0], (void *)params[1], params[2]));
int modmem_memcmp(INSTANCE *my, intptr_t *params) {
return (memcmp((void *)params[0], (void *)params[1], (size_t)params[2]));
}
int modmem_memmove(INSTANCE *my, int *params) {
memmove((void *)params[0], (void *)params[1], params[2]);
int modmem_memmove(INSTANCE *my, intptr_t *params) {
memmove((void *)params[0], (void *)params[1], (size_t)params[2]);
return 1;
}
int modmem_memcopy(INSTANCE *my, int *params) {
memcpy((void *)params[0], (void *)params[1], params[2]);
int modmem_memcopy(INSTANCE *my, intptr_t *params) {
memcpy((void *)params[0], (void *)params[1], (size_t)params[2]);
return 1;
}
int modmem_memset(INSTANCE *my, int *params) {
memset((void *)params[0], params[1], params[2]);
int modmem_memset(INSTANCE *my, intptr_t *params) {
memset((void *)params[0], params[1], (size_t)params[2]);
return 1;
}
int modmem_memsetw(INSTANCE *my, int *params) {
int modmem_memsetw(INSTANCE *my, intptr_t *params) {
uint16_t *ptr = (uint16_t *)params[0];
const uint16_t b = params[1];
int n;
intptr_t n;
for (n = params[2]; n; n--)
for (n = params[2]; n; n--) {
*ptr++ = b;
}
return 1;
}
int modmem_memseti(INSTANCE *my, int *params) {
int modmem_memseti(INSTANCE *my, intptr_t *params) {
uint32_t *ptr = (uint32_t *)params[0];
const uint32_t b = params[1];
int n;
......@@ -239,19 +240,19 @@ int modmem_memseti(INSTANCE *my, int *params) {
return 1;
}
int modmem_calloc(INSTANCE *my, int *params) {
int modmem_calloc(INSTANCE *my, intptr_t *params) {
return ((int)calloc(params[0], params[1]));
}
int modmem_alloc(INSTANCE *my, int *params) {
int modmem_alloc(INSTANCE *my, intptr_t *params) {
return ((int)malloc(params[0]));
}
int modmem_realloc(INSTANCE *my, int *params) {
int modmem_realloc(INSTANCE *my, intptr_t *params) {
return ((int)realloc((void *)params[0], params[1]));
}
int modmem_free(INSTANCE *my, int *params) {
int modmem_free(INSTANCE *my, intptr_t *params) {
free((void *)params[0]);
return 1;
}
......
......@@ -33,34 +33,18 @@
#include <pxtdl.h>
#ifndef __PXTB__
extern int modmem_calloc( INSTANCE * my, int * params );
extern int modmem_alloc( INSTANCE * my, int * params );
extern int modmem_free( INSTANCE * my, int * params );
extern int modmem_realloc( INSTANCE * my, int * params );
extern int modmem_memcmp( INSTANCE * my, int * params );
extern int modmem_memset( INSTANCE * my, int * params );
extern int modmem_memsetw( INSTANCE * my, int * params );
extern int modmem_memseti( INSTANCE * my, int * params );
extern int modmem_memsetw( INSTANCE * my, int * params );
extern int modmem_memseti( INSTANCE * my, int * params );
extern int modmem_memcopy( INSTANCE * my, int * params );
extern int modmem_memmove( INSTANCE * my, int * params );
extern int modmem_memory_free( INSTANCE * my, int * params );
extern int modmem_memory_total( INSTANCE * my, int * params );
extern int modmem_calloc( INSTANCE * my, int * params );
extern int modmem_alloc( INSTANCE * my, int * params );
extern int modmem_free( INSTANCE * my, int * params );
extern int modmem_realloc( INSTANCE * my, int * params );
extern int modmem_memcmp( INSTANCE * my, int * params );
extern int modmem_memset( INSTANCE * my, int * params );
extern int modmem_memsetw( INSTANCE * my, int * params );
extern int modmem_memseti( INSTANCE * my, int * params );
extern int modmem_memsetw( INSTANCE * my, int * params );
extern int modmem_memseti( INSTANCE * my, int * params );
extern int modmem_memcopy( INSTANCE * my, int * params );
extern int modmem_memmove( INSTANCE * my, int * params );
extern int modmem_memory_free( INSTANCE * my, int * params );
extern int modmem_memory_total( INSTANCE * my, int * params );
extern int modmem_calloc( INSTANCE * my, intptr_t * params );
extern int modmem_alloc( INSTANCE * my, intptr_t * params );
extern int modmem_free( INSTANCE * my, intptr_t * params );
extern int modmem_realloc( INSTANCE * my, intptr_t * params );
extern int modmem_memcmp( INSTANCE * my, intptr_t * params );
extern int modmem_memset( INSTANCE * my, intptr_t * params );
extern int modmem_memsetw( INSTANCE * my, intptr_t * params );
extern int modmem_memseti( INSTANCE * my, intptr_t * params );
extern int modmem_memcopy( INSTANCE * my, intptr_t * params );
extern int modmem_memmove( INSTANCE * my, intptr_t * params );
extern int modmem_memory_free( INSTANCE * my, intptr_t * params );
extern int modmem_memory_total( INSTANCE * my, intptr_t * params );
#endif
DLSYSFUNCS __pxtexport( mod_mem, exported_functions )[] = {
......
......@@ -5,7 +5,9 @@ if (${CMAKE_C_COMPILER_ID} MATCHES "GNU" OR
${CMAKE_C_COMPILER_ID} MATCHES "Clang" OR
${CMAKE_C_COMPILER_ID} MATCHES "AppleClang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -Wall -Wshadow -fno-strict-aliasing")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va")
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} -O2")
elseif (MSVC)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment