PageRenderTime 100ms CodeModel.GetById 41ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lscript/lscript_byteformat.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 556 lines | 500 code | 29 blank | 27 comment | 4 complexity | 8e981be53c78c5bb74eedf8014a3c162 MD5 | raw file
  1/** 
  2 * @file lscript_byteformat.h
  3 * @brief Shared code between compiler and assembler and LSL
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LSCRIPT_BYTEFORMAT_H
 28#define LL_LSCRIPT_BYTEFORMAT_H
 29
 30// Data shared between compiler/assembler and lscript execution code
 31
 32#include "stdtypes.h"
 33
 34const S32 LSL2_VERSION_NUMBER = 0x0200;
 35const S32 LSL2_VERSION1_END_NUMBER = 0x0101;
 36const S32 LSL2_VERSION2_START_NUMBER = 0x0200;
 37
 38const S32 LSL2_MAJOR_VERSION_ONE = 1;
 39const S32 LSL2_MAJOR_VERSION_TWO = 2;
 40const S32 LSL2_CURRENT_MAJOR_VERSION = LSL2_MAJOR_VERSION_TWO;
 41
 42const S32 TOP_OF_MEMORY = 16384;
 43
 44typedef enum e_lscript_registers
 45{
 46	LREG_INVALID,
 47	LREG_IP,		// instruction pointer
 48	LREG_VN,		// version number
 49	LREG_BP,		// base pointer - what local variables are referenced from
 50	LREG_SP,		// stack pointer - where the top of the stack is
 51	LREG_HR,		// heap register - where in memory does the heap start
 52	LREG_HP,		// heap pointer - where is the top of the heap?
 53	LREG_CS,		// current state - what state are we currently in?
 54	LREG_NS,		// next state - what state are we currently in?
 55	LREG_CE,		// current events - what events are waiting to be handled?
 56	LREG_IE,		// in event - which event handler are we currently in?
 57	LREG_ER,		// event register - what events do we have active handlers for?
 58	LREG_FR,		// fault register - which errors are currently active?
 59	LREG_SLR,		// sleep register - are we sleeping?
 60	LREG_GVR,		// global variable register - where do global variables start
 61	LREG_GFR,		// global function register - where do global functions start
 62	LREG_SR,		// state register - where do states start
 63	LREG_TM,		// top of memory - where is the top of memory
 64	LREG_PR,		// parameter register - data passed to script from launcher
 65	LREG_ESR,		// energy supply register - how much energy do we have on board?
 66	LREG_NCE,		// 64 bit current envents - what events are waiting to be handled?
 67	LREG_NIE,		// 64 bit in event - which event handler are we currently in?
 68	LREG_NER,		// 64 bit event register - what events do we have active handlers for?
 69	LREG_EOF
 70} LSCRIPTRegisters;
 71
 72const S32 gLSCRIPTRegisterAddresses[LREG_EOF] =	/* Flawfinder: ignore */
 73{
 74	0,			// LREG_INVALID
 75	4,			// LREG_IP
 76	8,			// LREG_VN
 77	12,			// LREG_BP
 78	16,			// LREG_SP
 79	20,			// LREG_HR
 80	24,			// LREG_HP
 81	28,			// LREG_CS
 82	32,			// LREG_NS
 83	36,			// LREG_CE
 84	40,			// LREG_IE
 85	44,			// LREG_ER
 86	48,			// LREG_FR
 87	52,			// LREG_SLR
 88	56,			// LREG_GVR
 89	60,			// LREG_GFR
 90	72,			// LREG_SR
 91	0,			// LREG_TM
 92	64,			// LREG_PR
 93	68,			// LREG_ESR
 94	76,			// LREG_NCE
 95	84,			// LREG_NIE
 96	92,			// LREG_NER
 97};
 98
 99const char * const gLSCRIPTRegisterNames[LREG_EOF] =
