/*
- * Copyright (c) 2011-2014 ARM Limited
+ * Copyright (c) 2011-2014,2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* Rick Strong
*/
+#include "sim/system.hh"
+
#include "arch/remote_gdb.hh"
#include "arch/utility.hh"
#include "base/loader/object_file.hh"
#include "base/loader/symtab.hh"
#include "base/str.hh"
#include "base/trace.hh"
+#include "config/use_kvm.hh"
+#if USE_KVM
+#include "cpu/kvm/base.hh"
+#include "cpu/kvm/vm.hh"
+#endif
+#include "cpu/base.hh"
#include "cpu/thread_context.hh"
#include "debug/Loader.hh"
#include "debug/WorkItems.hh"
#include "sim/byteswap.hh"
#include "sim/debug.hh"
#include "sim/full_system.hh"
-#include "sim/system.hh"
/**
* To avoid linking errors with LTO, only include the header if we
*/
#if THE_ISA != NULL_ISA
#include "kern/kernel_stats.hh"
+
#endif
using namespace std;
kernel(nullptr),
loadAddrMask(p->load_addr_mask),
loadAddrOffset(p->load_offset),
- nextPID(0),
+#if USE_KVM
+ kvmVM(p->kvm_vm),
+#else
+ kvmVM(nullptr),
+#endif
physmem(name() + ".physmem", p->memories, p->mmap_using_noreserve),
memoryMode(p->mem_mode),
_cacheLineSize(p->cache_line_size),
// add self to global system list
systemList.push_back(this);
+#if USE_KVM
+ if (kvmVM) {
+ kvmVM->setSystem(this);
+ }
+#endif
+
if (FullSystem) {
kernelSymtab = new SymbolTable;
if (!debugSymbolTable)
kernelEnd = kernel->bssBase() + kernel->bssSize();
kernelEntry = kernel->entryPoint();
+ // If load_addr_mask is set to 0x0, then auto-calculate
+ // the smallest mask to cover all kernel addresses so gem5
+ // can relocate the kernel to a new offset.
+ if (loadAddrMask == 0) {
+ Addr shift_amt = findMsbSet(kernelEnd - kernelStart) + 1;
+ loadAddrMask = ((Addr)1 << shift_amt) - 1;
+ }
+
// load symbols
if (!kernel->loadGlobalSymbols(kernelSymtab))
fatal("could not load kernel symbols\n");
// Loading only needs to happen once and after memory system is
// connected so it will happen in initState()
}
+
+ for (const auto &obj_name : p->kernel_extras) {
+ inform("Loading additional kernel object: %s", obj_name);
+ ObjectFile *obj = createObjectFile(obj_name);
+ fatal_if(!obj, "Failed to additional kernel object '%s'.\n",
+ obj_name);
+ kernelExtras.push_back(obj);
+ }
}
- // increment the number of running systms
+ // increment the number of running systems
numSystemsRunning++;
// Set back pointers to the system in all memories
return false;
}
-/**
- * Setting rgdb_wait to a positive integer waits for a remote debugger to
- * connect to that context ID before continuing. This should really
- be a parameter on the CPU object or something...
- */
-int rgdb_wait = -1;
-
ContextID
System::registerThreadContext(ThreadContext *tc, ContextID assigned)
{
- int id;
- if (assigned == InvalidContextID) {
- for (id = 0; id < threadContexts.size(); id++) {
- if (!threadContexts[id])
- break;
- }
-
- if (threadContexts.size() <= id)
- threadContexts.resize(id + 1);
- } else {
- if (threadContexts.size() <= assigned)
- threadContexts.resize(assigned + 1);
- id = assigned;
+ int id = assigned;
+ if (id == InvalidContextID) {
+ // Find an unused context ID for this thread.
+ id = 0;
+ while (id < threadContexts.size() && threadContexts[id])
+ id++;
}
- if (threadContexts[id])
- fatal("Cannot have two CPUs with the same id (%d)\n", id);
+ if (threadContexts.size() <= id)
+ threadContexts.resize(id + 1);
+
+ fatal_if(threadContexts[id],
+ "Cannot have two CPUs with the same id (%d)\n", id);
threadContexts[id] = tc;
_numContexts++;
#if THE_ISA != NULL_ISA
int port = getRemoteGDBPort();
if (port) {
- RemoteGDB *rgdb = new RemoteGDB(this, tc);
- GDBListener *gdbl = new GDBListener(rgdb, port + id);
- gdbl->listen();
+ RemoteGDB *rgdb = new RemoteGDB(this, tc, port + id);
+ rgdb->listen();
- if (rgdb_wait != -1 && rgdb_wait == id)
- gdbl->accept();
+ BaseCPU *cpu = tc->getCpuPtr();
+ if (cpu->waitForRemoteGDB()) {
+ inform("%s: Waiting for a remote GDB connection on port %d.\n",
+ cpu->name(), rgdb->port());
+ rgdb->connect();
+ }
if (remoteGDB.size() <= id) {
remoteGDB.resize(id + 1);
}
}
// Load program sections into memory
kernel->loadSections(physProxy, loadAddrMask, loadAddrOffset);
+ for (const auto &extra_kernel : kernelExtras) {
+ extra_kernel->loadSections(physProxy, loadAddrMask,
+ loadAddrOffset);
+ }
DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
DPRINTF(Loader, "Kernel end = %#x\n", kernelEnd);
remoteGDB[context_id]->replaceThreadContext(tc);
}
+bool
+System::validKvmEnvironment() const
+{
+#if USE_KVM
+ if (threadContexts.empty())
+ return false;
+
+ for (auto tc : threadContexts) {
+ if (dynamic_cast<BaseKvmCPU*>(tc->getCpuPtr()) == nullptr) {
+ return false;
+ }
+ }
+ return true;
+#else
+ return false;
+#endif
+}
+
Addr
System::allocPhysPages(int npages)
{
if (FullSystem)
kernelSymtab->serialize("kernel_symtab", cp);
SERIALIZE_SCALAR(pagePtr);
- SERIALIZE_SCALAR(nextPID);
serializeSymtab(cp);
// also serialize the memories in the system
if (FullSystem)
kernelSymtab->unserialize("kernel_symtab", cp);
UNSERIALIZE_SCALAR(pagePtr);
- UNSERIALIZE_SCALAR(nextPID);
unserializeSymtab(cp);
// also unserialize the memories in the system