Skip to content

Commit

Permalink
Merged in eCos port.
Browse files Browse the repository at this point in the history
Fixed problems on Big Endian processors with the debug information.
Completed overlay support (also in the assembler versions).
amxFile: extended fstat() function.
Bug fixes with overlay table generation.
Removed #emit and #endscript.
Removed PASCAL-like syntax for instructions ("if ... then begin ... end" instead of "if (...) { ... }").
  • Loading branch information
thiadmer.riemersma committed Nov 26, 2007
1 parent 7a2e24a commit 57f7de9
Show file tree
Hide file tree
Showing 36 changed files with 649 additions and 460 deletions.
1 change: 0 additions & 1 deletion amx/CMakeLists.txt
Expand Up @@ -23,7 +23,6 @@ ENDIF(HAVE_ALLOCA_H)

ADD_DEFINITIONS(-DFLOATPOINT -DFIXEDPOINT)
IF (UNIX)
ADD_DEFINITIONS(-DLINUX)
CHECK_INCLUDE_FILE("ffi.h" HAVE_FFI_H)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../linux)
ENDIF (UNIX)
Expand Down
65 changes: 37 additions & 28 deletions amx/amx.c
Expand Up @@ -18,7 +18,7 @@
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* Version: $Id: amx.c 3831 2007-10-19 17:25:41Z thiadmer $
* Version: $Id: amx.c 3853 2007-11-26 13:59:01Z thiadmer $
*/

#if BUILD_PLATFORM == WINDOWS && BUILD_TYPE == RELEASE && BUILD_COMPILER == MSVC && PAWN_CELL_SIZE == 64
Expand All @@ -42,7 +42,7 @@
#include <stdlib.h> /* for getenv() */
#include <string.h>
#include "osdefs.h"
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
#include <sclinux.h>
#if !defined AMX_NODYNALOAD
#include <dlfcn.h>
Expand All @@ -52,16 +52,23 @@
#include <sys/mman.h>
#endif
#endif
#if defined __LCC__ || defined LINUX
#if defined __LCC__ || defined __LINUX__
#include <wchar.h> /* for wcslen() */
#endif
#include "amx.h"

#if defined __ECOS__
/* eCos puts include files in cyg/package_name */
#include <cyg/pawn/amx.h>
#else
#include "amx.h"
#endif

#if (defined _Windows && !defined AMX_NODYNALOAD) || (defined JIT && __WIN32__)
#include <windows.h>
#endif


/* When one or more of the AMX_funcname macris are defined, we want
/* When one or more of the AMX_funcname macros are defined, we want
* to compile only those functions. However, when none of these macros
* is present, we want to compile everything.
*/
Expand Down Expand Up @@ -1097,12 +1104,12 @@ int AMXAPI amx_Init(AMX *amx,void *program)
AMX_HEADER *hdr;
int err,i;
unsigned char *data;
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if defined _Windows
char libname[sNAMEMAX+8]; /* +1 for '\0', +3 for 'amx' prefix, +4 for extension */
typedef int (FAR WINAPI *AMX_ENTRY)(AMX _FAR *amx);
HINSTANCE hlib;
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
char libname[_MAX_PATH];
char *root;
typedef int (*AMX_ENTRY)(AMX *amx);
Expand Down Expand Up @@ -1292,16 +1299,16 @@ int AMXAPI amx_Init(AMX *amx,void *program)
return err;

