home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / 68000DSM.ZIP / 68000DSM.C
Text File  |  1989-03-19  |  138KB  |  4,310 lines

  1. Article 2660 (70 more) in net.sources:
  2. From: jmc@inset.UUCP (John Collins)
  3. Subject: 68000 Disassembler
  4. Message-ID: <658@inset.UUCP>
  5. Date: 15 Aug 85 23:11:30 GMT
  6. Date-Received: 24 Aug 85 05:01:10 GMT
  7. Reply-To: jmc@inset.UUCP (John Collins)
  8. Organization: --- NONE ---
  9. Lines: 4303
  10. Xpath: icdoc ivax
  11.  
  12. --MORE--(0%)This is the 68000 disassembler mentioned on the net.
  13. It is not my final version by any means, but I have found it extremely
  14. useful and it represents severl weeks' work.
  15.  
  16.         John Collins.
  17.  
  18. You should get the following files:
  19.  
  20.         doc             - MM macros
  21.         makefile
  22.         unc.h
  23.         alloc.c
  24.         file.c
  25.         heur.c
  26.         iset.c
  27.         libmtch.c
  28.         main.c
  29.         prin.c
  30.         robj.c
  31.  
  32. To extract /bin/sh the remainder of the file after the next line
  33. ------------------------------cut here------------------------------
  34.  
  35. # To unbundle, sh this file
  36. echo doc 1>&2
  37. sed 's/.//' >doc <<'//GO.SYSIN DD doc'
  38. -.\"/*% nroff -cm -rL72 %|epson|spr -f plain.a -h uncdoc -w
  39. -.nr Hb 7
  40. -.nr Hs 3
  41. -.ds HF 3 3 3 3 3 3 3
  42. -.nr Hu 5
  43. -.nr Hc 1
  44. -.SA 1
  45. -.PH "''A Disassembler''"
  46. -.PF "'Issue %I%'- Page \\\\nP -'%G%'"
  47. -.H 1 "Introduction"
  48. -This document describes the first release of a disassembler for UNIX
  49. -executable files.
  50. -The key features are:
  51. -.AL
  52. -.LI
  53. -For object files the output can be assembled to generate the same
  54. -object module, (apart from minor variations in symbol table ordering) as the
  55. -input.
  56. -.LI
  57. -For stripped executable files object modules and libraries may be scanned,
  58. -modules in the main input identified and the appropriate names automatically
  59. -inserted into the output.
  60. -.LI
  61. -An option is available to convert most non-global names into local symbols,
  62. -which cuts down the symbols in the generated assembler file.
  63. -.LI
  64. -The disassembler copes reasonably with modules merged with the
  65. -.B "-r"
  66. -option to
  67. -.B "ld" ,
  68. -generating a warning message as to the number of modules involved.
  69. -.LE
  70. -.P
  71. -At present this is available forcertain Motorola 68000 ports of UNIX
  72. -System III and System V. Dependencies on
  73. -.AL a
  74. -.LI
  75. -Instruction set.
  76. -.LI
  77. -Object module format.
  78. -.LI
  79. -Library module format.
  80. -.LI
  81. -Assembler output format.
  82. -.LE
  83. -.P
  84. -are hopefully sufficiently localised to make the product useful as a
  85. -basis for other disassemblers for other versions of UNIX.
  86. -.P
  87. -The product is thus distributed in source form at present.
  88. -.H 1 "Use"
  89. -The disassembler is run by entering:
  90. -.DS I
  91. -unc mainfile lib1 lib2 ...
  92. -.DE
  93. -.P
  94. -The first named file is the file to be disassembled, which should be
  95. -a single file, either an object module, a (possibly stripped) executable
  96. -file, or a library member. Library members are designated using a
  97. -parenthesis notation, thus:
  98. -.DS I
  99. -unc '/lib/libc.a(printf.o)'
  100. -.DE
  101. -.P
  102. -It is usually necessary to escape the arguments in this case to prevent
  103. -misinterpretation by the shell. Libraries in standard places such as
  104. -.I "/lib"
  105. -and
  106. -.I "/usr/lib"
  107. -may be specified in the same way as to
  108. -.B "ld" ,
  109. -thus
  110. -.DS I
  111. -unc '-lc(printf.o)'
  112. -unc '-lcurses(wmove.o)'
  113. -.DE
  114. -.P
  115. -As an additional facility, the list of directories searched for
  116. -libraries may be varied by setting the environment variable
  117. -.B "LDPATH" ,
  118. -which is interpreted similarly to the shell
  119. -.B "PATH"
  120. -variable, and of course defaults to
  121. -.DS I
  122. -LDPATH=/lib:/usr/lib
  123. -.DE
  124. -.P
  125. -As a further facility, the insertion of
  126. -.B "lib"
  127. -before and
  128. -.B ".a"
  129. -after the argument may be suppressed by using a capital
  130. -.B "-L"
  131. -argument, thus to print out the assembler for
  132. -.I "/lib/crt0.o" ,
  133. -then the command
  134. -.DS I
  135. -unc -Lcrt0.o
  136. -.DE
  137. -.P
  138. -should have the desired effect.
  139. -.P
  140. -Second and subsequent file arguments are only referenced for stripped
  141. -executable files, and may consist of single object files and library
  142. -members, using the same syntax as before, or whole libraries of object
  143. -files, thus:
  144. -.DS I
  145. -unc strippedfile -Lcrt0.o -lcurses -ltermcap '-lm(sqrt.o)' -lc
  146. -.DE
  147. -.P
  148. -It is advisable to make some efort to put the libraries to be searched
  149. -in the order in which they were originally loaded. This is because the
  150. -search for each module starts where the previously matched module ended.
  151. -However, no harm is done if this rule is not adhered to apart from
  152. -increased execution time except in the rare cases where the disassembler
  153. -is confused by object modules which are very nearly similar.
  154. -.H 1 "Additional options"
  155. -The following options are available to modify the behaviour of the
  156. -disassembler.
  157. -.VL 15 2
  158. -.LI "-o file"
  159. -Causes output to be sent to the specified file instead of the standard
  160. -output.
  161. -.LI "-t prefix"
  162. -Causes temporary files to be created with the given prefix. The default
  163. -prefix is
  164. -.B "split" ,
  165. -thus causing two temporary files to be created with this prefix in the
  166. -current directory. If it is desired, for example, to create the files as
  167. -.B "/tmp/xx*" ,
  168. -then the argument
  169. -.B "-t /tmp/xx"
  170. -should be given. Note that the temporary files may be very large as a
  171. -complete map of the text and data segments is generated.
  172. -.LI "-a"
  173. -Suppresses the generation of non-global absolute symbols from the
  174. -output. This saves output from C compilations without any obvious
  175. -problems, but the symbols are by default included in the name of
  176. -producing as nearly identical output as possible to the original source.
  177. -.LI "-s"
  178. -Causes an additional scan to take place where all possible labels are
  179. -replaced by local symbols. The local symbols are inserted in strictly
  180. -ascending order, starting at 1.
  181. -.LI "-v"
  182. -Causes a blow-by-blow account of activities to be output on the standard
  183. -error.
  184. -.LE
  185. -.H 1 "Diagnostics etc"
  186. -Truncated or garbled object and library files usually cause processing
  187. -to stop with an explanatory message.
  188. -.P
  189. -The only other kinds of message are some passing warnings concerning
  190. -obscure constructs not handled, such as the relocation of byte fields,
  191. -or the relocation of overlapping fields. Occasionally a message
  192. -.DS I
  193. -Library clash: message
  194. -.DE
  195. -.P-may appear and processing cease. This message is found where at a late
  196. -stage in processing libraries, the program discovers that due to the
  197. -extreme similarity of two or more library members, it has come to the
  198. -wrong conclusion about which one to use. The remedy here is to spell out
  199. -to the program which members to take in which order.
  200. -.H 1 "Future development"
  201. -In the future it is hoped to devise ways of making the disassembler
  202. -independent of all the above-mentioned version dependencies, by first
  203. -reading a files defining these things. This will probably be applied
  204. -after the Common Object Format becomes more standard.
  205. -.P
  206. -In the long term it would be desirable and useful to enhance the product
  207. -to produce compilable C in addition to assemblable assembler. Stages in
  208. -the process are seen as follows:
  209. -.AL
  210. -.LI
  211. -Better identification of basic blocks in the code. Switch statements are
  212. -a major problem here, as are constant data held in the text segment.
  213. -.LI
  214. -Marrying of data to the corresponding text. It is in various places hard
  215. -to divorce static references "on the fly" (e.g. strings, and switch
  216. -lists in some implementations) from static at the head of a module. This
  217. -is part of the problem of identifying basic blocks.
  218. -.LI
  219. -Compilation of header files to work out structure references within the
  220. -text. At this stage some interaction may be needed.
  221. -.LE
  222. -.P
  223. -Meanwhile the product is one which is a useful tool to the author in its
  224. -present form. Comments and suggestions as to the most practical method
  225. -of improving the product in the ways suggested or in other ways would be
  226. -gratefully considered.
  227. //GO.SYSIN DD doc
  228. echo makefile 1>&2
  229. sed 's/.//' >makefile <<'//GO.SYSIN DD makefile'
  230. -CFLAGS=-v -OB
  231. -OBJS=alloc.o file.o libmtch.o robj.o iset.o prin.o heur.o main.o
  232. -
  233. -unc:   $(OBJS)
  234. -       cc -o unc $(OBJS)
  235. -
  236. -$(OBJS):       unc.h
  237. //GO.SYSIN DD makefile
  238. echo unc.h 1>&2
  239. sed 's/.//' >unc.h <<'//GO.SYSIN DD unc.h'
  240. -/*
  241. - *     SCCS:   @(#)unc.h       1.2     11/2/84 1421:02
  242. - *     Header file for uncompile program.
  243. - *
  244. - ***********************************************************************
  245. - *     This software is copyright of
  246. - *
  247. - *             John M Collins
  248. - *             47 Cedarwood Drive
  249. - *             St Albans
  250. - *             Herts, AL4 0DN
  251. - *             England                 +44 727 57267
  252. - *
  253. - *     and is released into the public domain on the following conditions:
  254. - *
  255. - *             1.  No free maintenance will be guaranteed.
  256. - *             2.  Nothing may be based on this software without
  257. - *                 acknowledgement, including incorporation of this
  258. - *                 notice.
  259. - *
  260. - *     Notwithstanding the above, the author welcomes correspondence and bug
  261. - *     fixes.
  262. - ***********************************************************************
  263. - */
  264. -
  265. -#define        MAXCHARS        50
  266. -#define        HASHMOD         97
  267. -
  268. -/*
  269. - *     The following structure is used to keep track of symbols.
  270. - */
  271. -
  272. -struct symstr  {
  273. -       struct  symstr  *s_next;                /*  Next in hash chain  */
  274. -       struct  symstr  *s_link;                /*  Next in duplicate labels */
  275. -       unsigned        s_type  :  3;           /*  Symbol type  */
  276. -       unsigned        s_newsym:  1;           /*  A new symbol  */
  277. -       unsigned        s_invent:  1;           /*  Invented symbol  */
  278. -       unsigned        s_glob  :  1;           /*  Global symbol  */
  279. -       long            s_value;                /*  Value if defined  */
  280. -       short           s_defs;                 /*  Defined count  */
  281. -       short           s_used;                 /*  Used count  */
  282. -       unsigned short  s_lsymb;                /*  Local symbol  */
  283. -       char            s_name[1];              /*  Chars of name null term */
  284. -};
  285. -
  286. -typedef        struct  symstr  *symbol;
  287. -
  288. -symbol symbhash[HASHMOD];
  289. -
  290. -typedef        struct  {
  291. -       int     ef_t;                   /*  Text file fd  */
  292. -       int     ef_d;                   /* Data file fd  */
  293. -       long    ef_entry;               /*  Entry point  */
  294. -       long    ef_tsize;               /*  Text size  */
  295. -       long    ef_dsize;               /*  Data size  */
  296. -       long    ef_bsize;               /*  Bss size  */
  297. -       long    ef_end;                 /*  End of it all  */
  298. -       long    ef_tbase;               /*  Text base  */
  299. -       long    ef_dbase;               /*  Data base  */
  300. -       long    ef_bbase;               /*  Bss base  */
  301. -       int     ef_stcnt;               /*  Number of symbols  */
  302. -       int     ef_stmax;               /*  Max number of symbols  */
  303. -       symbol  *ef_stvec;              /*  Symbol vector  */
  304. -}  ef_fids;
  305. -
  306. -typedef        ef_fids *ef_fid;
  307. -
  308. -/*
  309. - *     Description of word in text file.  This entry is held in the place
  310. - *     corresponding to the address in the text file.
  311. - */
  312. -
  313. -typedef        struct  {
  314. -       unsigned  short t_contents;             /*  Actual contents  */
  315. -       unsigned  short t_iindex;               /*  Index in table  */
  316. -       unsigned        t_type  :  2;           /*  Type  */
  317. -       unsigned        t_vins  :  1;           /*  Valid instruction  */
  318. -       unsigned        t_bdest :  1;           /*  Is branch dest  */
  319. -       unsigned        t_gbdest:  1;           /*  Is global dest  */
  320. -       unsigned        t_dref  :  1;           /*  Refered to in data  */
  321. -       unsigned        t_bchtyp:  2;           /*  Branch type  */
  322. -       unsigned        t_lng   :  3;           /*  Length in words  */
  323. -       unsigned        t_reloc :  2;           /*  Relocatable  */
  324. -       unsigned        t_rptr  :  2;           /*  Where relocated  */
  325. -       unsigned        t_rdisp :  1;           /*  Relocatable displacement */
  326. -       unsigned        t_isrel :  1;           /*  Relocated  */
  327. -       unsigned        t_amap  :  1;           /*  Worked out  */
  328. -       symbol          t_relsymb;              /*  Relocation symbol  */
  329. -       long            t_reldisp;              *  Offset + or - from symb */
  330. -       symbol          t_lab;                  /*  Label  */
  331. -       unsigned  short t_lsymb;                /*  Local symbol  */
  332. -       long            t_reflo;                /*  Lowest place referred  */
  333. -       long            t_refhi;                /*  Highest place referred  */
  334. -       unsigned  short t_match;                /*  Lib match lng  */
  335. -}  t_entry;
  336. -
  337. -/*
  338. - *     Types ......
  339. - */
  340. -
  341. -#define        T_UNKNOWN       0
  342. -#define        T_BEGIN         1
  343. -#define        T_CONT          2
  344. -
  345. -#define        R_NONE          0               /*  No relocation  */
  346. -#define        R_BYTE          1               /*  Byte relocation  */
  347. -#define        R_WORD          2               /*  Word relocation  */
  348. -#define        R_LONG          3               /*  Long relocation  */
  349. -
  350. -/*
  351. - *     Branch types.
  352. - */
  353. -
  354. -#define        T_NOBR          0
  355. -#define        T_CONDBR        1
  356. -#define        T_UNBR          2
  357. -#define        T_JSR           3
  358. -
  359. -typedef        struct  {
  360. -       unsigned  char  d_contents;             /*  Actual contents  */
  361. -       unsigned        d_type  :  4;           /*  Data type  */
  362. -       unsigned        d_reloc :  2;           /*  Relocatable  */
  363. -       unsigned        d_rptr  :  2;           /*  Where relocated  */
  364. -       short           d_lng;                  /*  Length -ve for D_CONT */
  365. -       symbol          d_relsymb;              /*  Relocation symbol  */
  366. -       long            d_reldisp;              /*  Offset + or - from symb */
  367. -       symbol          d_lab;                  /*  Label  */
  368. -}  d_entry;
  369. -
  370. -/*
  371. - *     Data types.
  372. - */
  373. -
  374. -#define        D_ASC           0               /*  Ascii chars  */
  375. -#define        D_ASCZ          1               /*  Null-term ascii  */
  376. -#define        D_BYTE          2               /*  Decimal bytes  */
  377. -#define        D_WORD          3               /*  Words  */
  378. -#define        D_LONG          4               /*  Longs  */
  379. -#define        D_ADDR         5               /*  Address pointer  */
  380. -#define        D_CONT          6               /*  Continuation of last  */
  381. -
  382. -/*
  383. - *     'Common' items.
  384. - */
  385. -
  386. -struct commit  {
  387. -       symbol  *c_symb;                /*  List of symbols  */
  388. -       int     c_int;                  /*  Current number  */
  389. -       int     c_max;                  /*  Maximum  */
  390. -};
  391. -
  392. -/*
  393. - *     Library file description.
  394. - */
  395. -
  396. -struct libit   {
  397. -       int     lf_fd;                  /*  File descriptor  */
  398. -       long    lf_offset;              /*  Offset of current file  */
  399. -       long    lf_next;                /*  Offset of next file  */
  400. -       char    lf_name[14];            /*  Name of item  */
  401. -};
  402. //GO.SYSIN DD unc.h
  403. echo alloc.c 1>&2
  404. sed 's/.//' >alloc.c <<'//GO.SYSIN DD alloc.c'
  405. -/*
  406. - *     SCCS:   @(#)alloc.c     1.2     11/2/84 14:17:20
  407. - *     Allocate space etc.
  408. - *
  409. - ***********************************************************************
  410. - *     This software is copyright of
  411. - *
  412. - *             John M Collins
  413. - *             47 Cedarwood Drive
  414. - *             St Albans
  415. - *             Herts, AL4 0DN
  416. - *             England                 +44 727 57267
  417. - *
  418. - *     and is released into the public domain on the following conditions:
  419. - *
  420. - *             1.  No free maintenance will be guaranteed.
  421. - *             2.  Nothing may be based on this software without
  422. - *                 acknowledgement, including incorporation of this
  423. - *                 notice.
  424. - *
  425. - *     Notwithstanding the above, the author welcomes correspondence and bug
  426. - *     fixes.
  427. - ***********************************************************************
  428. - */
  429. -
  430. -#include <stdio.h>
  431. -#include <a.out.h>
  432. -#include <setjmp.h>
  433. -#include "unc.h"
  434. -
  435. -#define        STINC   10
  436. -
  437. -char   *malloc(), *realloc();
  438. -char   *strncpy();
  439. -void   gette(), getde(), setde(), putte(), putde();
  440. -void   unimpl();
  441. -long   gettw();
  442. -
  443. -ef_fids        mainfile;
  444. -
  445. -/*
  446. - *     Oops! out of memory.....
  447. - */
  448. -
  449. void   nomem()
  450. -{
  451. -       (void) fprintf(stderr, "Sorry - run out of memory\n");
  452. -       exit(255);
  453. -}
  454. -
  455. -/*
  456. - *     Look up hash value of symbol.
  457. - */
  458. -
  459. -unsigned  shash(str)
  460. -register  char *str;
  461. -{
  462. -       register  unsigned  result = 0;
  463. -       register  int   cnt = 0;
  464. -       
  465. -       while  (*str  &&  cnt < MAXCHARS)  {
  466. -               result += *str++;
  467. -               cnt++;
  468. -       }
  469. -       return  result % HASHMOD;
  470. -}
  471. -
  472. -/*
  473. - *     Look up hash value of symbol, possibly allocating a new symbol.
  474. - */
  475. -
  476. -symbol lookup(str)
  477. -char   *str;
  478. -{
  479. -       register  symbol  res, *pp;
  480. -       register  int   len;
  481. -       
  482. -       pp = &symbhash[shash(str)];
  483. -       res = *pp;
  484. -       while  (res != NULL)  {
  485. -               if  (strncmp(res->s_name, str, MAXCHARS) == 0)
  486. -                       return  res;
  487. -               pp = &res->s_next;
  488. -               res = *pp;
  489. -       }
  490. -       for  (len = 0;  len < MAXCHARS;  len++)
  491. -               if  (str[len] == '\0')
  492. -                       break;
  493. -       len++;
  494. -       res = (symbol) malloc(sizeof(struct symstr) + len);
  495. -       if  (res == NULL)
  496. -               nomem();
  497. -       *pp = res;
  498. -       res->s_next = NULL;
  499. -       (void) strncpy(res->s_name, str, len);
  500. -       res->s_name[len] = '\0';                /*  Null-terminate  */
  501. -       res->s_newsym = 1;
  502. -       res->s_glob = 0;
  503. -       res->s_invent = 0;
  504. -       res->s_link = NULL;
  505. -       res->s_used = 0;
  506. -       res->s_defs = 0;
  507. -       res->s_lsymb = 0;
  508. -       return  res;
  509. -}
  510. -
  511. -/*
  512. - *     Invent a symbol, making sure that we don't know it.
  513. - */
  514. -
  515. -symbol inventsymb(prefix)
  516. -char   *prefix;
  517. -{
  518. -       static  int  nsymb = 0;
  519. -       char    schars[10];
  520. -       register  symbol  res;
  521. -       
  522. -       do      (void) sprintf(schars, "%s%d", prefix, ++nsymb);
  523. -       while  (!(res = lookup(schars))->s_newsym);
  524. -       
  525. -       res->s_newsym = 0;
  526. -       res->s_invent = 1;
  527. -       return  res;
  528. -}
  529. -        
  530. -/*
  531. - *     Reallocate symboltable.
  532. - */
  533. -
  534. -void   reallst(outf)
  535. -register  ef_fid  outf;
  536. -{
  537. -       outf->ef_stmax += STINC;
  538. -       if  (outf->ef_stvec == NULL)
  539. -               outf->ef_stvec = (symbol *) malloc(outf->ef_stmax * sizeof(symbol));
  540. -       else
  541. -               outf->ef_stvec = (symbol *) realloc(outf->ef_stvec,
  542. -                                       outf->ef_stmax * sizeof(symbol));
  543. -       if  (outf->ef_stvec == NULL)
  544. -               nomem();
  545. -}
  546. -
  547. -/*
  548. - *     Search through existing symbol table for symbol with given
  549. - *     value.  Invent a new one if needed.
  550. - */
  551. -
  552. -symbol getnsymb(fid, seg, pos)
  553. -register  ef_fid  fid;
  554. -unsigned  seg;
  555. -long   pos;
  556. -{
  557. -       register  int   i;
  558. -       register  symbol  res;
  559. -       
  560. -       /***********  MACHINE DEPENDENT  ******************************
  561. -        *      Convert relocation segment type (argument) to symbol type
  562. -        *      (as remembered in symbol table).  Don't ask me why they
  563. -        *      have to be different.....
  564. -        */
  565. -       
  566. -       seg += TEXT - RTEXT;
  567. -       
  568. -       /*
  569. -        *      See if the reference is to an external symbol.
  570. -        *      If so, use that.
  571. -        */
  572. -       
  573. -       for  (i = 0;  i < fid->ef_stcnt;  i++)  {
  574. -               res = fid->ef_stvec[i];
  575. -               if  (res->s_type == seg  &&  res->s_value == pos)
  576. -                       return  res;
  577. -       }
  578. -       
  579. -       /*
  580. -        *      Invent a symbol and use that.
  581. -        */
  582. -       
  583. -       res = inventsymb("RS");
  584. -       if  (fid->ef_stcnt >= fid->ef_stmax)
  585. -               reallst(fid);
  586. -       fid->ef_stvec[fid->ef_stcnt++] = res;
  587. -       res->s_type = seg;
  588. -       res->s_value = pos;
  589. -       if  (seg == TEXT)  {
  590. -               t_entry tent;
  591. -               gette(fid, pos, &tent);
  592. -               tent.t_bdest = 1;
  593. -               tent.t_lab = res;
  594. -               putte(fid, pos, &tent);
  595. -       }
  596. -       else  if  (seg == DATA  ||  seg == BSS)  {
  597. -               d_entry dent;
  598. -               getd(fid, pos, &dent);
  599. -               dent.d_lab = res;
  600. -               putde(fid, pos, &dent);
  601. -       }
  602. -
  603. -       return  res;
  604. -}
  605. -
  606. -/*
  607. - *     Assuming address given is in text segment, find its label, or invent
  608. - *     one.  Also set where refered from.
  609. - */
  610. -
  611. -symbol textlab(loc, refpos)
  612. -long   loc, refpos;
  613. -{
  614. -       t_entry tent;
  615. -
  616. -       gette(&mainfile, loc, &tent);
  617. -       if  (tent.t_type == T_CONT)
  618. -               return  NULL;
  619. -       if  (tent.t_lab == NULL)  {
  620. -               tent.t_lab = inventsymb("TS");
  621. -               tent.t_lab->s_type = TEXT;
  622. -               tent.t_lab->s_value = loc;
  623. -               tent.t_bdest = 1;
  624. -               putte(&mainfile, loc, &tent);
  625. -       }
  626. -       else
  627. -               tent.t_lab->s_used++;
  628. -       if  (tent.t_refhi < refpos)  {
  629. -               tent.t_refhi = refpos;
  630. -               putte(&mainfile, loc, &tent);
  631. -       }
  632. -       if  (tent.t_reflo > refpos)  {
  633. -               tent.t_reflo = refpos;
  634. -               putte(&mainfile, loc, &tent);
  635. -       }
  636. -       return  tent.t_lab;
  637. -}
  638. -
  639. -/*
  640. - *     Note references to data.
  641. - */
  642. -
  643. -void   mkdref(tpos, size)
  644. -long   tpos;
  645. -unsigned  size;
  646. -{
  647. -       t_entry tent;
  648. -       d_entry dent;
  649. -       register  symbol  ds;
  650. -       int     dchng = 0;
  651. -       int     wsize;
  652. -       long    dpos;
  653. -       
  654. -       gette(&mainfile, tpos, &tent);
  655. -       if  (tent.t_relsymb != NULL)
  656. -               return;
  657. -               
  658. -       dpos = gettw(&mainfile, tpos, R_LONG);
  659. -       if  (dpos < mainfile.ef_dbase  ||  dpos > mainfile.ef_end)
  660. -               return;
  661. -       
  662. -       switch  (size)  {
  663. -       default:
  664. -               wsize = D_BYTE;
  665. -               break;
  666. -       case  2:
  667. -               wsize = D_WORD;
  668. -               break;
  669. -       case  4:
  670. -               wsize = D_LONG;
  671. -               break;
  672. -       }
  673. -       
  674. -       getde(&mainfile, dpos, &dent);
  675. -       if  ((ds = dent.d_lab) == NULL)  {
  676. -               if  (dpos >= mainfile.ef_bbase)  
  677. -                       ds = inventsymb("BS");
  678. -                       ds->s_type = BSS;
  679. -               }
  680. -               else  {
  681. -                       ds = inventsymb("DS");
  682. -                       ds->s_type = DATA;
  683. -               }
  684. -               ds->s_value = dpos;
  685. -               dent.d_lab = ds;
  686. -               dchng++;
  687. -       }
  688. -       else
  689. -               ds->s_used++;
  690. -
  691. -       if  (dent.d_type != D_BYTE)  {
  692. -               if  (dent.d_type != wsize)  {
  693. -                       if  (dent.d_type == D_ADDR)  {
  694. -                               if  (wsize != D_LONG)
  695. -                                       unimpl("Addr word usage");
  696. -                       }
  697. -                       else  if  (dent.d_type > wsize)  {
  698. -                               dchng++;
  699. -                               dent.d_type = wsize;
  700. -                               dent.d_lng = size;
  701. -                       }
  702. -               }
  703. -       }
  704. -       else  {
  705. -               dent.d_type = wsize;
  706. -               dent.d_lng = size;
  707. -               dchng++;
  708. -       }
  709. -       if  (dchng)  {
  710. -               putde(&mainfile, dpos, &dent);
  711. -               for  (dchng = 1;  dchng < size; dchng++)
  712. -                       setde(&mainfile, dpos+dchng, D_CONT, 1);
  713. -       }
  714. -               
  715. -       tent.t_relsymb = ds;
  716. -       putte(&mainfile, tpos, &tent);
  717. -}
  718. -
  719. -/*
  720. - *     Add item to common or abs list.
  721. - */
  722. -
  723. -#define        COMINC  10
  724. -
  725. -void   addit(cp, symb)
  726. -register  struct  commit  *cp;
  727. -symbol symb;
  728. -{
  729. -       if  (cp->c_int >= cp->c_max)  {
  730. -               cp->c_max += COMINC;
  731. -               if  (cp->c_symb == NULL)
  732. -                       cp->c_symb = (symbol *) malloc(COMINC*sizeof(symbol));
  733. -               else
  734. -                       cp->c_symb = (symbol *)
  735. -                                       realloc(cp->c_symb,
  736. -                                               cp->c_max * sizeof(symbol));
  737. -               if  (cp->c_symb == NULL)
  738. -                       nomem();
  739. -      }
  740. -       cp->c_symb[cp->c_int++] = symb;
  741. -}
  742. //GO.SYSIN DD alloc.c
  743. echo file.c 1>&2
  744. sed 's/.//' >file.c <<'//GO.SYSIN DD file.c'
  745. -/*
  746. - *     SCCS:   @(#)file.c      1.2     11/2/84 14:17:35
  747. - *     Various operations on files.
  748. - *
  749. - ***********************************************************************
  750. - *     This software is copyright of
  751. - *
  752. - *             John M Collins
  753. - *             47 Cedarwood Drive
  754. - *             St Albans
  755. - *             Herts, AL4 0DN
  756. - *             England                 +44 727 57267
  757. - *
  758. - *     and is released into the public domain on the following conditions:
  759. - *
  760. - *             1.  No free maintenance will be guaranteed.
  761. - *             2.  Nothing may be based on this software without
  762. - *                 acknowledgement, including incorporation of this
  763. - *                 notice.
  764. - *
  765. - *     Notwithstanding the above, the author welcomes correspondence and bug
  766. - *     fixes.
  767. - ***********************************************************************
  768. - */
  769. -
  770. -#include <stdio.h>
  771. -#include <a.out.h>
  772. -#include "unc.h"
  773. -       
  774. -long   lseek();
  775. -void   unimpl();
  776. -
  777. -/*
  778. - *     Validate addr and get text entry corresponding to it from the given
  779. - *     file.
  780. - */
  781. -
  782. -void   gette(fid, addr, te)
  783. -register  ef_fid  fid;
  784. -register  long addr;
  785. -t_entry        *te;
  786. -{
  787. -       addr -= fid->ef_tbase;
  788. -       if  (addr < 0  ||  addr > fid->ef_tsize  || (addr & 1) != 0)  {
  789. -               (void) fprintf(stderr, "Invalid text address %lx\n", addr);
  790. -               exit(200);
  791. -       }
  792. -       (void) lseek(fid->ef_t, (long)(addr * sizeof(t_entry)/2), 0);
  793. -       if  (read(fid->ef_t, (char *) te, sizeof(t_entry)) != sizeof(t_entry))  {
  794. -               (void) fprintf(stderr, "Trouble reading text at %lx\n", addr);
  795. -               exit(201);
  796. -       }
  797. -}
  798. -
  799. -/*
  800. - *     Store a text entry.
  801. - */
  802. -
  803. -void   putte(fid, addr, te)
  804. -register  ef_fid  fid;
  805. -register  long addr;
  806. -t_entry        *te;
  807. -{
  808. -       addr -= fid->ef_tbase;
  809. -      if  (addr < 0  ||  addr > fid->ef_tsize  ||  (addr & 1) != 0)  {
  810. -               (void) fprintf(stderr, "Invalid text address %lx\n", addr);
  811. -               exit(200);
  812. -       }
  813. -       (void) lseek(fid->ef_t, (long)(addr * sizeof(t_entry)/2), 0);
  814. -       (void) write(fid->ef_t, (char *) te, sizeof(t_entry));
  815. -}
  816. -
  817. -/*
  818. - *     Validate addr and get data entry corresponding to it from the given
  819. - *     file.
  820. - */
  821. -
  822. -void   getde(fid, addr, de)
  823. -register  ef_fid  fid;
  824. -register  long addr;
  825. -d_entry        *de;
  826. -{
  827. -       if  (addr < fid->ef_dbase  ||  addr > fid->ef_end)  {
  828. -               (void) fprintf(stderr, "Invalid data address %lx\n", addr);
  829. -               exit(200);
  830. -       }
  831. -       addr -= fid->ef_dbase;
  832. -       (void) lseek(fid->ef_d, (long)(addr * sizeof(d_entry)), 0);
  833. -       if  (read(fid->ef_d, (char *) de, sizeof(d_entry)) != sizeof(d_entry))  {
  834. -               (void) fprintf(stderr, "Trouble reading data at %lx\n", addr);
  835. -               exit(201);
  836. -       }
  837. -}
  838. -
  839. -/*
  840. - *     Store a data entry.
  841. - */
  842. -
  843. -void   putde(fid, addr, de)
  844. -register  ef_fid  fid;
  845. -register  long addr;
  846. -d_entry        *de;
  847. -{
  848. -       if  (addr < fid->ef_dbase  ||  addr > fid->ef_end)  {
  849. -               (void) fprintf(stderr, "Invalid data address %lx\n", addr);
  850. -               exit(200);
  851. -       }
  852. -       addr -= fid->ef_dbase;
  853. -       (void) lseek(fid->ef_d, (long)(addr * sizeof(d_entry)), 0);
  854. -       (void) write(fid->ef_d, (char *) de, sizeof(d_entry));
  855. -}
  856. -
  857. -/*
  858. - *     Set type and length of given data entry.
  859. - */
  860. -
  861. -void   setde(fid, addr, type, lng)
  862. -ef_fid fid;
  863. -long   addr;
  864. -unsigned  type;
  865. -int    lng;
  866. -{
  867. -       d_entry dat;
  868. -
  869. -       if  (addr > fid->ef_end)
  870. -               return;
  871. -       getde(fid, addr, &dat);
  872. -       if  (type == D_CONT  &&  dat.d_reloc != R_NONE)  {
  873. -               char    obuf[30];
  874. -               (void) sprintf(obuf, "overlapped reloc 0x%x", addr);
  875. -               unimpl(obuf);
  876. -       }
  877. -       dat.d_type = type;
  878. -       at.d_lng = lng;
  879. -       putde(fid, addr, &dat);
  880. -}
  881. -       
  882. -/*
  883. - *     Get a word of data file, size as requested.
  884. - */
  885. -
  886. -long   getdw(fid, pos, size)
  887. -register  ef_fid  fid;
  888. -long   pos;
  889. -int    size;
  890. -{
  891. -       d_entry dat;
  892. -       register  long  res;
  893. -       register  int   i, lt;
  894. -       
  895. -       getde(fid, pos, &dat);
  896. -       
  897. -       switch  (size)  {
  898. -       case  R_BYTE:
  899. -               return  dat.d_contents;
  900. -               
  901. -       case  R_LONG:
  902. -               lt = 4;
  903. -               goto  rest;
  904. -               
  905. -       case  R_WORD:
  906. -               lt = 2;
  907. -       rest:
  908. -               res = dat.d_contents;
  909. -               for  (i = 1;  i < lt; i++)  {
  910. -                       getde(fid, pos+i, &dat);
  911. -                       res = (res << 8) + dat.d_contents;
  912. -               }
  913. -               return  res;
  914. -               
  915. -       default:
  916. -               (void) fprintf(stderr, "Data word size error\n");
  917. -               exit(20);
  918. -       }
  919. -       /*NOTREACHED*/
  920. -}
  921. -
  922. -/*
  923. - *     Get a word of text file.
  924. - */
  925. -
  926. -long   gettw(fid, pos, size)
  927. -register  ef_fid  fid;
  928. -long   pos;
  929. -int    size;
  930. -{
  931. -       t_entry tex;
  932. -       long    res;
  933. -       
  934. -       gette(fid, pos, &tex);
  935. -       
  936. -       switch  (size)  {
  937. -       case  R_BYTE:
  938. -               return  tex.t_contents >> 8;
  939. -               
  940. -       case  R_WORD:
  941. -               return  tex.t_contents;
  942. -               
  943. -       case  R_LONG:
  944. -               res = tex.t_contents;
  945. -               gette(fid, pos+2, &tex);
  946. -               return  (res << 16) + tex.t_contents;
  947. -       default:
  948. -               (void) fprintf(stderr, "Text word size error\n");
  949. -               exit(20);
  950. -       }
  951. -       /*NOTREACHED*/
  952. -}
  953. //GO.SYSIN DD file.c
  954. echo heur.c 1>&2
  955. sed 's/.//' >heur.c <<'//GO.SYSIN DD heur.c'
  956. -/*
  957. - *     SCCS:   @(#)heur.c      1.2     11/2/84 14:17:46
  958. - *     Attempt to guess things about the file.
  959. - *
  960. - **********************************************************************
  961. - *     This software is copyright of
  962. - *
  963. - *             John M Collins
  964. - *             47 Cedarwood Drive
  965. - *             St Albans
  966. - *             Herts, AL4 0DN
  967. - *             England                 +44 727 57267
  968. - *
  969. - *     and is released into the public domain on the following conditions:
  970. - *
  971. - *             1.  No free maintenance will be guaranteed.
  972. - *             2.  Nothing may be based on this software without
  973. - *                 acknowledgement, including incorporation of this
  974. - *                 notice.
  975. - *
  976. - *     Notwithstanding the above, the author welcomes correspondence and bug
  977. - *     fixes.
  978. - ***********************************************************************
  979. - */
  980. -
  981. -#include <stdio.h>
  982. -#include <a.out.h>
  983. -#include "unc.h"
  984. -
  985. -#define        INITDAT 256
  986. -#define        INCDAT  128
  987. -
  988. -#define        STRSCNT 3
  989. -#define        STRECNT 3
  990. -
  991. -char   *malloc(), *realloc();
  992. -
  993. -void   gette(), getde(), setde(), putte(), putde();
  994. -void   nomem();
  995. -long   getdw();
  996. -symbol inventsymb();
  997. -
  998. -long   endt;
  999. -ef_fids        mainfile;
  1000. -
  1001. -/*
  1002. - *     Talk about implemented things.....
  1003. - */
  1004. -
  1005. -void   unimpl(msg)
  1006. -char   *msg;
  1007. -{
  1008. -       (void) fprintf(stderr, "Warning: handling of \"%s\" not implemented\n", msg);
  1009. -}
  1010. -
  1011. -/*
  1012. - *     Return 1 if string char, otherwise 0.
  1013. - */
  1014. -
  1015. -int    possstr(x)
  1016. -unsigned  x;
  1017. -{
  1018. -       if  (x >= ' '  &&  x <= '~')
  1019. -               return  1;
  1020. -       if  (x == '\n'  ||  x == '\t')
  1021. -               return  1;
  1022. -       return  0;
  1023. -}
  1024. -
  1025. -/*
  1026. - *     Guess things about data files.
  1027. - */
  1028. -
  1029. -void   intudat(fid)
  1030. -ef_fid  fid;
  1031. -{
  1032. -       register  int   i, j;
  1033. -       int     lt, input, invcnt;
  1034. -       long    offs, soffs, endd;
  1035. -       d_entry fdat;
  1036. -       unsigned  char  *inbuf;
  1037. -       int     ibsize;
  1038. -       
  1039. -       inbuf = (unsigned  char *)malloc(INITDAT);
  1040. -       if  (inbuf == NULL)
  1041. -               nomem();
  1042. -       ibsize = INITDAT;
  1043. -       
  1044. -       offs = fid->ef_dbase;
  1045. -       endd = fid->e_bbase;
  1046. -
  1047. -       while  (offs < endd)  {
  1048. -               getde(fid, offs, &fdat);
  1049. -               if  (fdat.d_type != D_BYTE)  {
  1050. -                       offs += fdat.d_lng;
  1051. -                       continue;
  1052. -               }
  1053. -               
  1054. -               /*
  1055. -                *      Looks like general data.  Read in as much as possible.
  1056. -                */
  1057. -               
  1058. -               input = 0;
  1059. -               soffs = offs;
  1060. -               do  {
  1061. -                       if  (input >= ibsize)  {
  1062. -                               ibsize += INCDAT;
  1063. -                               inbuf = (unsigned  char *)
  1064. -                                       realloc((char *)inbuf, (unsigned)ibsize);
  1065. -                               if  (inbuf == NULL)
  1066. -                                       nomem();
  1067. -                       }
  1068. -                       inbuf[input++] = fdat.d_contents;
  1069. -                       offs++;
  1070. -                       if  (offs >= endd)
  1071. -                               break;
  1072. -                       getde(fid, offs, &fdat);
  1073. -               }  while  (fdat.d_type == D_BYTE && fdat.d_lab == NULL);
  1074. -               
  1075. -               /*
  1076. -                *      Now split up the data.
  1077. -                */
  1078. -               
  1079. -               for  (i = 0;  i < input;  )  {
  1080. -                       
  1081. -                       /*
  1082. -                        *      Might be a string.
  1083. -                        */
  1084. -                       
  1085. -                       if  (possstr(inbuf[i]))  {
  1086. -                               lt = input;
  1087. -                               if  (i + STRSCNT < lt)
  1088. -                                       lt = i + STRSCNT;
  1089. -                               for  (j = i + 1;  j < lt;  j++)  {
  1090. -                                       if  (inbuf[j] == '\0')
  1091. -                                               break;
  1092. -                                       if  (!possstr(inbuf[j]))
  1093. -                                               goto  notstr;
  1094. -                               }
  1095. -                              
  1096. -                               /*
  1097. -                                *      Looks like a string then.
  1098. -                                */
  1099. -                               
  1100. -                               invcnt = 0;
  1101. -                               for  (j = i + 1; j < input;  j++)  {
  1102. -                                       if  (inbuf[j] == '\0')  {
  1103. -                                               j++;
  1104. -                                               break;
  1105. -                                       }
  1106. -                                       if  (possstr(inbuf[j]))
  1107. -                                               invcnt = 0;
  1108. -                                       else  {
  1109. -                                               invcnt++;
  1110. -                                               if  (invcnt >= STRECNT)  {
  1111. -                                                       j -= invcnt - 1;
  1112. -                                                       break;
  1113. -                                               }
  1114. -                                       }
  1115. -                               }
  1116. -
  1117. -                               setde(fid,
  1118. -                                     soffs+i,
  1119. -                                     (unsigned)(inbuf[j-1]=='\0'?D_ASCZ:D_ASC),-                                     j - i);
  1120. -                               for  (i++;  i < j;  i++)
  1121. -                                       setde(fid, soffs+i, D_CONT, 1); 
  1122. -                               continue;
  1123. -                       }
  1124. -
  1125. -notstr:
  1126. -                       /*
  1127. -                        *      If on odd boundary, treat as a byte.
  1128. -                        */
  1129. -                       
  1130. -                       if  ((soffs + i) & 1  ||  i + 1 >= input)  {
  1131. -                               setde(fid, soffs + i, D_BYTE, 1);
  1132. -                               i++;
  1133. -                               continue;
  1134. -                       }
  1135. -
  1136. -                       /*
  1137. -                        *      Treat as longs unless not enough.-                        */
  1138. -                       
  1139. -                       if  (i + 3 >= input)  {
  1140. -                               setde(fid, soffs + i, D_WORD, 2);
  1141. -                               setde(fid, soffs + i + 1, D_CONT, -1);
  1142. -                               i += 2;
  1143. -                               continue;
  1144. -                       }
  1145. -
  1146. -                       /*
  1147. -                        *      Treat as a long but mark changable.
  1148. -                        */
  1149. -                       
  1150. -                       setde(fid, soffs + i, D_LONG, 4);
  1151. -                       for  (j = 1;  j < 4;  j++)
  1152. -                               setde(fid, soffs + i + j, D_CONT, -j);
  1153. -                       i += 4;
  1154. -               }
  1155. -       }
  1156. -       free((char *)inbuf);
  1157. -       
  1158. -       /*
  1159. -        *      Now zap bss segment.
  1160. -        */
  1161. -       
  1162. -       offs = fid->ef_bbase;
  1163. -       endd = fid->ef_end;
  1164. -
  1165. -       while  (offs < endd)  {
  1166. -               getde(fid, offs, &fdat);
  1167. -               if  (fdat.d_type != D_BYTE)  {
  1168. -                       offs += fdat.d_lng;
  1169. -                       continue;
  1170. -               }
  1171. -
  1172. -               soffs = offs;
  1173. -               do  {
  1174. -                       offs++;
  1175. -                       if  (offs >= endd)
  1176. -                               break;
  1177. -                       getde(fid, offs, &fdat);
  1178. -               }  while  (fdat.d_type == D_BYTE && fdat.d_lab == NULL);
  1179. -               
  1180. -               setde(fid, soffs, D_BYTE, (int)(offs-soffs));
  1181. -               for  (i = -1, soffs++;  soffs < offs; i--, soffs++)
  1182. -                       setde(fid, soffs, D_CONT, i); 
  1183. -       }
  1184. -}
  1185. -
  1186. -/*
  1187. - *     For non relocatable files, try to identify address pointers in
  1188. - *     the data.
  1189. - */
  1190. -
  1191. -void   inturdat(fid)
  1192. -ef_fid fid;
  1193. -{
  1194. -       register  long  offs = fid->ef_dbase;
  1195. -       register  int   i;
  1196. -       register  symbol  ds;
  1197. -       long  endd = fid->ef_bbase;
  1198. -       long  cont;
  1199. -       d_entry dent, refdent;
  1200. -
  1201. -       while  (offs < endd) {
  1202. -               getde(fid, offs, &dent);
  1203. -               if  (dent.d_type != D_LONG)
  1204. -                       goto  endit;
  1205. -               cont = getdw(fid, offs, R_LONG);
  1206. -               if  (cont < fid->ef_dbase || cont > fid->ef_end)
  1207. -                       goto  endit;
  1208. -               getde(fid, cont, &refdent);
  1209. -               if  (refdent.d_type == D_CONT)  {
  1210. -                       d_entry pdent;
  1211. -                       int     siz;
  1212. -                       
  1213. -                       if  (refdent.d_lng >= 0)
  1214. -                               goto  endit;
  1215. -                       getde(fid, cont+refdent.d_lng, &pdent);
  1216. -                       i = -refdent.d_lng;
  1217. -                       refdent.d_lng += pdent.d_lng;
  1218. -                       pdent.d_lng = i;
  1219. -                       if  (pdent.d_type == D_LONG  &&  i == 2)
  1220. -                               siz = D_WORD;
  1221. -                       else
  1222. -                               siz = D_BYTE;
  1223. -                       refdent.d_type = siz;
  1224. -                       pdent.d_type = siz;
  1225. -                       putde(fid, cont - i, &pdent);
  1226. -                       for  (i = 1;  i < refdent.d_lng;  i++)
  1227. -                               setde(fid, cont+i, D_CONT, -i);
  1228. -               }
  1229. -               if  ((ds = refdent.d_lab) == NULL)  {
  1230. -                       if  (cont >= fid->ef_bbase)  {
  1231. -                               ds = inventsymb("BS");
  1232. -                               ds->s_type = BSS;
  1233. -                       }
  1234. -                       else  {
  1235. -                               ds = inventsymb("DS");
  1236. -                               ds->s_type = DATA;
  1237. -                       }
  1238. -                       ds->s_value = cont;
  1239. -                       refdent.d_lab = ds;
  1240. -                       putde(fid, cont, &refdent);
  1241. -               }
  1242. -               else
  1243. -                       ds->s_used++;
  1244. -               dent.d_type = D_ADDR;
  1245. -               dent.d_relsymb = ds;
  1246. -               dent.d_rptr = ds->s_type;
  1247. -               putdefid, offs, &dent);
  1248. -               for  (i = 1;  i < 4;  i++)
  1249. -                       setde(fid, offs+i, D_CONT, 1);
  1250. -endit:
  1251. -               offs += dent.d_lng;
  1252. -       }
  1253. -}
  1254. -
  1255. -/*
  1256. - *     Recursively follow through the code, stopping at unconditional
  1257. - *     branches and invalid instructions.
  1258. - */
  1259. -
  1260. -void   follseq(pos)
  1261. -long   pos;
  1262. -{
  1263. -       t_entry tent;
  1264. -       int     lng;
  1265. -       long    npos;
  1266. -
  1267. -       while  (pos < endt)  {
  1268. -               gette(&mainfile, pos, &tent);
  1269. -               if  (tent.t_amap)       /*  Been here  */
  1270. -                       return;
  1271. -               tent.t_amap = 1;
  1272. -               lng = findinst(&tent, pos);
  1273. -               npos = pos + lng*2;
  1274. -               if  (npos > endt)  {
  1275. -                       tent.t_vins = 0;
  1276. -                       tent.t_lng = 1;
  1277. -                       tent.t_type = T_UNKNOWN;
  1278. -                       lng = 0;
  1279. -                       npos = endt;
  1280. -               }
  1281. -               putte(&mainfile, pos, &tent);
  1282. -               pos = npos;
  1283. -               
  1284. -               if  (lng <= 0)
  1285. -                       return;
  1286. -
  1287. -               switch  (tent.t_bchtyp)  {
  1288. -               case  T_UNBR:
  1289. -                       if  (tent.t_relsymb == NULL)
  1290. -                               return;
  1291. -                       pos = tent.t_relsymb->s_value;
  1292. -                       continue;
  1293. -               case  T_JSR:
  1294. -                       if  (tent.t_relsymb != NULL)
  1295. -                               follseq(tent.t_relsymb->s_value);
  1296. -                       continue;
  1297. -               case  T_CONDBR:
  1298. -                       follseq(tent.t_relsymb->s_value);
  1299. -               default:
  1300. -                       continue;
  1301. -               }
  1302. -       }
  1303. -}
  1304. -                       
  1305. -                       
  1306. -/*
  1307. - *     Try to work out things about text files.
  1308. - */
  1309. -
  1310. -void   intutext()
  1311. -{
  1312. -       long    pos;
  1313. -       t_entry tent;
  1314. -       int     lng;
  1315. -       
  1316. -       endt = mainfile.ef_tbase + mainfile.ef_tsize;
  1317. -      pos = mainfile.ef_entry;
  1318. -nextv:
  1319. -       for  (;  pos < endt;)  {
  1320. -               gette(&mainfile, pos, &tent);
  1321. -               if  (!tent.t_amap && tent.t_vins)  {
  1322. -                       follseq(pos);
  1323. -                       pos += 2;
  1324. -                       goto  nextiv;
  1325. -               }
  1326. -               pos += tent.t_lng * 2;
  1327. -               if  (tent.t_bchtyp == T_UNBR)
  1328. -                       goto  nextiv;
  1329. -       }
  1330. -       goto    dorest;
  1331. -nextiv:
  1332. -       for  (;  pos < endt;  pos += 2)  {
  1333. -               gette(&mainfile, pos, &tent);
  1334. -               if  (tent.t_bdest)
  1335. -                       goto  nextv;
  1336. -       }
  1337. -dorest:
  1338. -       /*
  1339. -        *      Deal with unmapped instructions.
  1340. -        */
  1341. -       
  1342. -       for  (pos = 0;  pos < endt;)  {
  1343. -               gette(&mainfile, pos, &tent);
  1344. -               switch  (tent.t_type)  {
  1345. -               case  T_BEGIN:
  1346. -                       pos += tent.t_lng * 2;
  1347. -                       continue;
  1348. -               case  T_UNKNOWN:
  1349. -                       if  (tent.t_vins)  {
  1350. -                               lng = findinst(&tent, pos);
  1351. -                               putte(&mainfile, pos, &tent);
  1352. -                               if  (lng > 0)  {
  1353. -                                       pos += lng * 2;
  1354. -                                       continue;
  1355. -                               }
  1356. -                       }
  1357. -               default:
  1358. -                       pos += 2;
  1359. -                       continue;
  1360. -               }
  1361. -       }
  1362. -}
  1363. -
  1364. -/*
  1365. - *     Invent local symbols.
  1366. - */
  1367. -
  1368. -void   intlsym()
  1369. -{
  1370. -       long    bpos, epos, hiref, hipos;
  1371. -       unsigned  llnum;
  1372. -       t_entry tent;
  1373. -       register  symbol  tl;
  1374. -       
  1375. -       endt = mainfile.ef_tbase + mainfile.ef_tsize;
  1376. -       epos = mainfile.ef_entry;
  1377. -       for  (;;)  {
  1378. -               bpos = epos;
  1379. -               hiref = bpos;
  1380. -               if  (epos >= endt)
  1381. -                       return;
  1382. -               gette(&mainfile, epos, &tent);
  1383. -              epos += tent.t_lng * 2;
  1384. -               for  (;  epos < endt;)  {
  1385. -                       gette(&mainfile, epos, &tent);
  1386. -                       if  (tent.t_gbdest  ||  tent.t_dref)
  1387. -                               break;
  1388. -                       if  (tent.t_reflo < bpos)
  1389. -                               break;
  1390. -                       if  (tent.t_refhi > hiref)  {
  1391. -                               hiref = tent.t_refhi;
  1392. -                               hipos = epos;
  1393. -                       }
  1394. -                       epos += tent.t_lng * 2;
  1395. -               }
  1396. -               if  (hiref > epos)
  1397. -                       epos = hipos;
  1398. -               llnum = 0;
  1399. -               for  (hipos = bpos;  hipos < epos;)  {
  1400. -                       gette(&mainfile, hipos, &tent);
  1401. -                       if  (!tent.t_gbdest && !tent.t_dref &&
  1402. -                        tent.t_reflo >= bpos && tent.t_refhi < epos &&
  1403. -                        (tl = tent.t_lab) != NULL)
  1404. -                               tl->s_lsymb = ++llnum;
  1405. -                       hipos += tent.t_lng * 2;
  1406. -               }
  1407. -       }
  1408. -}
  1409. -
  1410. -/*
  1411. - *     Given the main file, a possible candidate for matching in the
  1412. - *     file and an offset, see if text matches.  Return 1 if matches,
  1413. - *     or 0 if no match.
  1414. - */
  1415. -
  1416. -int    matchup(mf, lf, startpos)
  1417. -register  ef_fid  mf, lf;
  1418. -long   startpos;
  1419. -{
  1420. -       register  int   i, matches = 0;
  1421. -       t_entry ltent, mtent;
  1422. -
  1423. -       if  (lf->ef_tsize > mf->ef_tsize - startpos + mf->ef_tbase)
  1424. -               return  0;      /*  At end - can't fit  */
  1425. -
  1426. -       for  (i = 0;  i < lf->ef_tsize;  i += 2)  {
  1427. -               gette(lf, lf->ef_tbase + i, <ent);
  1428. -               if  (ltent.t_isrel)
  1429. -                       continue;
  1430. -               gette(mf, startpos + i, &mtent);
  1431. -               if  (mtent.t_contents != ltent.t_contents)
  1432. -                       return  0;
  1433. -               matches++;
  1434. -       }
  1435. -       
  1436. -       /*
  1437. -        *      Give up on zero length or all relocatable fils.
  1438. -        */
  1439. -       
  1440. -       return  matches > 0;
  1441. -}
  1442. -
  1443. -/*
  1444. - *     Scan through main file looking for a match.
  1445. - */
  1446. -
  1447. -long   findstart(mf, lf)
  1448. -register  ef_fid  mf, lf;
  1449. -{
  1450. -       register  long  res = mf->ef_tbase;
  1451. -       long    lim = mf->ef_tbase + mf->ef_tsize - lf->ef_tsize;
  1452. -       t_entry tent;
  1453. -       
  1454. -restart:
  1455. -       for  (;  res <= lim;  res += 2)  {
  1456. -               gette(mf, res, &tent);
  1457. -               if  (tent.t_match != 0)  {
  1458. -                       res += tent.t_match;
  1459. -                       goto  restart;
  1460. -               }
  1461. -               if  (matchup(mf, lf, res))
  1462. -                       return  res;
  1463. -       }
  1464. -       return  -1;
  1465. -}
  1466. -
  1467. -/*
  1468. - *     Mark the head of a matched module to save searching.
  1469. - */
  1470. -
  1471. -void   markmatch(mf, lf, pos)
  1472. -ef_fid mf, lf;
  1473. -long   pos;
  1474. -{
  1475. -       t_entry tent;
  1476. -       
  1477. -       gette(mf, pos, &tent);
  1478. -       tent.t_match = (unsigned) lf->ef_tsize;
  1479. -       putte(mf, pos, &tent);
  1480. -}
  1481. //GO.SYSIN DD heur.c
  1482. echo iset.c 1>&2
  1483. sed 's/.//' >iset.c <<'//GO.SYSIN DD iset.c'
  1484. -/*
  1485. - *     SCCS:   @(#)iset.c      1.2     11/2/84 14:18:23
  1486. - *     Decode instructions.
  1487. - *
  1488. - ***********************************************************************
  1489. - *     This software is copyright of
  1490. - *
  1491. - *             John M Collins
  1492. - *             47 Cedarwood Drive
  1493. - *             St Albans
  1494. - *             Herts, AL4 0DN
  1495. - *             England                 +44 727 57267
  1496. - *
  1497. - *     and is released into the public domain on the following conditions:
  1498. - *
  1499. - *             1.  No free maintenance will be guaranteed.
  1500. - *             2.  Nothing may be based on this software without
  1501. - *                 acknowledgement, including incorporation of this
  1502. - *                 notice.
  1503. - *
  1504. - *     Notwithstanding the above, the author welcomes correspondence and bug
  1505. - *     fixes.
  1506. - ***********************************************************************
  1507. - */
  1508. -
  1509. -#include <stdio.h>
  1510. -#include <a.out.h>
  1511. -#include "unc.h"
  1512. -
  1513. -ef_fids       mainfile;
  1514. -long   endt;
  1515. -
  1516. -void   gette(), putte();
  1517. -void   mkdref();
  1518. -long   gettw();
  1519. -symbol textlab();
  1520. -
  1521. -int    l1(), l2(), el1(), lea(), lmove(), lcbch(), jj();
  1522. -int    limed(), lsbit(), lmvml(), lone(), loone(), lonew(), lonel();
  1523. -
  1524. -int    pmove(), pcbch(), pdbcc(), pscc(), pcs(), pmovc(), pstop(), pexg();
  1525. -int    pimed(), pmovp(), psbit(), pdbit(), pcs2(), pone(), ppea();
  1526. -int    plea(), pdreg(), pmvml(), ptrap(), plink(), pareg(), podreg();
  1527. -int    pqu(), pmqu(), ptreg(), pcmpm(), pomode(), pmshf(), pshf();
  1528. -
  1529. -struct opstr   {
  1530. -       unsigned  short  mask;
  1531. -       unsigned  short  match;
  1532. -       int     (*opsize)();
  1533. -       int     (*opprin)();
  1534. -       char    *prarg;
  1535. -} optab[] = {
  1536. -       0xf000, 0x2000, lmove, pmove, "l",
  1537. -       0xf000, 0x3000, lmove, pmove, "w",
  1538. -       0xf000, 0x1000, lmove, pmove, "b",
  1539. -       0xf000, 0x6000, lcbch, pcbch, 0,
  1540. -       0xffbf, 0x003c, l2,    pcs,   "or",
  1541. -       0xff00, 0x0000, limed, pimed, "or",
  1542. -       0xffbf, 0x023c, l2,    pcs,   "and",
  1543. -       0xff00, 0x0200, limed, pimed, "and",
  1544. -       0xff00, 0x0400, limed, pimed, "sub",
  1545. -       0xff00, 0x0600, limed, pimed, "add",
  1546. -       0xffbf, 0x0a3c, l2,    pcs,   "eor",
  1547. -       0xff00, 0x0a00, limed, pimed, "eor",
  1548. -       0xff00, 0x0c00, limed, pimed, "cmp",
  1549. -       0xf138, 0x0108, l2,    pmovp, 0,
  1550. -       0xff00, 0x0800, lsbit, psbit, 0,
  1551. -       0xf100, 0x0100, lonew, pdbit, 0,
  1552. -       0xffc0, 0x40c0, lonew, pcs2,  "sr",
  1553. -       0xff00, 0x4000, lone,  pone,  "negx",
  1554. -       0xff00, 0x4200, lone,  pone,  "clr",
  1555. -       0xffc0, 0x44c0, lonew, pcs2,  "cc",
  1556. -       0xff00, 0x4400, lone,  pone,  "neg",
  1557. -       0xffc0, 0x46c0, lonew, pcs2,  "sr",
  1558. -       0xff00, 0x4600, lone,  pone,  "not",
  1559. -       0xffc0, 0x4800, lonew, ppea,  "nbcd",
  1560. -       0xfff8, 0x4840, l1,    pdreg, "swap",
  1561. -       0xffc0, 0x4840, lonel, ppea,  "pea",
  1562. -       0xfff8, 0x4880, l1,    pdreg, "extw",
  1563. -       0xfff8, 0x48c0, l1,    pdreg, "extl",
  1564. -       0xfb80, 0x4880, lmvml, pmvml, 0,
  1565. -       0ffc0, 0x4ac0, lonew, ppea,  "tas",
  1566. -       0xff00, 0x4a00, lone,  pone,  "tst",
  1567. -       0xfff0, 0x4e40, l1,    ptrap, 0,
  1568. -       0xfff8, 0x4e50, l2,    plink, 0,
  1569. -       0xfff8, 0x4e58, l1,    pareg, "unlk\t%s",
  1570. -       0xfff8, 0x4e60, l1,    pareg, "movl\t%s,usp",
  1571. -       0xfff8, 0x4e68, l1,    pareg, "movl\tusp,%s",
  1572. -       0xffff, 0x4e70, l1,    pareg, "reset",
  1573. -       0xffff, 0x4e71, l1,    pareg, "nop",
  1574. -       0xffff, 0x4e72, l2,    pstop, 0,
  1575. -       0xffff, 0x4e73, el1,   pareg, "rte",
  1576. -       0xffff, 0x4e75, el1,   pareg, "rts",
  1577. -       0xffff, 0x4e76, l1,    pareg, "trapv",
  1578. -       0xffff, 0x4e77, el1,   pareg, "rtr",
  1579. -       0xfffe, 0x4e7a, l2,    pmovc, 0,
  1580. -       0xffc0, 0x4e80, jj,    ppea,  "jsr",
  1581. -       0xffc0, 0x4ec0, jj,    ppea,  "jmp",
  1582. -       0xf1c0, 0x4180, lonew, podreg,"chk",
  1583. -       0xf1c0, 0x41c0, lonel, plea,  0,
  1584. -       0xf0f8, 0x50c8, lcbch, pdbcc, 0,
  1585. -       0xf0c0, 0x50c0, lonew, pscc,  0,
  1586. -       0xf100, 0x5000, lone,  pqu,   "add",
  1587. -       0xf100, 0x5100, lone,  pqu,   "sub",
  1588. -       0xf100, 0x7000, l1,    pmqu,  0,
  1589. -       0xf1c0, 0x80c0, lonew, podreg,"divu",
  1590. -       0xf1c0, 0x81c0, lonew, podreg,"divs",
  1591. -       0xf1f0, 0x8100, l1,    ptreg, "sbcd",
  1592. -       0xf000, 0x8000, loone, pomode,"or",
  1593. -       0xf1f0, 0x9100, l1,    ptreg, "subxb",
  1594. -       0xf1f0, 0x9140, l1,    ptreg, "subxw",
  1595. -       0xf1f0, 0x9180, l1,    ptreg, "subxl",
  1596. -       0xf000, 0x9000, loone, pomode,"sub",
  1597. -       0xf1f8, 0xb108, l1,    pcmpm, "cmpmb",
  1598. -       0xf1f8, 0xb148, l1,    pcmpm, "cmpmw",
  1599. -       0xf1f8, 0xb188, l1,    pcmpm, "cmpml",
  1600. -       0xf100, 0xb000, loone, pomode,"cmp",
  1601. -       0xf1c0, 0xb1c0, loone, pomode,"cmp",
  1602. -       0xf100, 0xb100, loone, pomode,"eor",
  1603. -       0xf1c0, 0xc0c0, lonew, podreg,"mulu",
  1604. -       0xf1c0, 0xc1c0, lonew, podreg,"muls",
  1605. -       0xf1f0, 0xc100, l1,    ptreg, "abcd",
  1606. -       0xf130, 0xc100, l1,    pexg,  0,
  1607. -       0xf000, 0xc000, loone, pomode,"and",
  1608. -       0xf1f0, 0xd100, l1,    ptreg, "addxb",
  1609. -       0xf1f0, 0xd140, 1,    ptreg, "addxw",
  1610. -       0xf1f0, 0xd180, l1,    ptreg, "addxl",
  1611. -       0xf000, 0xd000, loone, pomode,"add",
  1612. -       0xf8c0, 0xe0c0, lonew, pmshf,  0,
  1613. -       0xf000, 0xe000, l1,    pshf,   0,
  1614. -       0
  1615. -};
  1616. -
  1617. -char   *areg[] = { "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp"};
  1618. -char   *cclist[] = { "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs",
  1619. -                       "pl", "mi", "ge", "lt", "gt", "le"};
  1620. -       
  1621. -char   *shtype[] = { "as", "ls", "rox", "ro" };
  1622. -char   *bittyp[] = { "tst", "chg", "clr", "set" };
  1623. -
  1624. -char   *creg[] = { "sfc", "dfc", "usp", "vbr" };
  1625. -
  1626. -/*
  1627. - *     Length functions.
  1628. - */
  1629. -
  1630. -int    l1()
  1631. -{
  1632. -       return  1;
  1633. -}
  1634. -
  1635. -int    l2()
  1636. -{
  1637. -       return  2;
  1638. -}
  1639. -
  1640. -int    el1(te)
  1641. -t_entry        *te;
  1642. -{
  1643. -       te->t_bchtyp = T_UNBR;
  1644. -       return  1;
  1645. -}
  1646. -
  1647. -int    lea(instr, size, pos)
  1648. -unsigned  instr, size;
  1649. -long   pos;
  1650. -{
  1651. -       switch  ((instr >> 3) & 0x7)  {
  1652. -       case  0:
  1653. -       case  1:
  1654. -       case  2:
  1655. -       case  3:
  1656. -       case  4:
  1657. -               return  1;
  1658. -       case  5:
  1659. -       case  6:
  1660. -               return  2;
  1661. -       default:
  1662. -               switch  (instr & 0x7)  {
  1663. -               case  0:
  1664. -               case  2:
  1665. -               case  3:
  1666. -                       return  2;
  1667. -               case  1:
  1668. -                       mkdref(pos, size);
  1669. -                       return  3;
  1670. -               case  4:
  1671. -                       if  (size > 2)
  1672. -                               return  3;
  1673. -                       return  2;
  1674. -               default:
  1675. -                       return  0;
  1676. -               }
  1677. -       }
  1678. -}
  1679. -
  1680. -/*
  1681. - *     Lengths of move instructions.
  1682. - */
  1683. -
  1684. -int    lmove(te, pos)
  1685. -t_entry        *te;
  1686. -long   pos;
  1687. -{
  1688. -       register  unsigned  tc  =  te->t_contents;
  1689. -       unsigned  sz  =  1;
  1690. -       int     lng, lng2;
  1691. -       
  1692. -       lng  = tc & 0xf000;
  1693. -       if  (lng == 0x3000)
  1694. -               sz = 2;
  1695. -       else  if  (lng == 0x2000)
  1696. -               sz = 4;
  1697. -       
  1698. -       i  ((lng = lea(tc, sz, pos+2)) <= 0)
  1699. -               return  0;
  1700. -       lng2 = lea(((tc>>3) & 0x38) | ((tc>>9) & 0x7), sz, pos+lng+lng);
  1701. -       if  (lng2 <= 0)
  1702. -               return  0;
  1703. -       return  lng + lng2 - 1;
  1704. -}
  1705. -
  1706. -/*
  1707. - *     Lengths for conditional branches and dbcc instructions.
  1708. - */
  1709. -
  1710. -int    lcbch(te, pos)
  1711. -t_entry        *te;
  1712. -long   pos;
  1713. -{
  1714. -       unsigned  tc  =  te->t_contents;
  1715. -       long    dest  =  pos + 2;
  1716. -       int     res   =  2;
  1717. -       
  1718. -       if  ((tc & 0xf000) == 0x5000  ||  (tc & 0xff) == 0)
  1719. -               dest += (short)gettw(&mainfile, pos+2, R_WORD);
  1720. -       else  {
  1721. -               dest += (char) tc;
  1722. -               res = 1;
  1723. -       }
  1724. -       if  ((tc & 0xff00) == 0x6000)
  1725. -               te->t_bchtyp = T_UNBR;
  1726. -       else  if  ((tc & 0xff00) == 0x6100)
  1727. -               te->t_bchtyp = T_JSR;
  1728. -       else
  1729. -               te->t_bchtyp = T_CONDBR;
  1730. -
  1731. -       te->t_relsymb = textlab(dest, pos);
  1732. -       return  res;
  1733. -}
  1734. -
  1735. -int    jj(te, pos)
  1736. -t_entry        *te;
  1737. -long   pos;
  1738. -{
  1739. -       unsigned  tc  =  te->t_contents;
  1740. -       t_entry nextl;
  1741. -       
  1742. -       te->t_bchtyp = (tc & 0x40)? T_UNBR: T_JSR;
  1743. -       if  ((tc & 0x3f) == 0x39)  {
  1744. -               gette(&mainfile, pos+2, &nextl);
  1745. -               if  (nextl.t_relsymb == NULL)  {
  1746. -                       nextl.t_relsymb = textlab(gettw(&mainfile, pos+2, R_LONG), pos);
  1747. -                       putte(&mainfile, pos+2, &nextl);
  1748. -               }
  1749. -               te->t_relsymb = nextl.t_relsymb;        /*  Easy ref  */
  1750. -       }
  1751. -       return  lea(tc, 4, pos+2);
  1752. -}
  1753. -
  1754. -int    limed(te, pos)
  1755. -t_entry        *te;
  1756. -long   pos;
  1757. -{
  1758. -       unsigned  tc  =  te->t_contents;
  1759. -       int     lng;
  1760. -       
  1761. -       /*
  1762. -        *      Specifically exclude byte address register operands,
  1763. -        *      and ones which have lengths of 3.
  1764. -        */
  1765. -
  1766. -       if  ((tc & 0xf8) == 0x08)
  1767. -               return  0;
  1768. -       
  1769. -       if  ((tc & 0xc0) >= 0x80)  {
  1770. -               if  (tc &0x40)
  1771. -                       return  0;
  1772. -               lng = lea(tc, 4, pos+6);
  1773. -               if  (lng > 0)
  1774. -                       lng += 2;
  1775. -       }
  1776. -       else  {
  1777. -               lng = lea(tc, (unsigned)((tc & 0xc0)?2:1), pos+4);
  1778. -               if  (lng > 0)
  1779. -                       lng++;
  1780. -       }
  1781. -       return  lng;
  1782. -}
  1783. -
  1784. -int    lsbit(te, pos)
  1785. -t_entry        *te;
  1786. -long   pos;
  1787. -{
  1788. -       int     lng = lea(te->t_contents, 1, pos+4);
  1789. -       
  1790. -       if  (lng > 0)
  1791. -               lng++;
  1792. -       return  lng;
  1793. -}
  1794. -
  1795. -int    lmvml(te, pos)
  1796. -t_entry        *te;
  1797. -long   pos;
  1798. -{
  1799. -       int     lng = lea(te->t_contents,
  1800. -                       (unsigned)(te->t_contents&0x40? 4:2), pos+4);
  1801. -       
  1802. -       if  (lng > 0)
  1803. -               lng++;
  1804. -       return  lng;
  1805. -}
  1806. -
  1807. -/*
  1808. - *     Length depends on bits 6 and 7 of instruction.
  1809. - */
  1810. -
  1811. -int    lone(te, pos)
  1812. -t_entry        *te;
  1813. -long   pos;
  1814. -{
  1815. -       unsigned  tc  =  te->t_contents;
  1816. -       
  1817. -       return  lea(tc, 1 << ((tc >> 6) & 3), pos+2);
  1818. -}
  1819. -
  1820. -/*
  1821. - *     Length depends on bits 6-8 of instruction.
  1822. - */
  1823. -
  1824. -int    loone(te, pos)
  1825. -t_entry        *te;
  1826. -long   pos;
  1827. -{
  1828. -       unsigned  tc  =  te->t_contents;
  1829. -       
  1830. -       switch  ((tc >> 6) & 7)  {
  1831. -       case  0:
  1832. -       case  4:
  1833. -               return  lea(tc, 1, pos+2);
  1834. -       case  1:
  1835. -       case  3:
  1836. -       case  5:
  1837. -               return  lea(tc, 2, pos+2);
  1838. -       case  2:
  1839. -       case  6:
  1840. -       case  7:
  1841. -               return  lea(tc, 4, pos+2);
  1842. -       }
  1843. -       /*NOTREACHED*/
  1844. -}
  1845. -
  1846. -int    lonew(te, pos)
  1847. -t_entry        *te;
  1848. -long   pos;
  1849. -{
  1850. -       return  lea(te->t_contents, 2, pos+2);
  1851. -}
  1852. -
  1853. -int    lonel(te, pos)
  1854. -t_entry        *te;
  1855. -long   pos;
  1856. -{
  1857. -       return  lea(te->t_contents, 4, pos+2);
  1858. -}
  1859. -
  1860. -/*
  1861. - *     Print routines.
  1862. - */
  1863. -
  1864. -int    findleng(tc)
  1865. -unsigned  tc;
  1866. -{
  1867. -       switch  ((tc >> 6) & 3)  {
  1868. -       case  0:
  1869. -               return  'b';
  1870. -       case  1:
  1871. -               return  'w;
  1872. -       default:
  1873. -               return  'l';
  1874. -       }
  1875. -}
  1876. -
  1877. -void   piword(disp)
  1878. -unsigned  disp;
  1879. -{
  1880. -       int     szc;
  1881. -       
  1882. -       (void) printf("@(0x%x,", disp & 0xff);
  1883. -       if  (disp & 0x8000)
  1884. -               (void) printf("%s", areg[(disp >> 12) & 0x7]);
  1885. -       else
  1886. -               (void) printf("d%d", (disp >> 12) & 0x7);
  1887. -       szc = 'w';
  1888. -       if  (disp & (1 << 10))
  1889. -               szc = 'l';
  1890. -       (void) printf(":%c)", szc);
  1891. -}
  1892. -
  1893. -void   paddr(pos)
  1894. -long   pos;
  1895. -{
  1896. -       t_entry tent;
  1897. -       symbol  symb;
  1898. -       
  1899. -       gette(&mainfile, pos, &tent);
  1900. -       if  (tent.t_relsymb != NULL)  {
  1901. -               symb = tent.t_relsymb;
  1902. -               if  (symb->s_lsymb != 0)
  1903. -                       (void) printf("%u$", symb->s_lsymb);
  1904. -               else
  1905. -                       (void) printf("%s", symb->s_name);
  1906. -               if  (tent.t_reldisp != 0)
  1907. -                       (void) printf("+0x%x", tent.t_reldisp);
  1908. -               return;
  1909. -       }
  1910. -       (void) printf("0x%x", gettw(&mainfile, pos, R_LONG));
  1911. -}
  1912. -
  1913. -int    prea(ea, pos, sz)
  1914. -unsigned  ea, sz;
  1915. -long   pos;                    /*  Address of previous word to extn  */
  1916. -{
  1917. -       unsigned  reg  =  ea & 0x7;
  1918. -       long    disp;
  1919. -       
  1920. -       pos += 2;
  1921. -       
  1922. -       switch  ((ea >> 3) & 0x7)  {
  1923. -       case  0:
  1924. -               (void) printf("d%d", reg);
  1925. -               return  0;
  1926. -       case  1:
  1927. -               (void) printf("%s", areg[reg]);
  1928. -               return  0;
  1929. -       case  2:
  1930. -               (void) printf("%s@", areg[reg]);
  1931. -               return  0;
  1932. -       case  3:
  1933. -               (void) printf("%s@+", areg[reg]);
  1934. -               return  0;
  1935. -       case  4:
  1936. -               (void) printf("%s@-", areg[reg]);
  1937. -               return  0;
  1938. -       case  5:
  1939. -               disp = gettw(&mainfile, pos, R_WORD);
  1940. -               (void) printf("%s@(0x%x)", areg[reg], disp);
  1941. -               return  2;
  1942. -       case  6:
  1943. -               (void) printf("%s, areg[reg]);
  1944. -               piword((unsigned) gettw(&mainfile, pos, R_WORD));
  1945. -               return  2;
  1946. -       default:
  1947. -               switch  (reg)  {
  1948. -               case  0:
  1949. -                       disp = gettw(&mainfile, pos, R_WORD);
  1950. -                       (void) printf("0x%x:w", disp);
  1951. -                       return  2;
  1952. -               case  1:
  1953. -                       paddr(pos);
  1954. -                       return  4;
  1955. -               case  2:
  1956. -                       disp = gettw(&mainfile, pos, R_WORD);
  1957. -                       (void) printf("pc@(0x%x)", disp);
  1958. -                       return  2;
  1959. -               case  3:
  1960. -                       (void) printf("pc");
  1961. -                       piword((unsigned) gettw(&mainfile, pos, R_WORD));
  1962. -                       return  2;
  1963. -               case  4:
  1964. -                       (void) printf("#");
  1965. -                       if  (sz < 4)
  1966. -                               (void) printf("0x%x", gettw(&mainfile, pos, R_WORD));
  1967. -                       else
  1968. -                               paddr(pos);
  1969. -                       return  sz;
  1970. -               default:
  1971. -                       (void) fprintf(stderr, "Funny mode\n");
  1972. -                       exit(220);
  1973. -               }
  1974. -       }
  1975. -       /*NOTREACHED*/
  1976. -}
  1977. -       
  1978. -int    pmove(te, pos)
  1979. -t_entry        *te;
  1980. -long   pos;
  1981. -{
  1982. -       unsigned  sz  =  2;
  1983. -       unsigned  tc  =  te->t_contents;
  1984. -       
  1985. -       (void) printf("mov%s\t", optab[te->t_iindex].prarg);
  1986. -       
  1987. -       if  ((tc & 0xf000) == 0x2000)
  1988. -               sz = 4;
  1989. -       
  1990. -       pos += prea(tc, pos, sz);
  1991. -       putchar(',');
  1992. -       (void) prea(((tc >> 9) & 0x7) | ((tc >> 3) & 0x38), pos, sz);
  1993. -}
  1994. -
  1995. -int    pcbch(te)
  1996. -t_entry        *te;
  1997. -{
  1998. -       int     cc = ((te->t_contents >> 8) & 0xf) - 2;
  1999. -       char    *msg;
  2000. -       register  symbol  ts;
  2001. -       
  2002. -       if  (cc < 0)
  2003. -               msg = cc < -1? "ra": "sr";
  2004. -       else
  2005. -               msg = cclist[cc];
  2006. -       (void) printf("b%s",msg);
  2007. -       if  (te->t_lng < 2)
  2008. -               (void) printf("s");
  2009. -       ts = te->t_relsymb;
  2010. -       if  (ts->s_lsymb != 0)
  2011. -               (void) printf("\t%u$", ts->s_lsymb);
  2012. -       else
  2013. -               (void) printf("\t%s", ts->s_name);
  2014. -}
  2015. -
  2016. -int    pdbcc(te)
  2017. -t_entry        *te;
  2018. -{
  2019. -       unsigned  tc  =  te->t_contents;
  2020. -       int     cc = ((tc >> 8) & 0xf) - 2;
  2021. -       char    *msg;
  2022. -       register  symbol  ts;
  2023. -       
  2024. -       if  (cc < 0)
  2025. -               msg = cc < -1? "t": "f";
  2026. -       else
  2027. -               msg = cclist[cc];
  2028. -       ts = te->t_relsymb;
  2029. -       (void) printf("db%s\td%d,", msg, tc & 0x7);
  2030. -       if  (ts->s_lsymb)
  2031. -               (void) printf("%u$", ts->s_lsymb);
  2032. -       else
  2033. -               (void) printf("%s", ts->s_name);
  2034. -}
  2035. -
  2036. -int    pscc(te, pos)
  2037. -t_entry        *te;
  2038. -long   pos;
  2039. -{
  2040. -       unsigned  tc  =  te->t_contents;
  2041. -       int     cc = ((tc >> 8) & 0xf) - 2;
  2042. -       char    *msg;
  2043. -       
  2044. -       if  (cc < 0)
  2045. -               msg = cc < -1? "t": "f";
  2046. -       else
  2047. -               msg = cclist[cc];
  2048. -       (void) printf("s%s\t", msg);
  2049. -       (void) prea(tc, pos, 1);
  2050. -}
  2051. -
  2052. -int    pcs(te, pos)
  2053. -t_entry        *te;
  2054. -long   pos;
  2055. -{
  2056. -       long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  2057. -       
  2058. -       (void) printf("%s", optab[te->t_iindex].prarg);
  2059. -       if  ((te->t_contents & 0xc0) == 0)
  2060. -               (void) printf("b\t#0x%x,cc", disp);
  2061. -       else
  2062. -               (void) printf("w\t#0x%x,sr", disp);
  2063. -}
  2064. -
  2065. -int    pmovc(te, pos)
  2066. -t_entry        *te;
  2067. -long   pos;
  2068. -{
  2069. -       int     disp = gettw(&mainfile, pos+2, R_WORD);
  2070. -       int     ctrl = ((disp >> 10) & 2) | (disp & 1);
  2071. -
  2072. -       (void) printf("movec\t");
  2073. -       if  ((te->t_contents & 1) == 0)
  2074. -               (void) printf("%s,", creg[ctrl]);
  2075. -       if  (disp & 0x8000)
  2076. -               (void) printf("%s", areg[(disp >> 12) & 7]);
  2077. -       else
  2078. -               (void) printf("d%d", disp >> 12);
  2079. -       if  (te->t_contents & 1)
  2080. -              (void) printf(",%s", creg[ctrl]);
  2081. -}
  2082. -
  2083. -int    pimed(te, pos)
  2084. -t_entry        *te;
  2085. -long   pos;
  2086. -{
  2087. -       int     sz = findleng(te->t_contents);
  2088. -       
  2089. -       (void) printf("%s%c\t#", optab[te->t_iindex].prarg, sz);
  2090. -       if  (sz == 'l')  {
  2091. -               paddr(pos+2);
  2092. -               putchar(',');
  2093. -               (void) prea(te->t_contents, pos+4, 4);
  2094. -       }
  2095. -       else  {
  2096. -               (void) printf("0x%x,", gettw(&mainfile, pos+2, R_WORD));
  2097. -               (void) prea(te->t_contents, pos+2, 2);
  2098. -       }
  2099. -}
  2100. -
  2101. -int    pmovp(te, pos)
  2102. -t_entry        *te;
  2103. -long   pos;
  2104. -{
  2105. -       unsigned  tc  =  te->t_contents;
  2106. -       long    disp  =  gettw(&mainfile, pos+2, R_WORD);
  2107. -       int     dreg = tc >> 9;
  2108. -       char    *ar = areg[tc & 0x7];
  2109. -       
  2110. -       (void) printf("movep");
  2111. -       if  (tc & (1 << 6))
  2112. -               putchar('l');
  2113. -       else
  2114. -               putchar('w');
  2115. -
  2116. -       if  (tc & (1 << 7))
  2117. -               (void) printf("\td%d,%s@(0x%x)", dreg, ar, disp);
  2118. -       else
  2119. -               (void) printf("\t%s@(0x%x),d%d", ar, disp, dreg);
  2120. -}
  2121. -
  2122. -int    psbit(te, pos)
  2123. -t_entry        *te;
  2124. -long   pos;
  2125. -{
  2126. -       unsigned  tc  =  te->t_contents;
  2127. -       
  2128. -       (void) printf("b%s\t#%d,", bittyp[(tc >> 6) & 0x3], gettw(&mainfile, pos+2, R_WORD));
  2129. -       (void) prea(tc, pos+2, 1);
  2130. -}
  2131. -
  2132. -/*ARGSUSED*/
  2133. -int    pstop(te, pos)
  2134. -t_entry        *te;
  2135. -long   pos;
  2136. -{
  2137. -       (void) printf("stop\t#0x%x", gettw(&mainfile, pos+2, R_WORD));
  2138. -}
  2139. -
  2140. -int    pdbit(te, pos)
  2141. -t_entry        *te;
  2142. -long   pos;
  2143. -{
  2144. -       unsigned  tc  =  te->t_contents;
  2145. -       
  2146. -       (void) printf("b%s\td%d,", bittyp[(tc >> 6) & 0x3], (tc >> 9) & 0x7);
  2147. -       (void) prea(tc, pos, 1);
  2148. -}
  2149. -
  2150. -int    pcs2(te, pos)
  2151. -t_entry        *te;
  2152. -long   pos;
  2153. -{
  2154. -       unsigned  tc  =  te->t_contents;
  2155. -       
  2156. -       (void) printf("movw\t");
  2157. -       if  ((tc & 0xffc0) == 0x40c0)  {
  2158. -               (void) printf("sr,");
  2159. -               (void) prea(tc, pos, 2);
  2160. -      }
  2161. -       else  {
  2162. -               (void) prea(tc, pos, 2);
  2163. -               (void) printf(",%s", optab[te->t_iindex].prarg);
  2164. -       }
  2165. -}
  2166. -
  2167. -int    pone(te, pos)
  2168. -t_entry        *te;
  2169. -long   pos;
  2170. -{
  2171. -       unsigned  tc  =  te->t_contents;
  2172. -       int     sz = findleng(tc);
  2173. -       
  2174. -       (void) printf("%s%c\t", optab[te->t_iindex].prarg, sz);
  2175. -       (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  2176. -}
  2177. -
  2178. -int    ppea(te, pos)   /*  nbcd, pea, tas, jmp, jsr  */
  2179. -t_entry        *te;
  2180. -long   pos;
  2181. -{
  2182. -       (void) printf("%s\t", optab[te->t_iindex].prarg);
  2183. -       (void) prea(te->t_contents, pos, (unsigned)(te->t_lng > 2? 4: 2));
  2184. -}
  2185. -
  2186. -
  2187. -int    plea(te, pos)
  2188. -t_entry        *te;
  2189. -long   pos;
  2190. -{
  2191. -       (void) printf("lea\t");
  2192. -       (void) prea(te->t_contents, pos, 4);
  2193. -       (void) printf(",%s", areg[(te->t_contents >> 9) & 0x7]);
  2194. -}
  2195. -
  2196. -int    pdreg(te)
  2197. -t_entry        *te;
  2198. -{
  2199. -       (void) printf("%s\td%d", optab[te->t_iindex].prarg, te->t_contents & 7);-}
  2200. -
  2201. -
  2202. -int    pmvml(te, pos)
  2203. -t_entry        *te;
  2204. -long   pos;
  2205. -{
  2206. -       unsigned  tc  =  te->t_contents;
  2207. -       register  unsigned  dw  =  gettw(&mainfile, pos+2, R_WORD);
  2208. -       unsigned  sz = 4;
  2209. -       int     sc = 'l';
  2210. -       register  int   i;
  2211. -       register  unsigned  bit;
  2212. -       
  2213. -       (void) printf("movem");
  2214. -       if  ((tc & 0x40) == 0)  {
  2215. -               sc = 'w';
  2216. -               sz = 2;
  2217. -       }
  2218. -       
  2219. -       (void) printf("%c\t", sc);
  2220. -       
  2221. -       if  (tc & 0x400)  {
  2222. -               (void) prea(tc, pos+2, sz);
  2223. -               (void) printf(",#0x%x", dw);
  2224. -       }
  2225. -       else  {
  2226. -               (void) printf("#0x%x,", dw);
  2227. -               (void) prea(tc, pos+2, sz);
  2228. -       }
  2229. -       
  2230. -       (void) printf("\t|");
  2231. -       
  2232. -       if  ((tc & 0x38) == 0x20)  {
  2233. -               bit = 0x8000;
  2234. -               for  (i = 0;  i < 8;  i++)  {
  2235. -                       if  (dw & bit)
  2236. -                               (void) printf(" d%d", i);
  2237. -                      bit >>= 1;
  2238. -               }
  2239. -               for  (i = 0;  i < 8;  i++)  {
  2240. -                       if  (dw & bit)
  2241. -                               (void) printf(" %s", areg[i]);
  2242. -                       bit >>= 1;
  2243. -               }
  2244. -       }
  2245. -       else  {
  2246. -               bit = 1;
  2247. -               for  (i = 0;  i < 8;  i++)  {
  2248. -                       if  (dw & bit)
  2249. -                               (void) printf(" d%d", i);
  2250. -                       bit <<= 1;
  2251. -               }
  2252. -               for  (i = 0;  i < 8;  i++)  {
  2253. -                       if  (dw & bit)
  2254. -                               (void) printf(" %s", areg[i]);
  2255. -                       bit <<= 1;
  2256. -               }
  2257. -       }
  2258. -}
  2259. -
  2260. -int    ptrap(te)
  2261. -t_entry        *te;
  2262. -{
  2263. -       (void) printf("trap\t#0x%x", te->t_contents & 0xf);
  2264. -}
  2265. -
  2266. -int    plink(te, pos)
  2267. -t_entry        *te;
  2268. -long   pos;
  2269. -{
  2270. -       (void) printf("link\t%s,#0x%x", areg[te->t_contents & 0x7],
  2271. -                               gettw(&mainfile, pos+2, R_WORD));
  2272. -}
  2273. -
  2274. -
  2275. -int    pareg(te)
  2276. -t_entry        *te;
  2277. -{
  2278. -       (void) printf(optab[te->t_iindex].prarg, areg[te->t_contents & 0x7]);
  2279. -}
  2280. -
  2281. -int    podreg(te, pos)
  2282. -t_entry        *te;
  2283. -long   pos;
  2284. -{
  2285. -       unsigned  tc  =  te->t_contents;
  2286. -       
  2287. -       (void) printf("%s\t", optab[te->t_iindex].prarg);
  2288. -       (void) prea(tc, pos, 2);
  2289. -       (void) printf(",d%d", (tc >> 9) & 0x7);
  2290. -}
  2291. -
  2292. -int    pqu(te, pos)
  2293. -t_entry        *te;
  2294. -long   pos;
  2295. -{
  2296. -       unsigned  tc  =  te->t_contents;
  2297. -       int     sz  =  findleng(tc);
  2298. -       int     amt = (tc >> 9) & 0x7;
  2299. -       
  2300. -       if  (amt == 0)
  2301. -               amt = 8;
  2302. -       (void) printf("%sq%c\t#%d,", optab[te->t_iindex].prarg, sz, amt);
  2303. -       (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  2304. -}
  2305. -
  2306. -int    pmqu(te)
  2307. -t_entry        *te;
  2308. -{
  2309. -       unsigned  tc  =  te->t_contents;
  2310. -
  2311. -       (void) printf("moveq\t#0x%x,d%d", (char)tc, (tc >> 9) & 0x7);
  2312. -}
  2313. -
  2314. -int    ptreg(te)
  2315. -t_entry        *te;
  2316. -{
  2317. -       regster  unsigned  tc  =  te->t_contents;
  2318. -       int     rx = (tc >> 9) & 0x7;
  2319. -       int     ry = tc & 0x7;
  2320. -
  2321. -       (void) printf("%s\t", optab[te->t_iindex].prarg);
  2322. -       if  (tc & 0x8)
  2323. -               (void) printf("%s@-,%s@-", areg[ry], areg[rx]);
  2324. -       else
  2325. -               (void) printf("d%d,d%d", ry, rx);
  2326. -}
  2327. -
  2328. -int    pcmpm(te)
  2329. -t_entry        *te;
  2330. -{
  2331. -       register  unsigned  tc  =  te->t_contents;
  2332. -
  2333. -       (void) printf("%s\t%s@+,%s@+", optab[te->t_iindex].prarg,
  2334. -               areg[tc & 7], areg[(tc >> 9) & 7]);
  2335. -}
  2336. -
  2337. -int    pomode(te, pos)
  2338. -t_entry        *te;
  2339. -long   pos;
  2340. -{
  2341. -       unsigned  tc  =  te->t_contents;
  2342. -       char    bef[4], aft[4];
  2343. -       int     sz;
  2344. -       int     reg = (tc >> 9) & 7;
  2345. -
  2346. -       bef[0] = aft[0] = '\0';
  2347. -       
  2348. -       switch  ((tc >> 6) & 7)  {
  2349. -       case  0:
  2350. -               sz = 'b';
  2351. -               goto  toreg;
  2352. -       case  1:
  2353. -               sz = 'w';
  2354. -               goto  toreg;
  2355. -       case  2:
  2356. -               sz = 'l';
  2357. -       toreg:
  2358. -               (void) sprintf(aft, ",d%d", reg);
  2359. -               break;
  2360. -       case  3:
  2361. -               sz = 'w';
  2362. -               goto  toareg;
  2363. -       case  7:
  2364. -               sz = 'l';
  2365. -       toareg:
  2366. -               (void) sprintf(aft, ",%s", areg[reg]);
  2367. -               break;
  2368. -       case  4:
  2369. -               sz = 'b';
  2370. -               goto  frreg;
  2371. -       case  5:
  2372. -               sz = 'w';
  2373. -               goto  frreg;
  2374. -       case  6:
  2375. -               sz = 'l';
  2376. -       frreg:
  2377. -               (void) sprintf(bef, "d%d,", reg);
  2378. -               break;
  2379. -       }
  2380. -
  2381. -       (void) printf("%s%c\t%s", optab[te->t_iindex].prarg, sz, bef);
  2382. -       (void) prea(tc, pos, (unsigned)(sz == 'l'? 4: 2));
  2383. -       (void) printf(aft);
  2384. -}
  2385. -
  2386. -int    pexg(te)
  2387. -t_entry        *te;
  2388. -{
  2389. -       unsigned  tc  =  te->t_contents;
  2390. -       int     r1 = (tc >> 9) & 7, r2 = tc & 7;
  2391. -
  2392. -       (void) printf("exg\t");
  2393. -       
  2394. -       if  ((tc & 0x00f8) == 0x0048)
  2395. -              (void) printf("%s,", areg[r1]);
  2396. -       else
  2397. -               (void) printf("d%d,", r1);
  2398. -       if  (tc & 0x8)
  2399. -               (void) printf("%s", areg[r2]);
  2400. -       else
  2401. -               (void) printf("d%d", r2);
  2402. -}
  2403. -       
  2404. -int    pmshf(te, pos)
  2405. -t_entry        *te;
  2406. -long   pos;
  2407. -{
  2408. -       unsigned  tc  =  te->t_contents;
  2409. -       
  2410. -       (void) printf("%s%cw\t", shtype[(tc >> 9) & 3], tc & 0x100? 'l': 'r');
  2411. -       (void) prea(tc, pos, 2);
  2412. -}
  2413. -
  2414. -int    pshf(te)
  2415. -t_entry        *te;
  2416. -{
  2417. -       unsigned  tc  =  te->t_contents;
  2418. -       int     sz  =  findleng(tc);
  2419. -       int     disp = (tc >> 9) & 7;
  2420. -
  2421. -       (void) printf("%s%c%c\t", shtype[(tc >> 3) & 3], tc & 0x100? 'l': 'r', sz);
  2422. -       if  (tc & 0x20)
  2423. -               (void) printf("d%d", disp);
  2424. -       else
  2425. -               (void) printf("#%d", disp == 0? 8: disp);
  2426. -       (void) printf(",d%d", tc & 7);
  2427. -}
  2428. -
  2429. -/*
  2430. - *     Find length etc of instruction.
  2431. - */
  2432. -
  2433. -int    findinst(te, pos)
  2434. -register  t_entry  *te;
  2435. -long   pos;
  2436. -{
  2437. -       register  struct  opstr *op;
  2438. -       unsigned  tc  =  te->t_contents;
  2439. -       int     lng = 0;
  2440. -       register  int   i;
  2441. -
  2442. -       te->t_type = T_BEGIN;
  2443. -       te->t_bchtyp = T_NOBR;
  2444. -       
  2445. -       for  (op = &optab[0];  op->mask;  op++)  {
  2446. -               if  ((tc & op->mask) == op->match)  {
  2447. -                       te->t_iindex = op - optab;
  2448. -                       lng = (op->opsize)(te, pos);
  2449. -                       break;
  2450. -               }
  2451. -       }
  2452. -
  2453. -       for  (i = 1;  i < lng;  i++)  {
  2454. -               t_entry ctent;
  2455. -               long    npos = pos+i+i;
  2456. -               
  2457. -               if  (npos >= endt)
  2458. -                       goto  clearem;
  2459. -               gette(&mainfile, npos, &ctent);
  2460. -               if  (ctent.t_bdest || ctent.t_dref)  {
  2461. -clearem:               for  (i--; i > 0; i--)  {
  2462. -                               npos = pos + i + i;
  2463. -                               gette(&mainfile, npos, &ctent);
  2464. -                               ctent._type = T_UNKNOWN;
  2465. -                               putte(&mainfile, npos, &ctent);
  2466. -                       }
  2467. -                       lng = 0;
  2468. -                       goto  ginv;
  2469. -               }
  2470. -               ctent.t_type = T_CONT;
  2471. -               putte(&mainfile, npos, &ctent);
  2472. -       }
  2473. -       
  2474. -       if  (lng <= 0)  {
  2475. -ginv:          te->t_vins = 0;
  2476. -               te->t_lng = 1;
  2477. -               te->t_type = T_UNKNOWN;
  2478. -               te->t_bchtype = T_NOBR;
  2479. -       }
  2480. -       else
  2481. -               te->t_lng = lng;
  2482. -       return  lng;
  2483. -}
  2484. -
  2485. -/*
  2486. - *     Print instruction.
  2487. - */
  2488. -
  2489. -void   prinst(te, pos)
  2490. -t_entry        *te;
  2491. -long   pos;
  2492. -{
  2493. -       putchar('\t');
  2494. -       (optab[te->t_iindex].opprin)(te, pos);
  2495. -       putchar('\n');
  2496. -}
  2497. //GO.SYSIN DD iset.c
  2498. echo libmtch.c 1>&2
  2499. sed 's/.//' >libmtch.c <<'//GO.SYSIN DD libmtch.c'
  2500. -/*
  2501. - *     SCCS:   @(#)libmtch.c   1.2     11/2/84 14:18:55
  2502. - *     Read library files.
  2503. - *
  2504. - ***********************************************************************
  2505. - *     This software is copyright of
  2506. - *
  2507. - *             John M Collins
  2508. - *             47 Cedarwood Drive
  2509. - *             St Albans
  2510. - *             Herts, AL4 0DN
  2511. - *             England                 +44 727 57267
  2512. - *
  2513. - *     and is released into the public domain on the following conditions:
  2514. - *
  2515. - *             1.  No free maintenance will be guaranteed.
  2516. - *             2.  Nothing may be based on this software without
  2517. - *                 acknowledgement, including incorporation of this
  2518. - *                 notice.
  2519. - *
  2520. - *     Notwithstanding the above, the author welcomes correspondence and bug
  2521. - *     fixes.
  2522. - ***********************************************************************
  2523. - */
  2524. -
  2525. -#include <stdio.h>
  2526. -#include <fcntl.h>
  2527. -#include <a.out.h>
  2528. -#include <ar.h>
  2529. -#include <setjmp.h>
  2530. -#include "unc.h"
  2531. -
  2532. -long   lseek();
  2533. -void   bfopen(), bfclose(), nomem();
  2534. -void   rrell2(), markmatch();
  2535. -char   *strchr(), *strrchr(), *strncpy(), *strcat(), *strcpy(, *malloc();
  2536. -int    matchup();
  2537. -long   findstart();
  2538. -
  2539. -char   verbose;                /*  Tell the world what we are doing  */
  2540. -char   *tfnam;
  2541. -char   *cfile;
  2542. -ef_fids        mainfile;
  2543. -struct commit  dreltab;
  2544. -int    donedrel, donebrel;
  2545. -long   trelpos, drelpos, brelpos;
  2546. -static struct  libit   currlib = {-1, 0, -1, ""};
  2547. -
  2548. -void   lclash(str)
  2549. -char   *str;
  2550. -{
  2551. -       (void) fprintf(stderr, "Library scan failure - %s\n", str);
  2552. -       (void) fprintf(stderr, "Searching %s\n", cfile);
  2553. -       if  (currlib.lf_name[0])
  2554. -               (void) fprintf(stderr, "Member is %s\n", currlib.lf_name);
  2555. -       exit(255);
  2556. -}
  2557. -
  2558. -/*
  2559. - *     Find next member.
  2560. - */
  2561. -
  2562. -long   nextmemb(lfd)
  2563. -register  struct  libit         *lfd;
  2564. -{
  2565. -       struct  ar_hdr  arbuf;
  2566. -       
  2567. -       if  (lfd->lf_next < 0)
  2568. -               return  -1;
  2569. -       
  2570. -       (void) lseek(lfd->lf_fd, lfd->lf_next, 0);
  2571. -       if  (read(lfd->lf_fd, (char *)&arbuf, sizeof(arbuf)) != sizeof(arbuf))  {
  2572. -               lfd->lf_next = -1;
  2573. -               return  -1;
  2574. -       }
  2575. -       (void) strncpy(lfd->lf_name, arbuf.ar_name, sizeof(lfd->lf_name));
  2576. -       lfd->lf_offset = lfd->lf_next + sizeof(arbuf);
  2577. -       lfd->lf_next = (lfd->lf_offset + arbuf.ar_size + 1) & ~1;
  2578. -       return  lfd->lf_offset;
  2579. -}
  2580. -
  2581. -/*
  2582. - *     Decode a file name thus -
  2583. - *
  2584. - *     -lxxx decode as /lib/libxxx.a /usr/lib/libxxx.a etc
  2585. - *     -Lxxx forget "lib" ".a" bit thus -Lcrt0.o
  2586. - *     or read LDPATH environment var to give list of directories as sh
  2587. - *     (default /lib:/usr/lib).
  2588. - *
  2589. - *     Alternatively treat as normal pathname.
  2590. - *
  2591. - *     File names may be followed by (membername) if the file is an archive,
  2592. - *     thus
  2593. - *
  2594. - *             -lc(printf.o)
  2595. - *
  2596. - *     in which case the specified module is fetched.
  2597. - */
  2598. -
  2599. -struct libit   *getfnam(str)
  2600. -char   *str;
  2601. -{
  2602. -       char    *bp, *ep = NULL, *pathb, *pathe, *fullpath = NULL;
  2603. -       static  char    *pathn;
  2604. -       extern  char    *getenv();
  2605. -       long    magic;-       struct  ar_hdr  arhdr;
  2606. -       int     fd;
  2607. -
  2608. -       if  ((bp = strrchr(str, '(')) != NULL &&
  2609. -                (ep = strrchr(str, ')')) != NULL)
  2610. -               *ep = *bp = '\0';
  2611. -
  2612. -       if  (str[0] == '-'  &&  (str[1] == 'l' || str[1] == 'L'))  {
  2613. -               if  (pathn == NULL)  {
  2614. -                       if  ((pathn = getenv("LDPATH")) == NULL)
  2615. -                               pathn = "/lib:/usr/lib";
  2616. -               }
  2617. -               fullpath = malloc((unsigned)(strlen(pathn) + strlen(str) + 1));
  2618. -               if  (fullpath == NULL)
  2619. -                       nomem();
  2620. -               pathb = pathn;
  2621. -               do  {
  2622. -                       pathe = strchr(pathb, ':');
  2623. -                       if  (*pathb == ':')
  2624. -                               fullpath[0] = '\0';
  2625. -                       else  {
  2626. -                               if  (pathe != NULL)
  2627. -                                       *pathe = '\0';
  2628. -                               (void) strcpy(fullpath, pathb);
  2629. -                               (void) strcat(fullpath, "/");
  2630. -                               if  (pathe != NULL)
  2631. -                                       *pathe = ':';
  2632. -                       }
  2633. -                       if  (str[1] == 'l')
  2634. -                               (void) strcat(fullpath, "lib");
  2635. -                       (void) strcat(fullpath, &str[2]);
  2636. -                       if  (str[1] == 'l')
  2637. -                               (void) strcat(fullpath, ".a");
  2638. -                       if  ((fd = open(fullpath, O_RDONLY)) >= 0)
  2639. -                               goto  found;
  2640. -                       pathb = pathe + 1;
  2641. -               }   while  (pathe != NULL);
  2642. -               
  2643. -               (void) fprintf(stderr, "Unable to locate lib%s.a in %s\n",
  2644. -                       &str[2], pathn);
  2645. -               exit(101);
  2646. -       }
  2647. -       else  if  ((fd = open(str, O_RDONLY)) < 0)  {
  2648. -               (void) fprintf(stderr, "Cannot open %s\n", str);
  2649. -               exit(102);
  2650. -       }
  2651. -       
  2652. -found:
  2653. -
  2654. -       if  ((read(fd, (char *) &magic, sizeof(magic)) != sizeof(magic)  ||
  2655. -               magic != ARMAG))  {
  2656. -               if  (ep != NULL)  {
  2657. -                       (void) fprintf(stderr, "%s is not library file\n",
  2658. -                                       fullpath != NULL? fullpath: str);
  2659. -                       exit(103);
  2660. -               }
  2661. -               if  (fullpath != NULL)
  2662. -                       free(fullpath);
  2663. -               currlib.lf_fd = fd;
  2664. -               currlib.lf_offset = 0;
  2665. -               currlib.lf_next = -1;
  2666. -               currlib.lf_name[0] = '\0';
  2667. -               return  &currlib;
  2668. -       }
  2669. -       
  2670. -       /*
  2671. -        *      It appears to be a library file - see if we want a specific
  2672. -        *      one.
  2673. -        */
  2674. -       
  2675. -       if  (ep != NULL)  {
  2676. -               currlib.lf_offset = sizeof(magic) + sizeof(struct ar_hdr);
  2677. -               for  (;;)  {
  2678. -                       if  (read(fd, &arhdr, sizeof(arhdr)) != sizeof(arhdr))  {
  2679. -                               (void) fprintf(stderr, "Cannot find member %s in %s\n",
  2680. -                                       bp+1, fullpath?fullpath: str);
  2681. -                               exit(103);
  2682. -                       }
  2683. -                       if  (strncmp(bp+1, arhdr.ar_name, sizeof(arhdr.ar_name)) == 0)
  2684. -                               break;
  2685. -                       currlib.lf_offset += arhdr.ar_size + sizeof(arhdr) + 1;
  2686. -                       currlib.lf_offset &= ~ 1;
  2687. -                       (void) lseek(fd, (long)(currlib.lf_offset - sizeof(arhdr)), 0);
  2688. -               }
  2689. -               if  (fullpath != NULL)
  2690. -                       free(fullpath);
  2691. -               currlib.lf_fd = fd;
  2692. -               currlib.lf_next = -1;
  2693. -               currlib.lf_name[0] = '\0';
  2694. -               *bp = '(';
  2695. -               *ep = ')';
  2696. -               return  &currlib;
  2697. -       }
  2698. -       
  2699. -       /*
  2700. -        *      Otherwise point to 1st member in library.
  2701. -        */
  2702. -       
  2703. -       if  (read(fd, &arhdr, szeof(arhdr)) != sizeof(arhdr))  {
  2704. -               (void) fprintf(stderr, "Library %s empty\n", fullpath? fullpath: str);
  2705. -               exit(104);
  2706. -       }
  2707. -       if  (fullpath != NULL)
  2708. -               free(fullpath);
  2709. -       currlib.lf_offset = sizeof(magic) + sizeof(arhdr);
  2710. -       currlib.lf_next = currlib.lf_offset + arhdr.ar_size + 1;
  2711. -       currlib.lf_next &= ~1;
  2712. -       currlib.lf_fd = fd;
  2713. -       (void) strncpy(currlib.lf_name, arhdr.ar_name, sizeof(currlib.lf_name));-       return  &currlib;
  2714. -}
  2715. -
  2716. -/*
  2717. - *     Process library files.
  2718. - */
  2719. -
  2720. -#define        MINTEXT 6
  2721. -
  2722. -void   lscan(nfiles, fnames)
  2723. -int    nfiles;
  2724. -char   **fnames;
  2725. -{
  2726. -       ef_fids libfile;
  2727. -       register  ef_fid  ll = &libfile;
  2728. -       register  struct  libit  *clf;
  2729. -       extern  symbol  dolsymb();
  2730. -       int     firstfile;
  2731. -       
  2732. -       for  (;  nfiles > 0;  fnames++, nfiles--)  {
  2733. -               clf = getfnam(*fnames);
  2734. -               cfile = *fnames;
  2735. -               firstfile = 1;
  2736. -               do  {
  2737. -                       bfopen(tfnam, ll);
  2738. -
  2739. -                       /*
  2740. -                        *      If file is garbled, silently forget it and go
  2741. -                        *      on to the next one.
  2742. -                        */
  2743. -
  2744. -                       if  (!rtext(clf->lf_fd, clf->lf_offset, ll))
  2745. -                               goto  closeit;
  2746. -                               
  2747. -                       if  (ll->ef_tsize < MINTEXT)
  2748. -                               goto  closeit;
  2749. -                               
  2750. -                       if  (!rdata(clf->lf_fd, clf->lf_offset, ll))
  2751. -                               goto  closeit;
  2752. -                               
  2753. -                       if  (rrell1(clf->lf_fd, clf->lf_offset, ll) < 0)
  2754. -                               goto  closeit;
  2755. -                               
  2756. -                       /*
  2757. -                        *      If first file in library, find it from
  2758. -                        *      beginning of main file.
  2759. -                       */
  2760. -                       
  2761. -                       if  (firstfile)  {
  2762. -                               if  ((trelpos = findstart(&mainfile, ll)) < 0)
  2763. -                                       goto  closeit;
  2764. -                               firstfile = 0;
  2765. -                       }
  2766. -                       else   if  (!matchup(&mainfile, ll, trelpos))
  2767. -                                       goto  closeit;
  2768. -                       
  2769. -                       /*
  2770. -                        *      Found a match.
  2771. -                        */
  2772. -                       
  2773. -                       if  (!rsymb(clf->lf_fd, clf->lf_offset, dolsymb, ll))  {-                               (void) fprintf(stderr, "Corrupt file %s\n",
  2774. -                                                       *fnames);
  2775. -                               exit(150);
  2776. -                       }
  2777. -                       
  2778. -                       donedrel = 0;
  2779. -                       donebrel = 0;
  2780. -                       rrell2(clf->lf_fd, clf->lf_offset, ll);
  2781. -                       if  (verbose)  {
  2782. -                               (void) fprintf(stderr, "Found: ");
  2783. -                               if  (clf->lf_name[0])
  2784. -                                       (void) fprintf(stderr, "%.14s in ",
  2785. -                                                       clf->lf_name);
  2786. -                               (void) fprintf(stderr, "%s\n", *fnames);
  2787. -                       }
  2788. -                       if  (libfile.ef_stvec != NULL)  {
  2789. -                               free(libfile.ef_stvec);
  2790. -                               libfile.ef_stvec = NULL;
  2791. -                               libfile.ef_stcnt = 0;
  2792. -                       }
  2793. -                       dreltab.c_int = 0;
  2794. -                               
  2795. -                       /*
  2796. -                        *      Start looking next time round
  2797. -                        *      where last one left off.
  2798. -                        */
  2799. -                       
  2800. -                       markmatch(&mainfile, ll, trelos);
  2801. -                       trelpos += libfile.ef_tsize;
  2802. -closeit:
  2803. -                       bfclose(ll);
  2804. -               }  while  (nextmemb(clf) >= 0);
  2805. -       }
  2806. -}
  2807. //GO.SYSIN DD libmtch.c
  2808. echo main.c 1>&2
  2809. sed 's/.//' >main.c <<'//GO.SYSIN DD main.c'
  2810. -/*
  2811. - *     SCCS:   @(#)main.c      1.2     11/2/84 14:19:31
  2812. - *     Main routine etc.
  2813. - *
  2814. - ***********************************************************************
  2815. - *     This software is copyright of
  2816. - *
  2817. - *             John M Collins
  2818. - *             47 Cedarwood Drive
  2819. - *             St Albans
  2820. - *             Herts, AL4 0DN
  2821. - *             England                 +44 727 57267
  2822. - *
  2823. - *     and is released into the public domain on the following conditions:
  2824. - *
  2825. - *             1.  No free maintenance will be guaranteed.
  2826. - *             2.  Nothing may be based on this software without
  2827. - *                 acknowledgement, including incorporation of this
  2828. - *                 notice.
  2829. - *
  2830. - *     Notwithstanding the above, the author welcomes correspondence and bug
  2831. - *     fixes.
  2832. - ***********************************************************************
  2833. - */
  2834. -
  2835. -#include <stdio.h>
  2836. -#include <fcntl.h>
  2837. -#include <a.out.h>
  2838. -#include <sys/var.h>
  2839. -#include "unc.h"
  2840. -
  2841. -#define        LINELNG 70
  2842. -
  2843. -void   inturdat(), intutext(), intudat(), intlsym();
  2844. -void   ptext(), pdata(), pabs(), pbss(), lscan();
  2845. -
  2846. -ef_fids        mainfile;
  2847. -
  2848. -int    par_entry, par_round;   /*  68000 parameters  */
  2849. -int    nmods;                  /*  Number of modules it looks like  */
  2850. -
  2851. -char   *tfnam = "split";
  2852. -
  2853. -char   lsyms;                  /*  Generate local symbols  */
  2854. -char   verbose;                /*  Tell the world what we are doing  */
  2855. -char   noabs;                  /*  No non-global absolutes  */
  2856. -int    rel;                    /*  File being analysed is relocatable  */
  2857. -int    lpos;
  2858. -
  2859. -symbol dosymb();
  2860. -struct libit   *getfnam();
  2861. -
  2862. -/*
  2863. - *     Get hex characters, also allowing for 'k' and 'm'.
  2864. - */
  2865. -
  2866. -int    ghex(str)
  2867. -registe  char *str;
  2868. -{
  2869. -       register  int   result = 0;
  2870. -       register  int   lt;
  2871. -
  2872. -       for  (;;)  {
  2873. -               lt = *str++;
  2874. -               switch  (lt)  {
  2875. -               default:
  2876. -err:                   (void) fprintf(stderr, "Invalid hex digit \'%c\'\n", lt);
  2877. -                       exit(1);
  2878. -                       
  2879. -               case '\0':
  2880. -                       return  result;
  2881. -                       
  2882. -               case '0':case '1':case '2':case '3':case '4':
  2883. -               case '5':case '6':case '7':case '8':case '9':
  2884. -                       result = (result << 4) + lt - '0';
  2885. -                       continue;
  2886. -                       
  2887. -               case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
  2888. -                       result = (result << 4) + lt - 'a' + 10;
  2889. -                       continue;
  2890. -
  2891. -               case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
  2892. -                       result = (result << 4) + lt - 'A' + 10;
  2893. -                       continue;
  2894. -               
  2895. -               case 'k':case 'K':
  2896. -                       if  (*str != '\0')
  2897. -                               goto  err;
  2898. -                       return  result << 10;
  2899. -                       
  2900. -               case 'm':case 'M':
  2901. -                       if  (*str != '\0')
  2902. -                               goto  err;
  2903. -                       return  result << 20;
  2904. -               }
  2905. -       }
  2906. -}
  2907. -
  2908. -/*
  2909. - *     Process entry line options.  Return number dealt with.
  2910. - */
  2911. -
  2912. -int    doopts(av)
  2913. -char   *av[];
  2914. -{
  2915. -       register  int   cnt = 0, lt;
  2916. -       register  char  *arg;
  2917. -       struct  var     vs;
  2918. -       
  2919. -       uvar(&vs);
  2920. -       par_entry = vs.v_ustart;
  2921. -       par_round = vs.v_txtrnd - 1;
  2922. -       
  2923. -       for  (;;)  {
  2924. -               arg = *++av;
  2925. -               if  (*arg++ != '-')
  2926. -                       return  cnt;
  2927. -               cnt++;
  2928. -               
  2929. -nx:            switch  (lt = *arg++)  {
  2930. -               default:
  2931. -                       (void)fprintf(stderr, "Bad option -%c\n", lt);
  2932. -                       exit(1);
  2933. -                       
  2934. -               case  '\0':
  2935. -                       continue;
  2936. -                       
  2937. -               case  'l':      /*  A file name  */
  2938. -               case  'L':
  2939. -                       return  cnt - 1;
  2940. -                       
  2941. -               case  's':
  2942. -                       lsyms++;
  2943. -                       goto  nx;
  2944. -                       
  2945. -               case  'v':
  2946. -                       verbose++;
  2947. -                       goto  nx;
  2948. -                       
  2949. -               case  'a':
  2950. -                       noabs++;
  2951. -                       goto  nx;
  2952. -
  2953. -               case  'R':
  2954. -               case  'N':
  2955. -                       if  (*arg == '\0')  {
  2956. -                               cnt++;
  2957. -                               arg = *++av;
  2958. -                               if  (arg == NULL)  {
  2959. -bo:                                    (void) fprintf(stderr,"Bad -%c option\n",lt);
  2960. -                                       exit(1);
  2961. -                               }
  2962. -                       }
  2963. -                       if  (lt == 'R')
  2964. -                               par_entry = ghex(arg);
  2965. -                       else
  2966. -                               par_round = ghex(arg) - 1;
  2967. -                       continue;
  2968. -                       
  2969. -               case  't':
  2970. -                       if  (*arg == '\0')  {
  2971. -                               cnt++;
  2972. -                               arg = *++av;
  2973. -                               if  (arg == NULL)
  2974. -                                       goto  bo;
  2975. -                       }
  2976. -                       tfnam = arg;
  2977. -                       continue;
  2978. -                       
  2979. -               case  'o':
  2980. -                       if  (*arg == '\0')  {
  2981. -                               cnt++;
  2982. -                               arg = *++av;
  2983. -                               if  (arg == NULL)
  2984. -                                       goto  bo;
  2985. -                      }
  2986. -                       if  (freopen(arg, "w", stdout) == NULL)  {
  2987. -                               (void) fprintf(stderr, "Help! cant open %s\n", arg);
  2988. -                               exit(20);
  2989. -                       }
  2990. -                       continue;
  2991. -               }
  2992. -       }
  2993. -}
  2994. -       
  2995. -/*
  2996. - *     Open binary files.  Arrange to erase them when finished.
  2997. - */
  2998. -
  2999. -void   bfopen(nam, fid)
  3000. -char   *nam;
  3001. -ef_fid fid;
  3002. -{
  3003. -       char    fnam[80];
  3004. -       
  3005. -       (void) sprintf(fnam, "%s.tx", nam);
  3006. -       if  ((fid->ef_t = open(fnam, O_RDWR|O_CREAT, 0666)) < 0)  {
  3007. -efil:          (void) fprintf(stderr, "Help could not open %s\n", fnam);
  3008. -               exit(4);
  3009. -       }
  3010. -       (void) unlink(fnam);
  3011. -       (void) sprintf(fnam, "%s.dt", nam);
  3012. -       if  ((fid->ef_d = open(fnam, O_RDWR|O_CREAT, 0666)) < 0)
  3013. -               goto  efil;
  3014. -       (void) unlink(fnam);
  3015. -}
  3016. -
  3017. -/*
  3018. - *     Close binary files.  They should get zapped anyway.
  3019. - */
  3020. -
  3021. -void   bfclose(fid)
  3022. -ef_fid fid;
  3023. -{
  3024. -       (void) close(fid->ef_t);
  3025. -       (void) close(fid->ef_d);
  3026. -}
  3027. -
  3028. -/*
  3029. - *     Main routine.
  3030. - */
  3031. -
  3032. -main(argc, argv)
  3033. -int    argc;
  3034. -char   *argv[];
  3035. -{
  3036. -       int     i;
  3037. -       char    *progname = argv[0];
  3038. -       char    *msg;
  3039. -       register  struct  libit  *lfd;
  3040. -       
  3041. -       i = doopts(argv);
  3042. -       argc -= i;
  3043. -       argv += i;
  3044. -       
  3045. -       if  (argc < 2)  {
  3046. -               (void) fprintf(stderr, "Usage: %s [ options ] file\n", progname);
  3047. -               exit(1);
  3048. -       }
  3049. -       
  3050. -       lfd = getfnam(argv[1]);
  3051. -       if  (lfd->lf_next > 0)  {
  3052. -               (void) fprintf(stderr, "Main file (%s) cannot be library\n", argv[1]);
  3053. -               exit(2);
  3054. -       }
  3055. -       
  3056. -       bfopen(tfnam, &mainfile);
  3057. -       if  (verbose)
  3058. -               (void) fprintf(stderr, "Scanning text\n");
  3059. -       if  (!rtext(lfd->lf_fd, lfd->lf_offset, &mainfile))  {
  3060. -               msg = "text";
  3061. -bf:            (void) fprintf(stderr, "Bad format input file -reading %s\n", msg);
  3062. -               exit(5);
  3063. -       }
  3064. -       if  (verbose)
  3065. -               (void) fprintf(stderr, "Scanning data\n");
  3066. -       if  (!rdata(lfd->lf_fd, lfd->lf_offset, &mainfile))  {
  3067. -               msg = "data";
  3068. -               goto  bf;
  3069. -       }
  3070. -       if  (verbose)
  3071. -               (void) fprintf(stderr, "Scanning symbols\n");
  3072. -       if  (!rsymb(lfd->lf_fd, lfd->lf_offset, dosymb, &mainfile))  {
  3073. -               msg = "symbols";
  3074. -               goto  bf;
  3075. -       }
  3076. -       if  (verbose)
  3077. -               (void) fprintf(stderr, "Scanning for relocation\n");
  3078. -       if  ((rel = rrel(lfd->lf_fd, lfd->lf_offset, &mainfile)) < 0)  {
  3079. -               msg = "reloc";
  3080. -               goto  bf;
  3081. -       }
  3082. -       
  3083. -       if  (rel)  {
  3084. -               if  (verbose)
  3085. -                       (void) fprintf(stderr, "File is relocatable\n");
  3086. -               if  (argc > 2)
  3087. -                       (void) fprintf(stderr, "Sorry - no scan on reloc files\n");
  3088. -       }
  3089. -       else
  3090. -               lscan(argc - 2, &argv[2]);
  3091. -
  3092. -       if  (verbose)
  3093. -               (void) fprintf(stderr, "End of input\n");
  3094. -       
  3095. -       (void) close(lfd->lf_fd);
  3096. -       if  (nmods > 0)
  3097. -               (void) fprintf(stderr, "Warning: at least %d merged modules\n",
  3098. -                       nmods + 1);
  3099. -
  3100. -       if  (mainfile.ef_stvec != NULL)  {
  3101. -               free(mainfile.ef_stvec);
  3102. -               mainfile.ef_stvec = NULL;
  3103. -               mainfile.ef_stcnt = 0;
  3104. -       }
  3105. -       
  3106. -       if  (verbose)
  3107. -               (void) fprintf(stderr, "Text anal 1\n");
  3108. -       intutext();
  3109. -       if  (verbose)
  3110. -               (void) fprintf(stderr, "Data anal 1\n");
  3111. -       intudat(&mainfile);
  3112. -       if  (!rel)  {
  3113. -               if  (verbose)
  3114. -                       (void) fprintf(stderr, "Data anal 2\n");
  3115. -               inturdat(&mainfile);
  3116. -       }
  3117. -       if  (lsyms)  {
  3118. -               if  (verbose)
  3119. -                       (void) fprintf(stderr, "Local symbol scan\n");
  3120. -              intlsym();
  3121. -       }
  3122. -       pabs();
  3123. -       ptext(&mainfile);
  3124. -       pdata(&mainfile);
  3125. -       pbss(&mainfile);
  3126. -       bfclose(&mainfile);
  3127. -       exit(0);
  3128. -}
  3129. //GO.SYSIN DD main.c
  3130. echo prin.c 1>&2
  3131. sed 's/.//' >prin.c <<'//GO.SYSIN DD prin.c'
  3132. -/*
  3133. - *     SCCS:   @(#)prin.c      1.2     11/2/84 14:19:47
  3134. - *     Print stuff.
  3135. - *
  3136. - ***********************************************************************
  3137. - *     This software is copyright of
  3138. - *
  3139. - *             John M Collins
  3140. - *             47 Cedarwood Drive
  3141. - *             St Albans
  3142. - *             Herts, AL4 0DN
  3143. - *             England                 +44 727 57267
  3144. - *
  3145. - *     and is released into the public domain on the following conditions:
  3146. - *
  3147. - *             1.  No free maintenance will be guaranteed.
  3148. - *             2.  Nothing may be based on this software without
  3149. - *                 acknowledgement, including incorporation of this
  3150. - *                 notice.
  3151. - *
  3152. - *     Notwithstanding the above, the author welcomes correspondence and bug
  3153. - *     fixes.
  3154. - ***********************************************************************
  3155. - */
  3156. -
  3157. -#include <stdio.h>
  3158. -#include <a.out.h>
  3159. -#include "unc.h"
  3160. -
  3161. -#define        LINELNG 70
  3162. -
  3163. -void   gette(), getde();
  3164. -long   gettw(), getdw();
  3165. -void   prinst();
  3166. -
  3167. -char   noabs;                  /*  No non-global absolutes  */
  3168. -int    rel;                    /*  File being analysed is relocatable  */
  3169. -int    lpos;
  3170. -
  3171. -struct commit  abstab, comtab;
  3172. -
  3173. -/*
  3174. - *     Print absolute and common values.
  3175. - */
  3176. -
  3177. -void   pabs()
  3178. -{
  3179. -       register  int   i;
  3180. -       register  symbol  cs;
  3181. -
  3182. -       for  (i = 0;  i < abstab.c_int;  i++)
  3183. -       
  3184. -       for  (i = 0;  i < abstab.c_int;  i++)  {
  3185. -               cs = abstab.c_symb[i];
  3186. -               if  (cs->s_glob)
  3187. -                       (void) printf("\t.globl\t%s\n", cs->s_name);
  3188. -               else  if  (noabs)
  3189. -                       continue;
  3190. -               (void) printf("%s\t=\t0x%lx\n", cs->s_name, cs->s_valu);
  3191. -       }
  3192. -       for  (i = 0;  i < comtab.c_int;  i++)  {
  3193. -               cs = comtab.c_symb[i];
  3194. -               (void) printf("\t.comm\t%s,%d\n", cs->s_name, cs->s_value);
  3195. -       }
  3196. -}
  3197. -
  3198. -/*
  3199. - *     Print out labels.
  3200. - */
  3201. -
  3202. -void   plabs(ls, seg)
  3203. -register  symbol  ls;
  3204. -int    seg;
  3205. -{
  3206. -       for  (; ls != NULL;  ls = ls->s_link)  {
  3207. -               if  (ls->s_type != seg)
  3208. -                       continue;
  3209. -               if  (ls->s_lsymb)  {
  3210. -                       (void) printf("%u$:\n", ls->s_lsymb);
  3211. -                       return;         /*  Set last  */
  3212. -               }
  3213. -               if  (ls->s_glob)
  3214. -                       (void) printf("\n\t.globl\t%s", ls->s_name);
  3215. -               (void) printf("\n%s:\n", ls->s_name);
  3216. -       }
  3217. -}
  3218. -
  3219. -/*
  3220. - *     Print out text.
  3221. - */
  3222. -
  3223. -void   ptext(fid)
  3224. -register  ef_fid  fid;
  3225. -{
  3226. -       register  long  tpos, endt;
  3227. -       t_entry tstr;
  3228. -
  3229. -       (void) printf(".text\n");
  3230. -       
  3231. -       tpos = fid->ef_tbase;
  3232. -       endt = tpos + fid->ef_tsize;
  3233. -contin:        
  3234. -       for  (;  tpos < endt;  tpos += tstr.t_lng * 2)  {
  3235. -               gette(fid, tpos, &tstr);
  3236. -               plabs(tstr.t_lab, TEXT);
  3237. -               if  (tstr.t_type == T_BEGIN)
  3238. -                       prinst(&tstr, tpos);
  3239. -               else  if  (tstr.t_relsymb != NULL)  {
  3240. -                       (void) printf("\t.long\t%s", tstr.t_relsymb->s_name);
  3241. -                       if  (tstr.t_relsymb->s_type!=TEXT &&
  3242. -                               tstr.t_relsymb->s_type!=DATA)
  3243. -                               (void) printf("+0x%x", gettw(fid, tpos, R_LONG));
  3244. -                       putchar('\n');
  3245. -                       tpos += 4;
  3246. -                       goto  contin;
  3247. -               }
  3248. -               else
  3249. -                       (void) printf("\t.word\t0x%x\n", tstr.t_contents);
  3250. -       }
  3251. -
  3252. -       /*
  3253. -        *      Print out any trailing label.
  3254. -        */
  3255. -       
  3256. -       gette(fid, tpos, &tstr);
  3257. -       plabs(tstr.t_lab, TEXT);
  3258. -}
  3259.  
  3260. -/*
  3261. - *     Print out data.
  3262. - */
  3263. -
  3264. -void   pdata(fid)
  3265. -register  ef_fid  fid;
  3266. -{
  3267. -       register  long  dpos, endd;
  3268. -       register  int   lng;
  3269. -       unsigned  ctyp;
  3270. -       int     had, par, inc;
  3271. -       char    *msg;
  3272. -       d_entry dstr;
  3273. -       
  3274. -       (void) printf("\n.data\n");
  3275. -       
  3276. -       dpos = fid->ef_dbase;
  3277. -       endd = dpos + fid->ef_dsize;
  3278. -
  3279. -       while  (dpos < endd)  {
  3280. -               
  3281. -               getde(fid, dpos, &dstr);
  3282. -               plabs(dstr.d_lab, DATA);
  3283. -                       
  3284. -               switch  (dstr.d_type)  {
  3285. -               case  D_CONT:
  3286. -                       (void) fprintf(stderr, "Data sync error\n");
  3287. -                       exit(200);
  3288. -                       
  3289. -               case  D_ASC:
  3290. -               case  D_ASCZ:
  3291. -                       ctyp = dstr.d_type;
  3292. -                       lng = dstr.d_lng;
  3293. -                       (void) printf("\t.asci");
  3294. -                       if  (ctyp == D_ASC)
  3295. -                               (void) printf("i\t\"");
  3296. -                       else  {
  3297. -                               (void) printf("z\t\"");
  3298. -                               lng--;
  3299. -                       }
  3300. -                               
  3301. -                       while  (lng > 0)  {
  3302. -                               getde(fid, dpos, &dstr);
  3303. -                               switch  (dstr.d_contents)  {
  3304. -                               default:
  3305. -                                       if  (dstr.d_contents < ' ' ||
  3306. -                                               dstr.d_contents > '~')
  3307. -                                               (void) printf("\\%.3o", dstr.d_contents);
  3308. -                                       else
  3309. -                                               putchar(dstr.d_contents);
  3310. -                                       break;
  3311. -                               case  '\"':
  3312. -                               case  '\'':
  3313. -                               case  '\\':
  3314. -                               case  '|':
  3315. -                                      (void) printf("\\%c", dstr.d_contents);
  3316. -                                       break;
  3317. -                               case  '\b':
  3318. -                                       (void) printf("\\b");
  3319. -                                       break;
  3320. -                               case  '\n':
  3321. -                                       (void) printf("\\n");
  3322. -                                       break;
  3323. -                               case  '\r':
  3324. -                                       (void) printf("\\r");
  3325. -                                       break;
  3326. -                               }
  3327. -                               
  3328. -                               lng--;
  3329. -                               dpos++;
  3330. -                       }
  3331. -                       (void) printf("\"\n");
  3332. -                       if  (ctyp == D_ASCZ)
  3333. -                               dpos++;
  3334. -                       break;
  3335. -
  3336. -               case  D_BYTE:
  3337. -                       msg = "byte";
  3338. -                       par = R_BYTE;
  3339. -                       inc = 1;
  3340. -                       goto  wrest;
  3341. -                       
  3342. -               case  D_WORD:
  3343. -                       msg = "word";
  3344. -                       par = R_WORD;
  3345. -                       inc = 2;
  3346. -                       goto  wrest;
  3347. -                       
  3348. -               case  D_LONG:
  3349. -                       msg = "long";
  3350. -                       par = R_LONG;
  3351. -                       inc = 4;
  3352. -               wrest:
  3353. -                       (void) printf("\t.%s\t", msg);
  3354. -                       lng = dstr.d_lng;
  3355. -                       lpos = 16;
  3356. -                       had = 0;
  3357. -                       while  (lng > 0)  {
  3358. -                               if  (lpos > LINELNG)  {
  3359. -                                       (void) printf("\n\t.%s\t", msg);
  3360. -                                       lpos = 16;
  3361. -                               }
  3362. -                               else  if  (had)
  3363. -                                       lpos += printf", ");
  3364. -
  3365. -                               lpos += printf("0x%x", getdw(fid, dpos, par));
  3366. -                               lng -= inc;
  3367. -                               dpos += inc;
  3368. -                               had++;
  3369. -                       }
  3370. -                       putchar('\n');
  3371. -                       break;
  3372. -
  3373. -               case  D_ADDR:
  3374. -                       (void) printf("\t.long\t");
  3375. -                       lng = dstr.d_lng;
  3376. -                       lpos = 16;
  3377. -                       had = 0;
  3378. -                       while  (lng > 0)  {
  3379. -                               if  (lpos > LINELNG)  {
  3380. -                                       (void) printf("\n\t.long\t");
  3381. -                                       lpos = 16;
  3382. -                               }
  3383. -                               else  if  (had)
  3384. -                                       lpos += printf(", ");
  3385. -
  3386. -                               getde(fid, dpos, &dstr);
  3387. -                               lpos += printf("%s", dstr.d_relsymb->s_name);
  3388. -                               lng -= sizeof(long);
  3389. -                               dpos += sizeof(long);
  3390. -                               had++;
  3391. -                       }
  3392. -                       putchar('\n');
  3393. -                       break;
  3394. -               }
  3395. -       }
  3396. -       
  3397. -       /*
  3398. -        *      Print trailing label.
  3399. -        */
  3400. -       
  3401. -       getde(fid, dpos, &dstr);
  3402. -       plabs(dstr.d_lab, DATA);
  3403. -}
  3404. -
  3405. -void   pbss(fid)
  3406. -register  ef_fid  fid;
  3407. -{
  3408. -       register  long  bpos = fid->ef_bbase;
  3409. -       long    endb = fid->ef_end;
  3410. -       d_entry bstr;
  3411. -       
  3412. -       (void) printf("\n.bss\n");
  3413. -       
  3414. -       while  (bpos < endb)  {
  3415. -               getde(fid, bpos, &bstr);
  3416. -               plabs(bstr.d_lab, BSS);
  3417. -               (void) printf("\t.space\t%d\n", bstr.d_lng);
  3418. -               bpos += bstr.d_lng;
  3419. -       }
  3420. -       
  3421. -       getde(fid, endb, &bstr);
  3422. -       plabs(bstr.d_lab, BSS);
  3423. -}
  3424. //GO.SYSIN DD prin.c
  3425. echo robj.c 1>&2
  3426. sed 's/.//' >robj.c <'//GO.SYSIN DD robj.c'
  3427. -/*
  3428. - *     SCCS:   @(#)robj.c      1.2     11/2/84 14:19:59
  3429. - *     Read object files.
  3430. - *
  3431. - ***********************************************************************
  3432. - *     This software is copyright of
  3433. - *
  3434. - *             John M Collins
  3435. - *             47 Cedarwood Drive
  3436. - *             St Albans
  3437. - *             Herts, AL4 0DN
  3438. - *             England                 +44 727 57267
  3439. - *
  3440. - *     and is released into the public domain on the following conditions:
  3441. - *
  3442. - *             1.  No free maintenance will be guaranteed.
  3443. - *             2.  Nothing may be based on this software without
  3444. - *                 acknowledgement, including incorporation of this
  3445. - *                 notice.
  3446. - *
  3447. - *     Notwithstanding the above, the author welcomes correspondence and bug
  3448. - *     fixes.
  3449. - ***********************************************************************
  3450. - *
  3451. - *     This particular module will obviously have to be munged beyond
  3452. - *     recognition for another object format.
  3453. - */
  3454. -
  3455. -#include <stdio.h>
  3456. -#include <a.out.h>
  3457. -#include "unc.h"
  3458. -
  3459. -void   gette(), getde(), setde(), putte(), putde();
  3460. -long   gettw(), getdw();
  3461. -void   reallst(), lclash(), nomem(), unimpl();
  3462. -void   addit();
  3463. -char   *malloc();
  3464. -long   lseek();
  3465. -
  3466. -int    par_entry, par_round, nmods, donedrel, donebrel;
  3467. -struct commit  abstab, comtab, dreltab;
  3468. -long   trelpos, drelpos, brelpos;
  3469. -
  3470. -ef_fids        mainfile;
  3471. -
  3472. -symbol lookup(), inventsymb(), getnsymb();
  3473. -
  3474. -#define        DBSIZE  100
  3475. -#define        STINIT  20
  3476. -
  3477. -/*
  3478. - *     Read text segment.  Return 0 if not ok.
  3479. - */
  3480. -
  3481. -int    rtext(inf, offset, outf)
  3482. -int    inf;            /*  a.out file (possibly in library)  */
  3483. -long   offset;         /*  Offset from start of inf of a.out file  */
  3484. -ef_fid outf;           /*  Output file descriptor  */
  3485. -{
  3486. -       t_entry         tstr;
  3487. -       struct  bhdr    filhdr;
  3488. -       register  long  size;
  3489. -       register  int   i, l;
  3490. -       unsigned  short inbuf[DBSIZE/2];
  3491. -
  3492. -      /*
  3493. -        *      Initialise fields in structure.
  3494. -        */
  3495. -       
  3496. -       tstr.t_type = T_UNKNOWN;
  3497. -       tstr.t_vins = 1;                /*  For the moment  */
  3498. -       tstr.t_bdest = 0;
  3499. -       tstr.t_gbdest = 0;
  3500. -       tstr.t_lng = 1;
  3501. -       tstr.t_reloc = R_NONE;
  3502. -       tstr.t_rdisp = 0;
  3503. -       tstr.t_isrel = 0;
  3504. -       tstr.t_amap = 0;
  3505. -       tstr.t_dref = 0;
  3506. -       tstr.t_relsymb = NULL;
  3507. -       tstr.t_reldisp = 0;
  3508. -       tstr.t_lab = NULL;
  3509. -       tstr.t_lsymb = 0;
  3510. -       tstr.t_refhi = 0;
  3511. -       tstr.t_reflo = 0x7fffffff;
  3512. -       tstr.t_match = 0;
  3513. -       
  3514. -       /*
  3515. -        *      Read a.out header.
  3516. -        */
  3517. -       
  3518. -       (void) lseek(inf, offset, 0);
  3519. -
  3520. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3521. -               return  0;
  3522. -
  3523. -       if  (filhdr.fmagic != FMAGIC  &&  filhdr.fmagic != NMAGIC)
  3524. -               return  0;
  3525. -
  3526. -       /*
  3527. -        *      Warn user if entry point does not tie up.
  3528. -        */
  3529. -       
  3530. -       if  (filhdr.entry != par_entry)
  3531. -               (void) fprintf(stderr, "Warning: File has -R%X\n", filhdr.entry);
  3532. -
  3533. -       outf->ef_entry = filhdr.entry;
  3534. -       outf->ef_tbase = filhdr.entry;
  3535. -       outf->ef_dbase = filhdr.tsize + filhdr.entry;
  3536. -
  3537. -       if  (filhdr.fmagic == NMAGIC)
  3538. -               outf->ef_dbase = (outf->ef_dbase + par_round) & (~par_round);
  3539. -
  3540. -       outf->ef_bbase = outf->ef_dbase + filhdr.dsize;
  3541. -       outf->ef_end = outf->ef_bbase + filhdr.bsize;
  3542. -
  3543. -       outf->ef_tsize = filhdr.tsize;
  3544. -       outf->ef_dsize = filhdr.dsize;
  3545. -       outf->ef_bsize = filhdr.bsize;
  3546. -       
  3547. -       (void) lseek(inf, offset + TEXTPOS, 0);
  3548. -       
  3549. -       size = outf->ef_tsize;
  3550. -       
  3551. -       while  (size > 1)  {
  3552. -               l = size > DBSIZE? DBSIZE: size;
  3553. -               if  (read(inf, (char *)inbuf, l) != l)
  3554. -                       return  0;
  3555. -               l /= 2;
  3556. -               for  (i = 0;  i < l;  i++)  {
  3557. -                       tstr.t_contents = inbuf[i];
  3558. -                       (void) write(outf->ef_t, (char *)&tstr, sizeof(tstr));
  3559. -               }
  3560. -               size -= l + l;
  3561. -       }
  3562. -       
  3563. -       /*
  3564. -        *      Extra one to cope with "etext".
  3565. -        */
  3566. -       
  3567. -       (void) write(outf->ef_t, (char *)&tstr, sizeof(tstr));
  3568. -       return  1;
  3569. -}
  3570. -
  3571. -/*
  3572. - *     Same sort of thing for the data segment.
  3573. - */
  3574. -
  3575. -int    rdata(inf, offset, outf)
  3576. -int    inf;            /*  a.out file (possibly in library)  */
  3577. -long   offset;         /*  Offset from start of inf of a.out file  */
  3578. -ef_fid outf;           /*  Output file descriptor  */
  3579. -{
  3580. -       d_entry         dstr;
  3581. -       struct  bhdr    filhdr;
  3582. -       register  long  size;
  3583. -       register  int   i, l;
  3584. -       unsigned  char  inbuf[DBSIZE];
  3585. -
  3586. -       /*
  3587. -        *      Initialise fields in structure.
  3588. -        */
  3589. -       
  3590. -       dstr.d_type = D_BYTE;
  3591. -       dstr.d_reloc = R_NONE;
  3592. -       dstr.d_lng = 1;
  3593. -       dstr.d_relsymb = NULL;
  3594. -       dstr.d_reldisp = 0;
  3595. -       dstr.d_lab = NULL;
  3596. -       
  3597. -       /*
  3598. -        *      Read a.out header.
  3599. -        */
  3600. -       
  3601. -       (void) lseek(inf, offset, 0);
  3602. -
  3603. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3604. -               return  0;
  3605. -
  3606. -       (void) lseek(inf, offset + DATAPOS, 0);
  3607. -       
  3608. -       size = outf->ef_dsize;
  3609. -       
  3610. -       while  (size > 0)  {
  3611. -               l = size > DBSIZE? DBSIZE: size;
  3612. -               if  (read(inf, (char *)inbuf, l) != l)
  3613. -                       return  0;
  3614. -               for  (i = 0;  i < l;  i++)  {
  3615. -                       dstr.d_contents = inbuf[i];
  3616. -                       (void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
  3617. -               }
  3618. -               size -= l;
  3619. -       }
  3620. -       
  3621. -       /*
  3622. -        *      Repeat for BSS segment.
  3623. -        */
  3624. -
  3625. -       dstr.d_contents = 0;
  3626. -       for  (size = outf->ef_bsize;  size > 0;  size--)
  3627. -               (void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
  3628. -       
  3629. -      /*
  3630. -        *      Extra one to cope with "end".
  3631. -        */
  3632. -       
  3633. -       (void) write(outf->ef_d, (char *)&dstr, sizeof(dstr));
  3634. -       return  1;
  3635. -}
  3636. -
  3637. -/*
  3638. - *     Process symbol table segment.
  3639. - */
  3640. -
  3641. -int    rsymb(inf, offset, dproc, outf)
  3642. -int    inf;            /*  a.out file (possibly in library)  */
  3643. -long   offset;         /*  Offset from start of inf of a.out file  */
  3644. -symbol (*dproc)();
  3645. -register  ef_fid  outf;        /*  Output file descriptor  */
  3646. -{
  3647. -       register  symbol  csym;
  3648. -       struct  bhdr    filhdr;
  3649. -       struct  sym     isym;
  3650. -       register  long  size;
  3651. -       register  int   i, l;
  3652. -       char    inbuf[SYMLENGTH+1];
  3653. -
  3654. -       /*
  3655. -        *      Read a.out header.
  3656. -        */
  3657. -       
  3658. -       (void) lseek(inf, offset, 0);
  3659. -
  3660. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3661. -               return  0;
  3662. -
  3663. -       offset += SYMPOS;
  3664. -       size = filhdr.ssize;
  3665. -       if  (size <= 0)
  3666. -               return  1;
  3667. -
  3668. -       /*
  3669. -        *      Guesstimate symbol table vector size.
  3670. -        */
  3671. -
  3672. -       l = size / (sizeof(struct sym) + 4);
  3673. -       if  (l <= 0)
  3674. -               l = STINIT;
  3675. -
  3676. -       outf->ef_stvec = (symbol *) malloc(l * sizeof(symbol));
  3677. -       if  (outf->ef_stvec == NULL)
  3678. -               nomem();
  3679. -
  3680. -       outf->ef_stcnt = 0;
  3681. -       outf->ef_stmax = l;
  3682. -       
  3683. -       while  (size > sizeof(struct sym))  {
  3684. -               (void) lseek(inf, offset, 0);
  3685. -               if  (read(inf, (char *)&isym, sizeof(isym)) != sizeof(isym))
  3686. -                       return  0;
  3687. -               size -= sizeof(isym);
  3688. -               l = SYMLENGTH;
  3689. -               if  (l > size)
  3690. -                       l = size;
  3691. -               if  (read(inf, inbuf, l) != l)
  3692. -                       return  0;
  3693. -               inbuf[l] = '\0';
  3694. -               for  (i = 0; inbuf[i] != '\0';  i++)
  3695. -                       ;
  3696. -               size -= i + 1;
  3697. -               offset += sizeof(isym) + i + 1;
  3698. -               csm = (*dproc)(lookup(inbuf), isym.stype, isym.svalue, outf);
  3699. -               if  (outf->ef_stcnt >= outf->ef_stmax)
  3700. -                       reallst(outf);
  3701. -               outf->ef_stvec[outf->ef_stcnt++] = csym;
  3702. -       }
  3703. -       return  1;
  3704. -}
  3705. -
  3706. -/*
  3707. - *     Process relocation stuff.  -1 error, 0 no relocation, 1 relocation.
  3708. - */
  3709. -
  3710. -int    rrel(inf, offset, outf)
  3711. -int    inf;            /*  a.out file (possibly in library)  */
  3712. -long   offset;         /*  Offset from start of inf of a.out file  */
  3713. -ef_fid outf;           /*  Output file descriptor  */
  3714. -{
  3715. -       struct  bhdr    filhdr;
  3716. -       struct  reloc   crel;
  3717. -       t_entry tstr;
  3718. -       d_entry dstr;
  3719. -       register  long  size;
  3720. -       long    cont, pos;
  3721. -
  3722. -       /*
  3723. -        *      Read a.out header.
  3724. -        */
  3725. -       
  3726. -       (void) lseek(inf, offset, 0);
  3727. -
  3728. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3729. -               return  -1;
  3730. -       if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  3731. -               return  0;
  3732. -
  3733. -       size  =  filhdr.rtsize;
  3734. -
  3735. -       (void) lseek(inf, RTEXTPOS + offset, 0);
  3736. -       while  (size >= sizeof(struct reloc))  {
  3737. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  3738. -                       return  -1;
  3739. -
  3740. -               pos = crel.rpos + outf->ef_tbase;
  3741. -               gette(outf, pos, &tstr);
  3742. -               tstr.t_reloc = crel.rsize + 1;  /*  Fiddle!  YUK!!!  */
  3743. -               tstr.t_rdisp = crel.rdisp;
  3744. -               tstr.t_rptr = crel.rsegment;
  3745. -               if  (crel.rsegment == REXT)  {
  3746. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  3747. -                               return  -1;
  3748. -                       tstr.t_relsymb = outf->ef_stvec[crel.rsymbol];
  3749. -                       tstr.t_reldisp = gettw(outf, pos, (int)crel.rsize+1);
  3750. -               }
  3751. -               else  {
  3752. -                       cont = gettw(outf, pos, (int)crel.rsize+1);
  3753. -                       tstr.t_relsymb = getnsymb(outf, crel.rsegent, cont);
  3754. -               }
  3755. -               tstr.t_relsymb->s_used++;
  3756. -               putte(outf, pos, &tstr);
  3757. -               size -= sizeof(crel);
  3758. -       }
  3759. -       
  3760. -       /*
  3761. -        *      And now repeat all that for data relocations.
  3762. -        */
  3763. -       
  3764. -       size  =  filhdr.rdsize;
  3765. -       
  3766. -       (void) lseek(inf, RDATAPOS + offset, 0);
  3767. -       while  (size >= sizeof(struct reloc))  {
  3768. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  3769. -                       return  -1;
  3770. -
  3771. -               pos = crel.rpos + outf->ef_dbase;
  3772. -               getde(outf, pos, &dstr);
  3773. -               dstr.d_reloc = crel.rsize + 1;  /*  Fiddle!  YUK!!!  */
  3774. -               dstr.d_rptr = crel.rsegment;
  3775. -
  3776. -               if  (crel.rsegment == REXT)  {
  3777. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  3778. -                               return  -1;
  3779. -                       dstr.d_relsymb = outf->ef_stvec[crel.rsymbol];
  3780. -                       dstr.d_reldisp = getdw(outf, pos, (int)crel.rsize+1);
  3781. -               }
  3782. -               else  {
  3783. -                       cont = getdw(outf, pos, (int)crel.rsize+1);
  3784. -                       dstr.d_relsymb = getnsymb(outf, crel.rsegment, cont);
  3785. -                       if  (dstr.d_relsymb->s_type == TEXT)  {
  3786. -                               gette(outf, cont, &tstr);
  3787. -                               tstr.t_dref = 1;
  3788. -                               putte(outf, cont, &tstr);
  3789. -                       }
  3790. -               }
  3791. -               switch  (crel.rsize)  {
  3792. -               default:
  3793. -                       unimpl("Data byte relocation");
  3794. -                       break;
  3795. -               case  RWORD:
  3796. -                       unimpl("data word reloc");
  3797. -                       dstr.d_type = D_WORD;
  3798. -                       dstr.d_lng = 2;
  3799. -                       setde(outf, pos+1, D_CONT, 1);
  3800. -                       break;
  3801. -               case  RLONG:
  3802. -                       dstr.d_type = D_ADDR;
  3803. -                       dstr._lng = 4;
  3804. -                       setde(outf, pos+1, D_CONT, 1);
  3805. -                       setde(outf, pos+2, D_CONT, 1);
  3806. -                       setde(outf, pos+3, D_CONT, 1);
  3807. -                       break;
  3808. -               }
  3809. -               dstr.d_relsymb->s_used++;
  3810. -               putde(outf, pos, &dstr);
  3811. -               size -= sizeof(crel);
  3812. -       }
  3813. -       return 1;
  3814. -}
  3815. -
  3816. -/*
  3817. - *     Process a symbol.
  3818. - */
  3819. -
  3820. -symbol dosymb(sy, type, val, fid)
  3821. -register  symbol  sy;
  3822. -int    type;
  3823. -long   val;
  3824. -ef_fid fid;
  3825. -{
  3826. -       t_entry tstr;
  3827. -       d_entry dstr;
  3828. -       
  3829. -       if  (!sy->s_newsym)  {
  3830. -               if  (type & EXTERN)  {
  3831. -                       (void) fprintf(stderr, "Duplicate symbol %s\n", sy->s_name);
  3832. -                       exit(10);
  3833. -               }
  3834. -               if  (++sy->s_defs > nmods)
  3835. -                       nmods = sy->s_defs;
  3836. -               sy = inventsymb("DUP");
  3837. -       }
  3838. -
  3839. -       sy->s_value = val;
  3840. -       
  3841. -       switch  (type)  {
  3842. -       default:
  3843. -               return  NULL;
  3844. -               
  3845. -       case  EXTERN|UNDEF:
  3846. -               if  (val != 0)  {
  3847. -                       sy->s_type = COMM;
  3848. -                       addit(&comtab, sy);
  3849. -               }
  3850. -               else
  3851. -                       sy->s_type = N_UNDF;
  3852. -               sy->s_glob = 1;
  3853. -               break;
  3854. -               
  3855. -       case  EXTERN|ABS:
  3856. -               sy->s_type = N_ABS;
  3857. -               sy->s_glob = 1;
  3858. -               addit(&abstab, sy);
  3859. -               break;
  3860. -               
  3861. -       case  ABS:
  3862. -               sy->s_type = N_ABS;
  3863. -               addit(&abstab, sy);
  3864. -               break;
  3865. -               
  3866. -       case  EXTERN|TEXT:
  3867. -       case  TEXT:
  3868. -               sy->s_type = N_TEXT;
  3869. -               gette(fid, val, &tstr);
  3870. -               tstr.t_bdest = 1;
  3871. -               if  (type & EXTERN)  {
  3872. -                       tstr.t_gbdest = 1;
  3873. -                       sy->s_glob = 1;
  3874. -               }
  3875. -               sy->s_link = tsr.t_lab;
  3876. -               tstr.t_lab = sy;
  3877. -               putte(fid, val, &tstr);
  3878. -               break;
  3879. -               
  3880. -       case  BSS:
  3881. -       case  EXTERN|BSS:
  3882. -               sy->s_type = N_BSS;
  3883. -               goto    datrest;
  3884. -       case  DATA:
  3885. -       case  EXTERN|DATA:
  3886. -               sy->s_type = N_DATA;
  3887. -       datrest:
  3888. -               getde(fid, val, &dstr);
  3889. -               if  (type & EXTERN)
  3890. -                       sy->s_glob = 1;
  3891. -               sy->s_link = dstr.d_lab;
  3892. -               dstr.d_lab = sy;
  3893. -               putde(fid, val, &dstr);
  3894. -               break;
  3895. -       }
  3896. -       
  3897. -       sy->s_newsym = 0;
  3898. -       return  sy;
  3899. -}
  3900. -
  3901. -/*
  3902. - *     Process relocation stuff in putative library modules.
  3903. - *     The main function of all this is to mark which bits of the text
  3904. - *     not to look at as I compare the stuff.
  3905. - *
  3906. - *     As with "rrel", return -1 error, 0 no relocation, 1 relocation.
  3907. - */
  3908. -
  3909. -int    rrell1(inf, offset, outf)
  3910. -int    inf;            /*  a.out file (possibly in library)  */
  3911. -long   offset;         /*  Offset from start of inf of a.out file  */
  3912. -ef_fid outf;           /*  Output file descriptor  */
  3913. -{
  3914. -       struct  bhdr    filhdr;
  3915. -       struct  reloc   crel;
  3916. -       t_entry tstr;
  3917. -       register  long  size;
  3918. -       long    pos;
  3919. -
  3920. -       /*
  3921. -        *      Read a.out header.
  3922. -        */
  3923. -       
  3924. -       (void) lseek(inf, offset, 0);
  3925. -
  3926. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  3927. -               return  -1;
  3928. -       if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  3929. -               return  0;
  3930. -
  3931. -       size  =  filhdr.rtsize;
  3932. -
  3933. -       (void) lseek(inf, RTEXTPOS + offset, 0);
  3934. -       while  (size >= sizeof(struct reloc))  {
  3935. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  3936. -                       return  -1;
  3937. -
  3938. -               pos = crel.rpos + outf->ef_tbase;
  3939. -               gette(outf, pos, &tstr);
  3940. -               tstr.t_reloc = crel.rsize + 1;  /*  Fidde!  YUK!!!  */
  3941. -               tstr.t_rdisp = crel.rdisp;
  3942. -               tstr.t_rptr = crel.rsegment;
  3943. -               tstr.t_isrel = 1;
  3944. -               putte(outf, pos, &tstr);
  3945. -               if  (crel.rsize == RLONG)  {
  3946. -                       gette(outf, pos+2, &tstr);
  3947. -                       tstr.t_isrel = 1;
  3948. -                       putte(outf, pos+2, &tstr);
  3949. -               }
  3950. -               size -= sizeof(crel);
  3951. -       }
  3952. -       
  3953. -       /*
  3954. -        *      Dont bother with data relocation at this stage. We'll
  3955. -        *      tie that up later.
  3956. -        */
  3957. -       
  3958. -       return 1;
  3959. -}
  3960. -
  3961. -/*
  3962. - *     Process a symbol in library file.  The extern variable trelpos gives
  3963. - *     the place in the main file where the library module is relocated.
  3964. - *     We don't know the data position until we do the final merge, perhaps
  3965. - *     not even then.
  3966. - */
  3967. -
  3968. -symbol dolsymb(sy, type, val, fid)
  3969. -register  symbol  sy;
  3970. -int    type;
  3971. -long   val;
  3972. -ef_fid fid;
  3973. -{
  3974. -       t_entry tstr;
  3975. -       
  3976. -       switch  (type)  {
  3977. -       default:
  3978. -               return  NULL;
  3979. -               
  3980. -       case  EXTERN|UNDEF:
  3981. -               if  (!sy->s_newsym)
  3982. -                       return  sy;
  3983. -               sy->s_value = val;
  3984. -               if  (val != 0)  {
  3985. -                       sy->s_type = COMM;
  3986. -                       addit(&dreltab, sy);
  3987. -               }
  3988. -               else
  3989. -                       sy->s_type = N_UNDF;
  3990. -               sy->s_glob = 1;
  3991. -               break;
  3992. -               
  3993. -       case  EXTERN|ABS:
  3994. -               if  (!sy->s_newsym)  {
  3995. -                       if  (sy->s_type != N_ABS || sy->s_value != val)
  3996. -                               lclash("abs");
  3997. -               }
  3998. -               sy->s_type = N_ABS;
  3999. -               sy->s_value = val;
  4000. -               sy->s_glob = 1;
  4001. -               addit(&abstab, sy);
  4002. -               break;
  4003. -               
  4004. -       case  EXTERN|TEXT:
  4005. -               sy->s_type = N_TEXT;
  4006. -               val += trelpos - fid-ef_tbase;
  4007. -               if  (!sy->s_newsym)  {
  4008. -                       if  (val != sy->s_value)
  4009. -                               lclash("tsym");
  4010. -                       return  sy;
  4011. -               }
  4012. -               sy->s_value = val;
  4013. -               gette(&mainfile, val, &tstr);
  4014. -               tstr.t_bdest = 1;
  4015. -               tstr.t_gbdest = 1;
  4016. -               sy->s_glob = 1;
  4017. -               sy->s_link = tstr.t_lab;
  4018. -               tstr.t_lab = sy;
  4019. -               putte(&mainfile, val, &tstr);
  4020. -               break;
  4021. -
  4022. -       case  EXTERN|BSS:
  4023. -               if  (!sy->s_newsym)
  4024. -                       return  sy;
  4025. -               sy->s_type = N_BSS;
  4026. -               sy->s_value = val - fid->ef_bbase;
  4027. -               goto    datrest;
  4028. -
  4029. -       case  EXTERN|DATA:
  4030. -               if  (!sy->s_newsym)
  4031. -                       return  sy;
  4032. -               sy->s_type = N_DATA;
  4033. -               sy->s_value = val - fid->ef_dbase;
  4034. -       datrest:
  4035. -               sy->s_glob = 1;
  4036. -               addit(&dreltab, sy);
  4037. -               break;
  4038. -       }
  4039. -       
  4040. -       sy->s_newsym = 0;
  4041. -       return  sy;
  4042. -}
  4043. -
  4044. -/*
  4045. - *     Change definition of undefined symbol as we define it.
  4046. - */
  4047. -
  4048. -void   reassign(sy, val)
  4049. -register  symbol  sy;
  4050. -long   val;
  4051. -{
  4052. -       sy->s_value = val;
  4053. -
  4054. -       if  (val < mainfile.ef_tbase)  {
  4055. -               sy->s_type = N_ABS;
  4056. -               addit(&abstab, sy);
  4057. -       }
  4058. -       else  if  (val < mainfile.ef_dbase)  {
  4059. -               t_entry tstr;
  4060. -               
  4061. -               sy->s_type = N_TEXT;
  4062. -               gette(&mainfile, val, &tstr);
  4063. -               tstr.t_bdest = 1;
  4064. -               tstr.t_gbdest = 1;
  4065. -               sy->s_glob = 1;
  4066. -               sy->s_link = tstr.t_lab;
  4067. -               tstr.t_lab = sy;
  4068. -               putte(&mainfile, val, &tstr);
  4069. -       }
  4070. -       else  {
  4071. -               d_entry dstr;
  4072. -               
  4073. -               sy->s_type = val < mainfile.ef_bbase? N_DATA: N_BSS;
  4074. -               getde(&mainfile, val &dstr);
  4075. -               sy->s_link = dstr.d_lab;
  4076. -               dstr.d_lab = sy;
  4077. -               putde(&mainfile, val, &dstr);
  4078. -       }
  4079. -}
  4080. -
  4081. -/*
  4082. - *     When we discover where bss or data come, reallocate the table.
  4083. - */
  4084. -
  4085. -void   zapdat(seg, inc)
  4086. -int    seg;
  4087. -long   inc;
  4088. -{
  4089. -       register  int   i;
  4090. -       register  symbol  csymb;
  4091. -       d_entry dent;
  4092. -       
  4093. -       for  (i = 0;  i < dreltab.c_int;  i++) {
  4094. -               csymb = dreltab.c_symb[i];
  4095. -               if  (csymb->s_type != seg)
  4096. -                       continue;
  4097. -               csymb->s_value += inc;
  4098. -               getde(&mainfile, csymb->s_value, &dent);
  4099. -               csymb->s_link = dent.d_lab;
  4100. -               dent.d_lab = csymb;
  4101. -               putde(&mainfile, csymb->s_value, &dent);
  4102. -       }
  4103. -}
  4104. -
  4105. -/*
  4106. - *     Process relocation stuff in library module which we are inserting.
  4107. - *     Horrors if something goes wrong.
  4108. - */
  4109. -
  4110. -void   rrell2(inf, offset, outf)
  4111. -int    inf;            /*  a.out file (possibly in library)  */
  4112. -long   offset;         /*  Offset from start of inf of a.out file  */
  4113. -ef_fid outf;           /*  Output file descriptor  */
  4114. -{
  4115. -       struct  bhdr    filhdr;
  4116. -       struct  reloc   crel;
  4117. -       t_entry mtstr;
  4118. -       d_entry mdstr;
  4119. -       register  long  size;
  4120. -       register  symbol  csymb;
  4121. -       long    pos, mpos, mval, lval;
  4122. -       int     dhere = 0;              /*  Mark whether bss done  */
  4123. -
  4124. -       /*
  4125. -        *      Read a.out header.
  4126. -        */
  4127. -       
  4128. -       (void) lseek(inf, offset, 0);
  4129. -
  4130. -       if  (read(inf, (char *)&filhdr, sizeof(filhdr)) != sizeof(filhdr))
  4131. -               return;
  4132. -       if  (filhdr.rtsize <= 0  &&  filhdr.rdsize <= 0)
  4133. -               return;
  4134. -
  4135. -       size  =  filhdr.rtsize;
  4136. -
  4137. -       (void) lseek(inf, RTEXTPOS + offset, 0);
  4138. -       for  (;  size >= sizeof(struct reloc);  size -= sizeof(crel))  {
  4139. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  4140. -                       lclash("rd rel");
  4141. -
  4142. -               pos = crel.rpos + outf->ef_tbase;
  4143. -               mpos = crel.rpos + trelpos;
  4144. -               gette(&mainfile, mpos, &mtstr);
  4145. -               lval = gettw(outf, pos, (int)crel.rsize+1);
  4146. -               mval = gettw(&mainfile, mpos, (int)crel.rsize+1);
  4147. -               
  4148. -               switch  (crel.rsegment)  {
  4149. -               case  RTEXT:
  4150. -                       if  (lval + trelpos - outf->ef_tbase != mval)
  4151. -                               lclash("Trel");
  4152. -                       continue;
  4153. -               case  RDATA:
  4154. -                       if  (donedrel)  {
  4155. -                               if  (lval + drelpos - outf->ef_dbase != mval)
  4156. -                                       lclash("Drel");
  4157. -                       }
  4158. -                       else  {
  4159. -                               donedrel++;
  4160. -                               drelpos = mval - lval + outf->ef_dbase;
  4161. -                       }
  4162. -                       continue;
  4163. -               case  RBSS:
  4164. -                       if  (donebrel)  {
  4165. -                               if  (lval + brelpos - outf->ef_bbase != mval)
  4166. -                                       lclash("brel");
  4167. -                       }
  4168. -                       else  {
  4169. -                               donebrel++;
  4170. -                               brelpos = mval - lval + outf->ef_bbase;
  4171. -                       }
  4172. -                       continue;
  4173. -               case  REXT:
  4174. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  4175. -                               lclash("Bad sy no");
  4176. -                       csymb = outf->ef_stvec[crel.rsymbol];
  4177. -                       if  (csymb == NULL)
  4178. -                               continue;
  4179. -                       switch  (csymb->s_type)  {
  4180. -                       case  N_UNDF:
  4181. -                               reassign(csymb, mval - lval);
  4182. -                               break;
  4183. -                       case  N_ABS:
  4184. -                               if  (lval + csymb->s_value != mval)
  4185. -                                      lclash("abs rel");
  4186. -                               break;
  4187. -                       case  N_TEXT:
  4188. -                               if  (lval + csymb->s_value != mval)
  4189. -                                       lclash("text rel");
  4190. -                               break;
  4191. -                       case  N_DATA:
  4192. -                               if  (lval + csymb->s_value != mval)
  4193. -                                       lclash("data rel");
  4194. -                               break;
  4195. -                       case  N_BSS:
  4196. -                               if  (lval + csymb->s_value != mval)
  4197. -                                       lclash("bss rel");
  4198. -                               break;
  4199. -                       case  COMM:
  4200. -                               reassign(csymb, mval - lval);
  4201. -                               break;
  4202. -                       }
  4203. -                       mtstr.t_relsymb = csymb;
  4204. -                       mtstr.t_reldisp = lval;
  4205. -                       break;
  4206. -               }
  4207. -       }
  4208. -       
  4209. -       /*
  4210. -        *      Relocate data and bss if possible.
  4211. -        */
  4212. -       
  4213. -       if  (donebrel)  {
  4214. -               zapdat(N_BSS, brelpos);
  4215. -               dhere++;
  4216. -       }
  4217. -       
  4218. -       if  (!donedrel)
  4219. -               return;
  4220. -               
  4221. -
  4222. -       zapdat(N_DATA, drelpos);
  4223. -       
  4224. -       /*
  4225. -        *      And now repeat all that for data relocations if possible
  4226. -        */
  4227. -       
  4228. -       size  =  filhdr.rdsize;
  4229. -       
  4230. -       (void) lseek(inf, RDATAPOS + offset, 0);
  4231. -       for  (;  size >= sizeof(struct reloc); size -= sizeof(crel))  {
  4232. -               if  (read(inf, (char *)&crel, sizeof(crel)) != sizeof(crel))
  4233. -                       lclash("Rd drel");
  4234. -
  4235. -               if  (crel.rsize != RLONG)
  4236. -                       continue;
  4237. -
  4238. -               pos = crel.rpos + outf->ef_dbase;
  4239. -               mpos = crel.rpos + drelpos;
  4240. -               getde(&mainfile, mpos, &mdstr);
  4241. -               lval = getdw(outf, pos, (int)crel.rsize+1);
  4242. -              mval = getdw(&mainfile, mpos, (int)crel.rsize+1);
  4243. -               switch  (crel.rsegment)  {
  4244. -               case  RTEXT:
  4245. -                       if  (lval + trelpos - outf->ef_tbase != mval)
  4246. -                               lclash("Trel-d");
  4247. -                       continue;
  4248. -               case  RDATA:
  4249. -                       if  (lval + drelpos - outf->ef_dbase != mval)
  4250. -                               lclash("Drel-d");
  4251. -                       continue;
  4252. -               case  RBSS:
  4253. -                       if  (donebrel)  {
  4254. -                               if  (lval + brelpos - outf->ef_bbase != mval)
  4255. -                                       lclash("brel");
  4256. -                       }
  4257. -                       else  {
  4258. -                               donebrel++;
  4259. -                               brelpos = mval - lval + outf->ef_bbase;
  4260. -                       }
  4261. -                       continue;
  4262. -               case  REXT:
  4263. -                       if  (crel.rsymbol >= outf->ef_stcnt)
  4264. -                               lclash("Bad sy no");
  4265. -                       csymb = outf->ef_stvec[crel.rsymbol];
  4266. -                       if  (csymb == NULL)
  4267. -                               continue;
  4268. -                       switch  (csymb->s_type)  {
  4269. -                       case  N_UNDF:
  4270. -                               reassign(csymb, mval - lval);
  4271. -                               break;
  4272. -                       case  N_ABS:
  4273. -                               if  (lval + csymb->s_value != mval)
  4274. -                                       lclash("abs rel");
  4275. -                               break;
  4276. -                       case  N_TEXT:
  4277. -                               if  (lval + csymb->s_value != mval)
  4278. -                                       lclash("text rel");
  4279. -                               break;
  4280. -                       case  N_DATA:
  4281. -                               if  (lval + csymb->s_value != mval)
  4282. -                                       lclash("data rel");
  4283. -                               break;
  4284. -                      case  N_BSS:
  4285. -                               if  (lval + csymb->s_value != mval)
  4286. -                                       lclash("bss rel");
  4287. -                               break;
  4288. -                       case  COMM:
  4289. -                               reassign(csymb, mval - lval);
  4290. -                               break;
  4291. -                       }
  4292. -                       mtstr.t_relsymb = csymb;
  4293. -                       mtstr.t_reldisp = lval;
  4294. -                       break;
  4295. -               }
  4296. -       }
  4297. -
  4298. -       if  (dhere || !donebrel)
  4299. -               return;
  4300. -
  4301. -       zapdat(N_BSS, brelpos);
  4302. -}
  4303. //GO.SYSIN DD robj.c
  4304. -- 
  4305. John M Collins          ....mcvax!ist!inset!jmc
  4306. Phone:  +44 727 57267
  4307. Snail Mail: 47 Cedarwood Drive, St Albans, Herts, AL4 0DN, England.
  4308.                          brelpos = mval - lval + outf->ef_bbase;
  4309. -                       }
  4310. -