Final VS 2005 + Linux tomfoolery

This commit is contained in:
Scott Ehlert 2008-08-16 20:13:12 +00:00
parent adaf207b58
commit c07d8f3d93
22 changed files with 195 additions and 146 deletions

View File

@ -10,7 +10,7 @@ BINARY = amxxpc
OBJECTS = amx.cpp amxxpc.cpp Binary.cpp OBJECTS = amx.cpp amxxpc.cpp Binary.cpp
LINK = -lz /lib/libstdc++.a LINK = -lz /lib32/libstdc++.a
INCLUDE = -I. -L. INCLUDE = -I. -L.
@ -27,14 +27,14 @@ CFLAGS += -DLINUX -DNDEBUG -Wno-deprecated -fexceptions -DHAVE_STDINT_H -DAMX_AN
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o) OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
$(BIN_DIR)/%.o: %.cpp $(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) -m32 -o $@ -c $<
all: all:
mkdir -p $(BIN_DIR) mkdir -p $(BIN_DIR)
$(MAKE) amxxpc $(MAKE) amxxpc
amxxpc: $(OBJ_LINUX) amxxpc: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(CFLAGS) -m32 $(OBJ_LINUX) $(LINK) -ldl -lm -o$(BIN_DIR)/$(BINARY)
default: all default: all

View File

