1224006Shrs/* Matsushita AM33/2.0 support for 32-bit GNU/Linux ELF
2224006Shrs   Copyright (C) 2003-2020 Free Software Foundation, Inc.
3224006Shrs
4224006Shrs   This file is part of BFD, the Binary File Descriptor library.
5224006Shrs
6224006Shrs   This program is free software; you can redistribute it and/or modify
7224006Shrs   it under the terms of the GNU General Public License as published by
8224006Shrs   the Free Software Foundation; either version 3 of the License, or
9224006Shrs   (at your option) any later version.
10224006Shrs
11224006Shrs   This program is distributed in the hope that it will be useful,
12224006Shrs   but WITHOUT ANY WARRANTY; without even the implied warranty of
13224006Shrs   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14224006Shrs   GNU General Public License for more details.
15224006Shrs
16224006Shrs   You should have received a copy of the GNU General Public License
17224006Shrs   along with this program; if not, write to the Free Software
18224006Shrs   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19224006Shrs   MA 02110-1301, USA.  */
20224006Shrs
21224006Shrs#include "sysdep.h"
22224006Shrs#include "bfd.h"
23224006Shrs#include "elf-bfd.h"
24224006Shrs#include "elf/mn10300.h"
25224006Shrs
26224006Shrs#define elf_symbol_leading_char 0
27224006Shrs
28224006Shrs#define TARGET_LITTLE_SYM	am33_elf32_linux_vec
29224006Shrs#define TARGET_LITTLE_NAME	"elf32-am33lin"
30224006Shrs#define ELF_ARCH		bfd_arch_mn10300
31224006Shrs#define ELF_MACHINE_CODE	EM_MN10300
32224006Shrs#define ELF_MACHINE_ALT1	EM_CYGNUS_MN10300
33224006Shrs#define ELF_MAXPAGESIZE		0x1000
34224006Shrs
35224006Shrs/* Rename global functions.  */
36224006Shrs#define _bfd_mn10300_elf_merge_private_bfd_data	 _bfd_am33_elf_merge_private_bfd_data
37224006Shrs#define _bfd_mn10300_elf_object_p		 _bfd_am33_elf_object_p
38224006Shrs#define _bfd_mn10300_elf_final_write_processing	 _bfd_am33_elf_final_write_processing
39224006Shrs
40224006Shrs/* Support for core dump NOTE sections.  */
41224006Shrsstatic bfd_boolean
42224006Shrself32_am33lin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
43224006Shrs{
44224006Shrs  int offset;
45224006Shrs  unsigned int size;
46224006Shrs
47224006Shrs  switch (note->descsz)
48224006Shrs    {
49224006Shrs      default:
50224006Shrs	return FALSE;
51224006Shrs
52224006Shrs      case 184:
53224006Shrs      case 188:		/* Linux/am33 */
54224006Shrs	/* pr_cursig */
55224006Shrs	elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
56224006Shrs
57224006Shrs	/* pr_pid */
58225519Shrs	elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
59224006Shrs
60224006Shrs	/* pr_reg */
61224006Shrs	offset = 72;
62224006Shrs	size = 112;
63224006Shrs
64224006Shrs	break;
65224006Shrs    }
66224006Shrs
67224006Shrs  /* Make a ".reg/999" section.  */
68224006Shrs  return _bfd_elfcore_make_pseudosection (abfd, ".reg", size,
69224006Shrs					  note->descpos + offset);
70224006Shrs}
71224006Shrs
72224006Shrsstatic bfd_boolean
73224006Shrself32_am33lin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
74224006Shrs{
75224006Shrs  switch (note->descsz)
76224006Shrs    {
77224006Shrs      default:
78224006Shrs	return FALSE;
79224006Shrs
80224006Shrs      case 124:		/* Linux/am33 elf_prpsinfo */
81224006Shrs	elf_tdata (abfd)->core->program
82224006Shrs	 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
83224006Shrs	elf_tdata (abfd)->core->command
84224006Shrs	 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
85224006Shrs    }
86224006Shrs
87224006Shrs  /* Note that for some reason, a spurious space is tacked
88224006Shrs     onto the end of the args in some (at least one anyway)
89224006Shrs     implementations, so strip it off if it exists.  */
90224006Shrs
91224006Shrs  {
92224006Shrs    char *command = elf_tdata (abfd)->core->command;
93224006Shrs    int n = strlen (command);
94225519Shrs
95299515Scem    if (0 < n && command[n - 1] == ' ')
96224006Shrs      command[n - 1] = '\0';
97225519Shrs  }
98299515Scem
99299515Scem  return TRUE;
100224006Shrs}
101224006Shrs
102224006Shrs#define elf_backend_grok_prstatus	elf32_am33lin_grok_prstatus
103225519Shrs#define elf_backend_grok_psinfo		elf32_am33lin_grok_psinfo
104224006Shrs
105224006Shrs#define elf_backend_linux_prpsinfo32_ugid16	TRUE
106225519Shrs
107224006Shrs#include "elf-m10300.c"
108224006Shrs