OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [bfd/] [aoutf1.h] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* A.out "format 1" file handling code for BFD.
2
   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
3
   Free Software Foundation, Inc.
4
   Written by Cygnus Support.
5
 
6
This file is part of BFD, the Binary File Descriptor library.
7
 
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
 
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
21
 
22
#include "bfd.h"
23
#include "sysdep.h"
24
#include "libbfd.h"
25
 
26
#include "aout/sun4.h"
27
#include "libaout.h"            /* BFD a.out internal data structures */
28
 
29
#include "aout/aout64.h"
30
#include "aout/stab_gnu.h"
31
#include "aout/ar.h"
32
 
33
/* This is needed to reject a NewsOS file, e.g. in
34
   gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
35
   I needed to add M_UNKNOWN to recognize a 68000 object, so this will
36
   probably no longer reject a NewsOS object.  <ian@cygnus.com>. */
37
#ifndef MACHTYPE_OK
38
#define MACHTYPE_OK(mtype) \
39
  (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
40
   || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
41
       && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
42
#endif
43
 
44
/*
45
The file @code{aoutf1.h} contains the code for BFD's
46
a.out back end. Control over the generated back end is given by these
47
two preprocessor names:
48
@table @code
49
@item ARCH_SIZE
50
This value should be either 32 or 64, depending upon the size of an
51
int in the target format. It changes the sizes of the structs which
52
perform the memory/disk mapping of structures.
53
 
54
The 64 bit backend may only be used if the host compiler supports 64
55
ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
56
With this name defined, @emph{all} bfd operations are performed with 64bit
57
arithmetic, not just those to a 64bit target.
58
 
59
@item TARGETNAME
60
The name put into the target vector.
61
@item
62
@end table
63
 
64
*/
65
 
66
/*SUPPRESS558*/
67
/*SUPPRESS529*/
68
 
69
#if ARCH_SIZE == 64
70
#define sunos_set_arch_mach sunos_64_set_arch_mach
71
#define sunos_write_object_contents aout_64_sunos4_write_object_contents
72
#else
73
#define sunos_set_arch_mach sunos_32_set_arch_mach
74
#define sunos_write_object_contents aout_32_sunos4_write_object_contents
75
#endif
76
 
77
static boolean sunos_merge_private_bfd_data PARAMS ((bfd *, bfd *));
78
static void sunos_set_arch_mach PARAMS ((bfd *, int));
79
static void choose_reloc_size PARAMS ((bfd *));
80
static boolean sunos_write_object_contents PARAMS ((bfd *));
81
static const bfd_target *sunos4_core_file_p PARAMS ((bfd *));
82
static char *sunos4_core_file_failing_command PARAMS ((bfd *));
83
static int sunos4_core_file_failing_signal PARAMS ((bfd *));
84
static boolean sunos4_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
85
static boolean sunos4_set_sizes PARAMS ((bfd *));
86
 
87
/* Merge backend data into the output file.
88
   This is necessary on sparclet-aout where we want the resultant machine
89
   number to be M_SPARCLET if any input file is M_SPARCLET.  */
90
 
91
#define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
92
 
93
static boolean
94
sunos_merge_private_bfd_data (ibfd, obfd)
95
     bfd *ibfd, *obfd;
96
{
97
  if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour
98
      || bfd_get_flavour (obfd) != bfd_target_aout_flavour)
99
    return true;
100
 
101
  if (bfd_get_arch (obfd) == bfd_arch_sparc)
102
    {
103
      if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
104
        bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
105
    }
106
 
107
  return true;
108
}
109
 
110
/* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
111
   depending upon ARCH_SIZE.  */
112
 
113
static void
114
sunos_set_arch_mach (abfd, machtype)
115
     bfd *abfd;
116
     int machtype;
