Pristine Ack-5.5
[Ack-5.5.git] / util / int / proctab.c
1 /*
2         Handling the proctable
3 */
4
5 /* $Id: proctab.c,v 2.3 1994/06/24 10:48:37 ceriel Exp $ */
6
7 #include        "logging.h"
8 #include        "global.h"
9 #include        "log.h"
10 #include        "alloc.h"
11 #include        "proctab.h"
12
13 struct proc *proctab;
14 PRIVATE long pr_cnt;
15
16 init_proctab()
17 {
18         proctab = (struct proc *)
19                         Malloc(NProc * sizeof (struct proc), "proctable");
20         pr_cnt = 0;
21 }
22
23 add_proc(nloc, ep)
24         size nloc;
25         ptr ep;
26 {
27         register struct proc *pr = &proctab[pr_cnt++];
28         register struct proc *p;
29         register ptr ff = DB;
30
31         LOG((" r6 add_proc: pr_cnt = %ld, nloc = %lu, ep = %lu",
32                                 pr_cnt-1, nloc, ep));
33         if (ep > DB)
34                 fatal("procedure entry point outside text segment");
35
36         pr->pr_nloc = nloc;
37         pr->pr_ep = ep;
38         /* examine all old proc descriptors */
39         for (p = &proctab[0]; p < pr; p++) {
40                 if (    /* the old one starts earlier */
41                         p->pr_ep < pr->pr_ep
42                 &&      /* it seems to end later */
43                         p->pr_ff > pr->pr_ep
44                 ) {     /* update its limit */
45                         p->pr_ff = pr->pr_ep;
46                 }
47                 if (    /* the old one starts later */
48                         p->pr_ep > pr->pr_ep
49                 &&      /* our limit is beyond the old procedure entry point*/
50                         ff > p->pr_ep
51                 ) {     /* update our limit */
52                         ff = p->pr_ep;
53                 }
54         }
55         pr->pr_ff = ff;
56 }
57
58 end_init_proctab()
59 {
60 #ifdef  LOGGING
61         register long p;
62
63         if (!check_log(" r6"))
64                 return;
65
66         for (p = 0; p < NProc; p++) {
67                 register struct proc *pr = &proctab[p];
68
69                 LOG((" r5: proctab[%ld]: nloc = %d, ep = %lu, ff = %lu",
70                                 p, pr->pr_nloc, pr->pr_ep, pr->pr_ff));
71         }
72 #endif  /* LOGGING */
73 }
74