aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/lscript/lscript_byteformat.h
blob: fa82e6be6534d37c37369e41a48ae69d30d583cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/** 
 * @file lscript_byteformat.h
 * @brief Shared code between compiler and assembler and LSL
 *
 * $LicenseInfo:firstyear=2002&license=viewergpl$
 * 
 * Copyright (c) 2002-2008, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#ifndef LL_LSCRIPT_BYTEFORMAT_H
#define LL_LSCRIPT_BYTEFORMAT_H

// Data shared between compiler/assembler and lscript execution code

#include "stdtypes.h"

const S32 LSL2_VERSION_NUMBER = 0x0200;
const S32 LSL2_VERSION1_END_NUMBER = 0x0101;
const S32 LSL2_VERSION2_START_NUMBER = 0x0200;

const S32 LSL2_MAJOR_VERSION_ONE = 1;
const S32 LSL2_MAJOR_VERSION_TWO = 2;
const S32 LSL2_CURRENT_MAJOR_VERSION = LSL2_MAJOR_VERSION_TWO;

const S32 TOP_OF_MEMORY = 16384;

typedef enum e_lscript_registers
{
	LREG_INVALID,
	LREG_IP,		// instruction pointer
	LREG_VN,		// version number
	LREG_BP,		// base pointer - what local variables are referenced from
	LREG_SP,		// stack pointer - where the top of the stack is
	LREG_HR,		// heap register - where in memory does the heap start
	LREG_HP,		// heap pointer - where is the top of the heap?
	LREG_CS,		// current state - what state are we currently in?
	LREG_NS,		// next state - what state are we currently in?
	LREG_CE,		// current events - what events are waiting to be handled?
	LREG_IE,		// in event - which event handler are we currently in?
	LREG_ER,		// event register - what events do we have active handlers for?
	LREG_FR,		// fault register - which errors are currently active?
	LREG_SLR,		// sleep register - are we sleeping?
	LREG_GVR,		// global variable register - where do global variables start
	LREG_GFR,		// global function register - where do global functions start
	LREG_SR,		// state register - where do states start
	LREG_TM,		// top of memory - where is the top of memory
	LREG_PR,		// parameter register - data passed to script from launcher
	LREG_ESR,		// energy supply register - how much energy do we have on board?
	LREG_NCE,		// 64 bit current envents - what events are waiting to be handled?
	LREG_NIE,		// 64 bit in event - which event handler are we currently in?
	LREG_NER,		// 64 bit event register - what events do we have active handlers for?
	LREG_EOF
} LSCRIPTRegisters;

const S32 gLSCRIPTRegisterAddresses[LREG_EOF] =	/* Flawfinder: ignore */
{
	0,			// LREG_INVALID
	4,			// LREG_IP
	8,			// LREG_VN
	12,			// LREG_BP
	16,			// LREG_SP
	20,			// LREG_HR
	24,			// LREG_HP
	28,			// LREG_CS
	32,			// LREG_NS
	36,			// LREG_CE
	40,			// LREG_IE
	44,			// LREG_ER
	48,			// LREG_FR
	52,			// LREG_SLR
	56,			// LREG_GVR
	60,			// LREG_GFR
	72,			// LREG_SR
	0,			// LREG_TM
	64,			// LREG_PR
	68,			// LREG_ESR
	76,			// LREG_NCE
	84,			// LREG_NIE
	92,			// LREG_NER
};

const char * const gLSCRIPTRegisterNames[LREG_EOF] =
{
	"INVALID",		// LREG_INVALID
	"IP",			// LREG_IP
	"VN",			// LREG_VN
	"BP",			// LREG_BP
	"SP",			// LREG_SP
	"HR",			// LREG_HR
	"HP",			// LREG_HP
	"CS",			// LREG_CS
	"NS",			// LREG_NS
	"CE",			// LREG_CE
	"IE",			// LREG_IE
	"ER",			// LREG_ER
	"FR",			// LREG_FR
	"SLR",			// LREG_SLR
	"GVR",			// LREG_GVR
	"GFR",			// LREG_GFR
	"SR",			// LREG_SR
	"TM",			// LREG_TM
	"PR",			// LREG_PR
	"ESR",			// LREG_ESR
	"NCE",			// LREG_NCE
	"NIE",			// LREG_NIE
	"NER",			// LREG_NER
};