100{
101	"INVALID",		// LREG_INVALID
102	"IP",			// LREG_IP
103	"VN",			// LREG_VN
104	"BP",			// LREG_BP
105	"SP",			// LREG_SP
106	"HR",			// LREG_HR
107	"HP",			// LREG_HP
108	"CS",			// LREG_CS
109	"NS",			// LREG_NS
110	"CE",			// LREG_CE
111	"IE",			// LREG_IE
112	"ER",			// LREG_ER
113	"FR",			// LREG_FR
114	"SLR",			// LREG_SLR
115	"GVR",			// LREG_GVR
116	"GFR",			// LREG_GFR
117	"SR",			// LREG_SR
118	"TM",			// LREG_TM
119	"PR",			// LREG_PR
120	"ESR",			// LREG_ESR
121	"NCE",			// LREG_NCE
122	"NIE",			// LREG_NIE
123	"NER",			// LREG_NER
124};
125
126typedef enum e_lscript_op_codes
127{
128	LOPC_INVALID,
129	LOPC_NOOP,
130	LOPC_POP,
131	LOPC_POPS,
132	LOPC_POPL,
133	LOPC_POPV,
134	LOPC_POPQ,
135	LOPC_POPARG,
136	LOPC_POPIP,
137	LOPC_POPBP,
138	LOPC_POPSP,
139	LOPC_POPSLR,
140	LOPC_DUP,
141	LOPC_DUPS,
142	LOPC_DUPL,
143	LOPC_DUPV,
144	LOPC_DUPQ,
145	LOPC_STORE,
146	LOPC_STORES,
147	LOPC_STOREL,
148	LOPC_STOREV,
149	LOPC_STOREQ,
150	LOPC_STOREG,
151	LOPC_STOREGS,
152	LOPC_STOREGL,
153	LOPC_STOREGV,
154	LOPC_STOREGQ,
155	LOPC_LOADP,
156	LOPC_LOADSP,
157	LOPC_LOADLP,
158	LOPC_LOADVP,
159	LOPC_LOADQP,
160	LOPC_LOADGP,
161	LOPC_LOADGLP,
162	LOPC_LOADGSP,
163	LOPC_LOADGVP,
164	LOPC_LOADGQP,
165	LOPC_PUSH,
166	LOPC_PUSHS,
167	LOPC_PUSHL,
168	LOPC_PUSHV,
169	LOPC_PUSHQ,
170	LOPC_PUSHG,
171	LOPC_PUSHGS,
172	LOPC_PUSHGL,
173	LOPC_PUSHGV,
174	LOPC_PUSHGQ,
175	LOPC_PUSHIP,
176	LOPC_PUSHBP,
177	LOPC_PUSHSP,
178	LOPC_PUSHARGB,
179	LOPC_PUSHARGI,
180	LOPC_PUSHARGF,
181	LOPC_PUSHARGS,
182	LOPC_PUSHARGV,
183	LOPC_PUSHARGQ,
184	LOPC_PUSHE,
185	LOPC_PUSHEV,
186	LOPC_PUSHEQ,
187	LOPC_PUSHARGE,
188	LOPC_ADD,
189	LOPC_SUB,
190	LOPC_MUL,
191	LOPC_DIV,
192	LOPC_MOD,
193	LOPC_EQ,
194	LOPC_NEQ,
195	LOPC_LEQ,
196	LOPC_GEQ,
197	LOPC_LESS,
198	LOPC_GREATER,
199	LOPC_BITAND,
200	LOPC_BITOR,
201	LOPC_BITXOR,
202	LOPC_BOOLAND,
203	LOPC_BOOLOR,
204	LOPC_NEG,
205	LOPC_BITNOT,
206	LOPC_BOOLNOT,
207	LOPC_JUMP,
208	LOPC_JUMPIF,
209	LOPC_JUMPNIF,
210	LOPC_STATE,
211	LOPC_CALL,
212	LOPC_RETURN,
213	LOPC_CAST,
214	LOPC_STACKTOS,
215	LOPC_STACKTOL,
216	LOPC_PRINT,
217	LOPC_CALLLIB,
218	LOPC_CALLLIB_TWO_BYTE,
219	LOPC_SHL,
220	LOPC_SHR,
221	LOPC_EOF
222} LSCRIPTOpCodesEnum;
223
224const U8 LSCRIPTOpCodes[LOPC_EOF] =
225{
226	0x00,	// LOPC_INVALID
227	0x00,	// LOPC_NOOP
228	0x01,	// LOPC_POP
229	0x02,	// LOPC_POPS
230	0x03,	// LOPC_POPL
231	0x04,	// LOPC_POPV
232	0x05,	// LOPC_POPQ
233	0x06,	// LOPC_POPARG
234	0x07,	// LOPC_POPIP
235	0x08,	// LOPC_POPBP
236	0x09,	// LOPC_POPSP
237	0x0a,	// LOPC_POPSLR
238	0x20,	// LOPC_DUP
239	0x21,	// LOPC_DUPS
240	0x22,	// LOPC_DUPL
241	0x23,	// LOPC_DUPV
242	0x24,	// LOPC_DUPQ
243	0x30,	// LOPC_STORE
244	0x31,	// LOPC_STORES
245	0x32,	// LOPC_STOREL
246	0x33,	// LOPC_STOREV
247	0x34,	// LOPC_STOREQ
248	0x35,	// LOPC_STOREG
249	0x36,	// LOPC_STOREGS
250	0x37,	// LOPC_STOREGL
251	0x38,	// LOPC_STOREGV
252	0x39,	// LOPC_STOREGQ
253	0x3a,	// LOPC_LOADP
254	0x3b,	// LOPC_LOADSP
255	0x3c,	// LOPC_LOADLP
256	0x3d,	// LOPC_LOADVP
257	0x3e,	// LOPC_LOADQP
258	0x3f,	// LOPC_LOADGP
259	0x40,	// LOPC_LOADGSP
260	0x41,	// LOPC_LOADGLP
261	0x42,	// LOPC_LOADGVP
262	0x43,	// LOPC_LOADGQP
263	0x50,	// LOPC_PUSH
264	0x51,	// LOPC_PUSHS
265	0x52,	// LOPC_PUSHL
266	0x53,	// LOPC_PUSHV
267	0x54,	// LOPC_PUSHQ
268	0x55,	// LOPC_PUSHG
269	0x56,	// LOPC_PUSHGS
270	0x57,	// LOPC_PUSHGL
271	0x58,	// LOPC_PUSHGV
272	0x59,	// LOPC_PUSHGQ
273	0x5a,	// LOPC_PUSHIP
274	0x5b,	// LOPC_PUSHBP
275	0x5c,	// LOPC_PUSHSP
276	0x5d,	// LOPC_PUSHARGB
277	0x5e,	// LOPC_PUSHARGI
278	0x5f,	// LOPC_PUSHARGF
279	0x60,	// LOPC_PUSHARGS
280	0x61,	// LOPC_PUSHARGV
281	0x62,	// LOPC_PUSHARGQ
282	0x63,	// LOPC_PUSHE
283	0x64,	// LOPC_PUSHEV
284	0x65,	// LOPC_PUSHEQ
285	0x66,	// LOPC_PUSHARGE
286	0x70,	// LOPC_ADD
287	0x71,	// LOPC_SUB
288	0x72,	// LOPC_MUL
289	0x73,	// LOPC_DIV
290	0x74,	// LOPC_MOD
291	0x75,	// LOPC_EQ
292	0x76,	// LOPC_NEQ
293	0x77,	// LOPC_LEQ
294	0x78,	// LOPC_GEQ
295	0x79,	// LOPC_LESS
296	0x7a,	// LOPC_GREATER
297	0x7b,	// LOPC_BITAND
298	0x7c,	// LOPC_BITOR
299	0x7d,	// LOPC_BITXOR
300	0x7e,	// LOPC_BOOLAND
301	0x7f,	// LOPC_BOOLOR
302	0x80,	// LOPC_NEG
303	0x81,	// LOPC_BITNOT
304	0x82,	// LOPC_BOOLNOT
305	0x90,	// LOPC_JUMP
306	0x91,	// LOPC_JUMPIF
307	0x92,	// LOPC_JUMPNIF
308	0x93,	// LOPC_STATE
309	0x94,	// LOPC_CALL
310	0x95,	// LOPC_RETURN
311	0xa0,	// LOPC_CAST
312	0xb0,	// LOPC_STACKTOS
313	0xb1,	// LOPC_STACKTOL
314	0xc0,	// LOPC_PRINT
315	0xd0,	// LOPC_CALLLIB
316	0xd1,	// LOPC_CALLLIB_TWO_BYTE
317	0xe0,	// LOPC_SHL
318	0xe1	// LOPC_SHR
319};
320
321typedef enum e_lscript_state_event_type
322{
323	LSTT_NULL,
324	LSTT_STATE_ENTRY,
325	LSTT_STATE_EXIT,
326	LSTT_TOUCH_START,
327	LSTT_TOUCH,
328	LSTT_TOUCH_END,
329	LSTT_COLLISION_START,
330	LSTT_COLLISION,
331	LSTT_COLLISION_END,
332	LSTT_LAND_COLLISION_START,
333	LSTT_LAND_COLLISION,
334	LSTT_LAND_COLLISION_END,
335	LSTT_TIMER,
336	LSTT_CHAT,
337	LSTT_REZ,
338	LSTT_SENSOR,
339	LSTT_NO_SENSOR,
340	LSTT_CONTROL,
341	LSTT_MONEY,
342	LSTT_EMAIL,
343	LSTT_AT_TARGET,
344	LSTT_NOT_AT_TARGET,
345	LSTT_AT_ROT_TARGET,
346	LSTT_NOT_AT_ROT_TARGET,
347	LSTT_RTPERMISSIONS,
348	LSTT_INVENTORY,
349	LSTT_ATTACH,
350	LSTT_DATASERVER,
351	LSTT_LINK_MESSAGE,
352	LSTT_MOVING_START,
353	LSTT_MOVING_END,
354	LSTT_OBJECT_REZ,
355	LSTT_REMOTE_DATA,
356	LSTT_HTTP_RESPONSE,
357	LSTT_HTTP_REQUEST,
358	LSTT_EOF,
359	
360	LSTT_STATE_BEGIN = LSTT_STATE_ENTRY,
361	LSTT_STATE_END = LSTT_EOF
362} LSCRIPTStateEventType;
363
364const U64 LSCRIPTStateBitField[LSTT_EOF] =
365{
366	0x0000000000000000,		//	LSTT_NULL
367	0x0000000000000001,		//	LSTT_STATE_ENTRY
368	0x0000000000000002,		//	LSTT_STATE_EXIT
369	0x0000000000000004,		//	LSTT_TOUCH_START
370	0x0000000000000008,		//	LSTT_TOUCH
371	0x0000000000000010,		//	LSTT_TOUCH_END
372	0x0000000000000020,		//	LSTT_COLLISION_START
373	0x0000000000000040,		//	LSTT_COLLISION
374	0x0000000000000080,		//	LSTT_COLLISION_END
375	0x0000000000000100,		//	LSTT_LAND_COLLISION_START
376	0x0000000000000200,		//	LSTT_LAND_COLLISION
377	0x0000000000000400,		//	LSTT_LAND_COLLISION_END
378	0x0000000000000800,		//	LSTT_TIMER
379	0x0000000000001000,		//	LSTT_CHAT
380	0x0000000000002000,		//	LSTT_REZ
381	0x0000000000004000,		//	LSTT_SENSOR
382	0x0000000000008000,		//	LSTT_NO_SENSOR
383	0x0000000000010000,		//	LSTT_CONTROL
384	0x0000000000020000,		//	LSTT_MONEY
385	0x0000000000040000,		//	LSTT_EMAIL
386	0x0000000000080000,		//	LSTT_AT_TARGET
387	0x0000000000100000,		//	LSTT_NOT_AT_TARGET
388	0x0000000000200000,		//	LSTT_AT_ROT_TARGET
389	0x0000000000400000,		//	LSTT_NOT_AT_ROT_TARGET
390	0x0000000000800000,		//	LSTT_RTPERMISSIONS
391	0x0000000001000000,		//	LSTT_INVENTORY
392	0x0000000002000000,		//	LSTT_ATTACH
393	0x0000000004000000,		//	LSTT_DATASERVER
394	0x0000000008000000,		//  LSTT_LINK_MESSAGE
395	0x0000000010000000,		//  LSTT_MOVING_START
396	0x0000000020000000,		//  LSTT_MOVING_END
397	0x0000000040000000,		//  LSTT_OBJECT_REZ
398	0x0000000080000000,		//  LSTT_REMOTE_DATA
399	0x0000000100000000LL,	// LSTT_HTTP_RESPOSE
400	0x0000000200000000LL 	// LSTT_HTTP_REQUEST
401};
402
403inline S32 get_event_handler_jump_position(U64 bit_field, LSCRIPTStateEventType type)
404{
405	S32 count = 0, position = LSTT_STATE_ENTRY;
406	while (position < type)
407	{
408		if (bit_field & 0x1)
409		{
410			count++;
411		}
412		bit_field >>= 1;
413		position++;
414	}
415	return count;
416}
417
418inline S32 get_number_of_event_handlers(U64 bit_field)
419{
420	S32 count = 0, position = 0;
421	while (position < LSTT_EOF)
422	{
423		if (bit_field & 0x1)
424		{
425			count++;
426		}
427		bit_field >>= 1;
428		position++;
429	}
430	return count;
431}
432
433typedef enum e_lscript_types
434{
435	LST_NULL,
436	LST_INTEGER,
437	LST_FLOATINGPOINT,
438	LST_STRING,
439	LST_KEY,
440	LST_VECTOR,
441	LST_QUATERNION,
442	LST_LIST,
443	LST_UNDEFINED,
444	LST_EOF
445} LSCRIPTType;
446
447const U8 LSCRIPTTypeByte[LST_EOF] =
448{
449	LST_NULL,
450	LST_INTEGER,
451	LST_FLOATINGPOINT,
452	LST_STRING,
453	LST_KEY,
454	LST_VECTOR,
455	LST_QUATERNION,
456	LST_LIST,
457	LST_NULL,
458};
459
460const U8 LSCRIPTTypeHi4Bits[LST_EOF] =
461{
462	LST_NULL,
463	LST_INTEGER << 4,
464	LST_FLOATINGPOINT << 4,
465	LST_STRING << 4,
466	LST_KEY << 4,
467	LST_VECTOR << 4,
468	LST_QUATERNION << 4,
469	LST_LIST << 4,
470	LST_UNDEFINED << 4,
471};
472
473const char * const LSCRIPTTypeNames[LST_EOF] = 	/*Flawfinder: ignore*/
474{
475	"VOID",
476	"integer",
477	"float",
478	"string",
479	"key",
480	"vector",
481	"quaternion",
482	"list",
483	"invalid"
484};
485
486const S32 LSCRIPTDataSize[LST_EOF] =
487{
488	0,	// VOID
489	4,	// integer
490	4,	// float
491	4,	// string
492	4,	// key
493	12,	// vector
494	16,	// quaternion
495	4,	// list
496	0	// invalid
497};
498
499
500typedef enum e_lscript_runtime_faults
501{
502	LSRF_INVALID,
503	LSRF_MATH,
504	LSRF_STACK_HEAP_COLLISION,
505	LSRF_BOUND_CHECK_ERROR,
506	LSRF_HEAP_ERROR,
507	LSRF_VERSION_MISMATCH,
508	LSRF_MISSING_INVENTORY,
509	LSRF_SANDBOX,
510	LSRF_CHAT_OVERRUN,
511	LSRF_TOO_MANY_LISTENS,
512	LSRF_NESTING_LISTS,
513	LSRF_CLI,
514	LSRF_EOF
515} LSCRIPTRunTimeFaults;
516
517extern const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF]; 	/*Flawfinder: ignore*/
518
519typedef enum e_lscript_runtime_permissions
520{
521	SCRIPT_PERMISSION_DEBIT,
522	SCRIPT_PERMISSION_TAKE_CONTROLS,
523	SCRIPT_PERMISSION_REMAP_CONTROLS,
524	SCRIPT_PERMISSION_TRIGGER_ANIMATION,
525	SCRIPT_PERMISSION_ATTACH,
526	SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
527	SCRIPT_PERMISSION_CHANGE_LINKS,
528	SCRIPT_PERMISSION_CHANGE_JOINTS,
529	SCRIPT_PERMISSION_CHANGE_PERMISSIONS,
530	SCRIPT_PERMISSION_TRACK_CAMERA,
531	SCRIPT_PERMISSION_CONTROL_CAMERA,
532	SCRIPT_PERMISSION_EOF
533} LSCRIPTRunTimePermissions;
534
535const U32 LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_EOF] =
536{
537	(0x1 << 1),	//	SCRIPT_PERMISSION_DEBIT,
538	(0x1 << 2),	//	SCRIPT_PERMISSION_TAKE_CONTROLS,
539	(0x1 << 3),	//	SCRIPT_PERMISSION_REMAP_CONTROLS,
540	(0x1 << 4),	//	SCRIPT_PERMISSION_TRIGGER_ANIMATION,
541	(0x1 << 5),	//	SCRIPT_PERMISSION_ATTACH,
542	(0x1 << 6),	//	SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
543	(0x1 << 7),	//	SCRIPT_PERMISSION_CHANGE_LINKS,
544	(0x1 << 8),	//	SCRIPT_PERMISSION_CHANGE_JOINTS,
545	(0x1 << 9),	//	SCRIPT_PERMISSION_CHANGE_PERMISSIONS
546	(0x1 << 10),//	SCRIPT_PERMISSION_TRACK_CAMERA
547	(0x1 << 11),//	SCRIPT_PERMISSION_CONTROL_CAMERA
548};
549
550// http_request string constants
551extern const char* URL_REQUEST_GRANTED;
552extern const char* URL_REQUEST_DENIED;
553extern const U64 LSL_HTTP_REQUEST_TIMEOUT_USEC;
554
555#endif
556