1*0687c322Sjasper /* $OpenBSD: dw.h,v 1.2 2017/08/11 14:58:56 jasper Exp $ */ 2*0687c322Sjasper 3192095f7Smpi /* 4192095f7Smpi * Copyright (c) 2016 Martin Pieuchot 5192095f7Smpi * 6192095f7Smpi * Permission to use, copy, modify, and distribute this software for any 7192095f7Smpi * purpose with or without fee is hereby granted, provided that the above 8192095f7Smpi * copyright notice and this permission notice appear in all copies. 9192095f7Smpi * 10192095f7Smpi * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11192095f7Smpi * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12192095f7Smpi * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13192095f7Smpi * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14192095f7Smpi * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15192095f7Smpi * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16192095f7Smpi * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17192095f7Smpi */ 18192095f7Smpi 19192095f7Smpi #ifndef _DW_H_ 20192095f7Smpi #define _DW_H_ 21192095f7Smpi 22192095f7Smpi struct dwbuf { 23192095f7Smpi const char *buf; 24192095f7Smpi size_t len; 25192095f7Smpi }; 26192095f7Smpi 27192095f7Smpi struct dwattr { 28192095f7Smpi SIMPLEQ_ENTRY(dwattr) dat_next; 29192095f7Smpi uint64_t dat_attr; 30192095f7Smpi uint64_t dat_form; 31192095f7Smpi }; 32192095f7Smpi 33192095f7Smpi struct dwaval { 34192095f7Smpi SIMPLEQ_ENTRY(dwaval) dav_next; 35192095f7Smpi struct dwattr *dav_dat; /* corresponding attribute */ 36192095f7Smpi union { 37192095f7Smpi struct dwbuf _buf; 38192095f7Smpi struct { 39192095f7Smpi const char *_str; 40192095f7Smpi union { 41192095f7Smpi uint64_t _u64; 42192095f7Smpi int64_t _s64; 43192095f7Smpi uint32_t _u32; 44192095f7Smpi uint16_t _u16; 45192095f7Smpi uint8_t _u8; 46192095f7Smpi } _T; 47192095f7Smpi } _V; 48192095f7Smpi } AV; 49192095f7Smpi #define dav_buf AV._buf 50192095f7Smpi #define dav_str AV._V._str 51192095f7Smpi #define dav_u64 AV._V._T._u64 52192095f7Smpi #define dav_s64 AV._V._T._s64 53192095f7Smpi #define dav_u32 AV._V._T._u32 54192095f7Smpi #define dav_u16 AV._V._T._u16 55192095f7Smpi #define dav_u8 AV._V._T._u8 56192095f7Smpi }; 57192095f7Smpi 58192095f7Smpi SIMPLEQ_HEAD(dwaval_queue, dwaval); 59192095f7Smpi 60192095f7Smpi struct dwdie { 61192095f7Smpi SIMPLEQ_ENTRY(dwdie) die_next; 62192095f7Smpi struct dwabbrev *die_dab; 63192095f7Smpi size_t die_offset; 64192095f7Smpi uint8_t die_lvl; 65192095f7Smpi struct dwaval_queue die_avals; 66192095f7Smpi }; 67192095f7Smpi 68192095f7Smpi SIMPLEQ_HEAD(dwdie_queue, dwdie); 69192095f7Smpi 70192095f7Smpi struct dwabbrev { 71192095f7Smpi SIMPLEQ_ENTRY(dwabbrev) dab_next; 72192095f7Smpi uint64_t dab_code; 73192095f7Smpi uint64_t dab_tag; 74192095f7Smpi uint8_t dab_children; 75192095f7Smpi SIMPLEQ_HEAD(, dwattr) dab_attrs; 76192095f7Smpi }; 77192095f7Smpi 78192095f7Smpi SIMPLEQ_HEAD(dwabbrev_queue, dwabbrev); 79192095f7Smpi 80192095f7Smpi struct dwcu { 81192095f7Smpi uint64_t dcu_length; 82192095f7Smpi uint64_t dcu_abbroff; 83192095f7Smpi uint16_t dcu_version; 84192095f7Smpi uint8_t dcu_psize; 85192095f7Smpi size_t dcu_offset; /* offset in the segment */ 86192095f7Smpi struct dwabbrev_queue dcu_abbrevs; 87192095f7Smpi struct dwdie_queue dcu_dies; 88192095f7Smpi }; 89192095f7Smpi 90192095f7Smpi const char *dw_tag2name(uint64_t); 91192095f7Smpi const char *dw_at2name(uint64_t); 92192095f7Smpi const char *dw_form2name(uint64_t); 93192095f7Smpi const char *dw_op2name(uint8_t); 94192095f7Smpi 95192095f7Smpi int dw_loc_parse(struct dwbuf *, uint8_t *, uint64_t *, uint64_t *); 96192095f7Smpi 97192095f7Smpi int dw_ab_parse(struct dwbuf *, struct dwabbrev_queue *); 98192095f7Smpi int dw_cu_parse(struct dwbuf *, struct dwbuf *, size_t, struct dwcu **); 99192095f7Smpi 100192095f7Smpi void dw_dabq_purge(struct dwabbrev_queue *); 101192095f7Smpi void dw_dcu_free(struct dwcu *); 102192095f7Smpi 103192095f7Smpi 104192095f7Smpi #endif /* _DW_H_ */ 105