Charles.Forsyth20060303-partialeea662d19 years agoHistory
1824 lines · 48.0 KB · Text
RawDownload
.so /sys/lib/tmac/tmac.uni.TLDis Virtual Machine Specification.AU.I "Lucent Technologies Inc".I "30 September 1999" .I "Extensively revised by Vita Nuova Limited".I "5 June 2000, 9 January 2003".NH 1Introduction.LPThe Dis virtual machine provides the execution environment for programs running under the Inferno operating system. The virtual machine models a CISC-like, three operand, memory-to-memory architecture. Code can either be interpreted by a C library or compiled on-the-fly into machine code for the target architecture..LPThis paper defines the virtual machine informally.A separate paper by Winterbottom and Pike[2] discusses its design.The Dis object file format is also defined here.Literals and keywords are in.CW typewritertypeface..NH 1Addressing Modes.SHOperand Size.LPOperand sizes are defined as follows: a byte is 8 bits, a word or pointer is 32 bits, a float is 64 bits, a big integer is 64 bits. The operand size of each instruction is encoded explicitly by the operand code. The operand size and type are specified by the last character of the instruction mnemonic:.IP.TSlf(CW) lfR .W	word, 32-bit two's complementB	byte, 8-bit unsignedF	float, 64-bit IEEE formatL	big, 64-bit two's complementP	pointerC	Unicode string encoded in UTF-8M	memoryMP	memory containing pointers.TE.LPTwo more operand types are defined to provide `short'types for use by languages other than Limbo:signed 16-bit integers, called `short word'here, and 32-bit IEEE format floating-point numbers, called `short float' or `short real' here.Support for them is limited to conversion to and from words or floats respectively;the instructions are marked below with a dagger (†)..SHMemory Organization.LPMemory for a thread is divided into several separate regions. The code segment stores either a decoded virtual machine instruction stream suitable for execution by the interpreter or flash compiled native machine code for the host CPU. Neither type of code segment is addressable from the instruction set. At the object code level, PC values are offsets, counted in instructions, from the beginning of the code space..LPData memory is a linear array of bytes, addressed using 32-bit pointers. Words are stored in the native representation of the host CPU. Data types larger than a byte must be stored at addresses aligned toa multiple of the data size. A thread executing a module has access to two regions of addressable data memory. A module pointer.CW "mp" \& (register) defines a region of global storage for a particular module, a frame pointer.CW "fp" \& (register) defines the current activation record or frame for the thread. Frames are allocated dynamically from a stack by function call and return instructions. The stack is extended automatically from the heap..LPThe.CW mpand.CW fpregisters cannot be addressed directly, and therefore, can be modified only by call and return instructions..SHEffective Addresses.LPEach instruction can potentially address three operands. The source and destination operands are general, but the middle operand can use any address mode except double indirect. If the middle operand of a three address instruction is omitted, it is assumed to be the same as the destination operand..LPThe general operands generate an effective address from three basic modes: immediate, indirect and double indirect. The assembler syntax for each mode is:.IP.TSlf(CW) lfR .10(fp)	30-bit signed indirect from fp20(mp)	30-bit signed indirect from mp$0x123	30-bit signed immediate value10(20(fp))	two 16-bit unsigned offsets double indirect from fp10(20(mp))	two 16-bit unsigned offsets double indirect from mp.TE.SHGarbage Collection.LPThe Dis machine performs both reference counted and real time mark and sweep garbage collection. This hyrbrid approach allows code to be generated in several styles: pure reference counted, mark and sweep, or a hybrid of the two approaches. Compiler writers have the freedom to choose how specific types are handled by the machine to optimize code for performance or language implementation. Instruction selection determines which algorithm will be applied to specific types..LPWhen using reference counting, pointers are a special operand type and should only be manipulated using the pointer instructions in order to ensure the correct functioning of the garbage collector. Every memory location that stores a pointer must be known to the interpreter so that it can be initialized and deallocated correctly. The information is transmitted in the form of type descriptors in the object module. Each type descriptor contains a bit vector for a particular type where each bit corresponds to a word in memory. Type descriptors are generated automatically by the Limbo compiler. The assembler syntax for a type descriptor is:.P1desc	$10, 132, "001F".P2The first parameter is the descriptor number, the second is the size in bytes, and the third a pointer map. The map contains a list of hex bytes where each byte maps eight 32 bit words. The most significant bit represents the lowest memory address.A one bit indicates a pointer in memory. The map need not have an entry for every byte and unspecified bytes are assumed zero..LPThroughout this description, the symbolic constant.CW Hrefers to a nil pointer..NH 1Instruction Set.SHadd\fIx\fP \- Add.P1Syntax:		addb	src1, src2, dst		addf	src1, src2, dst		addw	src1, src2, dst		addl	src1, src2, dstFunction:	dst = src1 + src2.P2.LPThe .CW "add"instructions compute the sum of the operands addressed by .CW "src1"and .CW "src2"and stores the result in the.CW " dst"operand. For .CW "addb"the result is truncated to eight bits..SHaddc \- Add strings.P1Syntax:		addc	src1, src2, dstFunction:	dst = src1 + src2.P2.LPThe .CW "addc"instruction concatenates the two UTF strings pointed to by.CW " src1"and .CW "src2" ;the result is placed in the pointer addressed by .CW "dst" .If both pointers are .CW "H"the result will be a zero length string rather than .CW "H" ..SHalt \- Alternate between communications.P1Syntax:		alt	src, dst.P2The .CW "alt"instruction selects between a set of channels ready to communicate. The.CW srcargument is the address of a structure of the following form:.P1struct Alt {	int nsend;		/* Number of senders */	int nrecv;		/* Number of receivers */	struct {		Channel* c;		/* Channel */		void*	val;	/* Address of lval/rval */	} entry[];};.P2The vector is divided into two sections; the first lists the channels ready to send values, the second lists channels either ready to receive or an array of channels each of which may be ready to receive. The counts of the sender and receiver channels are stored as the first and second words addressed by.CW src .An .CW "alt"instruction proceeds by testing each channel for readiness to communicate. A ready channel is added to a list. If the list is empty after each channel has been considered, the thread blocks at the .CW "alt"instruction waiting for a channel to become ready; otherwise, a channel is picked at random from the ready set..LPThe.CW "alt"instruction then uses the selected channel to perform the communication using the .CW "val"address as either a source for send or a destination for receive. The numeric index of the selected vector element is placed in .CW "dst" ..SHand\fIx\fP \- Logical AND.P1Syntax:		andb	src1, src2, dst		andw	src1, src2, dst		andl	src1, src2, dstFunction:	dst = src1 & src2.P2The instructions compute the bitwise AND of the two operands addressed by .CW "src1"and .CW "src2"and stores the result in the .CW "dst"operand..SHbeq\fIx\fP \- Branch equal.P1Syntax:		beqb	src1, src2, dst		beqc	src1, src2, dst		beqf	src1, src2, dst		beqw	src1, src2, dst		beql	src1, src2, dstFunction:	if src1 == src2 then pc = dst.P2If the .CW "src1"operand is equal to the .CW "src2"operand, then control is transferred to the program counter specified by the .CW "dst"operand..SHbge\fIx\fP \- Branch greater or equal.P1Syntax:		bgeb	src1, src2, dst		bgec	src1, src2, dst		bgef	src1, src2, dst		bgew	src1, src2, dst		bgel	src1, src2, dstFunction:	if src1 >= src2 then pc = dst.P2If the .CW "src1"operand is greater than or equal to the .CW "src2"operand, then control is transferred to program counter specified by the .CW "dst"operand. This instruction performs a signed comparison..SHbgt\fIx\fP \- Branch greater.P1Syntax:		bgtb	src1, src2, dst		bgtc	src1, src2, dst		bgtf	src1, src2, dst		bgtw	src1, src2, dst		bgtl	src1, src2, dstFunction:	if src1 > src2 then pc = dst.P2If the .CW "src1"operand is greater than the .CW "src2"operand, then control is transferred to the program counter specified by the .CW "dst"operand. This instruction performs a signed comparison..SHble\fIx\fP \- Branch less than or equal.P1Syntax:		bleb	src1, src2, dst		blec	src1, src2, dst		blef	src1, src2, dst		blew	src1, src2, dst		blel	src1, src2, dstFunction:	if src1 <= src2 then pc = dst.P2If the .CW "src1"operand is less than or equal to the .CW "src2"operand, then control is transferred to the program counter specified by the .CW "dst"operand. This instruction performs a signed comparison..SHblt\fIx\fP \- Branch less than.P1Syntax:		bltb	src1, src2, dst		bltc	src1, src2, dst		bltf	src1, src2, dst		bltw	src1, src2, dst		bltl	src1, src2, dstFunction:	if src1 < src2 then pc = dst.P2If the .CW "src1"operand is less than the .CW "src2"operand, then control is transferred to the program counter specified by the .CW "dst"operand..SHbne\fIx\fP \- Branch not equal.P1Syntax:		bneb	src1, src2, dst		bnec	src1, src2, dst		bnef	src1, src2, dst		bnew	src1, src2, dst		bnel	src1, src2, dstFunction:	if src1 != src2 then pc = dst.P2If the .CW "src1"operand is not equal to the .CW "src2"operand, then control is transferred to the program counter specified by the .CW "dst"operand..SHcall \- Call local function.P1Syntax:		call	src, dstFunction:	link(src) = pc		frame(src) = fp		mod(src) = 0		fp = src		pc = dst.P2The .CW "call"instruction performs a function call to a routine in the same module. The .CW "src"argument specifies a frame created by .CW "new" .The current value of .CW "pc"is stored in link(src), the current value of .CW "fp"is stored in frame(src) and the module link register is set to 0. The value of .CW "fp"is then set to .CW "src"and control is transferred to the program counter specified by.CW dst ..SHcase \- Case compare integer and branch.P1Syntax:		case	src, dstFunction:	pc = 0..i: dst[i].pc where		  dst[i].lo >= src && dst[i].hi < src.P2The .CW "case"instruction jumps to a new location specified by a range of values. The .CW "dst"operand points to a table in memory containing a table of .CW "i"values. Each value is three words long: the first word specifies a low value, the second word specifies a high value, and the third word specifies a program counter. The first word of the table gives the number of entries. The .CW "case"instruction searches the table for the first matching value where the .CW "src"operand is greater than or equal to the low word and less than the high word. Control is transferred to the program counter stored in the first word of the matching entry..SHcasec \- Case compare string and branch.P1Syntax:		casec	src, dstFunction:	pc = 0..i: dst[i].pc where		   dst[i].lo >= src && dst[i].hi < src.P2The .CW "casec"instruction jumps to a new location specified by a range of string constants. The table is the same as described for the.CW caseinstruction..SHcons\fIx\fP \- Allocate new list element.P1Syntax:		consb	src, dst		consc	src, dst		consf	src, dst		consl	src, dst		consm	src, dst		consmp	src, dst		consp	src, dst		consw	src, dstFunction:	p = new(src, dst)		dst = p.P2The .CW "cons"instructions add a new element to the head of a list. A new list element is composed from the .CW "src"operand and a pointer to the head of an extant list specified by .CW "dst" .The resulting element is stored back into .CW "dst" ..SHcvtac \- Convert byte array to string.P1Syntax:		cvtac	src, dstFunction:	dst = string(src).P2The .CW "src"operand must be an array of bytes, which is converted into a character string and stored in .CW "dst" .The new string is a copy of the bytes in .CW "src" ..SHcvtbw \- Convert byte to word.P1Syntax:		cvtbw	src, dstFunction:	dst = src & 0xff.P2A byte is fetched from the .CW "src"operand extended to the size of a word and then stored into .CW "dst" ..SHcvtca \- Convert string to byte array.P1Syntax:		cvtca	src, dstFunction:	dst = array(src).P2The .CW "src"operand must be a string which is converted into an array of bytes and stored in .CW "dst" .The new array is a copy of the characters in src..SHcvtcf \- Convert string to real.P1Syntax:		cvtcf	src, dstFunction:	dst = (float)src.P2The string addressed by the .CW "src"operand is converted to a floating point value and stored in the .CW "dst"operand. Initial white space is ignored; conversion ceases at the first character in the string that is not part of the representation of the floating point value..SHcvtcl \- Convert string to big.P1Syntax:		cvtcl	src, dstFunction:	dst = (big)src.P2The string addressed by the .CW "src"operand is converted to a big integer and stored in the .CW "dst"operand. Initial white space is ignored; conversion ceases at the first non-digit in the string..SHcvtcw \- Convert string to word.P1Syntax:		cvtcw	src, dstFunction:	dst = (int)src.P2The string addressed by the .CW "src"operand is converted to a word and stored in the .CW "dst"operand. Initial white space is ignored; after a possible sign, conversion ceases at the first non-digit in the string..SHcvtfc \- Convert real to string.P1Syntax:		cvtfc	src, dstFunction:	dst = string(src).P2The floating point value addressed by the .CW "src"operand is converted to a string and stored in the .CW "dst"operand. The string is a floating point representation of the value..SHcvtfw \- Convert real to word.P1Syntax:		cvtfw	src, dstFunction:	dst = (int)src.P2The floating point value addressed by .CW "src"is converted into a word and stored into .CW "dst" .The floating point value is rounded to the nearest integer..SHcvtfl \- Convert real to big.P1Syntax:		cvtfl	src, dstFunction:	dst = (big)src.P2The floating point value addressed by .CW "src"is converted into a big integer and stored into .CW "dst" .The floating point value is rounded to the nearest integer..SHcvtfr \- Convert real to short real†.P1Syntax:		cvtfr	src, dstFunction:	dst = (short float)src.P2The floating point value addressed by .CW "src"is converted to a short (32-bit) floating point value and stored into .CW "dst" .The floating point value is rounded to the nearest integer..SHcvtlc \- Convert big to string.P1Syntax:		cvtlc	src, dstFunction:	dst = string(src).P2The big integer addressed by the .CW "src"operand is converted to a string and stored in the .CW "dst"operand. The string is the decimal representation of the big integer..SHcvtlw \- Convert big to word.P1Syntax:		cvtlw	src, dstFunction:	dst = (int)src.P2The big integer addressed by the .CW "src"operand is converted to a word and stored in the .CW "dst"operand..SHcvtsw \- Convert short word to word†.P1Syntax:		cvtsw	src, dstFunction:	dst = (int)src

Lines 1–500 of 1824.