4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _MDESC_IMPL_H_
28 #define _MDESC_IMPL_H_
34 #define LIBMD_MAGIC 0x4d61636844657363ULL /* MachDesc */
39 * Internal definitions
44 * Each MD has the following header to
45 * provide information about each section of the MD.
47 * There are 3 sections:
48 * The description list, the name table and the data block.
50 * All values are stored in network byte order.
52 * Elements in the first (description list) section are defined by their
53 * index location within the node block. An index is simply the byte offset
54 * within the block / element size (16bytes). All elements are refered to
55 * by their index, to avoid bugs related to alignment etc.
57 * The name_len field holds the storage length of an ASCII name, NOT the strlen.
58 * The header fields are written in network
63 uint32_t transport_version
;
64 uint32_t node_blk_sz
; /* size in bytes of the node block */
65 uint32_t name_blk_sz
; /* size in bytes of the name block */
66 uint32_t data_blk_sz
; /* size in bytes of the data block */
69 typedef struct md_header_s md_header_t
;
73 #if defined(_BIG_ENDIAN)
74 #define mdtoh8(x) ((uint8_t)(x))
75 #define mdtoh16(x) ((uint16_t)(x))
76 #define mdtoh32(x) ((uint32_t)(x))
77 #define mdtoh64(x) ((uint64_t)(x))
79 #define htomd16(x) (x)
80 #define htomd32(x) (x)
81 #define htomd64(x) (x)
83 #define mdtoh8(x) ((uint8_t)(x))
84 #define mdtoh16(x) BSWAP_16((uint16_t)(x))
85 #define mdtoh32(x) BSWAP_32((uint32_t)(x))
86 #define mdtoh64(x) BSWAP_64((uint64_t)(x))
87 #define htomd8(x) ((uint8_t)(x))
88 #define htomd16(x) BSWAP_16((uint16_t)(x))
89 #define htomd32(x) BSWAP_32((uint32_t)(x))
90 #define htomd64(x) BSWAP_64((uint64_t)(x))
99 uint32_t name_offset
; /* mde_str_cookie_t */
104 } prop_data
; /* for PROP_DATA and PROP_STR */
105 uint64_t prop_val
; /* for PROP_VAL */
106 uint64_t prop_idx
; /* for PROP_ARC and NODE */
110 typedef struct MD_ELEMENT md_element_t
;
112 struct MACHINE_DESCRIPTION
{
115 void *(*allocp
)(size_t);
116 void (*freep
)(void *, size_t);
118 md_header_t
*headerp
;
130 mde_cookie_t root_node
;
138 typedef struct MACHINE_DESCRIPTION md_impl_t
;
140 #define MDE_TAG(_p) mdtoh8((_p)->tag)
141 #define MDE_NAME(_p) mdtoh32((_p)->name_offset)
142 #define MDE_NAME_LEN(_p) mdtoh32((_p)->name_len)
143 #define MDE_PROP_DATA_OFFSET(_p) mdtoh32((_p)->d.prop_data.offset)
144 #define MDE_PROP_DATA_LEN(_p) mdtoh32((_p)->d.prop_data.len)
145 #define MDE_PROP_VALUE(_p) mdtoh64((_p)->d.prop_val)
146 #define MDE_PROP_INDEX(_p) mdtoh64((_p)->d.prop_idx)
148 extern mde_str_cookie_t
md_ident_name_str(char *);
150 extern mde_cookie_t
md_find_node_prop(md_impl_t
*,
160 #endif /* _MDESC_IMPL_H_ */