FileLoader Class Reference

Back to the index.

Public Member Functions | Static Public Member Functions | List of all members
FileLoader Class Reference

A class used to load binary files into emulated memory. More...

#include <FileLoader.h>

Inheritance diagram for FileLoader:
UnitTestable

Public Member Functions

 FileLoader (const string &filename)
 Constructs a FileLoader object. More...
 
const string & GetFilename () const
 Retrieves the filename of this FileLoader. More...
 
string DetectFileFormat (refcount_ptr< const FileLoaderImpl > &loader) const
 Attempt to detect the file format of the file. More...
 
bool Load (refcount_ptr< Component > component, ostream &messages) const
 Loads the file into a CPU or an AddressDataBus. More...
 

Static Public Member Functions

static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from UnitTestable
static void RunUnitTests (int &nSucceeded, int &nFailures)
 Runs unit test cases. More...
 

Detailed Description

A class used to load binary files into emulated memory.

A FileLoader is given a name of a binary file, e.g. an ELF file, and attempts to load it into emulated memory.

Binary files may be loaded to either physical or virtual memory addresses. To load to a physical address, we want to write to a component which is an AddressDataBus directly. To load to virtual addresses, we need to go via a particular CPU, because it is the CPU which does the virtual to physical address translation.

The type of the file is normally auto-detected by reading magic sequences at the start of the file.

Definition at line 53 of file FileLoader.h.

Constructor & Destructor Documentation

◆ FileLoader()

FileLoader::FileLoader ( const string &  filename)

Constructs a FileLoader object.

Parameters
filenameThe name of the file to open.

Definition at line 43 of file FileLoader.cc.

References FileLoader().

Referenced by FileLoader().

Member Function Documentation

◆ DetectFileFormat()

string FileLoader::DetectFileFormat ( refcount_ptr< const FileLoaderImpl > &  loader) const

Attempt to detect the file format of the file.

Parameters
loaderOn return from the function, if the file format has been detected, this is set to a pointer to a FileLoaderImpl. Otherwise (if no format was detected), it is NULL.
Returns
A string representing the file format.

Definition at line 59 of file FileLoader.cc.

Referenced by Load().

◆ GetFilename()

const string & FileLoader::GetFilename ( ) const

Retrieves the filename of this FileLoader.

Returns
The filename.

Definition at line 53 of file FileLoader.cc.

◆ Load()

bool FileLoader::Load ( refcount_ptr< Component component,
ostream &  messages 
) const

Loads the file into a CPU or an AddressDataBus.

Note: The file is usually loaded into a virtual address space. It is therefore necessary to load it into a CPU, and not directly into RAM.

Parameters
componentA CPUComponent (or any other component which implements the AddressDataBus interface), into which the file will be loaded.
messagesAn output stream where debug messages can be put.
Returns
True if loading succeeded, false otherwise.

Definition at line 97 of file FileLoader.cc.

References Component::AsAddressDataBus(), DetectFileFormat(), Component::GenerateShortestPossiblePath(), refcount_ptr< T >::IsNULL(), and FileLoaderImpl::LoadIntoComponent().

◆ RunUnitTests()

static void FileLoader::RunUnitTests ( int &  nSucceeded,
int &  nFailures 
)
static

The documentation for this class was generated from the following files:

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18