rs6000-core.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 726 行 · 第 1/2 页
C
726 行
/* IBM RS/6000 "XCOFF" back-end for BFD. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc. FIXME: Can someone provide a transliteration of this name into ASCII? Using the following chars caused a compiler warning on HIUX (so I replaced them with octal escapes), and isn't useful without an understanding of what character set it is. Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365, and John Gilmore. Archive support from Damon A. Permezel. Contributed by IBM Corporation and Cygnus Support.This file is part of BFD, the Binary File Descriptor library.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* This port currently only handles reading object files, except when compiled on an RS/6000 host. -- no archive support, no core files. In all cases, it does not support writing. This is in a separate file from coff-rs6000.c, because it includes system include files that conflict with coff/rs6000.h. *//* Internalcoff.h and coffcode.h modify themselves based on this flag. */#define RS6000COFF_C 1/* The AIX 4.1 kernel is obviously compiled with -D_LONG_LONG, so we have to define _LONG_LONG for older versions of gcc to get the proper alignments in the user structure. */#if defined(_AIX41) && !defined(_LONG_LONG)#define _LONG_LONG#endif#include "bfd.h"#include "sysdep.h"#include "libbfd.h"#ifdef AIX_CORE/* AOUTHDR is defined by the above. We need another defn of it, from the system include files. Punt the old one and get us a new name for the typedef in the system include files. */#ifdef AOUTHDR#undef AOUTHDR#endif#define AOUTHDR second_AOUTHDR#undef SCNHDR/* ------------------------------------------------------------------------ *//* Support for core file stuff.. *//* ------------------------------------------------------------------------ */#include <sys/user.h>#define __LDINFO_PTRACE32__ /* for __ld_info32 */#define __LDINFO_PTRACE64__ /* for __ld_info64 */#include <sys/ldr.h>#include <sys/core.h>#include <sys/systemcfg.h>#define core_hdr(bfd) ((CoreHdr *) bfd->tdata.any)/* AIX 4.1 changed the names and locations of a few items in the core file. AIX 4.3 defined an entirely new structure, core_dumpx, but kept support for the previous 4.1 structure, core_dump. AIX_CORE_DUMPX_CORE is defined (by configure) on AIX 4.3+, and CORE_VERSION_1 is defined (by AIX core.h) as 2 on AIX 4.3+ and as 1 on AIX 4.1 and 4.2. AIX pre-4.1 (aka 3.x) either doesn't define CORE_VERSION_1 or else defines it as 0. */#if defined(CORE_VERSION_1) && !CORE_VERSION_1# undef CORE_VERSION_1#endif/* The following union and macros allow this module to compile on all AIX versions and to handle both core_dumpx and core_dump on 4.3+. CNEW_*() and COLD_*() macros respectively retrieve core_dumpx and core_dump values. *//* Union of 32-bit and 64-bit versions of ld_info. */typedef union {#ifdef __ld_info32 struct __ld_info32 l32; struct __ld_info64 l64;#else struct ld_info l32; struct ld_info l64;#endif} LdInfo;/* Union of old and new core dump structures. */typedef union {#ifdef AIX_CORE_DUMPX_CORE struct core_dumpx new; /* new AIX 4.3+ core dump */#else struct core_dump new; /* for simpler coding */#endif struct core_dump old; /* old AIX 4.2- core dump, still used on 4.3+ with appropriate SMIT config */} CoreHdr;/* Union of old and new vm_info structures. */#ifdef CORE_VERSION_1typedef union {#ifdef AIX_CORE_DUMPX_CORE struct vm_infox new;#else struct vm_info new;#endif struct vm_info old;} VmInfo;#endif/* Return whether CoreHdr C is in new or old format. */#ifdef AIX_CORE_DUMPX_CORE# define CORE_NEW(c) (!(c).old.c_entries)#else# define CORE_NEW(c) 0#endif/* Return the c_stackorg field from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_STACKORG(c) (c).c_stackorg#else# define CNEW_STACKORG(c) 0#endif/* Return the offset to the loader region from struct core_dump C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_LOADER(c) (c).c_loader#else# define CNEW_LOADER(c) 0#endif/* Return the offset to the loader region from struct core_dump C. */#define COLD_LOADER(c) (c).c_tab/* Return the c_lsize field from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_LSIZE(c) (c).c_lsize#else# define CNEW_LSIZE(c) 0#endif/* Return the c_dataorg field from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_DATAORG(c) (c).c_dataorg#else# define CNEW_DATAORG(c) 0#endif/* Return the c_datasize field from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_DATASIZE(c) (c).c_datasize#else# define CNEW_DATASIZE(c) 0#endif/* Return the c_impl field from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_IMPL(c) (c).c_impl#else# define CNEW_IMPL(c) 0#endif/* Return the command string from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_COMM(c) (c).c_u.U_proc.pi_comm#else# define CNEW_COMM(c) 0#endif/* Return the command string from struct core_dump C. */#ifdef CORE_VERSION_1# define COLD_COMM(c) (c).c_u.U_comm#else# define COLD_COMM(c) (c).c_u.u_comm#endif/* Return the struct __context64 pointer from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_CONTEXT64(c) (c).c_flt.hctx.r64#else# define CNEW_CONTEXT64(c) c#endif/* Return the struct mstsave pointer from struct core_dumpx C. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_MSTSAVE(c) (c).c_flt.hctx.r32#else# define CNEW_MSTSAVE(c) c#endif/* Return the struct mstsave pointer from struct core_dump C. */#ifdef CORE_VERSION_1# define COLD_MSTSAVE(c) (c).c_mst#else# define COLD_MSTSAVE(c) (c).c_u.u_save#endif/* Return whether struct core_dumpx is from a 64-bit process. */#ifdef AIX_CORE_DUMPX_CORE# define CNEW_PROC64(c) IS_PROC64(&(c).c_u.U_proc)#else# define CNEW_PROC64(c) 0#endif/* Magic end-of-stack addresses for old core dumps. This is _very_ fragile, but I don't see any easy way to get that info right now. */#ifdef CORE_VERSION_1# define COLD_STACKEND 0x2ff23000#else# define COLD_STACKEND 0x2ff80000#endif/* Size of the leading portion that old and new core dump structures have in common. */#define CORE_COMMONSZ ((int) &((struct core_dump *) 0)->c_entries \ + sizeof (((struct core_dump *) 0)->c_entries))/* Try to read into CORE the header from the core file associated with ABFD. Return success. */static booleanread_hdr (bfd *abfd, CoreHdr *core){ bfd_size_type size; if (bfd_seek (abfd, 0, SEEK_SET) != 0) return false; /* Read the leading portion that old and new core dump structures have in common. */ if (bfd_read (core, CORE_COMMONSZ, 1, abfd) != CORE_COMMONSZ) return false; /* Read the trailing portion of the structure. */ size = CORE_NEW (*core) ? sizeof (core->new) : sizeof (core->old) - CORE_COMMONSZ; return bfd_read ((char *) core + CORE_COMMONSZ, size, 1, abfd) == size;}static asection *make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos) bfd *abfd; CONST char *name; flagword flags; bfd_size_type _raw_size; bfd_vma vma; file_ptr filepos;{ asection *asect; asect = bfd_make_section_anyway (abfd, name); if (!asect) return NULL; asect->flags = flags; asect->_raw_size = _raw_size; asect->vma = vma; asect->filepos = filepos; asect->alignment_power = 8; return asect;}/* Decide if a given bfd represents a `core' file or not. There really is no magic number or anything like, in rs6000coff. */const bfd_target *rs6000coff_core_p (abfd) bfd *abfd;{ CoreHdr core; struct stat statbuf; bfd_size_type size; char *tmpptr; /* Values from new and old core structures. */ int c_flag; file_ptr c_stack, c_regoff, c_loader; bfd_size_type c_size, c_regsize, c_lsize; bfd_vma c_stackend; void *c_regptr; int proc64; if (!read_hdr (abfd, &core)) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } /* Copy fields from new or old core structure. */ if (CORE_NEW (core)) { c_flag = core.new.c_flag; c_stack = (file_ptr) core.new.c_stack; c_size = core.new.c_size; c_stackend = CNEW_STACKORG (core.new) + c_size; c_lsize = CNEW_LSIZE (core.new); c_loader = CNEW_LOADER (core.new); proc64 = CNEW_PROC64 (core.new); } else { c_flag = core.old.c_flag; c_stack = (file_ptr) core.old.c_stack; c_size = core.old.c_size; c_stackend = COLD_STACKEND; c_lsize = 0x7ffffff; c_loader = (file_ptr) COLD_LOADER (core.old); proc64 = 0; } if (proc64) { c_regsize = sizeof (CNEW_CONTEXT64 (core.new)); c_regptr = &CNEW_CONTEXT64 (core.new); } else if (CORE_NEW (core)) { c_regsize = sizeof (CNEW_MSTSAVE (core.new)); c_regptr = &CNEW_MSTSAVE (core.new); } else { c_regsize = sizeof (COLD_MSTSAVE (core.old)); c_regptr = &COLD_MSTSAVE (core.old); } c_regoff = (char *) c_regptr - (char *) &core;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?