typedef enum e_lscript_op_codes
{
	LOPC_INVALID,
	LOPC_NOOP,
	LOPC_POP,
	LOPC_POPS,
	LOPC_POPL,
	LOPC_POPV,
	LOPC_POPQ,
	LOPC_POPARG,
	LOPC_POPIP,
	LOPC_POPBP,
	LOPC_POPSP,
	LOPC_POPSLR,
	LOPC_DUP,
	LOPC_DUPS,
	LOPC_DUPL,
	LOPC_DUPV,
	LOPC_DUPQ,
	LOPC_STORE,
	LOPC_STORES,
	LOPC_STOREL,
	LOPC_STOREV,
	LOPC_STOREQ,
	LOPC_STOREG,
	LOPC_STOREGS,
	LOPC_STOREGL,
	LOPC_STOREGV,
	LOPC_STOREGQ,
	LOPC_LOADP,
	LOPC_LOADSP,
	LOPC_LOADLP,
	LOPC_LOADVP,
	LOPC_LOADQP,
	LOPC_LOADGP,
	LOPC_LOADGLP,
	LOPC_LOADGSP,
	LOPC_LOADGVP,
	LOPC_LOADGQP,
	LOPC_PUSH,
	LOPC_PUSHS,
	LOPC_PUSHL,
	LOPC_PUSHV,
	LOPC_PUSHQ,
	LOPC_PUSHG,
	LOPC_PUSHGS,
	LOPC_PUSHGL,
	LOPC_PUSHGV,
	LOPC_PUSHGQ,
	LOPC_PUSHIP,
	LOPC_PUSHBP,
	LOPC_PUSHSP,
	LOPC_PUSHARGB,
	LOPC_PUSHARGI,
	LOPC_PUSHARGF,
	LOPC_PUSHARGS,
	LOPC_PUSHARGV,
	LOPC_PUSHARGQ,
	LOPC_PUSHE,
	LOPC_PUSHEV,
	LOPC_PUSHEQ,
	LOPC_PUSHARGE,
	LOPC_ADD,
	LOPC_SUB,
	LOPC_MUL,
	LOPC_DIV,
	LOPC_MOD,
	LOPC_EQ,
	LOPC_NEQ,
	LOPC_LEQ,
	LOPC_GEQ,
	LOPC_LESS,
	LOPC_GREATER,
	LOPC_BITAND,
	LOPC_BITOR,
	LOPC_BITXOR,
	LOPC_BOOLAND,
	LOPC_BOOLOR,
	LOPC_NEG,
	LOPC_BITNOT,
	LOPC_BOOLNOT,
	LOPC_JUMP,
	LOPC_JUMPIF,
	LOPC_JUMPNIF,
	LOPC_STATE,
	LOPC_CALL,
	LOPC_RETURN,
	LOPC_CAST,
	LOPC_STACKTOS,
	LOPC_STACKTOL,
	LOPC_PRINT,
	LOPC_CALLLIB,
	LOPC_CALLLIB_TWO_BYTE,
	LOPC_SHL,
	LOPC_SHR,
	LOPC_EOF
} LSCRIPTOpCodesEnum;

