include "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;
Init must be called before any other function, to initialise the module.
Loadobj reads a Dis object file from file, and returns a reference to a Mod adt 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 the reference is nil.
Op2s returns the assembly-language representation, as used by asm(1), of the Dis operation code op. It returns the string `OPop' if op does not correspond to a known operation code.
Inst2s returns a string corresponding to a disassembly of Dis instruction i, including addressing modes.
The module defines integer constants giving symbolic names to the Dis instruction codes, all of the form Iname where name is the name of the instruction, all in upper case:
The name MAXDIS is also defined; it has the value of the first unassigned Dis operation code.
Most of the members of the adt types have an obvious interpretation on reference to dis(6).
The adt Mod represents a single module. It contains values extracted from the module's header, and references to structures representing the contents of the Dis file's code, data, type and external linkage sections:
The Type adt represents the value of a type descriptor:
The Link adt represents the value of a link descriptor:
The Inst adt represents a single Dis instruction in the instruction stream. The member op is the Dis instruction code. The member addr contains the addressing mode flags for middle, source and destination operands. Constants are defined to help unpack it.
The middle operand description is selected by the constant mask ARM:
The valid results and interpretation are as follows:
The source operand's addressing mode is extracted as follows:
The following combinations are valid, where n is the value in i.src:
where fi is the offset for the first indirection, extracted from n:
and si is the offset for the second indirection, also extracted from n:
The destination addressing mode is interpreted in a similar way, except that the addressing mode is extracted as follows:
and the value of the offset n is found in i.dst. Fi and si are extracted from n as before.
Finally, Data adt represents a data item, which tells the system's module loader how to initialise part of the module's global data segment. It has the following members:
The alternatives of the pick select the correct variant to see the data values encoded in the object file as Limbo values of the correct type. The interpretation is straightforward for the tags Bytes, Words, Bigs and Reals: the corresponding array members are arrays of n elements of the appropriate type. The remaining cases are as follows:
DIS(2 ) | Rev: Thu Feb 15 14:43:27 GMT 2007 |