1da0c48c4Sopenharmony_ci/* SPARC specific core note handling.
2da0c48c4Sopenharmony_ci   Copyright (C) 2007 Red Hat, Inc.
3da0c48c4Sopenharmony_ci   Copyright (C) 2015 Oracle, Inc.
4da0c48c4Sopenharmony_ci   This file is part of elfutils.
5da0c48c4Sopenharmony_ci
6da0c48c4Sopenharmony_ci   This file is free software; you can redistribute it and/or modify
7da0c48c4Sopenharmony_ci   it under the terms of either
8da0c48c4Sopenharmony_ci
9da0c48c4Sopenharmony_ci     * the GNU Lesser General Public License as published by the Free
10da0c48c4Sopenharmony_ci       Software Foundation; either version 3 of the License, or (at
11da0c48c4Sopenharmony_ci       your option) any later version
12da0c48c4Sopenharmony_ci
13da0c48c4Sopenharmony_ci   or
14da0c48c4Sopenharmony_ci
15da0c48c4Sopenharmony_ci     * the GNU General Public License as published by the Free
16da0c48c4Sopenharmony_ci       Software Foundation; either version 2 of the License, or (at
17da0c48c4Sopenharmony_ci       your option) any later version
18da0c48c4Sopenharmony_ci
19da0c48c4Sopenharmony_ci   or both in parallel, as here.
20da0c48c4Sopenharmony_ci
21da0c48c4Sopenharmony_ci   elfutils is distributed in the hope that it will be useful, but
22da0c48c4Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
23da0c48c4Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24da0c48c4Sopenharmony_ci   General Public License for more details.
25da0c48c4Sopenharmony_ci
26da0c48c4Sopenharmony_ci   You should have received copies of the GNU General Public License and
27da0c48c4Sopenharmony_ci   the GNU Lesser General Public License along with this program.  If
28da0c48c4Sopenharmony_ci   not, see <http://www.gnu.org/licenses/>.  */
29da0c48c4Sopenharmony_ci
30da0c48c4Sopenharmony_ci#ifdef HAVE_CONFIG_H
31da0c48c4Sopenharmony_ci# include <config.h>
32da0c48c4Sopenharmony_ci#endif
33da0c48c4Sopenharmony_ci
34da0c48c4Sopenharmony_ci#include <elf.h>
35da0c48c4Sopenharmony_ci#include <inttypes.h>
36da0c48c4Sopenharmony_ci#include <stddef.h>
37da0c48c4Sopenharmony_ci#include <stdio.h>
38da0c48c4Sopenharmony_ci#include <sys/time.h>
39da0c48c4Sopenharmony_ci
40da0c48c4Sopenharmony_ci#ifndef BITS
41da0c48c4Sopenharmony_ci# define BITS 		32
42da0c48c4Sopenharmony_ci# define BACKEND	sparc_
43da0c48c4Sopenharmony_ci#else
44da0c48c4Sopenharmony_ci# define BITS 		64
45da0c48c4Sopenharmony_ci# define BACKEND	sparc64_
46da0c48c4Sopenharmony_ci#endif
47da0c48c4Sopenharmony_ci#include "libebl_CPU.h"
48da0c48c4Sopenharmony_ci
49da0c48c4Sopenharmony_ci#define GR(at, n, dwreg)						\
50da0c48c4Sopenharmony_ci    { .offset = at * BITS/8, .regno = dwreg, .count = n, .bits = BITS }
51da0c48c4Sopenharmony_ci
52da0c48c4Sopenharmony_cistatic const Ebl_Register_Location prstatus_regs[] =
53da0c48c4Sopenharmony_ci  {
54da0c48c4Sopenharmony_ci    GR (0, 32, 0),		/* %g0-%g7, %o0-%o7, %i0-%i7 */
55da0c48c4Sopenharmony_ci#if BITS == 32
56da0c48c4Sopenharmony_ci    GR (32, 1, 65),		/* %psr */
57da0c48c4Sopenharmony_ci    GR (33, 2, 68),		/* %pc, %npc */
58da0c48c4Sopenharmony_ci    GR (35, 1, 64),		/* %y */
59da0c48c4Sopenharmony_ci    GR (36, 1, 66),		/* %wim, %tbr */
60da0c48c4Sopenharmony_ci#else
61da0c48c4Sopenharmony_ci    GR (32, 1, 82),		/* %state */
62da0c48c4Sopenharmony_ci    GR (33, 2, 80),		/* %pc, %npc */
63da0c48c4Sopenharmony_ci    GR (35, 1, 85),		/* %y */
64da0c48c4Sopenharmony_ci#endif
65da0c48c4Sopenharmony_ci  };
66da0c48c4Sopenharmony_ci#define PRSTATUS_REGS_SIZE	(BITS / 8 * (32 + (BITS == 32 ? 6 : 4)))
67da0c48c4Sopenharmony_ci
68da0c48c4Sopenharmony_cistatic const Ebl_Register_Location fpregset_regs[] =
69da0c48c4Sopenharmony_ci  {
70da0c48c4Sopenharmony_ci#if BITS == 32
71da0c48c4Sopenharmony_ci    GR (0, 32, 32),		/* %f0-%f31 */
72da0c48c4Sopenharmony_ci    /* 				   padding word */
73da0c48c4Sopenharmony_ci    GR (33, 1, 70),		/* %fsr */
74da0c48c4Sopenharmony_ci    /* 	       			   qcnt, q_entrysize, en, q, padding */
75da0c48c4Sopenharmony_ci# define FPREGSET_SIZE		(34 * 4 + 4 + 64 * 4 + 4)
76da0c48c4Sopenharmony_ci#else
77da0c48c4Sopenharmony_ci    GR (0, 32, 32),		/* %f0-%f31 */
78da0c48c4Sopenharmony_ci    GR (32, 1, 83),		/* %fsr */
79da0c48c4Sopenharmony_ci    /*  33, 1, 			   %gsr */
80da0c48c4Sopenharmony_ci    GR (34, 1, 84),		/* %fprs */
81da0c48c4Sopenharmony_ci# define FPREGSET_SIZE		(35 * 8)
82da0c48c4Sopenharmony_ci#endif
83da0c48c4Sopenharmony_ci  };
84da0c48c4Sopenharmony_ci
85da0c48c4Sopenharmony_ci#if BITS == 32
86da0c48c4Sopenharmony_ci# define ULONG			uint32_t
87da0c48c4Sopenharmony_ci# define ALIGN_ULONG		4
88da0c48c4Sopenharmony_ci# define TYPE_ULONG		ELF_T_WORD
89da0c48c4Sopenharmony_ci# define TYPE_LONG		ELF_T_SWORD
90da0c48c4Sopenharmony_ci# define UID_T			uint16_t
91da0c48c4Sopenharmony_ci# define GID_T			uint16_t
92da0c48c4Sopenharmony_ci# define ALIGN_UID_T		2
93da0c48c4Sopenharmony_ci# define ALIGN_GID_T		2
94da0c48c4Sopenharmony_ci# define TYPE_UID_T		ELF_T_HALF
95da0c48c4Sopenharmony_ci# define TYPE_GID_T		ELF_T_HALF
96da0c48c4Sopenharmony_ci#else
97da0c48c4Sopenharmony_ci# define ULONG			uint64_t
98da0c48c4Sopenharmony_ci# define ALIGN_ULONG		8
99da0c48c4Sopenharmony_ci# define TYPE_ULONG		ELF_T_XWORD
100da0c48c4Sopenharmony_ci# define TYPE_LONG		ELF_T_SXWORD
101da0c48c4Sopenharmony_ci# define UID_T			uint32_t
102da0c48c4Sopenharmony_ci# define GID_T			uint32_t
103da0c48c4Sopenharmony_ci# define ALIGN_UID_T		4
104da0c48c4Sopenharmony_ci# define ALIGN_GID_T		4
105da0c48c4Sopenharmony_ci# define TYPE_UID_T		ELF_T_WORD
106da0c48c4Sopenharmony_ci# define TYPE_GID_T		ELF_T_WORD
107da0c48c4Sopenharmony_ci# define SUSECONDS_HALF		1
108da0c48c4Sopenharmony_ci#endif
109da0c48c4Sopenharmony_ci#define PID_T			int32_t
110da0c48c4Sopenharmony_ci#define ALIGN_PID_T		4
111da0c48c4Sopenharmony_ci#define TYPE_PID_T		ELF_T_SWORD
112da0c48c4Sopenharmony_ci
113da0c48c4Sopenharmony_ci#define PRSTATUS_REGSET_ITEMS						      \
114da0c48c4Sopenharmony_ci  {									      \
115da0c48c4Sopenharmony_ci    .name = "pc", .type = ELF_T_ADDR, .format = 'x',			      \
116da0c48c4Sopenharmony_ci    .offset = offsetof (struct EBLHOOK(prstatus), pr_reg[33]),		      \
117da0c48c4Sopenharmony_ci    .group = "register", .pc_register = true				      \
118da0c48c4Sopenharmony_ci  }
119da0c48c4Sopenharmony_ci
120da0c48c4Sopenharmony_ci#include "linux-core-note.c"
121