const U8 LSCRIPTOpCodes[LOPC_EOF] =
{
	0x00,	// LOPC_INVALID
	0x00,	// LOPC_NOOP
	0x01,	// LOPC_POP
	0x02,	// LOPC_POPS
	0x03,	// LOPC_POPL
	0x04,	// LOPC_POPV
	0x05,	// LOPC_POPQ
	0x06,	// LOPC_POPARG
	0x07,	// LOPC_POPIP
	0x08,	// LOPC_POPBP
	0x09,	// LOPC_POPSP
	0x0a,	// LOPC_POPSLR
	0x20,	// LOPC_DUP
	0x21,	// LOPC_DUPS
	0x22,	// LOPC_DUPL
	0x23,	// LOPC_DUPV
	0x24,	// LOPC_DUPQ
	0x30,	// LOPC_STORE
	0x31,	// LOPC_STORES
	0x32,	// LOPC_STOREL
	0x33,	// LOPC_STOREV
	0x34,	// LOPC_STOREQ
	0x35,	// LOPC_STOREG
	0x36,	// LOPC_STOREGS
	0x37,	// LOPC_STOREGL
	0x38,	// LOPC_STOREGV
	0x39,	// LOPC_STOREGQ
	0x3a,	// LOPC_LOADP
	0x3b,	// LOPC_LOADSP
	0x3c,	// LOPC_LOADLP
	0x3d,	// LOPC_LOADVP
	0x3e,	// LOPC_LOADQP
	0x3f,	// LOPC_LOADGP
	0x40,	// LOPC_LOADGSP
	0x41,	// LOPC_LOADGLP
	0x42,	// LOPC_LOADGVP
	0x43,	// LOPC_LOADGQP
	0x50,	// LOPC_PUSH
	0x51,	// LOPC_PUSHS
	0x52,	// LOPC_PUSHL
	0x53,	// LOPC_PUSHV
	0x54,	// LOPC_PUSHQ
	0x55,	// LOPC_PUSHG
	0x56,	// LOPC_PUSHGS
	0x57,	// LOPC_PUSHGL
	0x58,	// LOPC_PUSHGV
	0x59,	// LOPC_PUSHGQ
	0x5a,	// LOPC_PUSHIP
	0x5b,	// LOPC_PUSHBP
	0x5c,	// LOPC_PUSHSP
	0x5d,	// LOPC_PUSHARGB
	0x5e,	// LOPC_PUSHARGI
	0x5f,	// LOPC_PUSHARGF
	0x60,	// LOPC_PUSHARGS
	0x61,	// LOPC_PUSHARGV
	0x62,	// LOPC_PUSHARGQ
	0x63,	// LOPC_PUSHE
	0x64,	// LOPC_PUSHEV
	0x65,	// LOPC_PUSHEQ
	0x66,	// LOPC_PUSHARGE
	0x70,	// LOPC_ADD
	0x71,	// LOPC_SUB
	0x72,	// LOPC_MUL
	0x73,	// LOPC_DIV
	0x74,	// LOPC_MOD
	0x75,	// LOPC_EQ
	0x76,	// LOPC_NEQ
	0x77,	// LOPC_LEQ
	0x78,	// LOPC_GEQ
	0x79,	// LOPC_LESS
	0x7a,	// LOPC_GREATER
	0x7b,	// LOPC_BITAND
	0x7c,	// LOPC_BITOR
	0x7d,	// LOPC_BITXOR
	0x7e,	// LOPC_BOOLAND
	0x7f,	// LOPC_BOOLOR
	0x80,	// LOPC_NEG
	0x81,	// LOPC_BITNOT
	0x82,	// LOPC_BOOLNOT
	0x90,	// LOPC_JUMP
	0x91,	// LOPC_JUMPIF
	0x92,	// LOPC_JUMPNIF
	0x93,	// LOPC_STATE
	0x94,	// LOPC_CALL
	0x95,	// LOPC_RETURN
	0xa0,	// LOPC_CAST
	0xb0,	// LOPC_STACKTOS
	0xb1,	// LOPC_STACKTOL
	0xc0,	// LOPC_PRINT
	0xd0,	// LOPC_CALLLIB
	0xd1,	// LOPC_CALLLIB_TWO_BYTE
	0xe0,	// LOPC_SHL
	0xe1	// LOPC_SHR
};