117
{
118
  /* Determine the architecture and machine type of the object file.  */
119
  enum bfd_architecture arch;
120
  long machine;
121
  switch (machtype)
122
    {
123
 
124
    case M_UNKNOWN:
125
      /* Some Sun3s make magic numbers without cpu types in them, so
126
         we'll default to the 68000. */
127
      arch = bfd_arch_m68k;
128
      machine = bfd_mach_m68000;
129
      break;
130
 
131
    case M_68010:
132
    case M_HP200:
133
      arch = bfd_arch_m68k;
134
      machine = bfd_mach_m68010;
135
      break;
136
 
137
    case M_68020:
138
    case M_HP300:
139
      arch = bfd_arch_m68k;
140
      machine = bfd_mach_m68020;
141
      break;
142
 
143
    case M_SPARC:
144
      arch = bfd_arch_sparc;
145
      machine = 0;
146
      break;
147
 
148
    case M_SPARCLET:
149
      arch = bfd_arch_sparc;
150
      machine = bfd_mach_sparc_sparclet;
151
      break;
152
 
153
    case M_SPARCLITE_LE:
154
      arch = bfd_arch_sparc;
155
      machine = bfd_mach_sparc_sparclite_le;
156
      break;
157
 
158
    case M_386:
159
    case M_386_DYNIX:
160
      arch = bfd_arch_i386;
161
      machine = 0;
162
      break;
163
 
164
    case M_29K:
165
      arch = bfd_arch_a29k;
166
      machine = 0;
167
      break;
168
 
169
    case M_HPUX:
170
      arch = bfd_arch_m68k;
171
      machine = 0;
172
      break;
173
 
174
    default:
175
      arch = bfd_arch_obscure;
176
      machine = 0;
177
      break;
178
    }
179
  bfd_set_arch_mach (abfd, arch, machine);
180
}
181
 
182
#define SET_ARCH_MACH(ABFD, EXEC) \
183
  NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
184
  choose_reloc_size(ABFD);
185
 
186
/* Determine the size of a relocation entry, based on the architecture */
187
static void
188
choose_reloc_size (abfd)
189
     bfd *abfd;
190
{
191
  switch (bfd_get_arch (abfd))
192
    {
193
    case bfd_arch_sparc:
194
    case bfd_arch_a29k:
195
      obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
196
      break;
197
    default:
198
      obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
199
      break;
200
    }
201
}
202
 
203
/* Write an object file in SunOS format.  Section contents have
204
   already been written.  We write the file header, symbols, and
205
   relocation.  The real name of this function is either
206
   aout_64_sunos4_write_object_contents or
207
   aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE.  */
208
 
209
static boolean
210
sunos_write_object_contents (abfd)
211
     bfd *abfd;
212
{
213
  struct external_exec exec_bytes;
214
  struct internal_exec *execp = exec_hdr (abfd);
215
 
216
  /* Magic number, maestro, please!  */
217
  switch (bfd_get_arch (abfd))
218
    {
219
    case bfd_arch_m68k:
220
      switch (bfd_get_mach (abfd))
221
        {
222
        case bfd_mach_m68000:
223
          N_SET_MACHTYPE (*execp, M_UNKNOWN);
224
          break;
225
        case bfd_mach_m68010:
226
          N_SET_MACHTYPE (*execp, M_68010);
227
          break;
228
        default:
229
        case bfd_mach_m68020:
230
          N_SET_MACHTYPE (*execp, M_68020);
231
          break;
232
        }
233
      break;
234
    case bfd_arch_sparc:
235
      switch (bfd_get_mach (abfd))
236
        {
237
        case bfd_mach_sparc_sparclet:
238
          N_SET_MACHTYPE (*execp, M_SPARCLET);
239
          break;
240
        case bfd_mach_sparc_sparclite_le:
241
          N_SET_MACHTYPE (*execp, M_SPARCLITE_LE);
242
          break;
243
        default:
244
          N_SET_MACHTYPE (*execp, M_SPARC);
245
          break;
246
        }
247
      break;
248
    case bfd_arch_i386:
249
      N_SET_MACHTYPE (*execp, M_386);
250
      break;
251
    case bfd_arch_a29k:
252
      N_SET_MACHTYPE (*execp, M_29K);
253
      break;
254
    default:
255
      N_SET_MACHTYPE (*execp, M_UNKNOWN);
256
    }
257
 
258
  choose_reloc_size (abfd);
259
 
260
  N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
261
 
262
  N_SET_DYNAMIC (*execp, bfd_get_file_flags (abfd) & DYNAMIC);
263
 
264
  WRITE_HEADERS (abfd, execp);
265
 
266
  return true;
267
}
268
 
269
/* core files */
270
 
271
#define CORE_MAGIC 0x080456
272
#define CORE_NAMELEN 16
273
 
