gem5  v22.1.0.0
bufval.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __SIM_BUFVAL_HH__
29 #define __SIM_BUFVAL_HH__
30 
31 #include <cstddef>
32 #include <cstdint>
33 #include <string>
34 #include <utility>
35 
36 #include "enums/ByteOrder.hh"
37 
38 namespace gem5
39 {
40 
41 // Extract an integer with a given endianness from a variably sized buffer.
42 // Returns the value extraced (if any) and a bool indicating success.
43 std::pair<std::uint64_t, bool> getUintX(const void *buf, std::size_t bytes,
44  ByteOrder endian);
45 
46 // Set a variably sized buffer to an integer value with a given endianness.
47 // Returns whether the assignment was successful.
48 bool setUintX(std::uint64_t val, void *buf, std::size_t bytes,
49  ByteOrder endian);
50 
51 // Print an integer with a given endianness into a string from a variably
52 // sized buffer. Returns the string (if any) and a bool indicating success.
53 std::pair<std::string, bool> printUintX(const void *buf, std::size_t bytes,
54  ByteOrder endian);
55 
56 // Print a buffer as "chunk_size" sized groups of bytes. The endianness
57 // determines if the bytes are output in memory order (little) or inverse of
58 // memory order (big). The default is in memory order so that this acts like
59 // a hexdump type utility. The return value is a string holding the printed
60 // bytes.
61 std::string printByteBuf(const void *buf, std::size_t bytes,
62  ByteOrder endian=ByteOrder::little, std::size_t chunk_size=4);
63 
64 } // namespace gem5
65 
66 #endif // __SIM_BUFVAL_HH__
STL pair class.
Definition: stl.hh:58
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::pair< std::string, bool > printUintX(const void *buf, std::size_t bytes, ByteOrder endian)
Definition: bufval.cc:82
std::pair< std::uint64_t, bool > getUintX(const void *buf, std::size_t bytes, ByteOrder endian)
Definition: bufval.cc:41
bool setUintX(std::uint64_t val, void *buf, std::size_t bytes, ByteOrder endian)
Definition: bufval.cc:59
std::string printByteBuf(const void *buf, std::size_t bytes, ByteOrder endian, std::size_t chunk_size)
Definition: bufval.cc:99

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1