typedef enum e_lscript_state_event_type
{
	LSTT_NULL,
	LSTT_STATE_ENTRY,
	LSTT_STATE_EXIT,
	LSTT_TOUCH_START,
	LSTT_TOUCH,
	LSTT_TOUCH_END,
	LSTT_COLLISION_START,
	LSTT_COLLISION,
	LSTT_COLLISION_END,
	LSTT_LAND_COLLISION_START,
	LSTT_LAND_COLLISION,
	LSTT_LAND_COLLISION_END,
	LSTT_TIMER,
	LSTT_CHAT,
	LSTT_REZ,
	LSTT_SENSOR,
	LSTT_NO_SENSOR,
	LSTT_CONTROL,
	LSTT_MONEY,
	LSTT_EMAIL,
	LSTT_AT_TARGET,
	LSTT_NOT_AT_TARGET,
	LSTT_AT_ROT_TARGET,
	LSTT_NOT_AT_ROT_TARGET,
	LSTT_RTPERMISSIONS,
	LSTT_INVENTORY,
	LSTT_ATTACH,
	LSTT_DATASERVER,
	LSTT_LINK_MESSAGE,
	LSTT_MOVING_START,
	LSTT_MOVING_END,
	LSTT_OBJECT_REZ,
	LSTT_REMOTE_DATA,
	LSTT_HTTP_RESPONSE,
	LSTT_EOF,
	
	LSTT_STATE_BEGIN = LSTT_STATE_ENTRY,
	LSTT_STATE_END = LSTT_EOF
} LSCRIPTStateEventType;

const U64 LSCRIPTStateBitField[LSTT_EOF] =
{
	0x0000000000000000,		//	LSTT_NULL
	0x0000000000000001,		//	LSTT_STATE_ENTRY
	0x0000000000000002,		//	LSTT_STATE_EXIT
	0x0000000000000004,		//	LSTT_TOUCH_START
	0x0000000000000008,		//	LSTT_TOUCH
	0x0000000000000010,		//	LSTT_TOUCH_END
	0x0000000000000020,		//	LSTT_COLLISION_START
	0x0000000000000040,		//	LSTT_COLLISION
	0x0000000000000080,		//	LSTT_COLLISION_END
	0x0000000000000100,		//	LSTT_LAND_COLLISION_START
	0x0000000000000200,		//	LSTT_LAND_COLLISION
	0x0000000000000400,		//	LSTT_LAND_COLLISION_END
	0x0000000000000800,		//	LSTT_TIMER
	0x0000000000001000,		//	LSTT_CHAT
	0x0000000000002000,		//	LSTT_REZ
	0x0000000000004000,		//	LSTT_SENSOR
	0x0000000000008000,		//	LSTT_NO_SENSOR
	0x0000000000010000,		//	LSTT_CONTROL
	0x0000000000020000,		//	LSTT_MONEY
	0x0000000000040000,		//	LSTT_EMAIL
	0x0000000000080000,		//	LSTT_AT_TARGET
	0x0000000000100000,		//	LSTT_NOT_AT_TARGET
	0x0000000000200000,		//	LSTT_AT_ROT_TARGET
	0x0000000000400000,		//	LSTT_NOT_AT_ROT_TARGET
	0x0000000000800000,		//	LSTT_RTPERMISSIONS
	0x0000000001000000,		//	LSTT_INVENTORY
	0x0000000002000000,		//	LSTT_ATTACH
	0x0000000004000000,		//	LSTT_DATASERVER
	0x0000000008000000,		//  LSTT_LINK_MESSAGE
	0x0000000010000000,		//  LSTT_MOVING_START
	0x0000000020000000,		//  LSTT_MOVING_END
	0x0000000040000000,		//  LSTT_OBJECT_REZ
	0x0000000080000000,		//  LSTT_REMOTE_DATA
	0x0000000100000000LL     // LSTT_HTTP_RESPOSE
};

inline S32 get_event_handler_jump_position(U64 bit_field, LSCRIPTStateEventType type)
{
	S32 count = 0, position = LSTT_STATE_ENTRY;
	while (position < type)
	{
		if (bit_field & 0x1)
		{
			count++;
		}
		bit_field >>= 1;
		position++;
	}
	return count;
}

inline S32 get_number_of_event_handlers(U64 bit_field)
{
	S32 count = 0, position = 0;
	while (position < LSTT_EOF)
	{
		if (bit_field & 0x1)
		{
			count++;
		}
		bit_field >>= 1;
		position++;
	}
	return count;
}

