Charles.Forsyth20060303-partialeea662d19 years agoHistory
488 lines · 8.6 KB · Text
RawDownload
.TH DIS 2.SH NAMEdis \- read Dis object files.SH SYNOPSIS.EXinclude "dis.m";dis := load Dis Dis->PATH; Inst: adt{	op:		int;	addr:	int;	mid:		int;	src:		int;	dst:		int;}; Type: adt{	size:	int;	map:		array of byte;}; Data: adt{	op:	int;		# encoded op	n:	int;		# number of elements	off:	int;		# byte offset in data space	pick {	Zero =>		# DEFZ	Bytes =>		# DEFB		bytes:	array of byte;	Words =>		# DEFW		words:	array of int;	String =>		# DEFS		str:	string;	Reals =>		# DEFF		reals:	array of real;	Array =>		# DEFA		typex:	int;		length:	int;	Aindex =>		# DIND		index:	int;	Arestore =>	# DAPOP	Bigs =>		# DEFL		bigs:		array of big;	}}; Link: adt{	pc:		int;	desc:	int;	sig:		int;	name:	string;}; Import: adt{	sig:	int;	name:	string;}; Except: adt{	s:	string;	pc:	int;}; Handler: adt{	pc1:	int;	pc2:	int;	eoff:	int;	ne:	int;	t:	ref Type;	etab:	array of ref Except;}; Mod: adt{	name:	string;	srcpath:	string; 	magic:	int;	rt:		int;	ssize:	int;	isize:	int;	dsize:	int;	tsize:	int;	lsize:	int;	entry:	int;	entryt:	int; 	inst:	array of ref Inst;	types:	array of ref Type;	data:	list of ref Data;	links:	array of ref Link;	imports:	array of array of ref Import;	handlers:	array of ref Handler; 	sign:	array of byte;}; init:	fn();loadobj:	fn(file: string): (ref Mod, string);op2s:	fn(op: int): string;inst2s:	fn(i: ref Inst): string;.EE.SH DESCRIPTIONThe.B Dismodule decodes the contents of a Dis object file containing a single module,of the format defined by.IR dis (6).The module defines many constants, giving symbolic names toDis instruction codes, addressing mode masks, magic numbers, and otherbits of the object code..PP.B Initmust be called before any other function, to initialise the module..PP.B Loadobjreads a Dis object file from.IR file ,and returns a reference to a.B Modadt that represents the module's contents, as the first element of the tuple;the string element of the tuple is nil.On error, the string element contains a diagnostic, and thereference is nil..PP.B Op2sreturns the assembly-language representation, as used by.IR asm (1),of the Dis operation code.IR op .It returns the string.IB ` OP op'if.I opdoes not correspond to a known operation code..PP.B Inst2sreturns a string corresponding to a disassembly of Dis instruction.IR i ,including addressing modes..PPThe module defines integer constants givingsymbolic names to the Dis instruction codes, all of the form.BI I namewhere.I nameis the name of the instruction, all in upper case:.IP.BR INOP ,.BR IALT ,.BR INBALT ,\&....BR INEWZ ,.BR INEWAZ ,.BR IRAISE.PPThe name.B MAXDISis also defined; it has the value of the first unassigned Dis operation code..PPMost of the members of the adt types have an obvious interpretationon reference to.IR dis (6)..PPThe adt.B Modrepresents a single module.It contains values extracted from the module's header,and references to structures representing the contents ofthe Dis file's code, data, typeand external linkage sections:.TF entryt.PD.TP.B magicThe constant.B XMAGIC(unsigned Dis module)or the constant.B SMAGIC(signed Dis module)..TP.B signIf.B magicis.BR SMAGIC ,the.B signfield contains the bytes in the signature section of the module header.Otherwise, there is no signature and.B signis.BR nil ..TP.B nameThe name of the implementation module..TP.B srcpathThe source of the dis file relative to the inferno root..TP.B rtRun-time options: a bit mask of the constants.BR MUSTCOMPILE ,.B DONTCOMPILEand.BR SHAREMP ..TP.B ssizeStack extent.TP.B isizeNumber of instructions.TP.B dsizeSize in bytes of the module's global data area.TP.B tsizeNumber of type descriptors.TP.B lsizeNumber of external linkage descriptors.TP.B entryPC (instruction offset) of the default entry point for the module.TP.B entrytIndex of the type descriptor for the module's entry point.TP.B instArray representing the contents of the code segment;length.IB m .isize.TP.B typesArray of the module's type descriptors;length.IB m .tsize.TP.B datalist of data descriptors representing instructions for creating the module's data segment.TP.B linksarray of the module's external linkage descriptors (for exported functions); length.IB m .lsize.TP.B importsan array of import descriptor tables, one table for each module imported by thismodule. Each table is an array of pairs giving the signature and name of eachfunction imported..TP.B handlersan array of exception handlers used in this module. Each handler consists ofthe range of pc's it covers, the exception structure offset within theframe, the number of declared exceptions (as opposed to strings) in the handler,the type (if any) of any memory to clear when the exception occurs and a tableof exceptions. The latter is an array containing pairs of exceptions andpc values. The final entry gives the pc to jump toin the '*' case or -1 if not applicable..PPThe.B Typeadt represents the value of a type descriptor:.TF entryt.PD.TP.B sizeSize in bytes of the object represented by this descriptor.TP.B mapBitmap describing the location of pointers in the object (see.IR dis (6)).PPThe.B Linkadt represents the value of a link descriptor:.TF entryt.PD.TP.B nameName of the exported function.TP.B pcInstruction index in.B Mod.codeof the function's entry point.TP.B descIndex in.B Mod.typesof the type describing the function's stack frame.TP.B sigInteger hash of the function's type signature.PPThe.B Instadt represents a single Dis instruction in the instruction stream.The member.B opis the Dis instruction code.The member.B addrcontains the addressing mode flags for middle, source and destination operands.Constants are defined to help unpack it..PPThe middle operand description is selected by the constant mask.BR ARM :.IP.IB i ".addr & ARM".PPThe valid results and interpretation are as follows:.IP.RS.TF AXNON.TP.B AXNONNo middle operand..TP.B AXIMM.BI $ n.TP.B AXINF.IB n (fp).TP.B AXINM.IB n (mp).PD.RE.PPThe source operand's addressing mode is extracted as follows:.IP.BI ( i ".addr>>3)&AMASK".PPThe following combinations are valid, where.I nis the value in.IB i .src :.IP.RS.TF AIND|AMP.TP.B AXXXNo operand.TP.B AFPThe operand is.IB n (fp).TP.B AMPThe operand is.IB n (mp).TP.B AIMMThe operand is.BI $ n(ie, immediate literal.IR n ).TP.B AIND|AFPThe operand is.IB si ( fi (fp)).TP.B AIND|AMPThe operand is.IB si ( fi (mp)).RE.PD.PPwhere.I fiis the offset for the first indirection, extracted from.IR n :.IP.BI ( n ">>16)&16rFFFF)" ,.PPand.I siis the offset for the second indirection, also extracted from.IR n:.IP.BI ( n "&16rFFFF)" ..PPThe destination addressing mode is interpreted in a similar way,except that the addressing mode is extracted as follows:.IP.BI ( i ".addr&AMASK)".PPand the value of the offset.I nis found in.IB i .dst ..I Fiand.I siare extracted from.I nas before..PPFinally,.B Dataadt represents a data item, which tells the system's module loaderhow to initialise part of the module's global data segment.It has the following members:.TP.B opthe encoded type and length; usually ignored: the.B picktag and.BR n ,below,usually suffice.TP.B nthe number of data values.TP.B offthe byte offset of the first data value to initialise, relative to the current loading base.PPThe alternatives of the.B pickselect the correct variant to see the data values encoded in theobject file as Limbo valuesof the correct type.The interpretation is straightforward for the tags.BR Bytes ,.BR Words ,.B Bigsand.BR Reals :the corresponding array members are arrays of.B nelements of the appropriate type.The remaining cases are as follows:.TF Arestore.PD.TP.B StringThe member.B strhas the decoded representation of thecorresponding.I ndata bytes from the object file..TP.B ArrayThe member.B typexis the index in.B Mod.typesof the array's type, and member.B lengthis its length..TP.B AindexThis alternative can appear only following a value of.BR Data.Array .The member.B indexis an index into the corresponding array as represented in the global data space,which determines a new loading base address for subsequent.B Dataitems.The previous base address is stacked on an internal stack..TP.B ArestorePop the address from the internal address stack and make that the currentloading address.The request marks the end of a sequence of.B Dataitems initialising an array..SH SOURCE.B /appl/lib/dis.b.SH SEE ALSO.IR disdep (1),.B wm/rtin.IR wm-misc (1),.IR dis (6).br"The Dis Virtual Machine", in Volume 2.