gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
46 #include "base/loader/raw_image.hh"
47 
48 namespace gem5
49 {
50 
51 namespace loader
52 {
53 
55 
56 const 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 
91 const char *
93 {
94  switch (op_sys) {
95  case UnknownOpSys:
96  return "unknown";
97  case Tru64:
98  return "tru64";
99  case Linux:
100  case LinuxPower64ABIv1:
101  case LinuxPower64ABIv2:
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 
114 namespace
115 {
116 
117 typedef std::vector<ObjectFileFormat *> ObjectFileFormatList;
118 
119 ObjectFileFormatList &
120 object_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 
133 ObjectFile *
134 createObjectFile(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 
150 bool
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
gem5::loader::LinuxPower64ABIv1
@ LinuxPower64ABIv1
Definition: object_file.hh:87
gem5::loader::ObjectFile
Definition: object_file.hh:96
gem5::ArmISA::format
Bitfield< 31, 29 > format
Definition: misc_types.hh:704
gem5::loader::ObjectFile::ObjectFile
ObjectFile(ImageFileDataPtr ifd)
Definition: object_file.cc:54
gem5::loader::SPARC64
@ SPARC64
Definition: object_file.hh:64
gem5::loader::X86_64
@ X86_64
Definition: object_file.hh:67
gem5::loader::Solaris
@ Solaris
Definition: object_file.hh:85
std::vector
STL vector class.
Definition: stl.hh:37
gem5::loader::opSysToString
const char * opSysToString(OpSys op_sys)
Definition: object_file.cc:92
gem5::loader::Arm64
@ Arm64
Definition: object_file.hh:69
gem5::loader::FreeBSD
@ FreeBSD
Definition: object_file.hh:89
gem5::loader::UnknownOpSys
@ UnknownOpSys
Definition: object_file.hh:82
gem5::loader::Power
@ Power
Definition: object_file.hh:72
gem5::loader::ImageFileData
Definition: image_file_data.hh:44
gem5::loader::Mips
@ Mips
Definition: object_file.hh:66
gem5::loader::Power64
@ Power64
Definition: object_file.hh:73
gem5::loader::Arch
Arch
Definition: object_file.hh:61
gem5::loader::archToString
const char * archToString(Arch arch)
Definition: object_file.cc:57
gem5::loader::Riscv32
@ Riscv32
Definition: object_file.hh:75
gem5::loader::RawImage
Definition: raw_image.hh:41
gem5::loader::Tru64
@ Tru64
Definition: object_file.hh:83
gem5::loader::LinuxPower64ABIv2
@ LinuxPower64ABIv2
Definition: object_file.hh:88
gem5::loader::createObjectFile
ObjectFile * createObjectFile(const std::string &fname, bool raw)
Definition: object_file.cc:134
gem5::loader::archIs64Bit
bool archIs64Bit(const loader::Arch arch)
Determine whether the loader::Arch is 64-bit or 32-bit.
Definition: object_file.cc:151
gem5::loader::Thumb
@ Thumb
Definition: object_file.hh:71
gem5::loader::UnknownArch
@ UnknownArch
Definition: object_file.hh:63
gem5::loader::SPARC32
@ SPARC32
Definition: object_file.hh:65
raw_image.hh
gem5::loader::ImageFileDataPtr
std::shared_ptr< ImageFileData > ImageFileDataPtr
Definition: image_file_data.hh:60
gem5::loader::OpSys
OpSys
Definition: object_file.hh:80
gem5::loader::ObjectFileFormat::ObjectFileFormat
ObjectFileFormat()
Definition: object_file.cc:128
gem5::loader::I386
@ I386
Definition: object_file.hh:68
gem5::loader::LinuxArmOABI
@ LinuxArmOABI
Definition: object_file.hh:86
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
object_file.hh
gem5::loader::Arm
@ Arm
Definition: object_file.hh:70
gem5::loader::Riscv64
@ Riscv64
Definition: object_file.hh:74
gem5::loader::Linux
@ Linux
Definition: object_file.hh:84
gem5::loader::ImageFile
Definition: image_file.hh:45
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17