~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to o/rel_hp300.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 1994  W. Schelter
 
3
 
 
4
This file is part of GNU Common Lisp, herein referred to as GCL
 
5
 
 
6
GCL is free software; you can redistribute it and/or modify it under
 
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GCL is distributed in the hope that it will be useful, but WITHOUT
 
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
 
14
License for more details.
 
15
 
 
16
*/
 
17
 
 
18
#undef NSYMS
 
19
#define NSYMS(hdr) count_symbols(&hdr,fp)
 
20
#ifndef dprintf
 
21
#define dprintf(a,b) 
 
22
#endif
 
23
 
 
24
/* the routines other than relocate are also used in rsym.c */
 
25
 
 
26
 
 
27
#ifdef IN_RSYM
 
28
#define temp_malloc  malloc
 
29
#else
 
30
 
 
31
relocate()
 
32
{
 
33
  char *where;
 
34
  {
 
35
                unsigned int new_value;
 
36
                where = the_start + relocation_info.r_address;
 
37
                   switch(relocation_info.r_segment){
 
38
                     case RNOOP: goto DONT;
 
39
                     case REXT: 
 
40
                                new_value = symbol_table[relocation_info.
 
41
                                                         r_symbolnum].n_value;
 
42
                                break;
 
43
                     case RDATA: 
 
44
                     case RBSS: 
 
45
                     case RTEXT: new_value= (int)start_address; break;
 
46
                     default:
 
47
                        dprintf(relocation_info.r_address = %d, 
 
48
                                relocation_info.r_address);
 
49
                        printf(
 
50
"\nRel_Info {r_segment = %x, r_symbolnum= %x, r_address = %d} -- Ignored", 
 
51
                                      relocation_info.r_segment, 
 
52
                                      relocation_info.r_symbolnum,
 
53
                                      relocation_info.r_address); 
 
54
                        fflush(stdout);
 
55
                        goto DONT;
 
56
                };
 
57
                switch(relocation_info.r_length){
 
58
                   case 0: *( char *)where = new_value + *( char *) where;
 
59
                           break;
 
60
                   case 1: *( short *)where = new_value + *( short *) where;
 
61
                           break;
 
62
                   case 2: *( long *)where = new_value + *( long *) where;
 
63
                           break;
 
64
                }
 
65
DONT:          ;
 
66
              }
 
67
}
 
68
 
 
69
 
 
70
 
 
71
#ifdef PRIVATE_FASLINK
 
72
 
 
73
int
 
74
faslink(faslfile, ldargstring)
 
75
object faslfile, ldargstring;
 
