lscript_byteformat.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LSCRIPT_BYTEFORMAT_H
00033 #define LL_LSCRIPT_BYTEFORMAT_H
00034 
00035 // Data shared between compiler/assembler and lscript execution code
00036 
00037 #include "stdtypes.h"
00038 
00039 const S32 LSL2_VERSION_NUMBER = 0x0200;
00040 const S32 LSL2_VERSION1_END_NUMBER = 0x0101;
00041 const S32 LSL2_VERSION2_START_NUMBER = 0x0200;
00042 
00043 const S32 LSL2_MAJOR_VERSION_ONE = 1;
00044 const S32 LSL2_MAJOR_VERSION_TWO = 2;
00045 const S32 LSL2_CURRENT_MAJOR_VERSION = LSL2_MAJOR_VERSION_TWO;
00046 
00047 const S32 TOP_OF_MEMORY = 16384;
00048 
00049 typedef enum e_lscript_registers
00050 {
00051         LREG_INVALID,
00052         LREG_IP,                // instruction pointer
00053         LREG_VN,                // version number
00054         LREG_BP,                // base pointer - what local variables are referenced from
00055         LREG_SP,                // stack pointer - where the top of the stack is
00056         LREG_HR,                // heap register - where in memory does the heap start
00057         LREG_HP,                // heap pointer - where is the top of the heap?
00058         LREG_CS,                // current state - what state are we currently in?
00059         LREG_NS,                // next state - what state are we currently in?
00060         LREG_CE,                // current events - what events are waiting to be handled?
00061         LREG_IE,                // in event - which event handler are we currently in?
00062         LREG_ER,                // event register - what events do we have active handlers for?
00063         LREG_FR,                // fault register - which errors are currently active?
00064         LREG_SLR,               // sleep register - are we sleeping?
00065         LREG_GVR,               // global variable register - where do global variables start
00066         LREG_GFR,               // global function register - where do global functions start
00067         LREG_SR,                // state register - where do states start
00068         LREG_TM,                // top of memory - where is the top of memory
00069         LREG_PR,                // parameter register - data passed to script from launcher
00070         LREG_ESR,               // energy supply register - how much energy do we have on board?
00071         LREG_NCE,               // 64 bit current envents - what events are waiting to be handled?
00072         LREG_NIE,               // 64 bit in event - which event handler are we currently in?
00073         LREG_NER,               // 64 bit event register - what events do we have active handlers for?
00074         LREG_EOF
00075 } LSCRIPTRegisters;
00076 
00077 const S32 gLSCRIPTRegisterAddresses[LREG_EOF] = /* Flawfinder: ignore */
00078 {
00079         0,                      // LREG_INVALID
00080         4,                      // LREG_IP
00081         8,                      // LREG_VN
00082         12,                     // LREG_BP
00083         16,                     // LREG_SP
00084         20,                     // LREG_HR
00085         24,                     // LREG_HP
00086         28,                     // LREG_CS
00087         32,                     // LREG_NS
00088         36,                     // LREG_CE
00089         40,                     // LREG_IE
00090         44,                     // LREG_ER
00091         48,                     // LREG_FR
00092         52,                     // LREG_SLR
00093         56,                     // LREG_GVR
00094         60,                     // LREG_GFR
00095         72,                     // LREG_SR
00096         0,                      // LREG_TM
00097         64,                     // LREG_PR
00098         68,                     // LREG_ESR
00099         76,                     // LREG_NCE
00100         84,                     // LREG_NIE
00101         92,                     // LREG_NER
00102 };
00103 
00104 const char * const gLSCRIPTRegisterNames[LREG_EOF] =
00105 {
00106         "INVALID",              // LREG_INVALID
00107         "IP",                   // LREG_IP
00108         "VN",                   // LREG_VN
00109         "BP",                   // LREG_BP
00110         "SP",                   // LREG_SP
00111         "HR",                   // LREG_HR
00112         "HP",                   // LREG_HP
00113         "CS",                   // LREG_CS
00114         "NS",                   // LREG_NS
00115         "CE",                   // LREG_CE
00116         "IE",                   // LREG_IE
00117         "ER",                   // LREG_ER
00118         "FR",                   // LREG_FR
00119         "SLR",                  // LREG_SLR
00120         "GVR",                  // LREG_GVR
00121         "GFR",                  // LREG_GFR
00122         "SR",                   // LREG_SR
00123         "TM",                   // LREG_TM
00124         "PR",                   // LREG_PR
00125         "ESR",                  // LREG_ESR
00126         "NCE",                  // LREG_NCE
00127         "NIE",                  // LREG_NIE
00128         "NER",                  // LREG_NER
00129 };
00130 
00131 typedef enum e_lscript_op_codes
00132 {
00133         LOPC_INVALID,
00134         LOPC_NOOP,
00135         LOPC_POP,
00136         LOPC_POPS,
00137         LOPC_POPL,
00138         LOPC_POPV,
00139         LOPC_POPQ,
00140         LOPC_POPARG,
00141         LOPC_POPIP,
00142         LOPC_POPBP,
00143         LOPC_POPSP,
00144         LOPC_POPSLR,
00145         LOPC_DUP,
00146         LOPC_DUPS,
00147         LOPC_DUPL,
00148         LOPC_DUPV,
00149         LOPC_DUPQ,
00150         LOPC_STORE,
00151         LOPC_STORES,
00152         LOPC_STOREL,
00153         LOPC_STOREV,
00154         LOPC_STOREQ,
00155         LOPC_STOREG,
00156         LOPC_STOREGS,
00157         LOPC_STOREGL,
00158         LOPC_STOREGV,
00159         LOPC_STOREGQ,
00160         LOPC_LOADP,
00161         LOPC_LOADSP,
00162         LOPC_LOADLP,
00163         LOPC_LOADVP,
00164         LOPC_LOADQP,
00165         LOPC_LOADGP,
00166         LOPC_LOADGLP,
00167         LOPC_LOADGSP,
00168         LOPC_LOADGVP,
00169         LOPC_LOADGQP,
00170         LOPC_PUSH,
00171         LOPC_PUSHS,
00172         LOPC_PUSHL,
00173         LOPC_PUSHV,
00174         LOPC_PUSHQ,
00175         LOPC_PUSHG,
00176         LOPC_PUSHGS,
00177         LOPC_PUSHGL,
00178         LOPC_PUSHGV,
00179         LOPC_PUSHGQ,
00180         LOPC_PUSHIP,
00181         LOPC_PUSHBP,
00182         LOPC_PUSHSP,
00183         LOPC_PUSHARGB,
00184         LOPC_PUSHARGI,
00185         LOPC_PUSHARGF,
00186         LOPC_PUSHARGS,
00187         LOPC_PUSHARGV,
00188         LOPC_PUSHARGQ,
00189         LOPC_PUSHE,
00190         LOPC_PUSHEV,
00191         LOPC_PUSHEQ,
00192         LOPC_PUSHARGE,
00193         LOPC_ADD,
00194         LOPC_SUB,
00195         LOPC_MUL,
00196         LOPC_DIV,
00197         LOPC_MOD,
00198         LOPC_EQ,
00199         LOPC_NEQ,
00200         LOPC_LEQ,
00201         LOPC_GEQ,
00202         LOPC_LESS,
00203         LOPC_GREATER,
00204         LOPC_BITAND,
00205         LOPC_BITOR,
00206         LOPC_BITXOR,
00207         LOPC_BOOLAND,
00208         LOPC_BOOLOR,
00209         LOPC_NEG,
00210         LOPC_BITNOT,
00211         LOPC_BOOLNOT,
00212         LOPC_JUMP,
00213         LOPC_JUMPIF,
00214         LOPC_JUMPNIF,
00215         LOPC_STATE,
00216         LOPC_CALL,
00217         LOPC_RETURN,
00218         LOPC_CAST,
00219         LOPC_STACKTOS,
00220         LOPC_STACKTOL,
00221         LOPC_PRINT,
00222         LOPC_CALLLIB,
00223         LOPC_CALLLIB_TWO_BYTE,
00224         LOPC_SHL,
00225         LOPC_SHR,
00226         LOPC_EOF
00227 } LSCRIPTOpCodesEnum;
00228 
00229 const U8 LSCRIPTOpCodes[LOPC_EOF] =
00230 {
00231         0x00,   // LOPC_INVALID
00232         0x00,   // LOPC_NOOP
00233         0x01,   // LOPC_POP
00234         0x02,   // LOPC_POPS
00235         0x03,   // LOPC_POPL
00236         0x04,   // LOPC_POPV
00237         0x05,   // LOPC_POPQ
00238         0x06,   // LOPC_POPARG
00239         0x07,   // LOPC_POPIP
00240         0x08,   // LOPC_POPBP
00241         0x09,   // LOPC_POPSP
00242         0x0a,   // LOPC_POPSLR
00243         0x20,   // LOPC_DUP
00244         0x21,   // LOPC_DUPS
00245         0x22,   // LOPC_DUPL
00246         0x23,   // LOPC_DUPV
00247         0x24,   // LOPC_DUPQ
00248         0x30,   // LOPC_STORE
00249         0x31,   // LOPC_STORES
00250         0x32,   // LOPC_STOREL
00251         0x33,   // LOPC_STOREV
00252         0x34,   // LOPC_STOREQ
00253         0x35,   // LOPC_STOREG
00254         0x36,   // LOPC_STOREGS
00255         0x37,   // LOPC_STOREGL
00256         0x38,   // LOPC_STOREGV
00257         0x39,   // LOPC_STOREGQ
00258         0x3a,   // LOPC_LOADP
00259         0x3b,   // LOPC_LOADSP
00260         0x3c,   // LOPC_LOADLP
00261         0x3d,   // LOPC_LOADVP
00262         0x3e,   // LOPC_LOADQP
00263         0x3f,   // LOPC_LOADGP
00264         0x40,   // LOPC_LOADGSP
00265         0x41,   // LOPC_LOADGLP
00266         0x42,   // LOPC_LOADGVP
00267         0x43,   // LOPC_LOADGQP
00268         0x50,   // LOPC_PUSH
00269         0x51,   // LOPC_PUSHS
00270         0x52,   // LOPC_PUSHL
00271         0x53,   // LOPC_PUSHV
00272         0x54,   // LOPC_PUSHQ
00273         0x55,   // LOPC_PUSHG
00274         0x56,   // LOPC_PUSHGS
00275         0x57,   // LOPC_PUSHGL
00276         0x58,   // LOPC_PUSHGV
00277         0x59,   // LOPC_PUSHGQ
00278         0x5a,   // LOPC_PUSHIP
00279         0x5b,   // LOPC_PUSHBP
00280         0x5c,   // LOPC_PUSHSP
00281         0x5d,   // LOPC_PUSHARGB
00282         0x5e,   // LOPC_PUSHARGI
00283         0x5f,   // LOPC_PUSHARGF
00284         0x60,   // LOPC_PUSHARGS
00285         0x61,   // LOPC_PUSHARGV
00286         0x62,   // LOPC_PUSHARGQ
00287         0x63,   // LOPC_PUSHE
00288         0x64,   // LOPC_PUSHEV
00289         0x65,   // LOPC_PUSHEQ
00290         0x66,   // LOPC_PUSHARGE
00291         0x70,   // LOPC_ADD
00292         0x71,   // LOPC_SUB
00293         0x72,   // LOPC_MUL
00294         0x73,   // LOPC_DIV
00295         0x74,   // LOPC_MOD
00296         0x75,   // LOPC_EQ
00297         0x76,   // LOPC_NEQ
00298         0x77,   // LOPC_LEQ
00299         0x78,   // LOPC_GEQ
00300         0x79,   // LOPC_LESS
00301         0x7a,   // LOPC_GREATER
00302         0x7b,   // LOPC_BITAND
00303         0x7c,   // LOPC_BITOR
00304         0x7d,   // LOPC_BITXOR
00305         0x7e,   // LOPC_BOOLAND
00306         0x7f,   // LOPC_BOOLOR
00307         0x80,   // LOPC_NEG
00308         0x81,   // LOPC_BITNOT
00309         0x82,   // LOPC_BOOLNOT
00310         0x90,   // LOPC_JUMP
00311         0x91,   // LOPC_JUMPIF
00312         0x92,   // LOPC_JUMPNIF
00313         0x93,   // LOPC_STATE
00314         0x94,   // LOPC_CALL
00315         0x95,   // LOPC_RETURN
00316         0xa0,   // LOPC_CAST
00317         0xb0,   // LOPC_STACKTOS
00318         0xb1,   // LOPC_STACKTOL
00319         0xc0,   // LOPC_PRINT
00320         0xd0,   // LOPC_CALLLIB
00321         0xd1,   // LOPC_CALLLIB_TWO_BYTE
00322         0xe0,   // LOPC_SHL
00323         0xe1    // LOPC_SHR
00324 };
00325 
00326 typedef enum e_lscript_state_event_type
00327 {
00328         LSTT_NULL,
00329         LSTT_STATE_ENTRY,
00330         LSTT_STATE_EXIT,
00331         LSTT_TOUCH_START,
00332         LSTT_TOUCH,
00333         LSTT_TOUCH_END,
00334         LSTT_COLLISION_START,
00335         LSTT_COLLISION,
00336         LSTT_COLLISION_END,
00337         LSTT_LAND_COLLISION_START,
00338         LSTT_LAND_COLLISION,
00339         LSTT_LAND_COLLISION_END,
00340         LSTT_TIMER,
00341         LSTT_CHAT,
00342         LSTT_REZ,
00343         LSTT_SENSOR,
00344         LSTT_NO_SENSOR,
00345         LSTT_CONTROL,
00346         LSTT_MONEY,
00347         LSTT_EMAIL,
00348         LSTT_AT_TARGET,
00349         LSTT_NOT_AT_TARGET,
00350         LSTT_AT_ROT_TARGET,
00351         LSTT_NOT_AT_ROT_TARGET,
00352         LSTT_RTPERMISSIONS,
00353         LSTT_INVENTORY,
00354         LSTT_ATTACH,
00355         LSTT_DATASERVER,
00356         LSTT_LINK_MESSAGE,
00357         LSTT_MOVING_START,
00358         LSTT_MOVING_END,
00359         LSTT_OBJECT_REZ,
00360         LSTT_REMOTE_DATA,
00361         LSTT_HTTP_RESPONSE,
00362         LSTT_EOF,
00363         
00364         LSTT_STATE_BEGIN = LSTT_STATE_ENTRY,
00365         LSTT_STATE_END = LSTT_EOF
00366 } LSCRIPTStateEventType;
00367 
00368 const U64 LSCRIPTStateBitField[LSTT_EOF] =
00369 {
00370         0x0000000000000000,             //      LSTT_NULL
00371         0x0000000000000001,             //      LSTT_STATE_ENTRY
00372         0x0000000000000002,             //      LSTT_STATE_EXIT
00373         0x0000000000000004,             //      LSTT_TOUCH_START
00374         0x0000000000000008,             //      LSTT_TOUCH
00375         0x0000000000000010,             //      LSTT_TOUCH_END
00376         0x0000000000000020,             //      LSTT_COLLISION_START
00377         0x0000000000000040,             //      LSTT_COLLISION
00378         0x0000000000000080,             //      LSTT_COLLISION_END
00379         0x0000000000000100,             //      LSTT_LAND_COLLISION_START
00380         0x0000000000000200,             //      LSTT_LAND_COLLISION
00381         0x0000000000000400,             //      LSTT_LAND_COLLISION_END
00382         0x0000000000000800,             //      LSTT_TIMER
00383         0x0000000000001000,             //      LSTT_CHAT
00384         0x0000000000002000,             //      LSTT_REZ
00385         0x0000000000004000,             //      LSTT_SENSOR
00386         0x0000000000008000,             //      LSTT_NO_SENSOR
00387         0x0000000000010000,             //      LSTT_CONTROL
00388         0x0000000000020000,             //      LSTT_MONEY
00389         0x0000000000040000,             //      LSTT_EMAIL
00390         0x0000000000080000,             //      LSTT_AT_TARGET
00391         0x0000000000100000,             //      LSTT_NOT_AT_TARGET
00392         0x0000000000200000,             //      LSTT_AT_ROT_TARGET
00393         0x0000000000400000,             //      LSTT_NOT_AT_ROT_TARGET
00394         0x0000000000800000,             //      LSTT_RTPERMISSIONS
00395         0x0000000001000000,             //      LSTT_INVENTORY
00396         0x0000000002000000,             //      LSTT_ATTACH
00397         0x0000000004000000,             //      LSTT_DATASERVER
00398         0x0000000008000000,             //  LSTT_LINK_MESSAGE
00399         0x0000000010000000,             //  LSTT_MOVING_START
00400         0x0000000020000000,             //  LSTT_MOVING_END
00401         0x0000000040000000,             //  LSTT_OBJECT_REZ
00402         0x0000000080000000,             //  LSTT_REMOTE_DATA
00403         0x0000000100000000LL     // LSTT_HTTP_RESPOSE
00404 };
00405 
00406 inline S32 get_event_handler_jump_position(U64 bit_field, LSCRIPTStateEventType type)
00407 {
00408         S32 count = 0, position = LSTT_STATE_ENTRY;
00409         while (position < type)
00410         {
00411                 if (bit_field & 0x1)
00412                 {
00413                         count++;
00414                 }
00415                 bit_field >>= 1;
00416                 position++;
00417         }
00418         return count;
00419 }
00420 
00421 inline S32 get_number_of_event_handlers(U64 bit_field)
00422 {
00423         S32 count = 0, position = 0;
00424         while (position < LSTT_EOF)
00425         {
00426                 if (bit_field & 0x1)
00427                 {
00428                         count++;
00429                 }
00430                 bit_field >>= 1;
00431                 position++;
00432         }
00433         return count;
00434 }
00435 
00436 typedef enum e_lscript_types
00437 {
00438         LST_NULL,
00439         LST_INTEGER,
00440         LST_FLOATINGPOINT,
00441         LST_STRING,
00442         LST_KEY,
00443         LST_VECTOR,
00444         LST_QUATERNION,
00445         LST_LIST,
00446         LST_UNDEFINED,
00447         LST_EOF
00448 } LSCRIPTType;
00449 
00450 const U8 LSCRIPTTypeByte[LST_EOF] =
00451 {
00452         LST_NULL,
00453         LST_INTEGER,
00454         LST_FLOATINGPOINT,
00455         LST_STRING,
00456         LST_KEY,
00457         LST_VECTOR,
00458         LST_QUATERNION,
00459         LST_LIST,
00460         LST_NULL,
00461 };
00462 
00463 const U8 LSCRIPTTypeHi4Bits[LST_EOF] =
00464 {
00465         LST_NULL,
00466         LST_INTEGER << 4,
00467         LST_FLOATINGPOINT << 4,
00468         LST_STRING << 4,
00469         LST_KEY << 4,
00470         LST_VECTOR << 4,
00471         LST_QUATERNION << 4,
00472         LST_LIST << 4,
00473 };
00474 
00475 const char * const LSCRIPTTypeNames[LST_EOF] =  /*Flawfinder: ignore*/
00476 {
00477         "VOID",
00478         "integer",
00479         "float",
00480         "string",
00481         "key",
00482         "vector",
00483         "quaternion",
00484         "list",
00485         "invalid"
00486 };
00487 
00488 const S32 LSCRIPTDataSize[LST_EOF] =
00489 {
00490         0,      // VOID
00491         4,      // integer
00492         4,      // float
00493         4,      // string
00494         4,      // key
00495         12,     // vector
00496         16,     // quaternion
00497         4,      // list
00498         0       // invalid
00499 };
00500 
00501 
00502 typedef enum e_lscript_runtime_faults
00503 {
00504         LSRF_INVALID,
00505         LSRF_MATH,
00506         LSRF_STACK_HEAP_COLLISION,
00507         LSRF_BOUND_CHECK_ERROR,
00508         LSRF_HEAP_ERROR,
00509         LSRF_VERSION_MISMATCH,
00510         LSRF_MISSING_INVENTORY,
00511         LSRF_SANDBOX,
00512         LSRF_CHAT_OVERRUN,
00513         LSRF_TOO_MANY_LISTENS,
00514         LSRF_NESTING_LISTS,
00515         LSRF_EOF
00516 } LSCRIPTRunTimeFaults;
00517 
00518 extern char* LSCRIPTRunTimeFaultStrings[LSRF_EOF];      /*Flawfinder: ignore*/
00519 
00520 const S32 LSCRIPTRunTimeFaultBits[LSRF_EOF] =
00521 {
00522         0,              //      LSRF_INVALID
00523         1,              //      LSRF_MATH
00524         2,              //      LSRF_STACK_HEAP_COLLISION
00525         3,              //      LSREF_BOUND_CHECK_ERROR
00526         4,              //      LSREF_HEAP_ERROR
00527         5,              //      LSREF_VERSION_MISMATCH
00528         6,              //      LSREF_MISSING_INVENTORY
00529         7,              //      LSRF_SANDBOX
00530         8,              //      LSRF_CHAT_OVERRUN
00531         9,              //      LSRF_TOO_MANY_LISTENS
00532         10,             //      LSRF_NESTING_LISTS
00533 };
00534 
00535 typedef enum e_lscript_runtime_permissions
00536 {
00537         SCRIPT_PERMISSION_DEBIT,
00538         SCRIPT_PERMISSION_TAKE_CONTROLS,
00539         SCRIPT_PERMISSION_REMAP_CONTROLS,
00540         SCRIPT_PERMISSION_TRIGGER_ANIMATION,
00541         SCRIPT_PERMISSION_ATTACH,
00542         SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
00543         SCRIPT_PERMISSION_CHANGE_LINKS,
00544         SCRIPT_PERMISSION_CHANGE_JOINTS,
00545         SCRIPT_PERMISSION_CHANGE_PERMISSIONS,
00546         SCRIPT_PERMISSION_TRACK_CAMERA,
00547         SCRIPT_PERMISSION_CONTROL_CAMERA,
00548         SCRIPT_PERMISSION_EOF
00549 } LSCRIPTRunTimePermissions;
00550 
00551 const U32 LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_EOF] =
00552 {
00553         (0x1 << 1),     //      SCRIPT_PERMISSION_DEBIT,
00554         (0x1 << 2),     //      SCRIPT_PERMISSION_TAKE_CONTROLS,
00555         (0x1 << 3),     //      SCRIPT_PERMISSION_REMAP_CONTROLS,
00556         (0x1 << 4),     //      SCRIPT_PERMISSION_TRIGGER_ANIMATION,
00557         (0x1 << 5),     //      SCRIPT_PERMISSION_ATTACH,
00558         (0x1 << 6),     //      SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
00559         (0x1 << 7),     //      SCRIPT_PERMISSION_CHANGE_LINKS,
00560         (0x1 << 8),     //      SCRIPT_PERMISSION_CHANGE_JOINTS,
00561         (0x1 << 9),     //      SCRIPT_PERMISSION_CHANGE_PERMISSIONS
00562         (0x1 << 10),//  SCRIPT_PERMISSION_TRACK_CAMERA
00563         (0x1 << 11),//  SCRIPT_PERMISSION_CONTROL_CAMERA
00564 };
00565 
00566 #endif
00567 

Generated on Thu Jul 1 06:09:49 2010 for Second Life Viewer by  doxygen 1.4.7