gem5  v20.1.0.0
smbios.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Hewlett-Packard Development Company
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) 2008 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 
41 #include "arch/x86/bios/smbios.hh"
42 
43 #include "arch/x86/isa_traits.hh"
44 #include "base/types.hh"
45 #include "mem/port_proxy.hh"
46 #include "params/X86SMBiosBiosInformation.hh"
47 #include "params/X86SMBiosSMBiosStructure.hh"
48 #include "params/X86SMBiosSMBiosTable.hh"
49 #include "sim/byteswap.hh"
50 
51 using namespace std;
52 
55  SMBiosHeader::formattedArea[] = {0,0,0,0,0};
62 
63 template <class T>
64 uint64_t
66 {
67  uint64_t val = 0;
68  typename T::iterator vecIt;
69  for (vecIt = vec.begin(); vecIt != vec.end(); vecIt++) {
70  val |= (1 << (*vecIt));
71  }
72  return val;
73 }
74 
75 uint16_t
77 {
78  proxy.writeBlob(addr, &type, 1);
79 
80  uint8_t length = getLength();
81  proxy.writeBlob(addr + 1, &length, 1);
82 
83  uint16_t handleGuest = htole(handle);
84  proxy.writeBlob(addr + 2, &handleGuest, 2);
85 
86  return length + getStringLength();
87 }
88 
90  SimObject(p), type(_type), handle(0), stringFields(false)
91 {}
92 
93 void
95  PortProxy& proxy, Addr addr)
96 {
98  Addr offset = 0;
99 
100  const uint8_t nullTerminator = 0;
101 
102  // If there are string fields but none of them are used, that's a
103  // special case which is handled by this if.
104  if (strings.size() == 0 && stringFields) {
105  proxy.writeBlob(addr + offset, &nullTerminator, 1);
106  offset++;
107  } else {
108  for (it = strings.begin(); it != strings.end(); it++) {
109  proxy.writeBlob(addr + offset, it->c_str(), it->length() + 1);
110  offset += it->length() + 1;
111  }
112  }
113  proxy.writeBlob(addr + offset, &nullTerminator, 1);
114 }
115 
116 int
118 {
119  int size = 0;
121 
122  for (it = strings.begin(); it != strings.end(); it++) {
123  size += it->length() + 1;
124  }
125 
126  return size + 1;
127 }
128 
129 int
131 {
132  stringFields = true;
133  // If a string is empty, treat it as not existing. The index for empty
134  // strings is 0.
135  if (newString.length() == 0)
136  return 0;
137  strings.push_back(newString);
138  return strings.size();
139 }
140 
141 string
143 {
144  assert(n > 0 && n <= strings.size());
145  return strings[n - 1];
146 }
147 
148 void
149 X86ISA::SMBios::SMBiosStructure::setString(int n, std::string & newString)
150 {
151  assert(n > 0 && n <= strings.size());
152  strings[n - 1] = newString;
153 }
154 
156  SMBiosStructure(p, Type),
157  startingAddrSegment(p->starting_addr_segment),
158  romSize(p->rom_size),
159  majorVer(p->major), minorVer(p->minor),
160  embContFirmwareMajor(p->emb_cont_firmware_major),
161  embContFirmwareMinor(p->emb_cont_firmware_minor)
162  {
163  vendor = addString(p->vendor);
164  version = addString(p->version);
165  releaseDate = addString(p->release_date);
166 
167  characteristics = composeBitVector(p->characteristics);
169  composeBitVector(p->characteristic_ext_bytes);
170  }
171 
172 uint16_t
174 {
175  uint8_t size = SMBiosStructure::writeOut(proxy, addr);
176 
177  proxy.writeBlob(addr + 0x4, &vendor, 1);
178  proxy.writeBlob(addr + 0x5, &version, 1);
179 
180  uint16_t startingAddrSegmentGuest = htole(startingAddrSegment);
181  proxy.writeBlob(addr + 0x6, &startingAddrSegmentGuest, 2);
182 
183  proxy.writeBlob(addr + 0x8, &releaseDate, 1);
184  proxy.writeBlob(addr + 0x9, &romSize, 1);
185 
186  uint64_t characteristicsGuest = htole(characteristics);
187  proxy.writeBlob(addr + 0xA, &characteristicsGuest, 8);
188 
189  uint16_t characteristicExtBytesGuest =
190  htole(characteristicExtBytes);
191  proxy.writeBlob(addr + 0x12, &characteristicExtBytesGuest, 2);
192 
193  proxy.writeBlob(addr + 0x14, &majorVer, 1);
194  proxy.writeBlob(addr + 0x15, &minorVer, 1);
195  proxy.writeBlob(addr + 0x16, &embContFirmwareMajor, 1);
196  proxy.writeBlob(addr + 0x17, &embContFirmwareMinor, 1);
197 
198  writeOutStrings(proxy, addr + getLength());
199 
200  return size;
201 }
202 
204  SimObject(p), structures(p->structures)
205 {
206  smbiosHeader.majorVersion = p->major_version;
207  smbiosHeader.minorVersion = p->minor_version;
208  assert(p->major_version <= 9);
209  assert(p->minor_version <= 9);
211  (p->major_version << 4) | p->minor_version;
212 }
213 
214 void
216  Addr &headerSize, Addr &structSize)
217 {
218  headerSize = 0x1F;
219 
220  /*
221  * The main header
222  */
223  uint8_t mainChecksum = 0;
224 
225  proxy.writeBlob(addr, (uint8_t *)smbiosHeader.anchorString, 4);
226  for (int i = 0; i < 4; i++)
227  mainChecksum += smbiosHeader.anchorString[i];
228 
229  // The checksum goes here, but we're figuring it out as we go.
230 
231  proxy.writeBlob(addr + 0x5, &smbiosHeader.entryPointLength, 1);
232  mainChecksum += smbiosHeader.entryPointLength;
233  proxy.writeBlob(addr + 0x6, &smbiosHeader.majorVersion, 1);
234  mainChecksum += smbiosHeader.majorVersion;
235  proxy.writeBlob(addr + 0x7, &smbiosHeader.minorVersion, 1);
236  mainChecksum += smbiosHeader.minorVersion;
237  // Maximum structure size goes here, but we'll figure it out later.
238  proxy.writeBlob(addr + 0xA, &smbiosHeader.entryPointRevision, 1);
239  mainChecksum += smbiosHeader.entryPointRevision;
240  proxy.writeBlob(addr + 0xB, &smbiosHeader.formattedArea, 5);
241  for (int i = 0; i < 5; i++)
242  mainChecksum += smbiosHeader.formattedArea[i];
243 
244  /*
245  * The intermediate header
246  */
247  uint8_t intChecksum = 0;
248 
249  proxy.writeBlob(addr + 0x10,
250  smbiosHeader.intermediateHeader.anchorString, 5);
251  for (int i = 0; i < 5; i++)
252  intChecksum += smbiosHeader.intermediateHeader.anchorString[i];
253 
254  // The checksum goes here, but we're figuring it out as we go.
255  // Then the length of the structure table which we'll find later
256 
257  uint32_t tableAddrGuest =
258  htole(smbiosHeader.intermediateHeader.tableAddr);
259  proxy.writeBlob(addr + 0x18, &tableAddrGuest, 4);
260  for (int i = 0; i < 4; i++) {
261  intChecksum += tableAddrGuest;
262  tableAddrGuest >>= 8;
263  }
264 
265  uint16_t numStructs = letoh(structures.size());
266  proxy.writeBlob(addr + 0x1C, &numStructs, 2);
267  for (int i = 0; i < 2; i++) {
268  intChecksum += numStructs;
269  numStructs >>= 8;
270  }
271 
272  proxy.writeBlob(addr + 0x1E,
273  &smbiosHeader.intermediateHeader.smbiosBCDRevision, 1);
274  intChecksum += smbiosHeader.intermediateHeader.smbiosBCDRevision;
275 
276  /*
277  * Structure table
278  */
279 
280  Addr base = smbiosHeader.intermediateHeader.tableAddr;
281  Addr offset = 0;
282  uint16_t maxSize = 0;
284  for (it = structures.begin(); it != structures.end(); it++) {
285  uint16_t size = (*it)->writeOut(proxy, base + offset);
286  if (size > maxSize)
287  maxSize = size;
288  offset += size;
289  }
290 
291  structSize = offset;
292 
293  /*
294  * Header
295  */
296 
297  maxSize = htole(maxSize);
298  proxy.writeBlob(addr + 0x8, &maxSize, 2);
299  for (int i = 0; i < 2; i++) {
300  mainChecksum += maxSize;
301  maxSize >>= 8;
302  }
303 
304  // Set the checksum
305  mainChecksum = -mainChecksum;
306  proxy.writeBlob(addr + 0x4, &mainChecksum, 1);
307 
308  /*
309  * Intermediate header
310  */
311 
312  uint16_t tableSize = offset;
313  tableSize = htole(tableSize);
314  proxy.writeBlob(addr + 0x16, &tableSize, 2);
315  for (int i = 0; i < 2; i++) {
316  intChecksum += tableSize;
317  tableSize >>= 8;
318  }
319 
320  intChecksum = -intChecksum;
321  proxy.writeBlob(addr + 0x15, &intChecksum, 1);
322 }
323 
325 X86SMBiosBiosInformationParams::create()
326 {
327  return new X86ISA::SMBios::BiosInformation(this);
328 }
329 
331 X86SMBiosSMBiosTableParams::create()
332 {
333  return new X86ISA::SMBios::SMBiosTable(this);
334 }
X86ISA::SMBios::SMBiosTable::SMBiosHeader::IntermediateHeader::anchorString
static const char anchorString[]
Definition: smbios.hh:189
X86ISA::SMBios::SMBiosStructure::SMBiosStructure
SMBiosStructure(Params *p, uint8_t _type)
Definition: smbios.cc:89
X86ISA::SMBios::BiosInformation::vendor
uint8_t vendor
Definition: smbios.hh:119
X86ISA::SMBios::SMBiosStructure::writeOutStrings
void writeOutStrings(PortProxy &proxy, Addr addr)
Definition: smbios.cc:94
length
uint8_t length
Definition: inet.hh:422
X86ISA::SMBios::BiosInformation::writeOut
uint16_t writeOut(PortProxy &proxy, Addr addr)
Definition: smbios.cc:173
X86ISA::SMBios::SMBiosTable::SMBiosHeader::intermediateHeader
struct X86ISA::SMBios::SMBiosTable::SMBiosHeader::IntermediateHeader intermediateHeader
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
X86ISA::SMBios::SMBiosStructure::writeOut
virtual uint16_t writeOut(PortProxy &proxy, Addr addr)
Definition: smbios.cc:76
X86ISA::SMBios::SMBiosTable::Params
X86SMBiosSMBiosTableParams Params
Definition: smbios.hh:152
htole
T htole(T value)
Definition: byteswap.hh:140
type
uint8_t type
Definition: inet.hh:421
X86ISA::SMBios::SMBiosTable
Definition: smbios.hh:149
X86ISA::base
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
std::vector
STL vector class.
Definition: stl.hh:37
X86ISA::SMBios::SMBiosStructure::readString
std::string readString(int n)
Definition: smbios.cc:142
X86ISA::SMBios::SMBiosTable::SMBiosHeader::anchorString
static const char anchorString[]
Definition: smbios.hh:160
X86ISA::SMBios::SMBiosStructure::addString
int addString(std::string &newString)
Definition: smbios.cc:130
X86ISA::SMBios::SMBiosStructure::Params
X86SMBiosSMBiosStructureParams Params
Definition: smbios.hh:66
PortProxy::writeBlob
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:187
ArmISA::n
Bitfield< 31 > n
Definition: miscregs_types.hh:450
smbios.hh
letoh
T letoh(T value)
Definition: byteswap.hh:141
X86ISA::SMBios::SMBiosTable::writeOut
void writeOut(PortProxy &proxy, Addr addr, Addr &headerSize, Addr &structSize)
Definition: smbios.cc:215
X86ISA::SMBios::SMBiosTable::SMBiosHeader::IntermediateHeader::smbiosBCDRevision
uint8_t smbiosBCDRevision
Definition: smbios.hh:205
X86ISA::SMBios::SMBiosTable::SMBiosHeader::formattedArea
static const uint8_t formattedArea[5]
Definition: smbios.hh:181
X86ISA::SMBios::SMBiosTable::smbiosHeader
struct X86ISA::SMBios::SMBiosTable::SMBiosHeader smbiosHeader
X86ISA::SMBios::BiosInformation::characteristicExtBytes
uint16_t characteristicExtBytes
Definition: smbios.hh:133
port_proxy.hh
isa_traits.hh
X86ISA::SMBios::SMBiosTable::SMBiosHeader::minorVersion
uint8_t minorVersion
Definition: smbios.hh:172
X86ISA::SMBios::SMBiosStructure::getStringLength
int getStringLength()
Definition: smbios.cc:117
X86ISA::SMBios::BiosInformation
Definition: smbios.hh:110
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
X86ISA::SMBios::BiosInformation::releaseDate
uint8_t releaseDate
Definition: smbios.hh:125
X86ISA::SMBios::BiosInformation::BiosInformation
BiosInformation(Params *p)
Definition: smbios.cc:155
composeBitVector
uint64_t composeBitVector(T vec)
Definition: smbios.cc:65
X86ISA::SMBios::SMBiosTable::SMBiosHeader::entryPointRevision
static const uint8_t entryPointRevision
Definition: smbios.hh:178
X86ISA::offset
offset
Definition: misc.hh:1024
X86ISA::SMBios::SMBiosStructure::setString
void setString(int n, std::string &newString)
Definition: smbios.cc:149
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:79
X86ISA::SMBios::SMBiosStructure
Definition: smbios.hh:63
PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:80
X86ISA::p
Bitfield< 0 > p
Definition: pagetable.hh:151
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
types.hh
addr
ip6_addr_t addr
Definition: inet.hh:423
X86ISA::SMBios::SMBiosTable::SMBiosHeader::majorVersion
uint8_t majorVersion
Definition: smbios.hh:169
X86ISA::SMBios::BiosInformation::version
uint8_t version
Definition: smbios.hh:121
X86ISA::SMBios::BiosInformation::characteristics
uint64_t characteristics
Definition: smbios.hh:131
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
X86ISA::SMBios::SMBiosTable::SMBiosHeader::entryPointLength
static const uint8_t entryPointLength
Definition: smbios.hh:166
X86ISA::SMBios::SMBiosTable::SMBiosTable
SMBiosTable(Params *p)
Definition: smbios.cc:203
byteswap.hh
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17