LoadCommand.cc Source File
Back to the index.
Go to the documentation of this file.
38 :
Command(
"load",
"[filename [component-path]]")
48 static void ShowMsg(
GXemul& gxemul,
const string& msg)
54 bool LoadCommand::IsComponentTree(
GXemul& gxemul,
const string& filename)
const
56 std::ifstream file(filename.c_str());
61 file.read(buf,
sizeof(buf));
62 if (file.gcount() < 10)
66 return (strncmp(buf,
"component ", 10) == 0);
70 bool LoadCommand::LoadComponentTree(
GXemul& gxemul,
const string&filename,
73 const string extension =
".gxemul";
74 if (filename.length() < extension.length() || filename.substr(
75 filename.length() - extension.length()) != extension)
76 ShowMsg(gxemul,
"Warning: the name " + filename +
77 " does not have a .gxemul extension. Continuing anyway.\n");
82 std::ifstream file(filename.c_str());
84 ShowMsg(gxemul,
"Unable to open " + filename +
" for reading.\n");
89 file.seekg(0, std::ios::end);
90 std::streampos fileSize = file.tellg();
91 file.seekg(0, std::ios::beg);
98 buf.resize((
size_t)fileSize + 1);
100 memset(&buf[0], 0, fileSize);
101 file.read(&buf[0], fileSize);
102 if (file.gcount() != fileSize) {
103 ShowMsg(gxemul,
"Loading from " + filename +
" failed; "
104 "could not read all of the file?\n");
108 string str(&buf[0], fileSize);
113 stringstream messages;
116 if (messages.str().length() > 0)
117 ShowMsg(gxemul, messages.str());
120 ShowMsg(gxemul,
"Loading from " + filename +
" failed; "
121 "no component found?\n");
125 if (specifiedComponent.
IsNULL()) {
127 if (name == NULL || name->
ToString() !=
"root")
134 ShowMsg(gxemul, filename +
" loaded\n");
136 specifiedComponent->
AddChild(component);
138 ShowMsg(gxemul, filename +
" loaded into " +
150 if (arguments.size() > 2) {
151 ShowMsg(gxemul,
"Too many arguments.\n");
155 if (arguments.size() > 0)
156 filename = arguments[0];
158 if (filename ==
"") {
159 ShowMsg(gxemul,
"No filename given.\n");
163 if (arguments.size() > 1)
170 FindPathByPartialMatch(path);
171 if (matches.size() == 0) {
172 ShowMsg(gxemul, path +
173 " is not a path to a known component.\n");
176 if (matches.size() > 1) {
177 ShowMsg(gxemul, path +
178 " matches multiple components:\n");
179 for (
size_t i=0; i<matches.size(); i++)
180 ShowMsg(gxemul,
" " + matches[i] +
"\n");
186 if (specifiedComponent.
IsNULL()) {
187 ShowMsg(gxemul,
"Lookup of " + path +
" failed.\n");
193 if (IsComponentTree(gxemul, filename)) {
194 if (specifiedComponent.
IsNULL())
197 return LoadComponentTree(gxemul, filename, specifiedComponent);
200 if (specifiedComponent.
IsNULL()) {
201 ShowMsg(gxemul,
"The specified file to load (" + filename +
202 ") is not a configuration tree. If it is a binary to load,"
203 " you need to specify a component path where to load the"
210 stringstream messages;
211 if (fileLoader.
Load(specifiedComponent, messages)) {
213 filename +
" loaded\n" + messages.str());
217 "FAILED to load " + filename +
"\n" + messages.str());
225 return "Loads a file.";
232 "Loads a file into a location in the component tree. There are two different\n"
233 "uses, which all share the same general syntax but differ in meaning.\n"
235 "1. Loads an emulation setup (.gxemul) which was previously saved with the\n"
236 " 'save' command. For example, if a machine was previously saved into\n"
237 " myMachine.gxemul, then\n"
239 " load myMachine.gxemul root\n"
241 " will add the machine to the current emulation tree, next to any other\n"
244 " load myMachine.gxemul\n"
246 " will instead replace the whole configuration tree with what's in\n"
247 " myMachine.gxemul. The filename may be omitted, if it is known from an\n"
248 " earlier save or load command.\n"
250 "2. Loads a binary (ELF, a.out, ...) into a CPU or data bus. E.g.:\n"
252 " load netbsd-RAMDISK cpu0\n"
254 " will load a NetBSD kernel into cpu0 (assuming that cpu0 is not ambiguous).\n"
255 " The reason why files should be loaded into CPUs and not into RAM components\n"
256 " is that binaries are often linked to virtual addresses, and the CPU does\n"
257 " virtual to physical address translation.\n"
259 "See also: save (to save an emulation to a file)\n";
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
void ClearEmulation()
Discards the current emulation, and starts anew with just an empty root component.
static refcount_ptr< Component > Deserialize(ostream &messages, const string &str, size_t &pos)
Deserializes a string into a component tree.
StateVariables make up the persistent state of Component objects.
A Command is a named function, executed by the CommandInterpreter.
bool Load(refcount_ptr< Component > component, ostream &messages) const
Loads the file into a CPU or an AddressDataBus.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
void SetEmulationFilename(const string &filename)
Sets the current emulation setup's filename.
virtual void ShowDebugMessage(const string &msg)=0
Shows a debug message.
virtual bool Execute(GXemul &gxemul, const vector< string > &arguments)
Executes the command on a given GXemul instance.
const refcount_ptr< Component > LookupPath(string path) const
Looks up a path from this Component, and returns a pointer to the found Component,...
A class used to load binary files into emulated memory.
string ToString() const
Returns the variable as a readable string.
string GenerateShortestPossiblePath() const
Generates a short string representation of the path to the Component.
virtual string GetLongDescription() const
Returns a long description/help message for the command.
UI * GetUI()
Gets a pointer to the GXemul instance' active UI.
virtual string GetShortDescription() const
Returns a short (one-line) description of the command.
StateVariable * GetVariable(const string &name)
Gets a pointer to a state variable.
const string & GetEmulationFilename() const
Gets the current emulation setup's filename.
LoadCommand()
Constructs an LoadCommand.
void SetRootComponent(refcount_ptr< Component > newRootComponent)
Sets the root component, discarding the previous one.
Generated on Tue Mar 24 2020 14:04:48 for GXemul by
1.8.17