274
/* The core structure is taken from the Sun documentation.
275
  Unfortunately, they don't document the FPA structure, or at least I
276
  can't find it easily.  Fortunately the core header contains its own
277
  length.  So this shouldn't cause problems, except for c_ucode, which
278
  so far we don't use but is easy to find with a little arithmetic. */
279
 
280
/* But the reg structure can be gotten from the SPARC processor handbook.
281
  This really should be in a GNU include file though so that gdb can use
282
  the same info. */
283
struct regs
284
{
285
  int r_psr;
286
  int r_pc;
287
  int r_npc;
288
  int r_y;
289
  int r_g1;
290
  int r_g2;
291
  int r_g3;
292
  int r_g4;
293
  int r_g5;
294
  int r_g6;
295
  int r_g7;
296
  int r_o0;
297
  int r_o1;
298
  int r_o2;
299
  int r_o3;
300
  int r_o4;
301
  int r_o5;
302
  int r_o6;
303
  int r_o7;
304
};
305
 
306
/* Taken from Sun documentation: */
307
 
308
/* FIXME:  It's worse than we expect.  This struct contains TWO substructs
309
  neither of whose size we know, WITH STUFF IN BETWEEN THEM!  We can't
310
  even portably access the stuff in between!  */
311
 
312
struct external_sparc_core
313
  {
314
    int c_magic;                /* Corefile magic number */
315
    int c_len;                  /* Sizeof (struct core) */
316
#define SPARC_CORE_LEN  432
317
    int c_regs[19];             /* General purpose registers -- MACHDEP SIZE */
318
    struct external_exec c_aouthdr;     /* A.out header */
319
    int c_signo;                /* Killing signal, if any */
320
    int c_tsize;                /* Text size (bytes) */
321
    int c_dsize;                /* Data size (bytes) */
322
    int c_ssize;                /* Stack size (bytes) */
323
    char c_cmdname[CORE_NAMELEN + 1];   /* Command name */
324
    double fp_stuff[1];         /* external FPU state (size unknown by us) */
325
    /* The type "double" is critical here, for alignment.
326
    SunOS declares a struct here, but the struct's alignment
327
      is double since it contains doubles.  */
328
    int c_ucode;                /* Exception no. from u_code */
329
    /* (this member is not accessible by name since we don't
330
    portably know the size of fp_stuff.) */
331
  };
332
 
333
/* Core files generated by the BCP (the part of Solaris which allows
334
   it to run SunOS4 a.out files).  */
335
struct external_solaris_bcp_core
336
  {
337
    int c_magic;                /* Corefile magic number */
338
    int c_len;                  /* Sizeof (struct core) */
339
#define SOLARIS_BCP_CORE_LEN    456
340
    int c_regs[19];             /* General purpose registers -- MACHDEP SIZE */
341
    int c_exdata_vp;            /* exdata structure */
342
    int c_exdata_tsize;
343
    int c_exdata_dsize;
344
    int c_exdata_bsize;
345
    int c_exdata_lsize;
346
    int c_exdata_nshlibs;
347
    short c_exdata_mach;
348
    short c_exdata_mag;
349
    int c_exdata_toffset;
350
    int c_exdata_doffset;
351
    int c_exdata_loffset;
352
    int c_exdata_txtorg;
353
    int c_exdata_datorg;
354
    int c_exdata_entloc;
355
    int c_signo;                /* Killing signal, if any */
356
    int c_tsize;                /* Text size (bytes) */
357
    int c_dsize;                /* Data size (bytes) */
358
    int c_ssize;                /* Stack size (bytes) */
359
    char c_cmdname[CORE_NAMELEN + 1];   /* Command name */
360
    double fp_stuff[1];         /* external FPU state (size unknown by us) */
361
    /* The type "double" is critical here, for alignment.
362
    SunOS declares a struct here, but the struct's alignment
363
      is double since it contains doubles.  */
364
    int c_ucode;                /* Exception no. from u_code */
365
    /* (this member is not accessible by name since we don't
366
    portably know the size of fp_stuff.) */
367
  };
368
 
