LLVM  5.0.0
MSFCommon.h
Go to the documentation of this file.
1 //===- MSFCommon.h - Common types and functions for MSF files ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_DEBUGINFO_MSF_MSFCOMMON_H
11 #define LLVM_DEBUGINFO_MSF_MSFCOMMON_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/BitVector.h"
15 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/Error.h"
18 #include <cstdint>
19 #include <vector>
20 
21 namespace llvm {
22 namespace msf {
23 
24 static const char Magic[] = {'M', 'i', 'c', 'r', 'o', 's', 'o', 'f',
25  't', ' ', 'C', '/', 'C', '+', '+', ' ',
26  'M', 'S', 'F', ' ', '7', '.', '0', '0',
27  '\r', '\n', '\x1a', 'D', 'S', '\0', '\0', '\0'};
28 
29 // The superblock is overlaid at the beginning of the file (offset 0).
30 // It starts with a magic header and is followed by information which
31 // describes the layout of the file system.
32 struct SuperBlock {
33  char MagicBytes[sizeof(Magic)];
34  // The file system is split into a variable number of fixed size elements.
35  // These elements are referred to as blocks. The size of a block may vary
36  // from system to system.
38  // The index of the free block map.
40  // This contains the number of blocks resident in the file system. In
41  // practice, NumBlocks * BlockSize is equivalent to the size of the MSF
42  // file.
44  // This contains the number of bytes which make up the directory.
46  // This field's purpose is not yet known.
48  // This contains the block # of the block map.
50 };
51 
52 struct MSFLayout {
53  MSFLayout() = default;
54 
55  const SuperBlock *SB = nullptr;
59  std::vector<ArrayRef<support::ulittle32_t>> StreamMap;
60 };
61 
63  switch (Size) {
64  case 512:
65  case 1024:
66  case 2048:
67  case 4096:
68  return true;
69  }
70  return false;
71 }
72 
73 // Super Block, Fpm0, Fpm1, and Block Map
74 inline uint32_t getMinimumBlockCount() { return 4; }
75 
76 // Super Block, Fpm0, and Fpm1 are reserved. The Block Map, although required
77 // need not be at block 3.
78 inline uint32_t getFirstUnreservedBlock() { return 3; }
79 
80 inline uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) {
81  return alignTo(NumBytes, BlockSize) / BlockSize;
82 }
83 
84 inline uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) {
85  return BlockNumber * BlockSize;
86 }
87 
89  return L.SB->BlockSize;
90 }
91 
93  uint32_t Length = getFpmIntervalLength(L);
94  return alignTo(L.SB->NumBlocks, Length) / Length;
95 }
96 
98  return alignTo(L.SB->NumBlocks, 8) / 8;
99 }
100 
101 Error validateSuperBlock(const SuperBlock &SB);
102 
103 } // end namespace msf
104 } // end namespace llvm
105 
106 #endif // LLVM_DEBUGINFO_MSF_MSFCOMMON_H
MachineLoop * L
char MagicBytes[sizeof(Magic)]
Definition: MSFCommon.h:33
Error validateSuperBlock(const SuperBlock &SB)
Definition: MSFCommon.cpp:20
uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize)
Definition: MSFCommon.h:84
uint32_t getMinimumBlockCount()
Definition: MSFCommon.h:74
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
uint32_t getFpmIntervalLength(const MSFLayout &L)
Definition: MSFCommon.h:88
support::ulittle32_t BlockSize
Definition: MSFCommon.h:37
support::ulittle32_t BlockMapAddr
Definition: MSFCommon.h:49
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
static const char Magic[]
Definition: MSFCommon.h:24
support::ulittle32_t Unknown1
Definition: MSFCommon.h:47
uint32_t getNumFpmIntervals(const MSFLayout &L)
Definition: MSFCommon.h:92
static const int BlockSize
Definition: TarWriter.cpp:34
ArrayRef< support::ulittle32_t > DirectoryBlocks
Definition: MSFCommon.h:57
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
BitVector FreePageMap
Definition: MSFCommon.h:56
uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize)
Definition: MSFCommon.h:80
std::vector< ArrayRef< support::ulittle32_t > > StreamMap
Definition: MSFCommon.h:59
uint32_t getFullFpmByteSize(const MSFLayout &L)
Definition: MSFCommon.h:97
ArrayRef< support::ulittle32_t > StreamSizes
Definition: MSFCommon.h:58
support::ulittle32_t FreeBlockMapBlock
Definition: MSFCommon.h:39
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
bool isValidBlockSize(uint32_t Size)
Definition: MSFCommon.h:62
uint32_t getFirstUnreservedBlock()
Definition: MSFCommon.h:78
const SuperBlock * SB
Definition: MSFCommon.h:55
support::ulittle32_t NumDirectoryBytes
Definition: MSFCommon.h:45
support::ulittle32_t NumBlocks
Definition: MSFCommon.h:43