typedef enum e_lscript_types
{
	LST_NULL,
	LST_INTEGER,
	LST_FLOATINGPOINT,
	LST_STRING,
	LST_KEY,
	LST_VECTOR,
	LST_QUATERNION,
	LST_LIST,
	LST_UNDEFINED,
	LST_EOF
} LSCRIPTType;

const U8 LSCRIPTTypeByte[LST_EOF] =
{
	LST_NULL,
	LST_INTEGER,
	LST_FLOATINGPOINT,
	LST_STRING,
	LST_KEY,
	LST_VECTOR,
	LST_QUATERNION,
	LST_LIST,
	LST_NULL,
};

const U8 LSCRIPTTypeHi4Bits[LST_EOF] =
{
	LST_NULL,
	LST_INTEGER << 4,
	LST_FLOATINGPOINT << 4,
	LST_STRING << 4,
	LST_KEY << 4,
	LST_VECTOR << 4,
	LST_QUATERNION << 4,
	LST_LIST << 4,
	LST_UNDEFINED << 4,
};

const char * const LSCRIPTTypeNames[LST_EOF] = 	/*Flawfinder: ignore*/
{
	"VOID",
	"integer",
	"float",
	"string",
	"key",
	"vector",
	"quaternion",
	"list",
	"invalid"
};

const S32 LSCRIPTDataSize[LST_EOF] =
{
	0,	// VOID
	4,	// integer
	4,	// float
	4,	// string
	4,	// key
	12,	// vector
	16,	// quaternion
	4,	// list
	0	// invalid
};


typedef enum e_lscript_runtime_faults
{
	LSRF_INVALID,
	LSRF_MATH,
	LSRF_STACK_HEAP_COLLISION,
	LSRF_BOUND_CHECK_ERROR,
	LSRF_HEAP_ERROR,
	LSRF_VERSION_MISMATCH,
	LSRF_MISSING_INVENTORY,
	LSRF_SANDBOX,
	LSRF_CHAT_OVERRUN,
	LSRF_TOO_MANY_LISTENS,
	LSRF_NESTING_LISTS,
	LSRF_CLI,
	LSRF_EOF
} LSCRIPTRunTimeFaults;

extern const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF]; 	/*Flawfinder: ignore*/

typedef enum e_lscript_runtime_permissions
{
	SCRIPT_PERMISSION_DEBIT,
	SCRIPT_PERMISSION_TAKE_CONTROLS,
	SCRIPT_PERMISSION_REMAP_CONTROLS,
	SCRIPT_PERMISSION_TRIGGER_ANIMATION,
	SCRIPT_PERMISSION_ATTACH,
	SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
	SCRIPT_PERMISSION_CHANGE_LINKS,
	SCRIPT_PERMISSION_CHANGE_JOINTS,
	SCRIPT_PERMISSION_CHANGE_PERMISSIONS,
	SCRIPT_PERMISSION_TRACK_CAMERA,
	SCRIPT_PERMISSION_CONTROL_CAMERA,
	SCRIPT_PERMISSION_EOF
} LSCRIPTRunTimePermissions;

const U32 LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_EOF] =
{
	(0x1 << 1),	//	SCRIPT_PERMISSION_DEBIT,
	(0x1 << 2),	//	SCRIPT_PERMISSION_TAKE_CONTROLS,
	(0x1 << 3),	//	SCRIPT_PERMISSION_REMAP_CONTROLS,
	(0x1 << 4),	//	SCRIPT_PERMISSION_TRIGGER_ANIMATION,
	(0x1 << 5),	//	SCRIPT_PERMISSION_ATTACH,
	(0x1 << 6),	//	SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
	(0x1 << 7),	//	SCRIPT_PERMISSION_CHANGE_LINKS,
	(0x1 << 8),	//	SCRIPT_PERMISSION_CHANGE_JOINTS,
	(0x1 << 9),	//	SCRIPT_PERMISSION_CHANGE_PERMISSIONS
	(0x1 << 10),//	SCRIPT_PERMISSION_TRACK_CAMERA
	(0x1 << 11),//	SCRIPT_PERMISSION_CONTROL_CAMERA
};

#endif