Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. diff -r -u -N binutils-2.24/bfd/config.bfd kos32-binutils-2.24/bfd/config.bfd
  2. --- binutils-2.24/bfd/config.bfd        2013-11-04 19:33:37 +0400
  3. +++ kos32-binutils-2.24/bfd/config.bfd  2014-04-17 23:24:16 +0400
  4. @@ -6,12 +6,12 @@
  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. -#
  9. +#
  10.  # This program is distributed in the hope that it will be useful,
  11.  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  # GNU General Public License for more details.
  14. -#
  15. +#
  16.  # You should have received a copy of the GNU General Public License
  17.  # along with this program; see the file COPYING3.  If not see
  18.  # <http://www.gnu.org/licenses/>.
  19. @@ -730,6 +730,11 @@
  20.      targ_selvecs="i386pe_vec i386pei_vec bfd_elf32_i386_vec"
  21.      targ_underscore=yes
  22.      ;;
  23. +  i[3-7]86-*-kos32*)
  24. +    targ_defvec=i386aout_vec
  25. +    targ_selvecs="kos32_vec i386pe_vec i386pei_vec bfd_elf32_i386_vec"
  26. +    targ_underscore=yes
  27. +    ;;
  28.    i[3-7]86-none-*)
  29.      targ_defvec=i386coff_vec
  30.      ;;
  31. @@ -1640,12 +1645,12 @@
  32.    w65-*-*)
  33.      targ_defvec=w65_vec
  34.      ;;
  35. -    
  36. +
  37.    xgate-*-*)
  38.      targ_defvec=bfd_elf32_xgate_vec
  39.      targ_selvecs="bfd_elf32_xgate_vec"
  40.      ;;
  41. -      
  42. +
  43.    xstormy16-*-elf)
  44.      targ_defvec=bfd_elf32_xstormy16_vec
  45.      ;;
  46. diff -r -u -N binutils-2.24/bfd/configure kos32-binutils-2.24/bfd/configure
  47. --- binutils-2.24/bfd/configure 2013-12-02 13:30:30 +0400
  48. +++ kos32-binutils-2.24/bfd/configure   2014-04-18 00:30:37 +0400
  49. @@ -15453,6 +15453,7 @@
  50.      icoff_big_vec)             tb="$tb coff-i960.lo cofflink.lo" ;;
  51.      icoff_little_vec)          tb="$tb coff-i960.lo cofflink.lo" ;;
  52.      ieee_vec)                  tb="$tb ieee.lo" ;;
  53. +    kos32_vec)                  tb="$tb kos32.lo" ;;
  54.      m68k4knetbsd_vec)          tb="$tb m68k4knetbsd.lo aout32.lo" ;;
  55.      m68kaux_coff_vec)          tb="$tb coff-aux.lo coff-m68k.lo cofflink.lo" ;;
  56.      m68kcoff_vec)              tb="$tb coff-m68k.lo cofflink.lo" ;;
  57. diff -r -u -N binutils-2.24/bfd/configure.in kos32-binutils-2.24/bfd/configure.in
  58. --- binutils-2.24/bfd/configure.in      2013-12-02 13:30:28 +0400
  59. +++ kos32-binutils-2.24/bfd/configure.in        2014-04-18 00:32:16 +0400
  60. @@ -6,12 +6,12 @@
  61.  dnl it under the terms of the GNU General Public License as published by
  62.  dnl the Free Software Foundation; either version 3 of the License, or
  63.  dnl (at your option) any later version.
  64. -dnl
  65. +dnl
  66.  dnl This program is distributed in the hope that it will be useful,
  67.  dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
  68.  dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  69.  dnl GNU General Public License for more details.
  70. -dnl
  71. +dnl
  72.  dnl You should have received a copy of the GNU General Public License
  73.  dnl along with this program; see the file COPYING3.  If not see
  74.  dnl <http://www.gnu.org/licenses/>.
  75. @@ -868,7 +868,7 @@
  76.      bfd_elf64_ia64_big_vec)    tb="$tb elf64-ia64.lo elfxx-ia64.lo elf64.lo $elf"; target_size=64 ;;
  77.      bfd_elf64_ia64_hpux_big_vec) tb="$tb elf64-ia64.lo elfxx-ia64.lo elf64.lo $elf"; target_size=64 ;;
  78.      bfd_elf64_ia64_little_vec) tb="$tb elf64-ia64.lo elfxx-ia64.lo elf64.lo $elf"; target_size=64 ;;
  79. -    bfd_elf64_ia64_vms_vec)    tb="$tb elf64-ia64-vms.lo elf64-ia64.lo elfxx-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;    
  80. +    bfd_elf64_ia64_vms_vec)    tb="$tb elf64-ia64-vms.lo elf64-ia64.lo elfxx-ia64.lo elf64.lo vms-lib.lo vms-misc.lo $elf"; target_size=64 ;;
  81.      bfd_elf64_littleaarch64_vec)tb="$tb elf64-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf64.lo $elf"; target_size=64 ;;
  82.      bfd_elf32_littleaarch64_vec)tb="$tb elf32-aarch64.lo elfxx-aarch64.lo elf-ifunc.lo elf32.lo $elf"; target_size=64 ;;
  83.      bfd_elf64_little_generic_vec) tb="$tb elf64-gen.lo elf64.lo $elf"; target_size=64 ;;
  84. @@ -942,6 +942,7 @@
  85.      icoff_big_vec)             tb="$tb coff-i960.lo cofflink.lo" ;;
  86.      icoff_little_vec)          tb="$tb coff-i960.lo cofflink.lo" ;;
  87.      ieee_vec)                  tb="$tb ieee.lo" ;;
  88. +    kos32_vec)                  tb="$tb kos32.lo" ;;
  89.      m68k4knetbsd_vec)          tb="$tb m68k4knetbsd.lo aout32.lo" ;;
  90.      m68kaux_coff_vec)          tb="$tb coff-aux.lo coff-m68k.lo cofflink.lo" ;;
  91.      m68kcoff_vec)              tb="$tb coff-m68k.lo cofflink.lo" ;;
  92. diff -r -u -N binutils-2.24/bfd/kos32.c kos32-binutils-2.24/bfd/kos32.c
  93. --- binutils-2.24/bfd/kos32.c   1970-01-01 04:00:00 +0400
  94. +++ kos32-binutils-2.24/bfd/kos32.c     2014-04-18 01:09:22 +0400
  95. @@ -0,0 +1,224 @@
  96. +/* BFD back-end for MS-DOS executables.
  97. +   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002,
  98. +   2003, 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
  99. +   Written by Bryan Ford of the University of Utah.
  100. +
  101. +   Contributed by the Center for Software Science at the
  102. +   University of Utah (pa-gdb-bugs@cs.utah.edu).
  103. +
  104. +   This file is part of BFD, the Binary File Descriptor library.
  105. +
  106. +   This program is free software; you can redistribute it and/or modify
  107. +   it under the terms of the GNU General Public License as published by
  108. +   the Free Software Foundation; either version 3 of the License, or
  109. +   (at your option) any later version.
  110. +
  111. +   This program is distributed in the hope that it will be useful,
  112. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  113. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  114. +   GNU General Public License for more details.
  115. +
  116. +   You should have received a copy of the GNU General Public License
  117. +   along with this program; if not, write to the Free Software
  118. +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  119. +   MA 02110-1301, USA.  */
  120. +
  121. +
  122. +#include "sysdep.h"
  123. +#include "bfd.h"
  124. +#include "libbfd.h"
  125. +#include "libaout.h"
  126. +
  127. +#define KOS_MAGIC_0       0x554e454D
  128. +#define KOS_MAGIC_1       0x31305445
  129. +#define KOS_MAGIC_2       0x32305445
  130. +
  131. +
  132. +static int
  133. +kos32_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
  134. +                     struct bfd_link_info *info ATTRIBUTE_UNUSED)
  135. +{
  136. +  return 0;
  137. +}
  138. +
  139. +static bfd_boolean
  140. +kos32_write_object_contents (bfd *abfd)
  141. +{
  142. +  static char hdr[12];
  143. +  file_ptr outfile_size = sizeof(hdr);
  144. +  bfd_vma high_vma = 0;
  145. +  asection *sec;
  146. +
  147. +  /* Find the total size of the program on disk and in memory.  */
  148. +  for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next)
  149. +    {
  150. +      if (sec->size == 0)
  151. +        continue;
  152. +      if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
  153. +        {
  154. +         bfd_vma sec_vma = bfd_get_section_vma (abfd, sec) + sec->size;
  155. +         if (sec_vma > high_vma)
  156. +           high_vma = sec_vma;
  157. +       }
  158. +      if (bfd_get_section_flags (abfd, sec) & SEC_LOAD)
  159. +        {
  160. +         file_ptr sec_end = (sizeof (hdr)
  161. +                             + bfd_get_section_vma (abfd, sec)
  162. +                             + sec->size);
  163. +         if (sec_end > outfile_size)
  164. +           outfile_size = sec_end;
  165. +       }
  166. +    }
  167. +
  168. +  /* Make sure the program isn't too big.  */
  169. +//  if (high_vma > (bfd_vma)0xffff)
  170. +//    {
  171. +//      bfd_set_error(bfd_error_file_too_big);
  172. +//      return FALSE;
  173. +//    }
  174. +
  175. +  /* Constants.  */
  176. +  H_PUT_32 (abfd, KOS_MAGIC_0, &hdr[0]);
  177. +  H_PUT_32 (abfd, KOS_MAGIC_2, &hdr[4]);
  178. +  H_PUT_32 (abfd, 1, &hdr[8]);
  179. +
  180. +//  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
  181. +//      || bfd_bwrite (hdr, (bfd_size_type) sizeof(hdr), abfd) != sizeof(hdr))
  182. +//    return FALSE;
  183. +
  184. +  return TRUE;
  185. +}
  186. +
  187. +static bfd_boolean
  188. +kos32_set_section_contents (bfd *abfd,
  189. +                           sec_ptr section,
  190. +                           const void *location,
  191. +                           file_ptr offset,
  192. +                           bfd_size_type count)
  193. +{
  194. +
  195. +  if (count == 0)
  196. +    return TRUE;
  197. +
  198. +  section->filepos = bfd_get_section_vma (abfd, section);
  199. +
  200. +  if (bfd_get_section_flags (abfd, section) & SEC_LOAD)
  201. +    {
  202. +      if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
  203. +          || bfd_bwrite (location, count, abfd) != count)
  204. +        return FALSE;
  205. +    }
  206. +
  207. +  return TRUE;
  208. +}
  209. +
  210. +static bfd_boolean
  211. +kos32_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
  212. +{
  213. +  return TRUE;
  214. +}
  215. +
  216. +
  217. +#define kos32_make_empty_symbol _bfd_generic_make_empty_symbol
  218. +#define kos32_bfd_reloc_type_lookup aout_32_reloc_type_lookup
  219. +#define kos32_bfd_reloc_name_lookup aout_32_reloc_name_lookup
  220. +
  221. +#define kos32_close_and_cleanup _bfd_generic_close_and_cleanup
  222. +#define kos32_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
  223. +#define kos32_new_section_hook _bfd_generic_new_section_hook
  224. +#define kos32_get_section_contents _bfd_generic_get_section_contents
  225. +#define kos32_get_section_contents_in_window \
  226. +  _bfd_generic_get_section_contents_in_window
  227. +#define kos32_bfd_get_relocated_section_contents \
  228. +  bfd_generic_get_relocated_section_contents
  229. +#define kos32_bfd_relax_section bfd_generic_relax_section
  230. +#define kos32_bfd_gc_sections bfd_generic_gc_sections
  231. +#define kos32_bfd_merge_sections bfd_generic_merge_sections
  232. +#define kos32_bfd_is_group_section bfd_generic_is_group_section
  233. +#define kos32_bfd_discard_group bfd_generic_discard_group
  234. +#define kos32_section_already_linked \
  235. +  _bfd_generic_section_already_linked
  236. +#define kos32_bfd_define_common_symbol bfd_generic_define_common_symbol
  237. +#define kos32_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  238. +#define kos32_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
  239. +#define kos32_bfd_link_add_symbols _bfd_generic_link_add_symbols
  240. +#define kos32_bfd_link_just_syms _bfd_generic_link_just_syms
  241. +#define kos32_bfd_final_link _bfd_generic_final_link
  242. +#define kos32_bfd_link_split_section _bfd_generic_link_split_section
  243. +#define kos32_set_arch_mach _bfd_generic_set_arch_mach
  244. +
  245. +#define kos32_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
  246. +#define kos32_canonicalize_symtab _bfd_nosymbols_canonicalize_symtab
  247. +#define kos32_print_symbol _bfd_nosymbols_print_symbol
  248. +#define kos32_get_symbol_info _bfd_nosymbols_get_symbol_info
  249. +#define kos32_find_nearest_line _bfd_nosymbols_find_nearest_line
  250. +#define kos32_find_inliner_info _bfd_nosymbols_find_inliner_info
  251. +#define kos32_get_lineno _bfd_nosymbols_get_lineno
  252. +#define kos32_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
  253. +#define kos32_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
  254. +#define kos32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  255. +#define kos32_read_minisymbols _bfd_nosymbols_read_minisymbols
  256. +#define kos32_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
  257. +
  258. +#define kos32_canonicalize_reloc _bfd_norelocs_canonicalize_reloc
  259. +#define kos32_get_reloc_upper_bound _bfd_norelocs_get_reloc_upper_bound
  260. +#define kos32_32_bfd_link_split_section  _bfd_generic_link_split_section
  261. +
  262. +#define kos32_bfd_copy_link_hash_symbol_type _bfd_generic_copy_link_hash_symbol_type
  263. +#define kos32_bfd_lookup_section_flags        bfd_generic_lookup_section_flags
  264. +
  265. +const bfd_target kos32_vec =
  266. +  {
  267. +    "kos32",           /* name */
  268. +    bfd_target_msdos_flavour,
  269. +    BFD_ENDIAN_LITTLE,         /* target byte order */
  270. +    BFD_ENDIAN_LITTLE,         /* target headers byte order */
  271. +    (EXEC_P),                  /* object flags */
  272. +    ( SEC_HAS_CONTENTS |
  273. +      SEC_CODE | SEC_DATA | SEC_ALLOC | SEC_LOAD),    /* section flags */
  274. +    0,                         /* leading underscore */
  275. +    ' ',                       /* ar_pad_char */
  276. +    15,                                /* ar_max_namelen */
  277. +    0,              /* match priority.  */
  278. +    bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  279. +    bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  280. +    bfd_getl16, bfd_getl_signed_16, bfd_putl16,        /* data */
  281. +    bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  282. +    bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  283. +    bfd_getl16, bfd_getl_signed_16, bfd_putl16,        /* hdrs */
  284. +
  285. +    {
  286. +      _bfd_dummy_target,
  287. +      _bfd_dummy_target,               /* bfd_check_format */
  288. +      _bfd_dummy_target,
  289. +      _bfd_dummy_target,
  290. +    },
  291. +    {
  292. +      bfd_false,
  293. +      kos32_mkobject,
  294. +      _bfd_generic_mkarchive,
  295. +      bfd_false,
  296. +    },
  297. +    {                          /* bfd_write_contents */
  298. +      bfd_false,
  299. +      kos32_write_object_contents,
  300. +      _bfd_write_archive_contents,
  301. +      bfd_false,
  302. +    },
  303. +
  304. +    BFD_JUMP_TABLE_GENERIC (kos32),
  305. +    BFD_JUMP_TABLE_COPY (_bfd_generic),
  306. +    BFD_JUMP_TABLE_CORE (_bfd_nocore),
  307. +    BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
  308. +    BFD_JUMP_TABLE_SYMBOLS (kos32),
  309. +    BFD_JUMP_TABLE_RELOCS (kos32),
  310. +    BFD_JUMP_TABLE_WRITE (kos32),
  311. +    BFD_JUMP_TABLE_LINK (kos32),
  312. +    BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  313. +
  314. +    NULL,
  315. +
  316. +    (PTR) 0
  317. +  };
  318. +
  319. +
  320. diff -r -u -N binutils-2.24/bfd/targets.c kos32-binutils-2.24/bfd/targets.c
  321. --- binutils-2.24/bfd/targets.c 2013-11-04 19:33:37 +0400
  322. +++ kos32-binutils-2.24/bfd/targets.c   2014-04-18 00:47:36 +0400
  323. @@ -813,6 +813,7 @@
  324.  extern const bfd_target icoff_big_vec;
  325.  extern const bfd_target icoff_little_vec;
  326.  extern const bfd_target ieee_vec;
  327. +extern const bfd_target kos32_vec;
  328.  extern const bfd_target m68k4knetbsd_vec;
  329.  extern const bfd_target m68kaux_coff_vec;
  330.  extern const bfd_target m68kcoff_vec;
  331. diff -r -u -N binutils-2.24/config.sub kos32-binutils-2.24/config.sub
  332. --- binutils-2.24/config.sub    2013-11-26 15:37:33 +0400
  333. +++ kos32-binutils-2.24/config.sub      2014-04-17 23:31:31 +0400
  334. @@ -1376,7 +1376,7 @@
  335.               | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
  336.               | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
  337.               | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
  338. -             | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
  339. +              | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -kos32* )
  340.         # Remember, each alternative MUST END IN *, to match a version number.
  341.                 ;;
  342.         -qnx*)
  343. diff -r -u -N binutils-2.24/gas/configure.tgt kos32-binutils-2.24/gas/configure.tgt
  344. --- binutils-2.24/gas/configure.tgt     2013-11-04 19:33:37 +0400
  345. +++ kos32-binutils-2.24/gas/configure.tgt       2014-04-17 23:29:11 +0400
  346. @@ -6,12 +6,12 @@
  347.  # it under the terms of the GNU General Public License as published by
  348.  # the Free Software Foundation; either version 3 of the License, or
  349.  # (at your option) any later version.
  350. -#
  351. +#
  352.  # This program is distributed in the hope that it will be useful,
  353.  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  354.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  355.  # GNU General Public License for more details.
  356. -#
  357. +#
  358.  # You should have received a copy of the GNU General Public License
  359.  # along with this program; see the file COPYING3.  If not see
  360.  # <http://www.gnu.org/licenses/>.
  361. @@ -265,6 +265,7 @@
  362.        x86_64*)                         fmt=coff em=pep ;;
  363.        i*)                              fmt=coff em=pe ;;
  364.      esac ;;
  365. +  i386-*-kos32*)                        fmt=coff em=pe ;;
  366.    i386-*-nto-qnx*)                     fmt=elf ;;
  367.    i386-*-*nt*)                         fmt=coff em=pe ;;
  368.    i386-*-chaos)                                fmt=elf ;;
  369. @@ -445,7 +446,7 @@
  370.    vax-*-linux-*)                       fmt=elf em=linux ;;
  371.  
  372.    xstormy16-*-*)                       fmt=elf ;;
  373. -  
  374. +
  375.    xgate-*-*)                           fmt=elf ;;
  376.  
  377.    xtensa*-*-*)                         fmt=elf ;;
  378. diff -r -u -N binutils-2.24/ld/Makefile.in kos32-binutils-2.24/ld/Makefile.in
  379. --- binutils-2.24/ld/Makefile.in        2013-11-26 15:37:33 +0400
  380. +++ kos32-binutils-2.24/ld/Makefile.in  2014-04-18 02:44:03 +0400
  381. @@ -611,6 +611,7 @@
  382.         ei386bsd.c \
  383.         ei386coff.c \
  384.         ei386go32.c \
  385. +       ekos32.c \
  386.         ei386linux.c \
  387.         ei386lynx.c \
  388.         ei386mach.c \
  389. @@ -2922,6 +2923,9 @@
  390.  ei386pep.c: $(srcdir)/emulparams/i386pep.sh \
  391.    $(srcdir)/emultempl/pep.em $(srcdir)/scripttempl/pep.sc ${GEN_DEPENDS}
  392.         ${GENSCRIPTS} i386pep "$(tdir_i386pe)"
  393. +ekos32.c: $(srcdir)/emulparams/kos32.sh \
  394. +  $(srcdir)/emultempl/kos32.em $(srcdir)/scripttempl/kos32.sc ${GEN_DEPENDS}
  395. +       ${GENSCRIPTS} kos32 "$(tdir_kos32)"
  396.  elnk960.c: $(srcdir)/emulparams/lnk960.sh \
  397.    $(srcdir)/emultempl/lnk960.em $(srcdir)/scripttempl/i960.sc ${GEN_DEPENDS}
  398.         ${GENSCRIPTS} lnk960 "$(tdir_lnk960)"
  399. diff -r -u -N binutils-2.24/ld/configure.tgt kos32-binutils-2.24/ld/configure.tgt
  400. --- binutils-2.24/ld/configure.tgt      2013-11-26 15:37:33 +0400
  401. +++ kos32-binutils-2.24/ld/configure.tgt        2014-04-18 08:54:18 +0400
  402. @@ -6,12 +6,12 @@
  403.  # it under the terms of the GNU General Public License as published by
  404.  # the Free Software Foundation; either version 3 of the License, or
  405.  # (at your option) any later version.
  406. -#
  407. +#
  408.  # This program is distributed in the hope that it will be useful,
  409.  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  410.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  411.  # GNU General Public License for more details.
  412. -#
  413. +#
  414.  # You should have received a copy of the GNU General Public License
  415.  # along with this program; see the file COPYING3.  If not see
  416.  # <http://www.gnu.org/licenses/>.
  417. @@ -317,6 +317,9 @@
  418.                         test "$targ" != "$host" && LIB_PATH='${tooldir}/lib/w32api' ;;
  419.  i[3-7]86-*-mingw32*)   targ_emul=i386pe ;
  420.                         targ_extra_ofiles="deffilep.o pe-dll.o" ;;
  421. +i[3-7]86-*-kos32*)      targ_emul=i386pe ;
  422. +                        targ_extra_emuls=kos32 ;
  423. +                        targ_extra_ofiles="deffilep.o pe-dll.o" ;;
  424.  x86_64-*-pe | x86_64-*-pep) targ_emul=i386pep ;
  425.                         targ_extra_emuls=i386pe ;
  426.                         targ_extra_ofiles="deffilep.o pep-dll.o pe-dll.o" ;;
  427. @@ -752,7 +755,7 @@
  428.                         ;;
  429.  xtensa*-*-*)           targ_emul=elf32xtensa
  430.                         ;;
  431. -xgate-*-*)     targ_emul=xgateelf
  432. +xgate-*-*)     targ_emul=xgateelf
  433.                         ;;
  434.  z80-*-coff)            targ_emul=z80
  435.                         ;;
  436. @@ -783,6 +786,9 @@
  437.  hppa*64*-*-hpux11*)
  438.    NATIVE_LIB_DIRS=/usr/lib/pa20_64
  439.    ;;
  440. +i[3-7]86-*-kos32*)
  441. +  NATIVE_LIB_DIRS='/home/kos32/lib'
  442. +  ;;
  443.  
  444.  i[3-7]86-*-sysv4*)
  445.    NATIVE_LIB_DIRS='/usr/local/lib /usr/ccs/lib /lib /usr/lib'
  446. diff -r -u -N binutils-2.24/ld/emulparams/kos32.sh kos32-binutils-2.24/ld/emulparams/kos32.sh
  447. --- binutils-2.24/ld/emulparams/kos32.sh        1970-01-01 04:00:00 +0400
  448. +++ kos32-binutils-2.24/ld/emulparams/kos32.sh  2014-04-17 23:49:45 +0400
  449. @@ -0,0 +1,9 @@
  450. +ARCH=i386
  451. +SCRIPT_NAME=kos32
  452. +OUTPUT_FORMAT="kos32"
  453. +TARGET_PAGE_SIZE=0x1000
  454. +TEMPLATE_NAME=kos32
  455. +TEXT_START_ADDR=0
  456. +ENTRY="__start"
  457. +INITIAL_SYMBOL_CHAR=\"_\"
  458. +NOP=0x90909090
  459. diff -r -u -N binutils-2.24/ld/emultempl/kos32.em kos32-binutils-2.24/ld/emultempl/kos32.em
  460. --- binutils-2.24/ld/emultempl/kos32.em 1970-01-01 04:00:00 +0400
  461. +++ kos32-binutils-2.24/ld/emultempl/kos32.em   2014-04-18 02:24:20 +0400
  462. @@ -0,0 +1,281 @@
  463. +# This shell script emits a C file. -*- C -*-
  464. +#   Copyright 2007 Free Software Foundation, Inc.
  465. +#
  466. +# This file is part of the GNU Binutils.
  467. +#
  468. +# This program is free software; you can redistribute it and/or modify
  469. +# it under the terms of the GNU General Public License as published by
  470. +# the Free Software Foundation; either version 3 of the License, or
  471. +# (at your option) any later version.
  472. +#
  473. +# This program is distributed in the hope that it will be useful,
  474. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  475. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  476. +# GNU General Public License for more details.
  477. +#
  478. +# You should have received a copy of the GNU General Public License
  479. +# along with this program; if not, write to the Free Software
  480. +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  481. +# MA 02110-1301, USA.
  482. +#
  483. +
  484. +fragment <<EOF
  485. +
  486. +#include "sysdep.h"
  487. +#include "bfd.h"
  488. +#include "bfdlink.h"
  489. +#include "getopt.h"
  490. +#include "libiberty.h"
  491. +#include "filenames.h"
  492. +#include "ld.h"
  493. +#include "ldmain.h"
  494. +#include "ldexp.h"
  495. +#include "ldlang.h"
  496. +#include "ldfile.h"
  497. +#include "ldemul.h"
  498. +#include <ldgram.h>
  499. +#include "ldlex.h"
  500. +#include "ldmisc.h"
  501. +#include "ldctor.h"
  502. +#include "coff/internal.h"
  503. +
  504. +/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
  505. +   header in generic PE code.  */
  506. +#include "coff/i386.h"
  507. +#include "coff/pe.h"
  508. +
  509. +/* FIXME: This is a BFD internal header file, and we should not be
  510. +   using it here.  */
  511. +#include "../bfd/libcoff.h"
  512. +
  513. +#include "deffile.h"
  514. +#include "pe-dll.h"
  515. +#include "safe-ctype.h"
  516. +
  517. +static struct internal_extra_pe_aouthdr pe;
  518. +
  519. +static int is_underscoring (void)
  520. +{
  521. +  int u = 0;
  522. +  if (pe_leading_underscore != -1)
  523. +    return pe_leading_underscore;
  524. +  if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
  525. +    bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
  526. +
  527. +  if (u == -1)
  528. +    abort ();
  529. +  pe_leading_underscore = (u != 0 ? 1 : 0);
  530. +  return pe_leading_underscore;
  531. +}
  532. +
  533. +static void
  534. +gld_${EMULATION_NAME}_before_parse (void)
  535. +{
  536. +  ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
  537. +  config.has_shared = FALSE;
  538. +}
  539. +
  540. +
  541. +#define OPTION_STACK                   (300 + 1)
  542. +
  543. +static void
  544. +gld_${EMULATION_NAME}_add_options
  545. +  (int ns ATTRIBUTE_UNUSED,
  546. +   char **shortopts ATTRIBUTE_UNUSED,
  547. +   int nl,
  548. +   struct option **longopts,
  549. +   int nrl ATTRIBUTE_UNUSED,
  550. +   struct option **really_longopts ATTRIBUTE_UNUSED)
  551. +{
  552. +  static const struct option xtra_long[] = {
  553. +    /* KOS32 options */
  554. +    {"stack", required_argument, NULL, OPTION_STACK},
  555. +    {NULL, no_argument, NULL, 0}
  556. +  };
  557. +
  558. +  *longopts
  559. +    = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
  560. +  memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
  561. +}
  562. +
  563. +typedef struct
  564. +{
  565. +  void *ptr;
  566. +  int size;
  567. +  int value;
  568. +  char *symbol;
  569. +  int inited;
  570. +  /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
  571. +     C visible symbols can be prefixed by underscore dependent to target's
  572. +     settings.  */
  573. +  bfd_boolean is_c_symbol;
  574. +} definfo;
  575. +
  576. +/* Get symbol name dependent to kind and C visible state of
  577. +   underscore.  */
  578. +#define GET_INIT_SYMBOL_NAME(IDX) \
  579. +  (init[(IDX)].symbol \
  580. +  + ((init[(IDX)].is_c_symbol == FALSE || (is_underscoring () != 0)) ? 0 : 1))
  581. +#define D(field,symbol,def,usc)  {&pe.field,sizeof(pe.field), def, symbol, 0, usc}
  582. +
  583. +static definfo init[] =
  584. +{
  585. +  D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, FALSE),
  586. +  { NULL, 0, 0, NULL, 0, FALSE }
  587. +};
  588. +
  589. +static void
  590. +gld_${EMULATION_NAME}_list_options (FILE *file)
  591. +{
  592. +  fprintf (file, _("  --stack <size>                     Set size of the stack\n"));
  593. +}
  594. +
  595. +static void
  596. +set_pe_name (char *name, long val)
  597. +{
  598. +  int i;
  599. +
  600. +  /* Find the name and set it.  */
  601. +  for (i = 0; init[i].ptr; i++)
  602. +    {
  603. +      if (strcmp (name, init[i].symbol) == 0)
  604. +        {
  605. +          init[i].value = val;
  606. +          init[i].inited = 1;
  607. +          return;
  608. +        }
  609. +    }
  610. +  abort ();
  611. +}
  612. +
  613. +static void
  614. +set_pe_value (char *name)
  615. +{
  616. +  char *end;
  617. +
  618. +  set_pe_name (name,  strtoul (optarg, &end, 0));
  619. +
  620. +  if (end == optarg)
  621. +    einfo (_("%P%F: invalid hex number for KOS32 parameter '%s'\n"), optarg);
  622. +
  623. +  optarg = end;
  624. +}
  625. +
  626. +static bfd_boolean
  627. +gld_${EMULATION_NAME}_handle_option (int optc)
  628. +{
  629. +  switch (optc)
  630. +  {
  631. +    default:
  632. +      return FALSE;
  633. +
  634. +      /* PE options.  */
  635. +    case OPTION_STACK:
  636. +      set_pe_value ("__size_of_stack_reserve__");
  637. +      break;
  638. +  }
  639. +  return TRUE;
  640. +}
  641. +
  642. +static void
  643. +gld_${EMULATION_NAME}_set_symbols (void)
  644. +{
  645. +  /* Run through and invent symbols for all the
  646. +     names and insert the defaults. */
  647. +  int j;
  648. +
  649. +  is_underscoring ();
  650. +
  651. +  /* Glue the assignments into the abs section */
  652. +  push_stat_ptr (&abs_output_section->children);
  653. +
  654. +  for (j = 0; init[j].ptr; j++)
  655. +    {
  656. +      long val = init[j].value;
  657. +//      lang_assignment_statement_type *rv;
  658. +
  659. +      lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
  660. +                                            exp_intop (val), FALSE));
  661. +      if (init[j].size == sizeof(short))
  662. +        *(short *)init[j].ptr = val;
  663. +      else if (init[j].size == sizeof(int))
  664. +        *(int *)init[j].ptr = val;
  665. +      else if (init[j].size == sizeof(long))
  666. +        *(long *)init[j].ptr = val;
  667. +      /* This might be a long long or other special type.  */
  668. +      else if (init[j].size == sizeof(bfd_vma))
  669. +        *(bfd_vma *)init[j].ptr = val;
  670. +      else      abort();
  671. +    }
  672. +  /* Restore the pointer. */
  673. +  pop_stat_ptr ();
  674. +}
  675. +
  676. +static int
  677. +gld_${EMULATION_NAME}_find_potential_libraries
  678. +  (char *name, lang_input_statement_type *entry)
  679. +{
  680. +  return ldfile_open_file_search (name, entry, "", ".a");
  681. +}
  682. +
  683. +static char *
  684. +gld_${EMULATION_NAME}_get_script (int *isfile)
  685. +EOF
  686. +# Scripts compiled in.
  687. +# sed commands to quote an ld script as a C string.
  688. +sc="-f stringify.sed"
  689. +
  690. +fragment <<EOF
  691. +{
  692. +  *isfile = 0;
  693. +
  694. +  if (link_info.relocatable && config.build_constructors)
  695. +    return
  696. +EOF
  697. +sed $sc ldscripts/${EMULATION_NAME}.xu                  >> e${EMULATION_NAME}.c
  698. +echo '  ; else if (link_info.relocatable) return'       >> e${EMULATION_NAME}.c
  699. +sed $sc ldscripts/${EMULATION_NAME}.xr                  >> e${EMULATION_NAME}.c
  700. +echo '  ; else if (!config.text_read_only) return'      >> e${EMULATION_NAME}.c
  701. +sed $sc ldscripts/${EMULATION_NAME}.xbn                 >> e${EMULATION_NAME}.c
  702. +echo '  ; else if (!config.magic_demand_paged) return'  >> e${EMULATION_NAME}.c
  703. +sed $sc ldscripts/${EMULATION_NAME}.xn                  >> e${EMULATION_NAME}.c
  704. +if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
  705. +echo '  ; else if (link_info.pei386_auto_import == 1) return'   >> e${EMULATION_NAME}.c
  706. +sed $sc ldscripts/${EMULATION_NAME}.xa                  >> e${EMULATION_NAME}.c
  707. +fi
  708. +echo '  ; else return'                                  >> e${EMULATION_NAME}.c
  709. +sed $sc ldscripts/${EMULATION_NAME}.x                   >> e${EMULATION_NAME}.c
  710. +echo '; }'                                              >> e${EMULATION_NAME}.c
  711. +
  712. +fragment <<EOF
  713. +
  714. +
  715. +struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
  716. +{
  717. +  gld_${EMULATION_NAME}_before_parse,
  718. +  syslib_default,
  719. +  hll_default,
  720. +  after_parse_default,
  721. +  after_open_default,
  722. +  after_allocation_default,
  723. +  set_output_arch_default,
  724. +  ldemul_default_target,
  725. +  before_allocation_default,
  726. +  gld_${EMULATION_NAME}_get_script,
  727. +  "${EMULATION_NAME}",
  728. +  "${OUTPUT_FORMAT}",
  729. +  finish_default,
  730. +  NULL, /* Create output section statements.  */
  731. +  NULL, /* open dynamic archive */
  732. +  NULL,
  733. +  gld_${EMULATION_NAME}_set_symbols,
  734. +  NULL, /* parse_args */
  735. +  gld_${EMULATION_NAME}_add_options,
  736. +  gld_${EMULATION_NAME}_handle_option,
  737. +  NULL,
  738. +  gld_${EMULATION_NAME}_list_options,
  739. +  NULL,
  740. +  gld_${EMULATION_NAME}_find_potential_libraries,
  741. +  NULL  /* new_vers_pattern.  */
  742. +};
  743. +EOF
  744. diff -r -u -N binutils-2.24/ld/emultempl/pe.em kos32-binutils-2.24/ld/emultempl/pe.em
  745. --- binutils-2.24/ld/emultempl/pe.em    2013-11-26 15:37:33 +0400
  746. +++ kos32-binutils-2.24/ld/emultempl/pe.em      2014-04-18 09:35:18 +0400
  747. @@ -110,7 +110,7 @@
  748.  #undef NT_EXE_IMAGE_BASE
  749.  #undef PE_DEF_SECTION_ALIGNMENT
  750.  #undef PE_DEF_FILE_ALIGNMENT
  751. -#define NT_EXE_IMAGE_BASE              0x00010000
  752. +#define NT_EXE_IMAGE_BASE               0x00000000
  753.  
  754.  #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
  755.  #define PE_DEF_SECTION_ALIGNMENT       0x00001000
  756. @@ -522,46 +522,16 @@
  757.  {
  758.    const char *entry;
  759.    const char *initial_symbol_char;
  760. -  int i;
  761. -
  762. -  static const struct
  763. -    {
  764. -      const int value;
  765. -      const char *entry;
  766. -    }
  767. -  v[] =
  768. -    {
  769. -      { 1, "NtProcessStartup"  },
  770. -      { 2, "WinMainCRTStartup" },
  771. -      { 3, "mainCRTStartup"    },
  772. -      { 7, "__PosixProcessStartup"},
  773. -      { 9, "WinMainCRTStartup" },
  774. -      {14, "mainCRTStartup"    },
  775. -      { 0, NULL          }
  776. -    };
  777.  
  778.    /* Entry point name for arbitrary subsystem numbers.  */
  779. -  static const char default_entry[] = "mainCRTStartup";
  780. +  static const char default_entry[] = "__start";
  781.  
  782.    if (link_info.shared || dll)
  783.      {
  784. -#if defined (TARGET_IS_i386pe)
  785. -      entry = "DllMainCRTStartup@12";
  786. -#else
  787. -      entry = "DllMainCRTStartup";
  788. -#endif
  789. +      entry = "DllStartup";
  790.      }
  791.    else
  792.      {
  793. -
  794. -      for (i = 0; v[i].entry; i++)
  795. -        if (v[i].value == pe_subsystem)
  796. -          break;
  797. -
  798. -      /* If no match, use the default.  */
  799. -      if (v[i].entry != NULL)
  800. -        entry = v[i].entry;
  801. -      else
  802.          entry = default_entry;
  803.      }
  804.  
  805. @@ -2087,7 +2057,7 @@
  806.            libfoo.dll and foo.dll in the search.  */
  807.        { "lib%s.a", FALSE },
  808.        /* The 'native' spelling of an import lib name is "foo.lib".  */
  809. -      { "%s.lib", FALSE },
  810. +      { "%s.a", FALSE },
  811.  #ifdef DLL_SUPPORT
  812.        /* Try "<prefix>foo.dll" (preferred dll name, if specified).  */
  813.        {        "%s%s.dll", TRUE },
  814. @@ -2173,7 +2143,7 @@
  815.  gld_${EMULATION_NAME}_find_potential_libraries
  816.    (char *name, lang_input_statement_type *entry)
  817.  {
  818. -  return ldfile_open_file_search (name, entry, "", ".lib");
  819. +  return ldfile_open_file_search (name, entry, "", ".a");
  820.  }
  821.  
  822.  static char *
  823. diff -r -u -N binutils-2.24/ld/scripttempl/kos32.sc kos32-binutils-2.24/ld/scripttempl/kos32.sc
  824. --- binutils-2.24/ld/scripttempl/kos32.sc       1970-01-01 04:00:00 +0400
  825. +++ kos32-binutils-2.24/ld/scripttempl/kos32.sc 2014-04-18 00:38:18 +0400
  826. @@ -0,0 +1,131 @@
  827. +cat <<EOF
  828. +OUTPUT_FORMAT("${OUTPUT_FORMAT}")
  829. +OUTPUT_ARCH("${OUTPUT_ARCH}")
  830. +${LIB_SEARCH_DIRS}
  831. +ENTRY(__start)
  832. +SECTIONS
  833. +{
  834. +    .text 0x000000:
  835. +    {
  836. +        LONG(0x554e454D);
  837. +        LONG(0x32305445);
  838. +        LONG(1);
  839. +        LONG(__start);
  840. +        LONG(___iend);
  841. +        LONG(___memsize);
  842. +        LONG(___stacktop);
  843. +        LONG(___cmdline);
  844. +        LONG(___pgmname);     /*  full path    */
  845. +        LONG(0);              /*FIXME tls data */
  846. +        LONG(__idata_start)
  847. +        LONG(__idata_end)
  848. +        LONG(_main)
  849. +
  850. +        *(.init)
  851. +        *(.text)
  852. +        *(SORT(.text$*))
  853. +        *(.text.*)
  854. +        *(.glue_7t)
  855. +        *(.glue_7)
  856. +        ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
  857. +                        LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);
  858. +        ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
  859. +                        LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);
  860. +        *(.fini)
  861. +    /* ??? Why is .gcc_exc here?  */
  862. +        *(.gcc_exc)
  863. +        PROVIDE (etext = .);
  864. +        *(.gcc_except_table)
  865. +    }
  866. +
  867. +    .rdata ALIGN(16) :
  868. +    {
  869. +        *(.rdata)
  870. +        *(SORT(.rdata$*))
  871. +        ___RUNTIME_PSEUDO_RELOC_LIST__ = .;
  872. +        __RUNTIME_PSEUDO_RELOC_LIST__ = .;
  873. +        *(.rdata_runtime_pseudo_reloc)
  874. +        ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
  875. +        __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
  876. +    }
  877. +    .CRT ALIGN(16) :
  878. +    {
  879. +         ___crt_xc_start__ = . ;
  880. +        *(SORT(.CRT$XC*))  /* C initialization */
  881. +        ___crt_xc_end__ = . ;
  882. +        ___crt_xi_start__ = . ;
  883. +        *(SORT(.CRT$XI*))  /* C++ initialization */
  884. +        ___crt_xi_end__ = . ;
  885. +        ___crt_xl_start__ = . ;
  886. +        *(SORT(.CRT$XL*))  /* TLS callbacks */
  887. +    /* ___crt_xl_end__ is defined in the TLS Directory support code */
  888. +        ___crt_xp_start__ = . ;
  889. +        *(SORT(.CRT$XP*))  /* Pre-termination */
  890. +        ___crt_xp_end__ = . ;
  891. +        ___crt_xt_start__ = . ;
  892. +        *(SORT(.CRT$XT*))  /* Termination */
  893. +        ___crt_xt_end__ = . ;
  894. +    }
  895. +
  896. +   .data ALIGN(64) :
  897. +   {
  898. +        PROVIDE ( __data_start__ = .) ;
  899. +        *(.data)
  900. +        *(.data2)
  901. +        *(SORT(.data$*))
  902. +        *(.jcr)
  903. +        __CRT_MT = .;
  904. +        LONG(0);
  905. +        PROVIDE ( __data_end__ = .) ;
  906. +        *(.data_cygwin_nocopy)
  907. +        ___iend = . ;
  908. +   }
  909. +
  910. +   .idata ALIGN(16):
  911. +   {
  912. +      __idata_start = .;
  913. +      SORT(*)(.idata$2)
  914. +      SORT(*)(.idata$3)
  915. +    /* These zeroes mark the end of the import list. */
  916. +      LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
  917. +      SORT(*)(.idata$4)
  918. +      SORT(*)(.idata$5)
  919. +      SORT(*)(.idata$6)
  920. +      SORT(*)(.idata$7)
  921. +      __idata_end = .  ;
  922. +   }
  923. +
  924. +   bss ALIGN(16):
  925. +   {
  926. +        *(.bss)
  927. +        *(COMMON)
  928. +        . = ALIGN(16);
  929. +        ___cmdline = .;
  930. +        . = . + 256;
  931. +        ___pgmname = .;
  932. +        . = . + 1024 + 16;
  933. +        ___stacktop = .;
  934. +        ___memsize = . ;
  935. +   }
  936. +
  937. +  /DISCARD/ :
  938. +  {
  939. +    *(.debug$S)
  940. +    *(.debug$T)
  941. +    *(.debug$F)
  942. +    *(.drectve)
  943. +    *(.note.GNU-stack)
  944. +    *(.eh_frame)
  945. +    *(.comment)
  946. +    *(.debug_abbrev)
  947. +    *(.debug_info)
  948. +    *(.debug_line)
  949. +    *(.debug_frame)
  950. +    *(.debug_loc)
  951. +    *(.debug_pubnames)
  952. +    *(.debug_aranges)
  953. +    *(.debug_ranges)
  954. +  }
  955. +
  956. +}
  957. +EOF
  958.