369
struct external_sun3_core
370
  {
371
    int c_magic;                /* Corefile magic number */
372
    int c_len;                  /* Sizeof (struct core) */
373
#define SUN3_CORE_LEN   826     /* As of SunOS 4.1.1 */
374
    int c_regs[18];             /* General purpose registers -- MACHDEP SIZE */
375
    struct external_exec c_aouthdr;     /* A.out header */
376
    int c_signo;                /* Killing signal, if any */
377
    int c_tsize;                /* Text size (bytes) */
378
    int c_dsize;                /* Data size (bytes) */
379
    int c_ssize;                /* Stack size (bytes) */
380
    char c_cmdname[CORE_NAMELEN + 1];   /* Command name */
381
    double fp_stuff[1];         /* external FPU state (size unknown by us) */
382
    /* The type "double" is critical here, for alignment.
383
    SunOS declares a struct here, but the struct's alignment
384
      is double since it contains doubles.  */
385
    int c_ucode;                /* Exception no. from u_code */
386
    /* (this member is not accessible by name since we don't
387
    portably know the size of fp_stuff.) */
388
  };
389
 
390
struct internal_sunos_core
391
  {
392
    int c_magic;                /* Corefile magic number */
393
    int c_len;                  /* Sizeof (struct core) */
394
    long c_regs_pos;            /* file offset of General purpose registers */
395
    int c_regs_size;            /* size of General purpose registers */
396
    struct internal_exec c_aouthdr;     /* A.out header */
397
    int c_signo;                /* Killing signal, if any */
398
    int c_tsize;                /* Text size (bytes) */
399
    int c_dsize;                /* Data size (bytes) */
400
    bfd_vma c_data_addr;        /* Data start (address) */
401
    int c_ssize;                /* Stack size (bytes) */
402
    bfd_vma c_stacktop;         /* Stack top (address) */
403
    char c_cmdname[CORE_NAMELEN + 1];   /* Command name */
404
    long fp_stuff_pos;          /* file offset of external FPU state (regs) */
405
    int fp_stuff_size;          /* Size of it */
406
    int c_ucode;                /* Exception no. from u_code */
407
  };
408
 
409
static void swapcore_sun3
410
  PARAMS ((bfd *, char *, struct internal_sunos_core *));
411
static void swapcore_sparc
412
  PARAMS ((bfd *, char *, struct internal_sunos_core *));
413
static void swapcore_solaris_bcp
414
  PARAMS ((bfd *, char *, struct internal_sunos_core *));
415
 
416
/* byte-swap in the Sun-3 core structure */
417
static void
418
swapcore_sun3 (abfd, ext, intcore)
419
     bfd *abfd;
420
     char *ext;
421
     struct internal_sunos_core *intcore;
