1cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng/* Describe known core note formats.
2cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Copyright (C) 2007 Red Hat, Inc.
3cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   This file is part of Red Hat elfutils.
4cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
5cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Red Hat elfutils is free software; you can redistribute it and/or modify
6cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   it under the terms of the GNU General Public License as published by the
7cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Free Software Foundation; version 2 of the License.
8cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
9cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Red Hat elfutils is distributed in the hope that it will be useful, but
10cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   WITHOUT ANY WARRANTY; without even the implied warranty of
11cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   General Public License for more details.
13cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
14cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   You should have received a copy of the GNU General Public License along
15cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   with Red Hat elfutils; if not, write to the Free Software Foundation,
16cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
17cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
18cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   In addition, as a special exception, Red Hat, Inc. gives You the
19cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   additional right to link the code of Red Hat elfutils with code licensed
20cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   under any Open Source Initiative certified open source license
21cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   (http://www.opensource.org/licenses/index.php) which requires the
22cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   distribution of source code with any binary distribution and to
23cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   distribute linked combinations of the two.  Non-GPL Code permitted under
24cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   this exception must only link to the code of Red Hat elfutils through
25cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   those well defined interfaces identified in the file named EXCEPTION
26cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   found in the source code files (the "Approved Interfaces").  The files
27cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   of Non-GPL Code may instantiate templates or use macros or inline
28cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   functions from the Approved Interfaces without causing the resulting
29cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   work to be covered by the GNU General Public License.  Only Red Hat,
30cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Inc. may make changes or additions to the list of Approved Interfaces.
31cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Red Hat's grant of this exception is conditioned upon your not adding
32cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   any new exceptions.  If you wish to add a new Approved Interface or
33cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   exception, please contact Red Hat.  You must obey the GNU General Public
34cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   License in all respects for all of the Red Hat elfutils code and other
35cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   code used in conjunction with Red Hat elfutils except the Non-GPL Code
36cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   covered by this exception.  If you modify this file, you may extend this
37cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   exception to your version of the file, but you are not obligated to do
38cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   so.  If you do not wish to provide this exception without modification,
39cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   you must delete this exception statement from your version and license
40cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   this file solely under the GPL without exception.
41cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
42cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Red Hat elfutils is an included package of the Open Invention Network.
43cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   An included package of the Open Invention Network is a package for which
44cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Open Invention Network licensees cross-license their patents.  No patent
45cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   license is granted, either expressly or impliedly, by designation as an
46cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   included package.  Should you wish to participate in the Open Invention
47cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   Network licensing program, please visit www.openinventionnetwork.com
48cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng   <http://www.openinventionnetwork.com>.  */
49441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project
50441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#ifdef HAVE_CONFIG_H
51441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project# include <config.h>
52441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#endif
53441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project
54cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng#include <assert.h>
55cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng#include <byteswap.h>
56cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng#include <endian.h>
57441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <inttypes.h>
58441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <stdio.h>
59441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <stddef.h>
60441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project#include <libeblP.h>
61441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project
62441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project
63cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Chengint
64cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Chengebl_core_note (ebl, n_type, descsz,
65cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	       regs_offset, nregloc, reglocs, nitems, items)
66441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project     Ebl *ebl;
67cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     GElf_Word n_type;
68cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     GElf_Word descsz;
69cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     GElf_Word *regs_offset;
70cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     size_t *nregloc;
71cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     const Ebl_Register_Location **reglocs;
72cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     size_t *nitems;
73cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng     const Ebl_Core_Item **items;
74441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project{
75cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng  int result = ebl->core_note (n_type, descsz, regs_offset, nregloc, reglocs,
76cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng			       nitems, items);
77cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng  if (result == 0)
78cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng    {
79cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng      /* The machine specific function did not know this type.  */
80cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
81cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng      *regs_offset = 0;
82cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng      *nregloc = 0;
83cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng      *reglocs = NULL;
84cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng      switch (n_type)
85cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	{
86cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng#define ITEMS(type, table)				\
87cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	  case type:					\
88cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	    *items = table;				\
89cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	    *nitems = sizeof table / sizeof table[0];	\
90cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	    result = 1;					\
91cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	    break
92cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng
93cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	  static const Ebl_Core_Item platform[] =
94cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	    {
95441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project	      {
96cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng		.name = "Platform",
97cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng		.type = ELF_T_BYTE, .count = 0, .format = 's'
98441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project	      }
99cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	    };
100cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	  ITEMS (NT_PLATFORM, platform);
101441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project
102cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng#undef	ITEMS
103cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng	}
104cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng    }
105441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project
106cc6695e2684ce93cdf8bd2da63d55d2cf49ff076Ben Cheng  return result;
107441f72d43a9b550baa779fc82f70816da5f74f0eThe Android Open Source Project}
108