Pristine Ack-5.5
[Ack-5.5.git] / util / ceg / ce_back / obj_back / data.c
1 #include <system.h>
2 #include <out.h>
3 #include "back.h"
4 #include "mach.h"
5
6 /* Global datastructures : 
7  * - 'text_area' points to the text segment, 'text' points to first free
8  *    entry in the text segment.
9  * - 'data_area' points to the data segment, 'data' points to the first free
10  *    entry in the data segmnet.
11  * - 'string_area' points to the string area, 'string' points to the first free
12  *    entry in the string area.
13  * - 'reloc_info' points to the relocation table, 'relo' points to the first 
14  *    free entry in the relocation table.
15  * - 'symbol_table' points to the symbol table, 'nname' is the index of the 
16  *    first free entry in the symbol_table. If pointers were used it is a pain
17  *    to do a realloc on the symbol table, because all pointers in the 
18  *    relocation table to the symbol table have to be updated.
19  * - The bss segment contains only one vaue, so its enough to count the
20  *   the bytes wanted.
21  * - The 'size_*' variables count the number of entries in each segment.
22  * - 'cur_seg' contains the number of the segment to be filled.
23  *   (see "back.h")
24  */
25
26
27 char            *text_area,
28                 *data_area,
29                 *string_area,
30                 *text, *data, *string;
31 struct outrelo  *reloc_info, *relo;
32 struct outname  *symbol_table;
33
34
35 int             cur_seg = -1 , nname = 0;
36 long            nbss = 0, size_text, size_data, size_reloc, size_symbol,
37                 size_string, text_cnt, data_cnt;
38
39
40 put2(sect,addr,w)
41 char *sect;
42 long addr;
43 int w;
44 {
45 #ifdef BYTES_REVERSED
46         put1(sect, addr, (w>>8));
47         put1(sect, addr+1, w);
48 #else
49         put1(sect, addr, w);
50         put1(sect, addr+1, (w>>8));
51 #endif
52 }
53
54
55 put4(sect,addr,l)
56 char *sect;
57 long addr;
58 long l;
59 {
60 #ifdef WORDS_REVERSED
61         put2(sect,addr,(int) (l>>16));
62         put2(sect,addr+2,(int) l);
63 #else
64         put2(sect,addr,(int) l);
65         put2(sect,addr+2,(int) (l>>16));
66 #endif
67 }
68
69 int get2(sect,addr)
70 char *sect;
71 long addr;
72 {
73 #ifdef BYTES_REVERSED
74         return (get1(sect,addr) << 8) | (get1(sect,addr+1) & 255);
75 #else
76         return (get1(sect,addr+1) << 8) | (get1(sect,addr) & 255);
77 #endif
78 }
79
80         
81 long get4(sect,addr)
82 char *sect;
83 long addr;
84 {
85 #ifdef WORDS_REVERSED
86         return ((long)get2(sect,addr) << 16) | (get2(sect, addr+2) & 65535L);
87 #else
88         return ((long)get2(sect,addr+2) << 16) | (get2(sect, addr) & 65535L);
89 #endif
90 }