Commit | Line | Data |
---|---|---|
fc93b2bd MD |
1 | /* |
2 | * Common Trace Format | |
3 | * | |
4 | * Bitfields read/write functions. | |
5 | * | |
6 | * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | */ | |
22 | ||
23 | #include <ctf/bitfield.h> | |
24 | #include <endian.h> | |
25 | ||
bed864a7 MD |
26 | uint64_t ctf_bitfield_unsigned_read(struct stream_pos *pos, |
27 | const struct type_class_bitfield *bitfield_class) | |
fc93b2bd MD |
28 | { |
29 | uint64_t v; | |
30 | ||
bed864a7 MD |
31 | align_pos(pos, bitfield_class->p.p.alignment); |
32 | if (bitfield_class->p.byte_order == LITTLE_ENDIAN) | |
33 | ctf_bitfield_read_le(pos->base, pos->offset, | |
34 | bitfield_class->p.len, &v); | |
fc93b2bd | 35 | else |
bed864a7 MD |
36 | ctf_bitfield_read_be(pos->base, pos->offset, |
37 | bitfield_class->p.len, &v); | |
38 | move_pos(pos, bitfield_class->p.len); | |
fc93b2bd MD |
39 | return v; |
40 | } | |
41 | ||
bed864a7 MD |
42 | int64_t ctf_bitfield_signed_read(struct stream_pos *pos, |
43 | const struct type_class_bitfield *bitfield_class) | |
fc93b2bd MD |
44 | { |
45 | int64_t v; | |
46 | ||
bed864a7 MD |
47 | align_pos(pos, bitfield_class->p.p.alignment); |
48 | ||
49 | if (bitfield_class->p.byte_order == LITTLE_ENDIAN) | |
50 | ctf_bitfield_read_le(pos->base, pos->offset, | |
51 | bitfield_class->p.len, &v); | |
fc93b2bd | 52 | else |
bed864a7 MD |
53 | ctf_bitfield_read_be(pos->base, pos->offset, |
54 | bitfield_class->p.len, &v); | |
55 | move_pos(pos, bitfield_class->p.len); | |
fc93b2bd MD |
56 | return v; |
57 | } | |
58 | ||
bed864a7 MD |
59 | void ctf_bitfield_unsigned_write(struct stream_pos *pos, |
60 | const struct type_class_bitfield *bitfield_class, | |
61 | uint64_t v) | |
fc93b2bd | 62 | { |
bed864a7 MD |
63 | align_pos(pos, bitfield_class->p.p.alignment); |
64 | if (pos->dummy) | |
fc93b2bd | 65 | goto end; |
bed864a7 MD |
66 | if (bitfield_class->p.byte_order == LITTLE_ENDIAN) |
67 | ctf_bitfield_write_le(pos->base, pos->offset, | |
68 | bitfield_class->p.len, v); | |
fc93b2bd | 69 | else |
bed864a7 MD |
70 | ctf_bitfield_write_be(pos->base, pos->offset, |
71 | bitfield_class->p.len,, v); | |
fc93b2bd | 72 | end: |
bed864a7 | 73 | move_pos(pos, bitfield_class->p.len); |
fc93b2bd MD |
74 | } |
75 | ||
bed864a7 MD |
76 | void ctf_bitfield_signed_write(struct stream_pos *pos, |
77 | const struct type_class_bitfield *bitfield_class, | |
78 | int64_t v) | |
fc93b2bd | 79 | { |
bed864a7 MD |
80 | align_pos(pos, bitfield_class->p.p.alignment); |
81 | if (pos->dummy) | |
fc93b2bd | 82 | goto end; |
bed864a7 MD |
83 | if (bitfield_class->p.byte_order == LITTLE_ENDIAN) |
84 | ctf_bitfield_write_le(pos->base, pos->offset, | |
85 | bitfield_class->p.len, v); | |
fc93b2bd | 86 | else |
bed864a7 MD |
87 | ctf_bitfield_write_be(pos->base, pos->offset, |
88 | bitfield_class->p.len, v); | |
fc93b2bd | 89 | end: |
bed864a7 | 90 | move_pos(pos, bitfield_class->p.len); |
fc93b2bd | 91 | } |