gem5 v24.0.0.0
Loading...
Searching...
No Matches
object_file.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2004 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
42
43#include <string>
44#include <vector>
45
47
48namespace gem5
49{
50
51namespace loader
52{
53
55
56const char *
58{
59 switch (arch) {
60 case UnknownArch:
61 return "unknown";
62 case SPARC64:
63 return "sparc64";
64 case SPARC32:
65 return "sparc32";
66 case Mips:
67 return "mips";
68 case X86_64:
69 return "x86_64";
70 case I386:
71 return "i386";
72 case Arm64:
73 return "arm64";
74 case Arm:
75 return "arm";
76 case Thumb:
77 return "thumb";
78 case Power:
79 return "power";
80 case Power64:
81 return "power64";
82 case Riscv64:
83 return "riscv64";
84 case Riscv32:
85 return "riscv32";
86 default:
87 panic("Unrecognized arch %d.", arch);
88 }
89}
90
91const char *
93{
94 switch (op_sys) {
95 case UnknownOpSys:
96 return "unknown";
97 case Tru64:
98 return "tru64";
99 case Linux:
102 return "linux";
103 case Solaris:
104 return "solaris";
105 case LinuxArmOABI:
106 return "linux_arm_OABI";
107 case FreeBSD:
108 return "freebsd";
109 default:
110 panic("Unrecognized operating system %d.", op_sys);
111 }
112}
113
114namespace
115{
116
117typedef std::vector<ObjectFileFormat *> ObjectFileFormatList;
118
119ObjectFileFormatList &
120object_file_formats()
121{
122 static ObjectFileFormatList formats;
123 return formats;
124}
125
126} // anonymous namespace
127
129{
130 object_file_formats().emplace_back(this);
131}
132
134createObjectFile(const std::string &fname, bool raw)
135{
136 ImageFileDataPtr ifd(new ImageFileData(fname));
137
138 for (auto &format: object_file_formats()) {
139 ObjectFile *file_obj = format->load(ifd);
140 if (file_obj)
141 return file_obj;
142 }
143
144 if (raw)
145 return new RawImage(ifd);
146
147 return nullptr;
148}
149
150bool
152{
153 switch (arch) {
154 case SPARC64:
155 case X86_64:
156 case Arm64:
157 case Power64:
158 case Riscv64:
159 return true;
160 default:
161 return false;
162 }
163}
164
165} // namespace loader
166} // namespace gem5
ObjectFile(ImageFileDataPtr ifd)
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 31, 29 > format
bool archIs64Bit(const loader::Arch arch)
Determine whether the loader::Arch is 64-bit or 32-bit.
const char * archToString(Arch arch)
ObjectFile * createObjectFile(const std::string &fname, bool raw)
const char * opSysToString(OpSys op_sys)
std::shared_ptr< ImageFileData > ImageFileDataPtr
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0