netbsd.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* BFD back-end definitions used by all NetBSD targets.
  2. Copyright (C) 1990-2022 Free Software Foundation, Inc.
  3. This file is part of BFD, the Binary File Descriptor library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. /* Check for our machine type (part of magic number). */
  17. #ifndef MACHTYPE_OK
  18. #define MACHTYPE_OK(m) ((m) == DEFAULT_MID || (m) == M_UNKNOWN)
  19. #endif
  20. /* This is the normal load address for executables. */
  21. #define TEXT_START_ADDR TARGET_PAGE_SIZE
  22. /* NetBSD ZMAGIC has its header in the text segment. */
  23. #define N_HEADER_IN_TEXT(x) 1
  24. /* Determine if this is a shared library using the flags. */
  25. #define N_SHARED_LIB(x) (N_DYNAMIC (x))
  26. /* We have 6 bits of flags and 10 bits of machine ID. */
  27. #define N_MACHTYPE(execp) \
  28. ((enum machine_type) (((execp)->a_info >> 16) & 0x03ff))
  29. #define N_FLAGS(execp) \
  30. (((execp)->a_info >> 26) & 0x3f)
  31. #define N_SET_INFO(execp, magic, type, flags) \
  32. ((execp)->a_info = ((magic) & 0xffff) \
  33. | (((int) (type) & 0x3ff) << 16) \
  34. | (((flags) & 0x3f) << 24))
  35. #define N_SET_MACHTYPE(execp, machtype) \
  36. ((execp)->a_info = \
  37. ((execp)->a_info & 0xfb00ffff) | ((((int) (machtype)) & 0x3ff) << 16))
  38. #define N_SET_FLAGS(execp, flags) \
  39. ((execp)->a_info = \
  40. ((execp)->a_info & 0x03ffffff) | ((flags & 0x3fu) << 26))
  41. #include "sysdep.h"
  42. #include "bfd.h"
  43. #include "libbfd.h"
  44. #include "libaout.h"
  45. /* On NetBSD, the magic number is always in ntohl's "network" (big-endian)
  46. format. */
  47. #define SWAP_MAGIC(ext) bfd_getb32 (ext)
  48. /* On NetBSD, the entry point may be taken to be the start of the text
  49. section. */
  50. #define MY_entry_is_text_address 1
  51. #define MY_write_object_contents MY (write_object_contents)
  52. static bool MY (write_object_contents) (bfd *);
  53. #define MY_text_includes_header 1
  54. #include "aout-target.h"
  55. /* Write an object file.
  56. Section contents have already been written. We write the
  57. file header, symbols, and relocation. */
  58. static bool
  59. MY (write_object_contents) (bfd *abfd)
  60. {
  61. struct external_exec exec_bytes;
  62. struct internal_exec *execp = exec_hdr (abfd);
  63. /* We must make certain that the magic number has been set. This
  64. will normally have been done by set_section_contents, but only if
  65. there actually are some section contents. */
  66. if (! abfd->output_has_begun)
  67. NAME (aout, adjust_sizes_and_vmas) (abfd);
  68. obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  69. /* Magic number, maestro, please! */
  70. switch (bfd_get_arch(abfd))
  71. {
  72. case DEFAULT_ARCH:
  73. N_SET_MACHTYPE (execp, DEFAULT_MID);
  74. break;
  75. default:
  76. N_SET_MACHTYPE (execp, M_UNKNOWN);
  77. break;
  78. }
  79. /* The NetBSD magic number is always big-endian. */
  80. #ifndef TARGET_IS_BIG_ENDIAN_P
  81. /* XXX aren't there any macro to change byteorder of a word independent of
  82. the host's or target's endiannesses? */
  83. execp->a_info
  84. = (execp->a_info & 0xffu) << 24 | (execp->a_info & 0xff00) << 8
  85. | (execp->a_info & 0xff0000) >> 8 | (execp->a_info & 0xff000000) >> 24;
  86. #endif
  87. WRITE_HEADERS (abfd, execp);
  88. return true;
  89. }