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]
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
28 #ifndef _MDESC_IMPL_H_
29 #define _MDESC_IMPL_H_
36 #define LIBMD_MAGIC 0x4d61636844657363ULL /* MachDesc */
41 * Internal definitions
46 * Each MD has the following header to
47 * provide information about each section of the MD.
49 * There are 3 sections:
50 * The description list, the name table and the data block.
52 * All values are stored in network byte order.
54 * Elements in the first (description list) section are defined by their
55 * index location within the node block. An index is simply the byte offset
56 * within the block / element size (16bytes). All elements are refered to
57 * by their index, to avoid bugs related to alignment etc.
59 * The name_len field holds the storage length of an ASCII name, NOT the strlen.
60 * The header fields are written in network
65 uint32_t transport_version;
66 uint32_t node_blk_sz; /* size in bytes of the node block */
67 uint32_t name_blk_sz; /* size in bytes of the name block */
68 uint32_t data_blk_sz; /* size in bytes of the data block */
71 typedef struct md_header_s md_header_t;
75 #if defined(_BIG_ENDIAN) && !defined(lint)
76 #define mdtoh8(x) ((uint8_t)(x))
77 #define mdtoh16(x) ((uint16_t)(x))
78 #define mdtoh32(x) ((uint32_t)(x))
79 #define mdtoh64(x) ((uint64_t)(x))
81 #define htomd16(x) (x)
82 #define htomd32(x) (x)
83 #define htomd64(x) (x)
85 #define mdtoh8(x) ((uint8_t)(x))
86 extern uint16_t mdtoh16(uint16_t);
87 extern uint32_t mdtoh32(uint32_t);
88 extern uint64_t mdtoh64(uint64_t);
89 #define htomd8(x) ((uint8_t)(x))
90 extern uint16_t htomd16(uint16_t);
91 extern uint32_t htomd32(uint32_t);
92 extern uint64_t htomd64(uint64_t);
101 uint32_t name_offset; /* mde_str_cookie_t */
106 } prop_data; /* for PROP_DATA and PROP_STR */
107 uint64_t prop_val; /* for PROP_VAL */
108 uint64_t prop_idx; /* for PROP_ARC and NODE */
112 typedef struct MD_ELEMENT md_element_t;
114 struct MACHINE_DESCRIPTION {
117 void *(*allocp)(size_t);
118 void (*freep)(void *, size_t);
120 md_header_t *headerp;
132 mde_cookie_t root_node;
140 typedef struct MACHINE_DESCRIPTION md_impl_t;
142 #define MDE_TAG(_p) mdtoh8((_p)->tag)
143 #define MDE_NAME(_p) mdtoh32((_p)->name_offset)
144 #define MDE_NAME_LEN(_p) mdtoh32((_p)->name_len)
145 #define MDE_PROP_DATA_OFFSET(_p) mdtoh32((_p)->d.prop_data.offset)
146 #define MDE_PROP_DATA_LEN(_p) mdtoh32((_p)->d.prop_data.len)
147 #define MDE_PROP_VALUE(_p) mdtoh64((_p)->d.prop_val)
148 #define MDE_PROP_INDEX(_p) mdtoh64((_p)->d.prop_idx)
150 extern mde_str_cookie_t md_ident_name_str(char *);
152 extern mde_cookie_t md_find_node_prop(md_impl_t *,
162 #endif /* _MDESC_IMPL_H_ */