422
{
423
  struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
424
 
425
  intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
426
  intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
427
  intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
428
  intcore->c_regs_size = sizeof (extcore->c_regs);
429
#if ARCH_SIZE == 64
430
  aout_64_swap_exec_header_in
431
#else
432
  aout_32_swap_exec_header_in
433
#endif
434
    (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
435
  intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
436
  intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
437
  intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
438
  intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
439
  intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
440
  memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
441
  intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff);
442
  /* FP stuff takes up whole rest of struct, except c_ucode. */
443
  intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
444
    (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff);
445
  /* Ucode is the last thing in the struct -- just before the end */
446
  intcore->c_ucode =
447
    bfd_h_get_32 (abfd,
448
    intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
449
  intcore->c_stacktop = 0x0E000000;     /* By experimentation */
450
}
451
 
452
 
453
/* byte-swap in the Sparc core structure */
454
static void
455
swapcore_sparc (abfd, ext, intcore)
456
     bfd *abfd;
457
     char *ext;
458
     struct internal_sunos_core *intcore;
459
{
460
  struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
461
 
462
  intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
463
  intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
464
  intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
465
  intcore->c_regs_size = sizeof (extcore->c_regs);
466
#if ARCH_SIZE == 64
467
  aout_64_swap_exec_header_in
468
#else
469
  aout_32_swap_exec_header_in
470
#endif
471
    (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
472
  intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
473
  intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
474
  intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
475
  intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
476
  intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
477
  memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
478
  intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff);
479
  /* FP stuff takes up whole rest of struct, except c_ucode. */
480
  intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
481
    (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff);
482
  /* Ucode is the last thing in the struct -- just before the end */
483
  intcore->c_ucode =
484
    bfd_h_get_32 (abfd,
485
    intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
486
 
487
  /* Supposedly the user stack grows downward from the bottom of kernel memory.
488
     Presuming that this remains true, this definition will work.  */
489
  /* Now sun has provided us with another challenge.  The value is different
490
     for sparc2 and sparc10 (both running SunOS 4.1.3).  We pick one or
491
     the other based on the current value of the stack pointer.  This
492
     loses (a) if the stack pointer has been clobbered, or (b) if the stack
493
     is larger than 128 megabytes.
494
 
495
     It's times like these you're glad they're switching to ELF.
496
 
497
     Note that using include files or nlist on /vmunix would be wrong,
498
     because we want the value for this core file, no matter what kind of
499
     machine we were compiled on or are running on.  */
500
#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
501
#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
502
  {
503
    bfd_vma sp = bfd_h_get_32
504
    (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
505
    if (sp < SPARC_USRSTACK_SPARC10)
506
      intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
507
    else
508
      intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
509
  }
510
}
511
 
512
/* byte-swap in the Solaris BCP core structure */
513
static void
514
swapcore_solaris_bcp (abfd, ext, intcore)
515
     bfd *abfd;
516
     char *ext;
517
     struct internal_sunos_core *intcore;
518
{
519
  struct external_solaris_bcp_core *extcore =
520
    (struct external_solaris_bcp_core *) ext;
521
 
522
  intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
523
  intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
524
  intcore->c_regs_pos = (long) (((struct external_solaris_bcp_core *) 0)->c_regs);
525
  intcore->c_regs_size = sizeof (extcore->c_regs);
526
 
527
  /* The Solaris BCP exdata structure does not contain an a_syms field,
528
     so we are unable to synthesize an internal exec header.
529
     Luckily we are able to figure out the start address of the data section,
530
     which is the only thing needed from the internal exec header,
531
     from the exdata structure.
532
 
533
     As of Solaris 2.3, BCP core files for statically linked executables
534
     are buggy. The exdata structure is not properly filled in, and
535
     the data section is written from address zero instead of the data
536
     start address.  */
537
  memset ((PTR) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
538
  intcore->c_data_addr =
539
    bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_exdata_datorg);
540
  intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
541
  intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
542
  intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
543
  intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
544
  memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
545
  intcore->fp_stuff_pos =
546
    (long) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
547
  /* FP stuff takes up whole rest of struct, except c_ucode. */
548
  intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
549
    (file_ptr) (((struct external_solaris_bcp_core *) 0)->fp_stuff);
550
  /* Ucode is the last thing in the struct -- just before the end */
551
  intcore->c_ucode =
552
    bfd_h_get_32 (abfd,
553
    intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
554
 
555
  /* Supposedly the user stack grows downward from the bottom of kernel memory.
556
     Presuming that this remains true, this definition will work.  */
557
  /* Now sun has provided us with another challenge.  The value is different
558
     for sparc2 and sparc10 (both running SunOS 4.1.3).  We pick one or
559
     the other based on the current value of the stack pointer.  This
560
     loses (a) if the stack pointer has been clobbered, or (b) if the stack
561
     is larger than 128 megabytes.
562
 
563
     It's times like these you're glad they're switching to ELF.
564
 
565
     Note that using include files or nlist on /vmunix would be wrong,
566
     because we want the value for this core file, no matter what kind of
567
     machine we were compiled on or are running on.  */
568
#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
569
#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
570
  {
571
    bfd_vma sp = bfd_h_get_32
572
    (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
573
    if (sp < SPARC_USRSTACK_SPARC10)
574
      intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
575
    else
576
      intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
577
  }
578
}
579
 
580
/* need this cast because ptr is really void * */
581
#define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
582
#define core_datasec(bfd) (core_hdr(bfd)->data_section)
583
#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
584
#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
585
#define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section)
586
 
587
/* These are stored in the bfd's tdata */
588
struct sun_core_struct
589
{
590
  struct internal_sunos_core *hdr;      /* core file header */
591
  asection *data_section;
592
  asection *stack_section;
593
  asection *reg_section;
594
  asection *reg2_section;
595
};
596
 
597
static const bfd_target *
598
sunos4_core_file_p (abfd)
599
     bfd *abfd;
600
{
601
  unsigned char longbuf[4];     /* Raw bytes of various header fields */
602
  bfd_size_type core_size;
603
  unsigned long core_mag;
604
  struct internal_sunos_core *core;
605
  char *extcore;
606
  struct mergem
607
    {
608
      struct sun_core_struct suncoredata;
609
      struct internal_sunos_core internal_sunos_core;
610
      char external_core[1];
611
    }
612
   *mergem;
613
 
614
  if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
615
      sizeof (longbuf))
616
    return 0;
617
  core_mag = bfd_h_get_32 (abfd, longbuf);
618
 
619
  if (core_mag != CORE_MAGIC)
620
    return 0;
621
 
622
  /* SunOS core headers can vary in length; second word is size; */
623
  if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
624
      sizeof (longbuf))
625
    return 0;
626
  core_size = bfd_h_get_32 (abfd, longbuf);
627
  /* Sanity check */
628
  if (core_size > 20000)
629
    return 0;
630
 
631
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
632
    return 0;
633
 
634
  mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
635
  if (mergem == NULL)
636
    return 0;
637
 
638
  extcore = mergem->external_core;
639
 
640
  if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size)
641
    {
642
      bfd_release (abfd, (char *) mergem);
643
      return 0;
644
    }
645
 
646
  /* Validate that it's a core file we know how to handle, due to sun
647
     botching the positioning of registers and other fields in a machine
648
     dependent way.  */
649
  core = &mergem->internal_sunos_core;
650
  switch (core_size)
651
    {
652
    case SPARC_CORE_LEN:
653
      swapcore_sparc (abfd, extcore, core);
654
      break;
655
    case SUN3_CORE_LEN:
656
      swapcore_sun3 (abfd, extcore, core);
657
      break;
658
    case SOLARIS_BCP_CORE_LEN:
659
      swapcore_solaris_bcp (abfd, extcore, core);
660
      break;
661
    default:
662
      bfd_set_error (bfd_error_system_call);    /* FIXME */
663
      bfd_release (abfd, (char *) mergem);
664
      return 0;
665
    }
666
 
667
  abfd->tdata.sun_core_data = &mergem->suncoredata;
668
  abfd->tdata.sun_core_data->hdr = core;
669
 
670
  /* create the sections.  This is raunchy, but bfd_close wants to reclaim
671
     them */
672
  core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
673
  if (core_stacksec (abfd) == NULL)
674
    {
675
    loser:
676
      bfd_release (abfd, (char *) mergem);
677
      return 0;
678
    }
679
  core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
680
  if (core_datasec (abfd) == NULL)
681
    {
682
    loser1:
683
      bfd_release (abfd, core_stacksec (abfd));
684
      goto loser;
685
    }
686
  core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
687
  if (core_regsec (abfd) == NULL)
688
    {
689
    loser2:
690
      bfd_release (abfd, core_datasec (abfd));
691
      goto loser1;
692
    }
693
  core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
694
  if (core_reg2sec (abfd) == NULL)
695
    {
696
      bfd_release (abfd, core_regsec (abfd));
697
      goto loser2;
698
    }
699
 
700
  core_stacksec (abfd)->name = ".stack";
701
  core_datasec (abfd)->name = ".data";
702
  core_regsec (abfd)->name = ".reg";
703
  core_reg2sec (abfd)->name = ".reg2";
704
 
705
  core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
706
  core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
707
  core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
708
  core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
709
 
710
  core_stacksec (abfd)->_raw_size = core->c_ssize;
711
  core_datasec (abfd)->_raw_size = core->c_dsize;
712
  core_regsec (abfd)->_raw_size = core->c_regs_size;
713
  core_reg2sec (abfd)->_raw_size = core->fp_stuff_size;
714
 
715
  core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
716
  core_datasec (abfd)->vma = core->c_data_addr;
717
  core_regsec (abfd)->vma = 0;
718
  core_reg2sec (abfd)->vma = 0;
719
 
720
  core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
721
  core_datasec (abfd)->filepos = core->c_len;
722
  /* We'll access the regs afresh in the core file, like any section: */
723
  core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
724
  core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
725
 
726
  /* Align to word at least */
727
  core_stacksec (abfd)->alignment_power = 2;
728
  core_datasec (abfd)->alignment_power = 2;
729
  core_regsec (abfd)->alignment_power = 2;
730
  core_reg2sec (abfd)->alignment_power = 2;
731
 
732
  abfd->sections = core_stacksec (abfd);
733
  core_stacksec (abfd)->next = core_datasec (abfd);
734
  core_datasec (abfd)->next = core_regsec (abfd);
735
  core_regsec (abfd)->next = core_reg2sec (abfd);
736
 
737
  abfd->section_count = 4;
738
 
739
  return abfd->xvec;
740
}
741
 
742
static char *
743
sunos4_core_file_failing_command (abfd)
744
     bfd *abfd;
745
{
746
  return core_hdr (abfd)->hdr->c_cmdname;
747
}
748
 
749
static int
750
sunos4_core_file_failing_signal (abfd)
751
     bfd *abfd;
752
{
753
  return core_hdr (abfd)->hdr->c_signo;
754
}
755
 
756
static boolean
757
sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
758
     bfd *core_bfd;
759
     bfd *exec_bfd;
760
{
761
  if (core_bfd->xvec != exec_bfd->xvec)
762
    {
763
      bfd_set_error (bfd_error_system_call);
764
      return false;
765
    }
766
 
767
  /* Solaris core files do not include an aouthdr. */
768
  if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
769
    return true;
770
 
771
  return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
772
                  (char *) exec_hdr (exec_bfd),
773
                  sizeof (struct internal_exec)) == 0) ? true : false;
774
}
775
 