/* load any extension modules that the AMX refers to */
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
root=getenv("AMXLIB");
#endif
hdr=(AMX_HEADER *)amx->base;
numlibraries=NUMENTRIES(hdr,libraries,pubvars);
for (i=0; i<numlibraries; i++) {
lib=GETENTRY(hdr,libraries,i);
libname[0]='\0';
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
if (root!=NULL && *root!='\0') {
strcpy(libname,root);
if (libname[strlen(libname)-1]!='/')
Expand All @@ -1319,7 +1326,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
if (hlib<=HINSTANCE_ERROR)
hlib=NULL;
#endif
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
strcat(libname,".so");
hlib=dlopen(libname,RTLD_NOW);
#endif
Expand All @@ -1333,7 +1340,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
strcat(funcname,"Init");
#if defined _Windows
libinit=(AMX_ENTRY)GetProcAddress(hlib,funcname);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
libinit=(AMX_ENTRY)dlsym(hlib,funcname);
#endif
if (libinit!=NULL)
Expand Down Expand Up @@ -1369,7 +1376,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
return !VirtualProtect(addr, len, p, &prev);
}

#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__

/* Linux already has mprotect() */
#define ALIGN(addr) (char *)(((long)addr + sysconf(_SC_PAGESIZE)-1) & ~(sysconf(_SC_PAGESIZE)-1))
Expand Down Expand Up @@ -1450,10 +1457,10 @@ int AMXAPI amx_InitJIT(AMX *amx,void *compiled_program,void *reloc_table)
#if defined AMX_CLEANUP
int AMXAPI amx_Cleanup(AMX *amx)
{
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if defined _Windows
typedef int (FAR WINAPI *AMX_ENTRY)(AMX FAR *amx);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
typedef int (*AMX_ENTRY)(AMX *amx);
#endif
AMX_HEADER *hdr;
Expand All @@ -1463,7 +1470,7 @@ int AMXAPI amx_Cleanup(AMX *amx)
#endif

/* unload all extension modules */
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
#if (defined _Windows || defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
hdr=(AMX_HEADER *)amx->base;
assert(hdr->magic==AMX_MAGIC);
numlibraries=NUMENTRIES(hdr,libraries,pubvars);
Expand All @@ -1476,14 +1483,14 @@ int AMXAPI amx_Cleanup(AMX *amx)
strcat(funcname,"Cleanup");
#if defined _Windows
libcleanup=(AMX_ENTRY)GetProcAddress((HINSTANCE)lib->address,funcname);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
libcleanup=(AMX_ENTRY)dlsym((void*)lib->address,funcname);
#endif
if (libcleanup!=NULL)
libcleanup(amx);
#if defined _Windows
FreeLibrary((HINSTANCE)lib->address);
#elif defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#elif defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
dlclose((void*)lib->address);
#endif
} /* if */
Expand Down Expand Up @@ -1639,7 +1646,7 @@ int AMXAPI amx_NumPublics(AMX *amx, int *number)
return AMX_ERR_NONE;
}

int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname)
int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname, ucell *address)
{
AMX_HEADER *hdr;
AMX_FUNCSTUB *func;
Expand All @@ -1652,7 +1659,10 @@ int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname)
return AMX_ERR_INDEX;

func=GETENTRY(hdr,publics,index);
strcpy(funcname,GETENTRYNAME(hdr,func));
if (funcname!=NULL)
strcpy(funcname,GETENTRYNAME(hdr,func));
if (address!=NULL)
*address=func->address;
return AMX_ERR_NONE;
}