76
{
 
77
        struct exec tmpheader, faslheader;
 
78
 
 
79
        FILE *fp; TABL *table;
 
80
        char filename[MAXPATHLEN];
 
81
        char ldargstr[MAXPATHLEN];
 
82
        char stbfilename[32];
 
83
        char tmpfilename[32];
 
84
        char command[MAXPATHLEN * 2];
 
85
        char buf[BUFSIZ], *p;
 
86
        int i, res;
 
87
        object tmpfile, data;
 
88
        object *old_vs_base = vs_base;
 
89
        object *old_vs_top = vs_top;
 
90
 
 
91
        coerce_to_filename(ldargstring, ldargstr);
 
92
        coerce_to_filename(faslfile, filename);
 
93
 
 
94
/* Print out symbol table */
 
95
        sprintf(stbfilename, "/tmp/stb%d", getpid());
 
96
        fp = fopen(stbfilename, "w");
 
97
        for(i = 0, p = (char *)&tmpheader; i < sizeof(struct exec); i++) 
 
98
           *p++ = '\0';
 
99
        tmpheader.a_magic.system_id = HP9000S200_ID;
 
100
        tmpheader.a_magic.file_type = RELOC_MAGIC;
 
101
        tmpheader.a_stamp = 2;
 
102
 
 
103
        fwrite(&tmpheader, sizeof(struct exec), 1, fp);
 
104
        table = c_table.ptable;
 
105
        for(i = 0; i < c_table.length; i++) {
 
106
           struct nlist_ nbuf; int len;
 
107
           char *string; unsigned int address;
 
108
           string  =(*table)[i].string;
 
109
           address =(*table)[i].address;
 
110
           len = strlen(string);
 
111
           if (((strncmp(string,"_end",  4) == NULL) && (len == 4)) ||
 
112
               ((strncmp(string,"_etext",6) == NULL) && (len == 6)) ||
 
113
               ((strncmp(string,"_edata",6) == NULL) && (len == 6)))
 
114
              continue;
 
115
           nbuf.n_value = address; 
 
116
           nbuf.n_type = N_ABS | N_EXT;
 
117
           nbuf.n_length = len;
 
118
           nbuf.n_almod  = 0;
 
119
           nbuf.n_unused = 0;
 
120
           fwrite(&nbuf,sizeof(nbuf),1,fp);
 
121
           fwrite(string,len,1,fp);
 
122
           tmpheader.a_lesyms += sizeof(struct nlist_) + len;
 
123
        }
 
124
        fseek(fp,0,0);
 
125
        fwrite(&tmpheader, sizeof(struct exec), 1, fp);
 
126
        fclose(fp);
 
127
 
 
128
        sprintf(tmpfilename, "/tmp/fasl%d", getpid());
 
129
        sprintf(command,
 
130
                "ld -r -o %s -x %s %s %s -h _edata -h _etext", 
 
131
                 tmpfilename,
 
132
                 stbfilename,
 
133
                 filename,
 
134
                 ldargstr);
 
135
 
 
136
        if (system(command) != 0)
 
137
                FEerror("The linkage editor failed.", 0);
 
138
 
 
139
        unlink(stbfilename);
 
140
 
 
141
        faslfile = open_stream(faslfile, smm_input, Cnil, sKerror);
 
142
        vs_push(faslfile);
 
143
        fp = faslfile->sm.sm_fp;
 
144
        fread(&faslheader, sizeof(faslheader), 1, fp);
 
145
        fseek(fp,RDATA_OFFSET(faslheader)+faslheader.a_drsize,0);
 
146
 
 
147
        { FILE *tmpfp;
 
148
          int fpthis,fpend;
 
149
          fpthis = ftell(fp);
 
150
          fseek(fp,0,2);
 
151
          fpend  = ftell(fp);
 
152
          fseek(fp,fpthis,0);
 
153
          tmpfp = fopen(tmpfilename,"a+");
 
154
          fseek(tmpfp,0,2);
 
155
          filecpy(tmpfp,fp,fpend-fpthis);
 
156
          fclose(tmpfp);
 
157
        }
 
158
 
 
159
        close_stream(faslfile);
 
160
 
 
161
        tmpfile = make_simple_string(tmpfilename);
 
162
        vs_push(tmpfile);
 
163
 
 
164
        res = fasload(tmpfile);
 
165
 
 
166
        unlink(tmpfilename);
 
167
        vs_base = old_vs_base;
 
168
        vs_top = old_vs_top;
 
169
 
 
170
        return(res);
 
171
}
 
172
#endif
 
173
#endif
 
174
 
 
175
 
 
176
count_symbols(phdr,fp)
 
177
struct exec *phdr;
 
178
FILE *fp;
 
179
{int nsyms,i;
 
180
 fseek(fp,(int)(LESYM_OFFSET(*phdr)), 0);
 
181
 for(i = phdr->a_lesyms, nsyms = 0; i > 0; nsyms++) {
 
182
   struct syment tmp;
 
183
   fread((char *)&tmp, SYMESZ, 1, fp); i -= SYMESZ;
 
184
   fseek(fp,(int)tmp.n_length,1); i -= tmp.n_length;
 
185
 }
 
186
 return (nsyms);
 
187
}
 
188
 
 
189
 
 
190
#define READ_IN_STRING_TABLE(fp,size) \
 
191
  read_in_string_table(fp,&fileheader,size,OUR_ALLOCA(size))
 
192
 
 
193
char *
 
194
read_in_string_table(fp,pfileheader,string_size,buf)
 
195
FILE *fp;
 
196
struct exec *pfileheader;
 
197
int string_size ;
 
198
char *buf;
 
199
 
 
200
{
 
201
  char *p,*ans; 
 
202
  int slen,i,j;
 
203
  ans=p = buf;
 
204
  dprintf( string table leng = %d, string_size);
 
205
  fseek(fp,LESYM_OFFSET(*pfileheader),  0);
 
206
  for (i = pfileheader->a_lesyms,j=0;  i > 0;  i=i- slen-SYMESZ)
 
207
    {
 
208
      fseek(fp,SYMESZ, 1);
 
209
      slen = symbol_table[j++].n_length;
 
210
      fread(p,slen,1,fp);
 
211
      *((p)+slen) = '\0';
 
212
      dprintf( p  %s , p);
 
213
      dprintf( slen  %d,slen);
 
214
      
 
215
      p += slen + 1;
 
216
    }
 
217
  return (ans);
 
218
}