1/* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */
2
3/*
4 * Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#ifndef _SYS_CTF_H_
20#define _SYS_CTF_H_
21
22/*
23 * CTF ``Compact ANSI-C Type Format'' ABI header file.
24 */
25
26struct ctf_header {
27 uint16_t cth_magic;
28 uint8_t cth_version;
29 uint8_t cth_flags;
30 uint32_t cth_parlabel;
31 uint32_t cth_parname;
32 uint32_t cth_lbloff;
33 uint32_t cth_objtoff;
34 uint32_t cth_funcoff;
35 uint32_t cth_typeoff;
36 uint32_t cth_stroff;
37 uint32_t cth_strlen;
38};
39
40#define CTF_F_COMPRESS (1 << 0) /* zlib compression */
41
42struct ctf_lblent {
43 uint32_t ctl_label;
44 uint32_t ctl_typeidx;
45};
46
47struct ctf_stype {
48 uint32_t cts_name;
49 uint16_t cts_info;
50 union {
51 uint16_t _size;
52 uint16_t _type;
53 } _ST;
54#define cts_size _ST._size
55#define cts_type _ST._type
56};
57
58struct ctf_type {
59 struct ctf_stype _ctt_stype;
60#define ctt_name _ctt_stype.cts_name
61#define ctt_info _ctt_stype.cts_info
62#define ctt_size _ctt_stype.cts_size
63#define ctt_type _ctt_stype.cts_type
64 uint32_t ctt_lsizehi;
65 uint32_t ctt_lsizelo;
66};
67
68struct ctf_array {
69 uint16_t cta_contents;
70 uint16_t cta_index;
71 uint32_t cta_nelems;
72};
73
74struct ctf_member {
75 uint32_t ctm_name;
76 uint16_t ctm_type;
77 uint16_t ctm_offset;
78};
79
80struct ctf_lmember {
81 struct ctf_member _ctlm_member;
82#define ctlm_name _ctlm_member.ctm_name
83#define ctlm_type _ctlm_member.ctm_type
84#define ctlm_pad0 _ctlm_member.ctm_offset
85 uint32_t ctlm_offsethi;
86 uint32_t ctlm_offsetlo;
87};
88
89#define CTF_LSTRUCT_THRESH 8192
90
91struct ctf_enum {
92 uint32_t cte_name;
93 int32_t cte_value;
94};
95
96#define CTF_MAGIC 0xcff1
97#define CTF_VERSION 2
98
99#define CTF_MAX_NAME 0x7fffffff
100#define CTF_MAX_VLEN 0x03ff
101#define CTF_MAX_SIZE 0xfffe
102#define CTF_LSIZE_SENT CTF_MAX_SIZE+1 /* sentinel for cts vs ctt */
103
104#define CTF_STRTAB_0 0
105#define CTF_STRTAB_1 1
106
107/*
108 * Info macro.
109 */
110#define CTF_INFO_VLEN(i) (((i) & CTF_MAX_VLEN))
111#define CTF_INFO_ISROOT(i) (((i) & 0x0400) >> 10)
112#define CTF_INFO_KIND(i) (((i) & 0xf800) >> 11)
113#define CTF_K_UNKNOWN 0
114#define CTF_K_INTEGER 1
115#define CTF_K_FLOAT 2
116#define CTF_K_POINTER 3
117#define CTF_K_ARRAY 4
118#define CTF_K_FUNCTION 5
119#define CTF_K_STRUCT 6
120#define CTF_K_UNION 7
121#define CTF_K_ENUM 8
122#define CTF_K_FORWARD 9
123#define CTF_K_TYPEDEF 10
124#define CTF_K_VOLATILE 11
125#define CTF_K_CONST 12
126#define CTF_K_RESTRICT 13
127#define CTF_K_MAX 31
128
129/*
130 * Integer/Float Encoding macro.
131 */
132#define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24)
133#define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16)
134#define _CTF_BITS(e) (((e) & 0x0000ffff))
135#define _CTF_DATA(encoding, offset, bits) \
136 (((encoding) << 24) | ((offset) << 16) | (bits))
137
138#define CTF_INT_ENCODING(e) _CTF_ENCODING(e)
139#define CTF_INT_SIGNED (1 << 0)
140#define CTF_INT_CHAR (1 << 1)
141#define CTF_INT_BOOL (1 << 2)
142#define CTF_INT_VARARGS (1 << 3)
143#define CTF_INT_OFFSET(e) _CTF_OFFSET(e)
144#define CTF_INT_BITS(e) _CTF_BITS(e)
145#define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b)
146
147#define CTF_FP_ENCODING(e) _CTF_ENCODING(e)
148#define CTF_FP_SINGLE 1
149#define CTF_FP_DOUBLE 2
150#define CTF_FP_CPLX 3
151#define CTF_FP_DCPLX 4
152#define CTF_FP_LDCPLX 5
153#define CTF_FP_LDOUBLE 6
154#define CTF_FP_INTRVL 7
155#define CTF_FP_DINTRVL 8
156#define CTF_FP_LDINTRVL 9
157#define CTF_FP_IMAGRY 10
158#define CTF_FP_DIMAGRY 11
159#define CTF_FP_LDIMAGRY 12
160#define CTF_FP_OFFSET(e) _CTF_OFFSET(e)
161#define CTF_FP_BITS(e) _CTF_BITS(e)
162#define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b)
163
164/*
165 * Name reference macro.
166 */
167#define CTF_NAME_STID(n) ((n) >> 31)
168#define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME)
169
170/*
171 * Type macro.
172 */
173#define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32))
174#define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s))
175#define CTF_TYPE_LSIZE(t) \
176 (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
177
178/*
179 * Member macro.
180 */
181#define CTF_LMEM_OFFSET(m) \
182 (((uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
183#define CTF_OFFSET_TO_LMEMHI(off) ((uint32_t)((uint64_t)(off) >> 32))
184#define CTF_OFFSET_TO_LMEMLO(off) ((uint32_t)(off))
185
186#endif /* _SYS_CTF_H_ */