FileLoader.h Source File

Back to the index.

FileLoader.h
Go to the documentation of this file.
1 #ifndef FILELOADER_H
2 #define FILELOADER_H
3 
4 /*
5  * Copyright (C) 2008-2010 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include "misc.h"
32 
33 #include "Component.h"
34 #include "FileLoaderImpl.h"
35 #include "UnitTest.h"
36 
37 
38 /**
39  * \brief A class used to load binary files into emulated memory.
40  *
41  * A %FileLoader is given a name of a binary file, e.g. an ELF file, and
42  * attempts to load it into emulated memory.
43  *
44  * Binary files may be loaded to either physical or virtual memory addresses.
45  * To load to a physical address, we want to write to a component which
46  * is an AddressDataBus directly. To load to virtual addresses, we need to go
47  * via a particular CPU, because it is the CPU which does the virtual to
48  * physical address translation.
49  *
50  * The type of the file is normally auto-detected by reading magic sequences
51  * at the start of the file.
52  */
54  : public UnitTestable
55 {
56 public:
57  /**
58  * \brief Constructs a %FileLoader object.
59  *
60  * \param filename The name of the file to open.
61  */
62  FileLoader(const string& filename);
63 
64  /**
65  * \brief Retrieves the filename of this %FileLoader.
66  *
67  * \return The filename.
68  */
69  const string& GetFilename() const;
70 
71  /**
72  * \brief Attempt to detect the file format of the file.
73  *
74  * \param loader On return from the function, if the file format has
75  * been detected, this is set to a pointer to a FileLoaderImpl.
76  * Otherwise (if no format was detected), it is NULL.
77  * \return A string representing the file format.
78  */
80 
81  /**
82  * \brief Loads the file into a CPU or an AddressDataBus.
83  *
84  * Note: The file is usually loaded into a virtual address space.
85  * It is therefore necessary to load it into a CPU, and not directly
86  * into RAM.
87  *
88  * @param component A CPUComponent (or any other
89  * component which implements the AddressDataBus interface),
90  * into which the file will be loaded.
91  * @param messages An output stream where debug messages can be put.
92  * @return True if loading succeeded, false otherwise.
93  */
94  bool Load(refcount_ptr<Component> component, ostream& messages) const;
95 
96 
97  /********************************************************************/
98 
99  static void RunUnitTests(int& nSucceeded, int& nFailures);
100 
101 private:
102  // Disallow construction without arguments.
103  FileLoader();
104 
105 private:
106  typedef vector< refcount_ptr<const FileLoaderImpl> > FileLoaderImplVector;
107  const string m_filename;
108  FileLoaderImplVector m_fileLoaders;
109 };
110 
111 
112 #endif // FILELOADER_H
FileLoaderImpl.h
refcount_ptr< const FileLoaderImpl >
FileLoader::Load
bool Load(refcount_ptr< Component > component, ostream &messages) const
Loads the file into a CPU or an AddressDataBus.
Definition: FileLoader.cc:97
FileLoader::DetectFileFormat
string DetectFileFormat(refcount_ptr< const FileLoaderImpl > &loader) const
Attempt to detect the file format of the file.
Definition: FileLoader.cc:59
misc.h
FileLoader::RunUnitTests
static void RunUnitTests(int &nSucceeded, int &nFailures)
UnitTest.h
Component.h
FileLoader
A class used to load binary files into emulated memory.
Definition: FileLoader.h:53
FileLoader::GetFilename
const string & GetFilename() const
Retrieves the filename of this FileLoader.
Definition: FileLoader.cc:53
UnitTestable
Base class for unit testable classes.
Definition: UnitTest.h:74

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17