1d4e76214Sopenharmony_ci/* libunwind - a platform-independent unwind library
2d4e76214Sopenharmony_ci   Copyright (C) 2006-2007 IBM
3d4e76214Sopenharmony_ci   Contributed by
4d4e76214Sopenharmony_ci     Corey Ashford <cjashfor@us.ibm.com>
5d4e76214Sopenharmony_ci     Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com>
6d4e76214Sopenharmony_ci
7d4e76214Sopenharmony_ciThis file is part of libunwind.
8d4e76214Sopenharmony_ci
9d4e76214Sopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining
10d4e76214Sopenharmony_cia copy of this software and associated documentation files (the
11d4e76214Sopenharmony_ci"Software"), to deal in the Software without restriction, including
12d4e76214Sopenharmony_ciwithout limitation the rights to use, copy, modify, merge, publish,
13d4e76214Sopenharmony_cidistribute, sublicense, and/or sell copies of the Software, and to
14d4e76214Sopenharmony_cipermit persons to whom the Software is furnished to do so, subject to
15d4e76214Sopenharmony_cithe following conditions:
16d4e76214Sopenharmony_ci
17d4e76214Sopenharmony_ciThe above copyright notice and this permission notice shall be
18d4e76214Sopenharmony_ciincluded in all copies or substantial portions of the Software.
19d4e76214Sopenharmony_ci
20d4e76214Sopenharmony_ciTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21d4e76214Sopenharmony_ciEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22d4e76214Sopenharmony_ciMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23d4e76214Sopenharmony_ciNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24d4e76214Sopenharmony_ciLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25d4e76214Sopenharmony_ciOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26d4e76214Sopenharmony_ciWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
27d4e76214Sopenharmony_ci
28d4e76214Sopenharmony_ci#include <stdlib.h>
29d4e76214Sopenharmony_ci
30d4e76214Sopenharmony_ci#include <libunwind_i.h>
31d4e76214Sopenharmony_ci
32d4e76214Sopenharmony_ciunw_addr_space_t
33d4e76214Sopenharmony_ciunw_create_addr_space (unw_accessors_t *a, int byte_order)
34d4e76214Sopenharmony_ci{
35d4e76214Sopenharmony_ci#ifdef UNW_LOCAL_ONLY
36d4e76214Sopenharmony_ci  return NULL;
37d4e76214Sopenharmony_ci#else
38d4e76214Sopenharmony_ci  unw_addr_space_t as;
39d4e76214Sopenharmony_ci
40d4e76214Sopenharmony_ci  /*
41d4e76214Sopenharmony_ci   * We support both big- and little-endian on Linux ppc64.
42d4e76214Sopenharmony_ci   */
43d4e76214Sopenharmony_ci  if (byte_order != 0 && byte_order_is_valid(byte_order) == 0)
44d4e76214Sopenharmony_ci    return NULL;
45d4e76214Sopenharmony_ci
46d4e76214Sopenharmony_ci  as = malloc (sizeof (*as));
47d4e76214Sopenharmony_ci  if (!as)
48d4e76214Sopenharmony_ci    return NULL;
49d4e76214Sopenharmony_ci
50d4e76214Sopenharmony_ci  memset (as, 0, sizeof (*as));
51d4e76214Sopenharmony_ci
52d4e76214Sopenharmony_ci  as->acc = *a;
53d4e76214Sopenharmony_ci
54d4e76214Sopenharmony_ci  if (byte_order == 0)
55d4e76214Sopenharmony_ci    /* use host default: */
56d4e76214Sopenharmony_ci    as->big_endian = target_is_big_endian();
57d4e76214Sopenharmony_ci  else
58d4e76214Sopenharmony_ci    as->big_endian = byte_order_is_big_endian(byte_order);
59d4e76214Sopenharmony_ci
60d4e76214Sopenharmony_ci/* FreeBSD 13 and up are always ELFv2. */
61d4e76214Sopenharmony_ci#if defined(__FreeBSD__) && __FreeBSD__ >= 13
62d4e76214Sopenharmony_ci  as->abi = UNW_PPC64_ABI_ELFv2;
63d4e76214Sopenharmony_ci#else
64d4e76214Sopenharmony_ci  /* FIXME!  There is no way to specify the ABI.
65d4e76214Sopenharmony_ci     Default to ELFv1 on big-endian and ELFv2 on little-endian.  */
66d4e76214Sopenharmony_ci  if (as->big_endian)
67d4e76214Sopenharmony_ci    as->abi = UNW_PPC64_ABI_ELFv1;
68d4e76214Sopenharmony_ci  else
69d4e76214Sopenharmony_ci    as->abi = UNW_PPC64_ABI_ELFv2;
70d4e76214Sopenharmony_ci#endif
71d4e76214Sopenharmony_ci
72d4e76214Sopenharmony_ci  return as;
73d4e76214Sopenharmony_ci#endif
74d4e76214Sopenharmony_ci}
75