(*
    Title: 	UnixObj - Definitions
    LastEdit:	"Fri Nov 18 15:07:14 1983"
    Author: 	Mick Jordan
		Cambridge University Computer Laboratory

    Allows creation of Unix object modules
*)

DEFINITION MODULE UnixObj;

FROM SYSTEM IMPORT ADDRESS;
FROM Streams IMPORT Stream;

EXPORT QUALIFIED 
    SetObjStream,
    PutHeader, Flush, PutByte, PutLong, SizeNow, EndText, EndTextReloc,
    Nundf, Nabs, Ntext, Ndata, Nbss, Next, AddSymbol, AddRelocation,
    PutSeg;

TYPE BYTE = [0..255];

CONST 
    Nundf = 0; Nabs = 2; Ntext = 4; Ndata = 6; Nbss = 8; Next = 1;

PROCEDURE SetObjStream (s: Stream);
PROCEDURE PutSeg (add : ADDRESS; bytes : CARDINAL);
PROCEDURE PutHeader(magic: CARDINAL);
(*  output a dummy header (with magic number 'magic') to the stream.
*)
PROCEDURE Flush(udatasize: CARDINAL);
(*  output all the relocations and symbol table, and update the
    header to reflect the final sizes.
    'udatasize' is the size of the unitialised data section.
*)
PROCEDURE PutByte(b: BYTE);
(*  output the byte 'b' to the stream.
*)
PROCEDURE PutLong(w: CARDINAL);
(*  output 'w' as four bytes to the stream.
*)
PROCEDURE SizeNow(): CARDINAL;
(*  returns the current upper bound of the current segment.
*)
PROCEDURE EndText;
(*  marks the end of the text segment, initialised data now follows.
*)
PROCEDURE EndTextReloc;
(*  marks the end of the text relocation segment.
    data relocations now follow.
*)
PROCEDURE AddSymbol(VAR name: ARRAY OF CHAR; ntype, value: CARDINAL): CARDINAL;
(*  add a name to the symbol table of type 'ntype' and value 'value', 
    returning the id to be used in relocation references.
*)
PROCEDURE AddRelocation(address, symb: CARDINAL; extern: BOOLEAN);
(*  add a relocation entry at 'address' for 'symb' (returned
    from AddSymbol or = Ntext).
*)
PROCEDURE PutSymbols;
(* output the symbol/string table
*)

END UnixObj.