@ -212,7 +212,7 @@ typedef struct tagAMX_NATIVE_INFO {
typedef struct tagAMX_FUNCSTUB { typedef struct tagAMX_FUNCSTUB {
ucell address PACKED; ucell address PACKED;
char name[sEXPMAX+1] PACKED; char name[sEXPMAX+1];
} PACKED AMX_FUNCSTUB; } PACKED AMX_FUNCSTUB;
typedef struct tagFUNCSTUBNT { typedef struct tagFUNCSTUBNT {
@ -260,8 +260,8 @@ typedef struct tagAMX {
typedef struct tagAMX_HEADER { typedef struct tagAMX_HEADER {
int32_t size PACKED; /* size of the "file" */ int32_t size PACKED; /* size of the "file" */
uint16_t magic PACKED; /* signature */ uint16_t magic PACKED; /* signature */
char file_version PACKED; /* file format version */ char file_version; /* file format version */
char amx_version PACKED; /* required version of the AMX */ char amx_version; /* required version of the AMX */
int16_t flags PACKED; int16_t flags PACKED;
int16_t defsize PACKED; /* size of a definition record */ int16_t defsize PACKED; /* size of a definition record */
int32_t cod PACKED; /* initial value of COD - code block */ int32_t cod PACKED; /* initial value of COD - code block */

View File

@ -65,8 +65,8 @@ extern "C" {
typedef struct tagAMX_DBG_HDR { typedef struct tagAMX_DBG_HDR {
int32_t size PACKED; /* size of the debug information chunk */ int32_t size PACKED; /* size of the debug information chunk */
uint16_t magic PACKED; /* signature, must be 0xf1ef */ uint16_t magic PACKED; /* signature, must be 0xf1ef */
char file_version PACKED; /* file format version */ char file_version; /* file format version */
char amx_version PACKED; /* required version of the AMX */ char amx_version; /* required version of the AMX */
int16_t flags PACKED; /* currently unused */ int16_t flags PACKED; /* currently unused */
int16_t files PACKED; /* number of entries in the "file" table */ int16_t files PACKED; /* number of entries in the "file" table */
int16_t lines PACKED; /* number of entries in the "line" table */ int16_t lines PACKED; /* number of entries in the "line" table */
@ -74,51 +74,51 @@ typedef struct tagAMX_DBG_HDR {
int16_t tags PACKED; /* number of entries in the "tag" table */ int16_t tags PACKED; /* number of entries in the "tag" table */
int16_t automatons PACKED; /* number of entries in the "automaton" table */ int16_t automatons PACKED; /* number of entries in the "automaton" table */
int16_t states PACKED; /* number of entries in the "state" table */ int16_t states PACKED; /* number of entries in the "state" table */
} AMX_DBG_HDR PACKED; } AMX_DBG_HDR;
#define AMX_DBG_MAGIC 0xf1ef #define AMX_DBG_MAGIC 0xf1ef
typedef struct tagAMX_DBG_FILE { typedef struct tagAMX_DBG_FILE {
ucell address PACKED; /* address in the code segment where generated code (for this file) starts */ ucell address PACKED; /* address in the code segment where generated code (for this file) starts */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_FILE PACKED; } AMX_DBG_FILE;
typedef struct tagAMX_DBG_LINE { typedef struct tagAMX_DBG_LINE {
ucell address PACKED; /* address in the code segment where generated code (for this line) starts */ ucell address PACKED; /* address in the code segment where generated code (for this line) starts */
int32_t line PACKED; /* line number */ int32_t line PACKED; /* line number */
} AMX_DBG_LINE PACKED; } AMX_DBG_LINE;
typedef struct tagAMX_DBG_SYMBOL { typedef struct tagAMX_DBG_SYMBOL {
ucell address PACKED; /* address in the data segment or relative to the frame */ ucell address PACKED; /* address in the data segment or relative to the frame */
int16_t tag PACKED; /* tag for the symbol */ int16_t tag PACKED; /* tag for the symbol */
ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */ ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */
ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */ ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */
char ident PACKED; /* kind of symbol (function/variable) */ char ident; /* kind of symbol (function/variable) */
char vclass PACKED; /* class of symbol (global/local) */ char vclass; /* class of symbol (global/local) */
int16_t dim PACKED; /* number of dimensions */ int16_t dim PACKED; /* number of dimensions */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_SYMBOL PACKED; } AMX_DBG_SYMBOL;
typedef struct tagAMX_DBG_SYMDIM { typedef struct tagAMX_DBG_SYMDIM {
int16_t tag PACKED; /* tag for the array dimension */ int16_t tag PACKED; /* tag for the array dimension */
ucell size PACKED; /* size of the array dimension */ ucell size PACKED; /* size of the array dimension */
} AMX_DBG_SYMDIM PACKED; } AMX_DBG_SYMDIM;
typedef struct tagAMX_DBG_TAG { typedef struct tagAMX_DBG_TAG {
int16_t tag PACKED; /* tag id */ int16_t tag PACKED; /* tag id */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_TAG PACKED; } AMX_DBG_TAG;
typedef struct tagAMX_DBG_MACHINE { typedef struct tagAMX_DBG_MACHINE {
int16_t automaton PACKED; /* automaton id */ int16_t automaton PACKED; /* automaton id */
ucell address PACKED; /* address of state variable */ ucell address PACKED; /* address of state variable */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_MACHINE PACKED; } AMX_DBG_MACHINE;
typedef struct tagAMX_DBG_STATE { typedef struct tagAMX_DBG_STATE {
int16_t state PACKED; /* state id */ int16_t state PACKED; /* state id */
int16_t automaton PACKED; /* automaton id */ int16_t automaton PACKED; /* automaton id */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_STATE PACKED; } AMX_DBG_STATE;
typedef struct tagAMX_DBG { typedef struct tagAMX_DBG {
AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */ AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */
@ -128,7 +128,7 @@ typedef struct tagAMX_DBG {
AMX_DBG_TAG _FAR **tagtbl PACKED; AMX_DBG_TAG _FAR **tagtbl PACKED;
AMX_DBG_MACHINE _FAR **automatontbl PACKED; AMX_DBG_MACHINE _FAR **automatontbl PACKED;
AMX_DBG_STATE _FAR **statetbl PACKED; AMX_DBG_STATE _FAR **statetbl PACKED;
} AMX_DBG PACKED; } AMX_DBG;
#if !defined iVARIABLE #if !defined iVARIABLE
#define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */ #define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */

View File

@ -32,7 +32,7 @@ CFLAGS += $(OPT_FLAGS)
OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o) OBJ_LINUX := $(OBJECTS:%.c=$(BIN_DIR)/%.o)
$(BIN_DIR)/%.o: %.c $(BIN_DIR)/%.o: %.c
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $< $(CPP) $(INCLUDE) $(CFLAGS) -m32 -o $@ -c $<
all: all:
mkdir -p Release32 mkdir -p Release32
@ -41,7 +41,7 @@ all:
$(MAKE) pawn_make PAWN64=true $(MAKE) pawn_make PAWN64=true
pawn_make: $(OBJ_LINUX) pawn_make: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(CFLAGS) -m32 $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug: debug:
$(MAKE) all DEBUG=true $(MAKE) all DEBUG=true

View File

@ -221,7 +221,7 @@ typedef struct tagAMX_NATIVE_INFO {
typedef struct tagAMX_FUNCSTUB { typedef struct tagAMX_FUNCSTUB {
ucell address PACKED; ucell address PACKED;
char name[sEXPMAX+1] PACKED; char name[sEXPMAX+1];
} PACKED AMX_FUNCSTUB; } PACKED AMX_FUNCSTUB;
typedef struct tagFUNCSTUBNT { typedef struct tagFUNCSTUBNT {
@ -269,8 +269,8 @@ typedef struct tagAMX {
typedef struct tagAMX_HEADER { typedef struct tagAMX_HEADER {
int32_t size PACKED; /* size of the "file" */ int32_t size PACKED; /* size of the "file" */
uint16_t magic PACKED; /* signature */ uint16_t magic PACKED; /* signature */
char file_version PACKED; /* file format version */ char file_version; /* file format version */
char amx_version PACKED; /* required version of the AMX */ char amx_version; /* required version of the AMX */
int16_t flags PACKED; int16_t flags PACKED;
int16_t defsize PACKED; /* size of a definition record */ int16_t defsize PACKED; /* size of a definition record */
int32_t cod PACKED; /* initial value of COD - code block */ int32_t cod PACKED; /* initial value of COD - code block */

View File

@ -65,8 +65,8 @@ extern "C" {
typedef struct tagAMX_DBG_HDR { typedef struct tagAMX_DBG_HDR {
int32_t size PACKED; /* size of the debug information chunk */ int32_t size PACKED; /* size of the debug information chunk */
uint16_t magic PACKED; /* signature, must be 0xf1ef */ uint16_t magic PACKED; /* signature, must be 0xf1ef */
char file_version PACKED; /* file format version */ char file_version; /* file format version */
char amx_version PACKED; /* required version of the AMX */ char amx_version; /* required version of the AMX */
int16_t flags PACKED; /* currently unused */ int16_t flags PACKED; /* currently unused */
int16_t files PACKED; /* number of entries in the "file" table */ int16_t files PACKED; /* number of entries in the "file" table */
int16_t lines PACKED; /* number of entries in the "line" table */ int16_t lines PACKED; /* number of entries in the "line" table */
@ -74,51 +74,51 @@ typedef struct tagAMX_DBG_HDR {
int16_t tags PACKED; /* number of entries in the "tag" table */ int16_t tags PACKED; /* number of entries in the "tag" table */
int16_t automatons PACKED; /* number of entries in the "automaton" table */ int16_t automatons PACKED; /* number of entries in the "automaton" table */
int16_t states PACKED; /* number of entries in the "state" table */ int16_t states PACKED; /* number of entries in the "state" table */
} AMX_DBG_HDR PACKED; } AMX_DBG_HDR;
#define AMX_DBG_MAGIC 0xf1ef #define AMX_DBG_MAGIC 0xf1ef
typedef struct tagAMX_DBG_FILE { typedef struct tagAMX_DBG_FILE {
ucell address PACKED; /* address in the code segment where generated code (for this file) starts */ ucell address PACKED; /* address in the code segment where generated code (for this file) starts */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_FILE PACKED; } AMX_DBG_FILE;
typedef struct tagAMX_DBG_LINE { typedef struct tagAMX_DBG_LINE {
ucell address PACKED; /* address in the code segment where generated code (for this line) starts */ ucell address PACKED; /* address in the code segment where generated code (for this line) starts */
int32_t line PACKED; /* line number */ int32_t line PACKED; /* line number */
} AMX_DBG_LINE PACKED; } AMX_DBG_LINE;
typedef struct tagAMX_DBG_SYMBOL { typedef struct tagAMX_DBG_SYMBOL {
ucell address PACKED; /* address in the data segment or relative to the frame */ ucell address PACKED; /* address in the data segment or relative to the frame */
int16_t tag PACKED; /* tag for the symbol */ int16_t tag PACKED; /* tag for the symbol */
ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */ ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */
ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */ ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */
char ident PACKED; /* kind of symbol (function/variable) */ char ident; /* kind of symbol (function/variable) */
char vclass PACKED; /* class of symbol (global/local) */ char vclass; /* class of symbol (global/local) */
int16_t dim PACKED; /* number of dimensions */ int16_t dim PACKED; /* number of dimensions */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_SYMBOL PACKED; } AMX_DBG_SYMBOL;
typedef struct tagAMX_DBG_SYMDIM { typedef struct tagAMX_DBG_SYMDIM {
int16_t tag PACKED; /* tag for the array dimension */ int16_t tag PACKED; /* tag for the array dimension */
ucell size PACKED; /* size of the array dimension */ ucell size PACKED; /* size of the array dimension */
} AMX_DBG_SYMDIM PACKED; } AMX_DBG_SYMDIM;
typedef struct tagAMX_DBG_TAG { typedef struct tagAMX_DBG_TAG {
int16_t tag PACKED; /* tag id */ int16_t tag PACKED; /* tag id */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_TAG PACKED; } AMX_DBG_TAG;
typedef struct tagAMX_DBG_MACHINE { typedef struct tagAMX_DBG_MACHINE {
int16_t automaton PACKED; /* automaton id */ int16_t automaton PACKED; /* automaton id */
ucell address PACKED; /* address of state variable */ ucell address PACKED; /* address of state variable */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_MACHINE PACKED; } AMX_DBG_MACHINE;
typedef struct tagAMX_DBG_STATE { typedef struct tagAMX_DBG_STATE {
int16_t state PACKED; /* state id */ int16_t state PACKED; /* state id */
int16_t automaton PACKED; /* automaton id */ int16_t automaton PACKED; /* automaton id */
const char name[1] PACKED; /* ASCII string, zero-terminated */ const char name[1]; /* ASCII string, zero-terminated */
} AMX_DBG_STATE PACKED; } AMX_DBG_STATE;
typedef struct tagAMX_DBG { typedef struct tagAMX_DBG {
AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */ AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */
@ -128,7 +128,7 @@ typedef struct tagAMX_DBG {
AMX_DBG_TAG _FAR **tagtbl PACKED; AMX_DBG_TAG _FAR **tagtbl PACKED;
AMX_DBG_MACHINE _FAR **automatontbl PACKED; AMX_DBG_MACHINE _FAR **automatontbl PACKED;
AMX_DBG_STATE _FAR **statetbl PACKED; AMX_DBG_STATE _FAR **statetbl PACKED;
} AMX_DBG PACKED; } AMX_DBG;
#if !defined iVARIABLE #if !defined iVARIABLE
#define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */ #define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */

View File

@ -240,7 +240,7 @@ SC_FUNC stringlist *insert_path(char *path)
strcpy(extra_path, path); strcpy(extra_path, path);
#if defined __linux__ #if defined __linux__
strcat(extra_path, "/amxmod_compat/"); strcat(extra_path, "/amxmod_compat/");
#else if defined WIN32 || defined _WIN32 #elif defined WIN32 || defined _WIN32
strcat(extra_path, "\\amxmod_compat\\"); strcat(extra_path, "\\amxmod_compat\\");
#endif #endif
insert_string(&includepaths, extra_path); insert_string(&includepaths, extra_path);

View File

@ -2,12 +2,12 @@ CPPFILES = amxasm.cpp cexpr.cpp amx_symbol.cpp amx_proc.cpp \
amx_parser.cpp amx_natives.cpp amx_macro.cpp amx_label.cpp \ amx_parser.cpp amx_natives.cpp amx_macro.cpp amx_label.cpp \
amx_error.cpp amx_define.cpp amx_data.cpp amx_compiler.cpp amx_error.cpp amx_define.cpp amx_data.cpp amx_compiler.cpp
FLAGS = -march=i386 FLAGS = -march=i386 -m32
all: sasm all: sasm
sasm: sasm:
g++ $(FLAGS) -Wall $(CPPFILES) -o sasm -s g++ $(FLAGS) -DHAVE_STDINT_H -Wall $(CPPFILES) -o sasm -s
clean: clean:
-rm *.o -rm *.o

View File

@ -21,7 +21,7 @@ $gccf = "gcc";
my %OPTIONS, %OPT; my %OPTIONS, %OPT;
$OPT{"debug"} = "-g -ggdb"; $OPT{"debug"} = "-g -ggdb";
$OPT{"opt"} = "-O2 -ffast-math -funroll-loops -fomit-frame-pointer -s -DNDEBUG -Wall -Wno-unknown-pragmas -DOPT_TYPE=\"optimized\""; $OPT{"opt"} = "-O2 -ffast-math -funroll-loops -fomit-frame-pointer -s -DHAVE_STDINT_H -DNDEBUG -Wall -Wno-unknown-pragmas -DOPT_TYPE=\"optimized\"";
$OPTIONS{"include"} = ""; $OPTIONS{"include"} = "";
@ -63,7 +63,7 @@ if ($OPTIONS{"debug"})
{ {
$proc = 3; $proc = 3;
} }
$cflags = "-march=i".$proc."86 ".$OPT{"opt"}; $cflags = "-march=i".$proc."86 -m32 ".$OPT{"opt"};
} else { } else {
$cflags = $OPT{"opt"}; $cflags = $OPT{"opt"};
} }

View File

@ -1,6 +1,6 @@
/* Abstract Machine for the Small compiler /* Pawn Abstract Machine (for the Pawn language)
* *
* Copyright (c) ITB CompuPhase, 1997-2004 * Copyright (c) ITB CompuPhase, 1997-2005
* *
* This software is provided "as-is", without any express or implied warranty. * This software is provided "as-is", without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from * In no event will the authors be held liable for any damages arising from
@ -21,53 +21,90 @@
* Version: $Id$ * Version: $Id$
*/ */
#if defined LINUX #if defined FREEBSD && !defined __FreeBSD__
#define __FreeBSD__
#endif
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__
#include <sclinux.h> #include <sclinux.h>
#endif #endif
#ifndef AMX_H_INCLUDED #ifndef AMX_H_INCLUDED
#define AMX_H_INCLUDED #define AMX_H_INCLUDED
#if defined __LCC__ || defined __DMC__ || defined LINUX #if defined HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L #else
/* The ISO C99 defines the int16_t and int_32t types. If the compiler got #if defined __LCC__ || defined __DMC__ || defined LINUX
* here, these types are probably undefined. #if defined HAVE_INTTYPES_H
*/ #include <inttypes.h>
#if defined __FreeBSD__
#include <inttypes.h>
#else
typedef short int int16_t;
typedef unsigned short int uint16_t;
#if defined SN_TARGET_PS2
typedef int int32_t;
typedef unsigned int uint32_t;
#else #else
typedef long int int32_t; #include <stdint.h>
typedef unsigned long int uint32_t;
#endif #endif
#if defined __WIN32__ || defined _WIN32 || defined WIN32 #elif !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
typedef __int64 int64_t; /* The ISO C99 defines the int16_t and int_32t types. If the compiler got
typedef unsigned __int64 uint64_t; * here, these types are probably undefined.
#define HAVE_I64 */
#elif defined __GNUC__ #if defined __MACH__
typedef long long int64_t; #include <ppc/types.h>
typedef unsigned long long uint64_t; typedef unsigned short int uint16_t;
#define HAVE_I64 typedef unsigned long int uint32_t;
#elif defined __FreeBSD__
#include <inttypes.h>
#else
typedef short int int16_t;
typedef unsigned short int uint16_t;
#if defined SN_TARGET_PS2
typedef int int32_t;
typedef unsigned int uint32_t;
#else
typedef long int int32_t;
typedef unsigned long int uint32_t;
#endif
#if defined __WIN32__ || defined _WIN32 || defined WIN32
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#define HAVE_I64
#elif defined __GNUC__
typedef long long int64_t;
typedef unsigned long long uint64_t;
#define HAVE_I64
#endif
#endif #endif
#endif #endif
#define HAVE_STDINT_H
#endif
#if defined _LP64 || defined WIN64 || defined _WIN64
#if !defined __64BIT__
#define __64BIT__
#endif
#endif #endif
#if HAVE_ALLOCA_H
#include <alloca.h>
#endif
#if defined __WIN32__ || defined _WIN32 || defined WIN32 /* || defined __MSDOS__ */ #if defined __WIN32__ || defined _WIN32 || defined WIN32 /* || defined __MSDOS__ */
#if !defined alloca #if !defined alloca
#define alloca(n) _alloca(n) #define alloca(n) _alloca(n)
#endif #endif
#endif #endif
#if !defined arraysize
#define arraysize(array) (sizeof(array) / sizeof((array)[0]))
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if defined PAWN_DLL
#if !defined AMX_NATIVE_CALL
#define AMX_NATIVE_CALL __stdcall
#endif
#if !defined AMXAPI
#define AMXAPI __stdcall
#endif
#endif
/* calling convention for native functions */ /* calling convention for native functions */
#if !defined AMX_NATIVE_CALL #if !defined AMX_NATIVE_CALL
#define AMX_NATIVE_CALL #define AMX_NATIVE_CALL
@ -78,6 +115,8 @@ extern "C" {
#define AMXAPI __stdcall #define AMXAPI __stdcall
#elif defined CDECL #elif defined CDECL
#define AMXAPI __cdecl #define AMXAPI __cdecl
#elif defined GCC_HASCLASSVISIBILITY
#define AMXAPI __attribute__ ((visibility("default")))
#else #else
#define AMXAPI #define AMXAPI
#endif #endif
@ -95,31 +134,30 @@ extern "C" {
* 5 (tagnames table) 4 * 5 (tagnames table) 4
* 6 (reformatted header) 6 * 6 (reformatted header) 6
* 7 (name table, opcodes SYMTAG & SYSREQ.D) 7 * 7 (name table, opcodes SYMTAG & SYSREQ.D) 7
* 8 (opcode STMT, renewed debug interface) 8
*/ */
#define CUR_FILE_VERSION 7 /* current file version; also the current AMX version */ #define CUR_FILE_VERSION 8 /* current file version; also the current AMX version */
#define MIN_FILE_VERSION 6 /* lowest supported file format version for the current AMX version */ #define MIN_FILE_VERSION 6 /* lowest supported file format version for the current AMX version */
#define MIN_AMX_VERSION 7 /* minimum AMX version needed to support the current file format */ #define MIN_AMX_VERSION 8 /* minimum AMX version needed to support the current file format */
#if defined BIT16 #if !defined PAWN_CELL_SIZE
#define SMALL_CELL_SIZE 16 /* for backward compatibility */ #define PAWN_CELL_SIZE 32 /* by default, use 32-bit cells */
#endif #endif
#if !defined SMALL_CELL_SIZE #if PAWN_CELL_SIZE==16
#define SMALL_CELL_SIZE 32 /* by default, use 32-bit cells */
#endif
#if SMALL_CELL_SIZE==16
typedef uint16_t ucell; typedef uint16_t ucell;
typedef int16_t cell; typedef int16_t cell;
#elif SMALL_CELL_SIZE==32 #elif PAWN_CELL_SIZE==32
typedef uint32_t ucell; typedef uint32_t ucell;
typedef int32_t cell; typedef int32_t cell;
#elif SMALL_CELL_SIZE==64 #elif PAWN_CELL_SIZE==64
typedef uint64_t ucell; typedef uint64_t ucell;
typedef int64_t cell; typedef int64_t cell;
#else #else
#error Unsupported cell size (SMALL_CELL_SIZE) #error Unsupported cell size (PAWN_CELL_SIZE)
#endif #endif
#define UNPACKEDMAX ((1 << (sizeof(cell)-1)*8) - 1) #define UNPACKEDMAX ((1L << (sizeof(cell)-1)*8) - 1)
#define UNLIMITED (~1u >> 1)
struct tagAMX; struct tagAMX;
typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, cell *params); typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, cell *params);
@ -139,7 +177,7 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
/* Some compilers do not support the #pragma align, which should be fine. Some /* Some compilers do not support the #pragma align, which should be fine. Some
* compilers give a warning on unknown #pragmas, which is not so fine... * compilers give a warning on unknown #pragmas, which is not so fine...
*/ */
#if defined SN_TARGET_PS2 || defined __GNUC__ #if (defined SN_TARGET_PS2 || defined __GNUC__) && !defined AMX_NO_ALIGN
#define AMX_NO_ALIGN #define AMX_NO_ALIGN
#endif #endif
@ -150,8 +188,10 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX #if defined LINUX || defined __FreeBSD__
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
#elif defined MACOS && defined __MWERKS__
#pragma options align=mac68k
#else #else
#pragma pack(push) #pragma pack(push)
#pragma pack(1) /* structures must be packed (byte-aligned) */ #pragma pack(1) /* structures must be packed (byte-aligned) */
@ -161,25 +201,30 @@ typedef int (AMXAPI *AMX_DEBUG)(struct tagAMX *amx);
#endif #endif
#endif #endif
typedef struct { typedef struct tagAMX_NATIVE_INFO {
const char _FAR *name PACKED; const char _FAR *name PACKED;
AMX_NATIVE func PACKED; AMX_NATIVE func PACKED;
} AMX_NATIVE_INFO PACKED; } PACKED AMX_NATIVE_INFO;
#define AMX_USERNUM 4 #define AMX_USERNUM 4
#define sEXPMAX 19 /* maximum name length for file version <= 6 */ #define sEXPMAX 19 /* maximum name length for file version <= 6 */
#define sNAMEMAX 31 /* maximum name length of symbol name */ #define sNAMEMAX 31 /* maximum name length of symbol name */
typedef struct tagAMX_FUNCSTUB { typedef struct tagAMX_FUNCSTUB {
uint32_t address PACKED; ucell address PACKED;
char name[sEXPMAX+1] PACKED; char name[sEXPMAX+1];
} AMX_FUNCSTUB PACKED; } PACKED AMX_FUNCSTUB;
typedef struct tagFUNCSTUBNT {
ucell address PACKED;
ucell nameofs PACKED; //we need this for amxx to be backwards comaptible
} PACKED AMX_FUNCSTUBNT;
/* The AMX structure is the internal structure for many functions. Not all /* The AMX structure is the internal structure for many functions. Not all
* fields are valid at all times; many fields are cached in local variables. * fields are valid at all times; many fields are cached in local variables.
*/ */
typedef struct tagAMX { typedef struct tagAMX {
unsigned char _FAR *base PACKED; /* points to the AMX header ("amxhdr") plus the code, optionally also the data */ unsigned char _FAR *base PACKED; /* points to the AMX header plus the code, optionally also the data */
unsigned char _FAR *data PACKED; /* points to separate data+stack+heap, may be NULL */ unsigned char _FAR *data PACKED; /* points to separate data+stack+heap, may be NULL */
AMX_CALLBACK callback PACKED; AMX_CALLBACK callback PACKED;
AMX_DEBUG debug PACKED; /* debug callback */ AMX_DEBUG debug PACKED; /* debug callback */
@ -191,30 +236,23 @@ typedef struct tagAMX {
cell stk PACKED; /* stack pointer: relative to base + amxhdr->dat */ cell stk PACKED; /* stack pointer: relative to base + amxhdr->dat */
cell stp PACKED; /* top of the stack: relative to base + amxhdr->dat */ cell stp PACKED; /* top of the stack: relative to base + amxhdr->dat */
int flags PACKED; /* current status, see amx_Flags() */ int flags PACKED; /* current status, see amx_Flags() */
/* for assertions and debug hook */
cell curline PACKED;
cell curfile PACKED;
int dbgcode PACKED;
cell dbgaddr PACKED;
cell dbgparam PACKED;
char _FAR *dbgname PACKED;
/* user data */ /* user data */
long usertags[AMX_USERNUM] PACKED; long usertags[AMX_USERNUM] PACKED;
void _FAR *userdata[AMX_USERNUM] PACKED; void _FAR *userdata[AMX_USERNUM] PACKED;
/* native functions can raise an error */ /* native functions can raise an error */
int error PACKED; int error PACKED;
/* passing parameters requires a "count" field */
int paramcount;
/* the sleep opcode needs to store the full AMX status */ /* the sleep opcode needs to store the full AMX status */
cell pri PACKED; cell pri PACKED;
cell alt PACKED; cell alt PACKED;
cell reset_stk PACKED; cell reset_stk PACKED;
cell reset_hea PACKED; cell reset_hea PACKED;
cell sysreq_d PACKED; /* relocated address/value for the SYSREQ.D opcode */ cell sysreq_d PACKED; /* relocated address/value for the SYSREQ.D opcode */
#if defined JIT /* support variables for the JIT */
/* support variables for the JIT */ int reloc_size PACKED; /* required temporary buffer for relocations */
int reloc_size PACKED; /* required temporary buffer for relocations */ long code_size PACKED; /* estimated memory footprint of the native code */
long code_size PACKED; /* estimated memory footprint of the native code */ } PACKED AMX;
#endif
} AMX PACKED;
/* The AMX_HEADER structure is both the memory format as the file format. The /* The AMX_HEADER structure is both the memory format as the file format. The
* structure is used internaly. * structure is used internaly.
@ -222,8 +260,8 @@ typedef struct tagAMX {
typedef struct tagAMX_HEADER { typedef struct tagAMX_HEADER {
int32_t size PACKED; /* size of the "file" */ int32_t size PACKED; /* size of the "file" */
uint16_t magic PACKED; /* signature */ uint16_t magic PACKED; /* signature */
char file_version PACKED; /* file format version */ char file_version; /* file format version */
char amx_version PACKED; /* required version of the AMX */ char amx_version; /* required version of the AMX */
int16_t flags PACKED; int16_t flags PACKED;
int16_t defsize PACKED; /* size of a definition record */ int16_t defsize PACKED; /* size of a definition record */
int32_t cod PACKED; /* initial value of COD - code block */ int32_t cod PACKED; /* initial value of COD - code block */
@ -236,9 +274,11 @@ typedef struct tagAMX_HEADER {
int32_t libraries PACKED; /* offset to the table of libraries */ int32_t libraries PACKED; /* offset to the table of libraries */
int32_t pubvars PACKED; /* the "public variables" table */ int32_t pubvars PACKED; /* the "public variables" table */
int32_t tags PACKED; /* the "public tagnames" table */ int32_t tags PACKED; /* the "public tagnames" table */
int32_t nametable PACKED; /* name table, file version 7 only */ int32_t nametable PACKED; /* name table */
} AMX_HEADER PACKED; } PACKED AMX_HEADER;
#define AMX_MAGIC 0xf1e0
//This is always the same for us
#define AMX_MAGIC 0xf1e0
enum { enum {
AMX_ERR_NONE, AMX_ERR_NONE,
@ -255,6 +295,7 @@ enum {
AMX_ERR_NATIVE, /* native function failed */ AMX_ERR_NATIVE, /* native function failed */
AMX_ERR_DIVIDE, /* divide by zero */ AMX_ERR_DIVIDE, /* divide by zero */
AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */ AMX_ERR_SLEEP, /* go into sleepmode - code can be restarted */
AMX_ERR_INVSTATE, /* invalid state for this access */
AMX_ERR_MEMORY = 16, /* out of memory */ AMX_ERR_MEMORY = 16, /* out of memory */
AMX_ERR_FORMAT, /* invalid file format */ AMX_ERR_FORMAT, /* invalid file format */
@ -267,27 +308,17 @@ enum {
AMX_ERR_INIT_JIT, /* cannot initialize the JIT */ AMX_ERR_INIT_JIT, /* cannot initialize the JIT */
AMX_ERR_PARAMS, /* parameter error */ AMX_ERR_PARAMS, /* parameter error */
AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */ AMX_ERR_DOMAIN, /* domain error, expression result does not fit in range */
}; AMX_ERR_GENERAL, /* general error (unknown or unspecific error) */
enum {
DBG_INIT, /* query/initialize */
DBG_FILE, /* file number in curfile, filename in name */
DBG_LINE, /* line number in curline, file number in curfile */
DBG_SYMBOL, /* address in dbgaddr, class/type in dbgparam */
DBG_CLRSYM, /* stack address below which locals should be removed. stack address in stk */
DBG_CALL, /* function call, address jumped to in dbgaddr */
DBG_RETURN, /* function returns */
DBG_TERMINATE, /* program ends, code address in dbgaddr, reason in dbgparam */
DBG_SRANGE, /* symbol size and dimensions (arrays); level in dbgaddr (!); length in dbgparam */
DBG_SYMTAG, /* tag of the most recent symbol (if non-zero), tag in dbgparam */
}; };
/* AMX_FLAG_CHAR16 0x01 no longer used */ /* AMX_FLAG_CHAR16 0x01 no longer used */
#define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */ #define AMX_FLAG_DEBUG 0x02 /* symbolic info. available */
#define AMX_FLAG_COMPACT 0x04 /* compact encoding */ #define AMX_FLAG_COMPACT 0x04 /* compact encoding */
#define AMX_FLAG_BIGENDIAN 0x08 /* big endian encoding */ #define AMX_FLAG_BYTEOPC 0x08 /* opcode is a byte (not a cell) */
#define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking */ #define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking; no STMT opcode */
#define AMX_FLAG_BROWSE 0x4000 /* browsing/relocating or executing */ #define AMX_FLAG_NTVREG 0x1000 /* all native functions are registered */
#define AMX_FLAG_JITC 0x2000 /* abstract machine is JIT compiled */
#define AMX_FLAG_BROWSE 0x4000 /* busy browsing */
#define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */ #define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */
#define AMX_EXEC_MAIN -1 /* start at program entry point */ #define AMX_EXEC_MAIN -1 /* start at program entry point */
@ -295,16 +326,18 @@ enum {
#define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24)) #define AMX_USERTAG(a,b,c,d) ((a) | ((b)<<8) | ((long)(c)<<16) | ((long)(d)<<24))
#define AMX_EXPANDMARGIN 64 #if !defined AMX_COMPACTMARGIN
#define AMX_COMPACTMARGIN 64
#endif
/* for native functions that use floating point parameters, the following /* for native functions that use floating point parameters, the following
* two macros are convenient for casting a "cell" into a "float" type _without_ * two macros are convenient for casting a "cell" into a "float" type _without_
* changing the bit pattern * changing the bit pattern
*/ */
#if SMALL_CELL_SIZE==32 #if PAWN_CELL_SIZE==32
#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */ #define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
#define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */ #define amx_ctof(c) ( * ((float*)&c) ) /* cell to float */
#elif SMALL_CELL_SIZE==64 #elif PAWN_CELL_SIZE==64
#define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */ #define amx_ftoc(f) ( * ((cell*)&f) ) /* float to cell */
#define amx_ctof(c) ( * ((double*)&c) ) /* cell to float */ #define amx_ctof(c) ( * ((double*)&c) ) /* cell to float */
#else #else
@ -318,7 +351,7 @@ enum {
amx_StrLen(amx_cstr_, &amx_length_); \ amx_StrLen(amx_cstr_, &amx_length_); \
if (amx_length_ > 0 && \ if (amx_length_ > 0 && \
((result) = (void*)alloca((amx_length_ + 1) * sizeof(*(result)))) != NULL) \ ((result) = (void*)alloca((amx_length_ + 1) * sizeof(*(result)))) != NULL) \
amx_GetString((char*)(result), amx_cstr_, sizeof(*(result))>1); \ amx_GetString((char*)(result), amx_cstr_, sizeof(*(result))>1, amx_length_); \
else (result) = NULL; \ else (result) = NULL; \
} while (0) } while (0)
@ -331,9 +364,7 @@ int AMXAPI amx_Allot(AMX *amx, int cells, cell *amx_addr, cell **phys_addr);
int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params); int AMXAPI amx_Callback(AMX *amx, cell index, cell *result, cell *params);
int AMXAPI amx_Cleanup(AMX *amx); int AMXAPI amx_Cleanup(AMX *amx);
int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data); int AMXAPI amx_Clone(AMX *amxClone, AMX *amxSource, void *data);
int AMXAPI amx_Debug(AMX *amx); /* default debug procedure, does nothing */ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index);
int AMXAPI amx_Exec(AMX *amx, cell *retval, int index, int numparams, ...);
int AMXAPI amx_Execv(AMX *amx, cell *retval, int index, int numparams, cell params[]);
int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index); int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index);
int AMXAPI amx_FindPublic(AMX *amx, const char *funcname, int *index); int AMXAPI amx_FindPublic(AMX *amx, const char *funcname, int *index);
int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr); int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr);
@ -343,34 +374,52 @@ 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_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);
int AMXAPI amx_GetPubVar(AMX *amx, int index, char *varname, cell *amx_addr); 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); 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); int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id);
int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr); int AMXAPI amx_GetUserData(AMX *amx, long tag, void **ptr);
int AMXAPI amx_Init(AMX *amx, void *program); int AMXAPI amx_Init(AMX *amx, void *program);
int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code); int AMXAPI amx_InitJIT(AMX *amx, void *reloc_table, void *native_code);
int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap); int AMXAPI amx_MemInfo(AMX *amx, long *codesize, long *datasize, long *stackheap);
int AMXAPI amx_NameLength(AMX *amx, int *length); int AMXAPI amx_NameLength(AMX *amx, int *length);
AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name,AMX_NATIVE func); AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func);
int AMXAPI amx_NumNatives(AMX *amx, int *number); int AMXAPI amx_NumNatives(AMX *amx, int *number);
int AMXAPI amx_NumPublics(AMX *amx, int *number); int AMXAPI amx_NumPublics(AMX *amx, int *number);
int AMXAPI amx_NumPubVars(AMX *amx, int *number); int AMXAPI amx_NumPubVars(AMX *amx, int *number);
int AMXAPI amx_NumTags(AMX *amx, int *number); int AMXAPI amx_NumTags(AMX *amx, int *number);
int AMXAPI amx_Push(AMX *amx, cell value);
int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells);
int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar);
int AMXAPI amx_RaiseError(AMX *amx, int error); int AMXAPI amx_RaiseError(AMX *amx, int error);
int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *nativelist, int number); int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number);
int AMXAPI amx_Release(AMX *amx, cell amx_addr); int AMXAPI amx_Release(AMX *amx, cell amx_addr);
int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback); int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug); int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar); int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size);
int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr); int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr);
int AMXAPI amx_StrLen(cell *cstring, int *length); int AMXAPI amx_StrLen(const cell *cstring, int *length);
int AMXAPI amx_UTF8Check(const char *string, int *length);
int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value); int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value);
int AMXAPI amx_UTF8Len(const cell *cstr, int *length);
int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value); int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
int AMXAPI amx_UTF8Check(const char *string);
#if PAWN_CELL_SIZE==16
#define amx_AlignCell(v) amx_Align16(v)
#elif PAWN_CELL_SIZE==32
#define amx_AlignCell(v) amx_Align32(v)
#elif PAWN_CELL_SIZE==64 && (defined _I64_MAX || defined HAVE_I64)
#define amx_AlignCell(v) amx_Align64(v)
#else
#error Unsupported cell size
#endif
#define amx_RegisterFunc(amx, name, func) \
amx_Register((amx), amx_NativeInfo((name),(func)), 1);
#if !defined AMX_NO_ALIGN #if !defined AMX_NO_ALIGN
#if defined LINUX #if defined LINUX || defined __FreeBSD__
#pragma pack() /* reset default packing */ #pragma pack() /* reset default packing */
#elif defined MACOS && defined __MWERKS__
#pragma options align=reset
#else #else
#pragma pack(pop) /* reset previous packing */ #pragma pack(pop) /* reset previous packing */
#endif #endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.