776
#define MY_set_sizes sunos4_set_sizes
777
static boolean
778
sunos4_set_sizes (abfd)
779
     bfd *abfd;
780
{
781
  switch (bfd_get_arch (abfd))
782
    {
783
    default:
784
      return false;
785
    case bfd_arch_sparc:
786
      adata (abfd).page_size = 0x2000;
787
      adata (abfd).segment_size = 0x2000;
788
      adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
789
      return true;
790
    case bfd_arch_m68k:
791
      adata (abfd).page_size = 0x2000;
792
      adata (abfd).segment_size = 0x20000;
793
      adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
794
      return true;
795
    }
796
}
797
 
798
/* We default to setting the toolversion field to 1, as is required by
799
   SunOS.  */
800
#ifndef MY_exec_hdr_flags
801
#define MY_exec_hdr_flags 1
802
#endif
803
 
804
#ifndef MY_entry_is_text_address
805
#define MY_entry_is_text_address 0
806
#endif
807
#ifndef MY_add_dynamic_symbols
808
#define MY_add_dynamic_symbols 0
809
#endif
810
#ifndef MY_add_one_symbol
811
#define MY_add_one_symbol 0
812
#endif
813
#ifndef MY_link_dynamic_object
814
#define MY_link_dynamic_object 0
815
#endif
816
#ifndef MY_write_dynamic_symbol
817
#define MY_write_dynamic_symbol 0
818
#endif
819
#ifndef MY_check_dynamic_reloc
820
#define MY_check_dynamic_reloc 0
821
#endif
822
#ifndef MY_finish_dynamic_link
823
#define MY_finish_dynamic_link 0
824
#endif
825
 