Expand All @@ -1667,7 +1677,7 @@ int AMXAPI amx_FindPublic(AMX *amx, const char *name, int *index)
/* binary search */
while (first<=last) {
mid=(first+last)/2;
amx_GetPublic(amx,mid,pname);
amx_GetPublic(amx,mid,pname,NULL);
result=strcmp(pname,name);
if (result>0) {
last=mid-1;
Expand Down Expand Up @@ -2145,7 +2155,6 @@ static const void * const amx_opcodelist[] = {
cell pri,alt,stk,frm,hea;
cell reset_stk, reset_hea, *cip;
cell offs,val;
ucell codesize;
int num,i;

assert(amx!=NULL);
Expand Down Expand Up @@ -2548,15 +2557,15 @@ static const void * const amx_opcodelist[] = {
POP(frm);
POP(offs);
/* verify the return address */
if ((ucell)offs>=amx->codesize)
if ((long)offs>=amx->codesize)
ABORT(amx,AMX_ERR_MEMACCESS);
cip=(cell *)(amx->code+(int)offs);
NEXT(cip);
op_retn:
POP(frm);
POP(offs);
/* verify the return address */
if ((ucell)offs>=amx->codesize)
if ((long)offs>=amx->codesize)
ABORT(amx,AMX_ERR_MEMACCESS);
cip=(cell *)(amx->code+(int)offs);
stk+= _R(data,stk) + sizeof(cell); /* remove parameters from the stack */
Expand Down Expand Up @@ -2589,7 +2598,7 @@ static const void * const amx_opcodelist[] = {
/* verify the index */
stk+=_R(data,stk)+sizeof(cell); /* remove parameters from the stack */
num=amx->overlay(amx,amx->ovl_index); /* reload overlay */
if (num!=AMX_ERR_NONE || (ucell)offs>=(ucell)amx->codesize)
if (num!=AMX_ERR_NONE || (long)offs>=amx->codesize)
ABORT(amx,AMX_ERR_MEMACCESS);
cip=(cell *)(amx->code+(int)offs);
NEXT(cip);
Expand Down Expand Up @@ -4044,15 +4053,15 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
POP(frm);
POP(offs);
/* verify the return address */
if ((ucell)offs>=amx->codesize)
if ((long)offs>=amx->codesize)
ABORT(amx,AMX_ERR_MEMACCESS);
cip=(cell *)(amx->code+(int)offs);
break;
case OP_RETN:
POP(frm);
POP(offs);
/* verify the return address */
if ((ucell)offs>=amx->codesize)
if ((long)offs>=amx->codesize)
ABORT(amx,AMX_ERR_MEMACCESS);
cip=(cell *)(amx->code+(int)offs);
stk+=_R(data,stk)+sizeof(cell); /* remove parameters from the stack */
Expand Down Expand Up @@ -4085,7 +4094,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
/* verify the index */
stk+=_R(data,stk)+sizeof(cell); /* remove parameters from the stack */
num=amx->overlay(amx,amx->ovl_index); /* reload overlay */
if (num!=AMX_ERR_NONE || (ucell)offs>=(ucell)amx->codesize)
if (num!=AMX_ERR_NONE || (long)offs>=amx->codesize)
ABORT(amx,AMX_ERR_MEMACCESS);
cip=(cell *)(amx->code+(int)offs);
break;
Expand Down
16 changes: 10 additions & 6 deletions amx/amx.h
Expand Up @@ -18,7 +18,7 @@
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* Version: $Id: amx.h 3821 2007-10-15 16:54:20Z thiadmer $
* Version: $Id: amx.h 3853 2007-11-26 13:59:01Z thiadmer $
*/

#ifndef AMX_H_INCLUDED
Expand All @@ -27,17 +27,20 @@
#include <stdlib.h> /* for size_t */
#include <limits.h>

#if defined __linux || defined __linux__
#define __LINUX__
#endif
#if defined FREEBSD && !defined __FreeBSD__
#define __FreeBSD__
#endif
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#if defined __LINUX__ || defined __FreeBSD__ || defined __OpenBSD__
#include <sclinux.h>
#endif

#if defined HAVE_STDINT_H
#include <stdint.h>
#else
#if defined __LCC__ || defined __DMC__ || defined LINUX || (defined __WATCOMC__ && __WATCOMC__ >= 1200)
#if defined __LCC__ || defined __DMC__ || defined __LINUX__ || (defined __WATCOMC__ && __WATCOMC__ >= 1200)
#if defined HAVE_INTTYPES_H
#include <inttypes.h>
#else
Expand Down Expand Up @@ -213,7 +216,7 @@ typedef int (AMXAPI *AMX_IDLE)(struct tagAMX *amx, int AMXAPI Exec(struct tagAMX
#endif

#if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__
#if defined __LINUX__ || defined __FreeBSD__
#pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k
Expand Down Expand Up @@ -405,6 +408,7 @@ enum {
else (result) = NULL; \
} while (0)


uint16_t * AMXAPI amx_Align16(uint16_t *v);
uint32_t * AMXAPI amx_Align32(uint32_t *v);
#if defined _I64_MAX || defined HAVE_I64
Expand All @@ -422,7 +426,7 @@ int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname);
int AMXAPI amx_Flags(AMX *amx,uint16_t *flags);
int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr);
int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname);
int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname);
int AMXAPI amx_GetPublic(AMX *amx, int index, char *funcname, ucell *address);
int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr);
int AMXAPI amx_GetString(char *dest,const cell *source, int use_wchar, size_t size);
int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id);
Expand Down Expand Up @@ -466,7 +470,7 @@ int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
amx_Register((amx), amx_NativeInfo((name),(func)), 1);

#if !defined AMX_NO_ALIGN
#if defined LINUX || defined __FreeBSD__
#if defined __LINUX__ || defined __FreeBSD__
#pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__
#pragma options align=reset
Expand Down
8 changes: 4 additions & 4 deletions amx/amxargs.c
Expand Up @@ -18,7 +18,7 @@
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* Version: $Id: amxargs.c 3821 2007-10-15 16:54:20Z thiadmer $
* Version: $Id: amxargs.c 3853 2007-11-26 13:59:01Z thiadmer $
*/
#if defined _UNICODE || defined __UNICODE__ || defined UNICODE
# if !defined UNICODE /* for Windows */
Expand All @@ -35,13 +35,13 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined __MSDOS__
#include "osdefs.h"
#if defined __WIN32__ || defined __MSDOS__
#include <malloc.h>
#endif
#if defined __WIN32__ || defined _WIN32 || defined WIN32 || defined _Windows
#if defined __WIN32__ || defined _Windows
#include <windows.h>
#endif
#include "osdefs.h"
#include "amx.h"

#if defined _UNICODE
Expand Down

0 comments on commit 57f7de9

Please sign in to comment.