summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2012-01-07 02:10:34 -0800
committerGabe Black <gblack@eecs.umich.edu>2012-01-07 02:10:34 -0800
commit36a822f08e88483b41af214ace4fd3dccf3aa8cb (patch)
treed7c4c08590459d967a1d7638b02c586911826953 /src/sim
parent85424bef192c02a47c0d46c2d99ac0a5d6e55a99 (diff)
parentf171a29118e1d80c04c72d2fb5f024fed4fb62af (diff)
downloadgem5-36a822f08e88483b41af214ace4fd3dccf3aa8cb.tar.xz
Merge with main repository.
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/System.py11
-rw-r--r--src/sim/process.cc14
-rw-r--r--src/sim/process.hh2
-rw-r--r--src/sim/sim_object_params.hh58
-rw-r--r--src/sim/syscall_emul.cc3
-rw-r--r--src/sim/syscall_emul.hh55
-rw-r--r--src/sim/system.cc4
-rw-r--r--src/sim/system.hh4
8 files changed, 68 insertions, 83 deletions
diff --git a/src/sim/System.py b/src/sim/System.py
index 25643099d..db214abc0 100644
--- a/src/sim/System.py
+++ b/src/sim/System.py
@@ -41,8 +41,15 @@ class System(SimObject):
type = 'System'
@classmethod
- def swig_objdecls(cls, code):
- code('%include "python/swig/system.i"')
+ def export_method_cxx_predecls(cls, code):
+ code('#include "sim/system.hh"')
+
+ @classmethod
+ def export_methods(cls, code):
+ code('''
+ Enums::MemoryMode getMemoryMode();
+ void setMemoryMode(Enums::MemoryMode mode);
+''')
physmem = Param.PhysicalMemory("Physical Memory")
mem_mode = Param.MemoryMode('atomic', "The mode the memory system is in")
diff --git a/src/sim/process.cc b/src/sim/process.cc
index ba43a6b77..468f42955 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -159,7 +159,7 @@ Process::Process(ProcessParams * params)
mmap_start = mmap_end = 0;
nxm_start = nxm_end = 0;
- pTable = new PageTable(this);
+ pTable = new PageTable(name(), M5_pid);
// other parameters will be initialized when the program is loaded
}
@@ -318,13 +318,21 @@ Process::sim_fd_obj(int tgt_fd)
return &fd_map[tgt_fd];
}
+void
+Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
+{
+ int npages = divCeil(size, (int64_t)VMPageSize);
+ Addr paddr = system->allocPhysPages(npages);
+ pTable->map(vaddr, paddr, size, clobber);
+}
+
bool
Process::fixupStackFault(Addr vaddr)
{
// Check if this is already on the stack and there's just no page there
// yet.
if (vaddr >= stack_min && vaddr < stack_base) {
- pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize);
+ allocateMem(roundDown(vaddr, VMPageSize), VMPageSize);
return true;
}
@@ -337,7 +345,7 @@ Process::fixupStackFault(Addr vaddr)
fatal("Maximum stack size exceeded\n");
if (stack_base - stack_min > 8 * 1024 * 1024)
fatal("Over max stack size for one thread\n");
- pTable->allocate(stack_min, TheISA::PageBytes);
+ allocateMem(stack_min, TheISA::PageBytes);
inform("Increasing stack size by one page.");
};
return true;
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 82879c0e6..f738bb38a 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -203,6 +203,8 @@ class Process : public SimObject
virtual void syscall(int64_t callnum, ThreadContext *tc) = 0;
+ void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
+
/// Attempt to fix up a fault at vaddr by allocating a page on the stack.
/// @return Whether the fault has been fixed.
bool fixupStackFault(Addr vaddr);
diff --git a/src/sim/sim_object_params.hh b/src/sim/sim_object_params.hh
deleted file mode 100644
index 750181135..000000000
--- a/src/sim/sim_object_params.hh
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2001-2005 The Regents of The University of Michigan
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met: redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer;
- * redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution;
- * neither the name of the copyright holders nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Steve Reinhardt
- * Nathan Binkert
- */
-
-#ifndef __SIM_SIM_OBJECT_PARAMS_HH__
-#define __SIM_SIM_OBJECT_PARAMS_HH__
-
-#ifndef PY_VERSION
-struct PyObject;
-#endif
-
-#include <string>
-
-struct EventQueue;
-
-struct SimObjectParams
-{
- SimObjectParams()
- {
- extern EventQueue mainEventQueue;
- eventq = &mainEventQueue;
- }
- virtual ~SimObjectParams() {}
-
- std::string name;
- PyObject *pyobj;
- EventQueue *eventq;
-};
-
-
-#endif // __SIM_SIM_OBJECT_PARAMS_HH__
diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc
index 6873d4aa4..203eaff2a 100644
--- a/src/sim/syscall_emul.cc
+++ b/src/sim/syscall_emul.cc
@@ -166,8 +166,7 @@ brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
VMPageSize); !gen.done(); gen.next()) {
if (!p->pTable->translate(gen.addr()))
- p->pTable->allocate(roundDown(gen.addr(), VMPageSize),
- VMPageSize);
+ p->allocateMem(roundDown(gen.addr(), VMPageSize), VMPageSize);
// if the address is already there, zero it out
else {
diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh
index aff66ae9c..5c480272d 100644
--- a/src/sim/syscall_emul.hh
+++ b/src/sim/syscall_emul.hh
@@ -678,7 +678,7 @@ mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *
if (new_length > old_length) {
if ((start + old_length) == process->mmap_end) {
uint64_t diff = new_length - old_length;
- process->pTable->allocate(process->mmap_end, diff);
+ process->allocateMem(process->mmap_end, diff);
process->mmap_end += diff;
return start;
} else {
@@ -692,15 +692,15 @@ mremapFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *
process->mmap_end, process->mmap_end + new_length, new_length);
start = process->mmap_end;
// add on the remaining unallocated pages
- process->pTable->allocate(start + old_length, new_length - old_length);
+ process->allocateMem(start + old_length,
+ new_length - old_length);
process->mmap_end += new_length;
warn("returning %08p as start\n", start);
return start;
}
}
} else {
- process->pTable->deallocate(start + new_length, old_length -
- new_length);
+ process->pTable->unmap(start + new_length, old_length - new_length);
return start;
}
}
@@ -1028,20 +1028,45 @@ mmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
return -EINVAL;
}
- if (start != 0) {
- warn("mmap: ignoring suggested map address 0x%x, using 0x%x",
- start, p->mmap_end);
+ // are we ok with clobbering existing mappings? only set this to
+ // true if the user has been warned.
+ bool clobber = false;
+
+ // try to use the caller-provided address if there is one
+ bool use_provided_address = (start != 0);
+
+ if (use_provided_address) {
+ // check to see if the desired address is already in use
+ if (!p->pTable->isUnmapped(start, length)) {
+ // there are existing mappings in the desired range
+ // whether we clobber them or not depends on whether the caller
+ // specified MAP_FIXED
+ if (flags & OS::TGT_MAP_FIXED) {
+ // MAP_FIXED specified: clobber existing mappings
+ warn("mmap: MAP_FIXED at 0x%x overwrites existing mappings\n",
+ start);
+ clobber = true;
+ } else {
+ // MAP_FIXED not specified: ignore suggested start address
+ warn("mmap: ignoring suggested map address 0x%x\n", start);
+ use_provided_address = false;
+ }
+ }
}
- // pick next address from our "mmap region"
- if (OS::mmapGrowsDown()) {
- start = p->mmap_end - length;
- p->mmap_end = start;
- } else {
- start = p->mmap_end;
- p->mmap_end += length;
+ if (!use_provided_address) {
+ // no address provided, or provided address unusable:
+ // pick next address from our "mmap region"
+ if (OS::mmapGrowsDown()) {
+ start = p->mmap_end - length;
+ p->mmap_end = start;
+ } else {
+ start = p->mmap_end;
+ p->mmap_end += length;
+ }
}
- p->pTable->allocate(start, length);
+
+ p->allocateMem(start, length, clobber);
return start;
}
diff --git a/src/sim/system.cc b/src/sim/system.cc
index 654bcef80..3051cb64b 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -261,10 +261,10 @@ System::replaceThreadContext(ThreadContext *tc, int context_id)
}
Addr
-System::new_page()
+System::allocPhysPages(int npages)
{
Addr return_addr = pagePtr << LogVMPageSize;
- ++pagePtr;
+ pagePtr += npages;
if (return_addr >= physmem->size())
fatal("Out of memory, please increase size of physical memory.");
return return_addr;
diff --git a/src/sim/system.hh b/src/sim/system.hh
index a8d336d03..00d8360e0 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -271,7 +271,9 @@ class System : public SimObject
*/
Addr getKernelEntry() const { return kernelEntry; }
- Addr new_page();
+ /// Allocate npages contiguous unused physical pages
+ /// @return Starting address of first page
+ Addr allocPhysPages(int npages);
int registerThreadContext(ThreadContext *tc, int assigned=-1);
void replaceThreadContext(ThreadContext *tc, int context_id);