826
static CONST struct aout_backend_data sunos4_aout_backend =
827
{
828
  0,                             /* zmagic files are not contiguous */
829
  1,                            /* text includes header */
830
  MY_entry_is_text_address,
831
  MY_exec_hdr_flags,
832
  0,                             /* default text vma */
833
  sunos4_set_sizes,
834
  0,                             /* header is counted in zmagic text */
835
  MY_add_dynamic_symbols,
836
  MY_add_one_symbol,
837
  MY_link_dynamic_object,
838
  MY_write_dynamic_symbol,
839
  MY_check_dynamic_reloc,
840
  MY_finish_dynamic_link
841
};
842
 
843
#define MY_core_file_failing_command    sunos4_core_file_failing_command
844
#define MY_core_file_failing_signal     sunos4_core_file_failing_signal
845
#define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
846
 
847
#define MY_bfd_debug_info_start         bfd_void
848
#define MY_bfd_debug_info_end           bfd_void
849
#define MY_bfd_debug_info_accumulate    \
850
                        (void (*) PARAMS ((bfd *, struct sec *))) bfd_void
851
#define MY_core_file_p                  sunos4_core_file_p
852
#define MY_write_object_contents        NAME(aout,sunos4_write_object_contents)
853
#define MY_backend_data                 &sunos4_aout_backend
854
 
855
#ifndef TARGET_IS_LITTLE_ENDIAN_P
856
#define TARGET_IS_BIG_ENDIAN_P
857
#endif
858
 
859
#include "aout-target.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.