Deleted Added
sdiff udiff text old ( 5399:e951ca2d56e2 ) new ( 5477:dc04d655315a )
full compact
1/*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 38 unchanged lines hidden (view full) ---

47#include "mem/physical.hh"
48#include "sim/eventq.hh"
49#include "sim/host.hh"
50
51using namespace std;
52using namespace TheISA;
53
54PhysicalMemory::PhysicalMemory(const Params *p)
55 : MemObject(p), pmemAddr(NULL), lat(p->latency),
56 lat_var(p->latency_var)
57{
58 if (params()->range.size() % TheISA::PageBytes != 0)
59 panic("Memory Size not divisible by page size\n");
60
61 int map_flags = MAP_ANON | MAP_PRIVATE;
62 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(),
63 PROT_READ | PROT_WRITE, map_flags, -1, 0);
64
65 if (pmemAddr == (void *)MAP_FAILED) {
66 perror("mmap");
67 fatal("Could not mmap!\n");
68 }
69
70 //If requested, initialize all the memory to 0
71 if (p->zero)
72 memset(pmemAddr, 0, p->range.size());
73
74 pagePtr = 0;
75
76 cachedSize = params()->range.size();
77 cachedStart = params()->range.start;
78
79}
80
81void
82PhysicalMemory::init()
83{
84 if (ports.size() == 0) {
85 fatal("PhysicalMemory object %s is unconnected!", name());
86 }

--- 165 unchanged lines hidden (view full) ---

252 uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
253
254 if (pkt->cmd == MemCmd::SwapReq) {
255 IntReg overwrite_val;
256 bool overwrite_mem;
257 uint64_t condition_val64;
258 uint32_t condition_val32;
259
260 assert(sizeof(IntReg) >= pkt->getSize());
261
262 overwrite_mem = true;
263 // keep a copy of our possible write value, and copy what is at the
264 // memory address into the packet
265 std::memcpy(&overwrite_val, pkt->getPtr<uint8_t>(), pkt->getSize());
266 std::memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
267

--- 14 unchanged lines hidden (view full) ---

282 std::memcpy(hostAddr, &overwrite_val, pkt->getSize());
283
284 TRACE_PACKET("Read/Write");
285 } else if (pkt->isRead()) {
286 assert(!pkt->isWrite());
287 if (pkt->isLocked()) {
288 trackLoadLocked(pkt);
289 }
290 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
291 TRACE_PACKET("Read");
292 } else if (pkt->isWrite()) {
293 if (writeOK(pkt)) {
294 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
295 TRACE_PACKET("Write");
296 }
297 } else if (pkt->isInvalidate()) {
298 //upgrade or invalidate
299 if (pkt->needsResponse()) {
300 pkt->makeAtomicResponse();
301 }
302 } else {

--- 12 unchanged lines hidden (view full) ---

315{
316 assert(pkt->getAddr() >= start() &&
317 pkt->getAddr() + pkt->getSize() <= start() + size());
318
319
320 uint8_t *hostAddr = pmemAddr + pkt->getAddr() - start();
321
322 if (pkt->isRead()) {
323 memcpy(pkt->getPtr<uint8_t>(), hostAddr, pkt->getSize());
324 TRACE_PACKET("Read");
325 pkt->makeAtomicResponse();
326 } else if (pkt->isWrite()) {
327 memcpy(hostAddr, pkt->getPtr<uint8_t>(), pkt->getSize());
328 TRACE_PACKET("Write");
329 pkt->makeAtomicResponse();
330 } else if (pkt->isPrint()) {
331 Packet::PrintReqState *prs =
332 dynamic_cast<Packet::PrintReqState*>(pkt->senderState);
333 // Need to call printLabels() explicitly since we're not going
334 // through printObj().
335 prs->printLabels();

--- 107 unchanged lines hidden (view full) ---

443 else
444 changeState(Drained);
445 return count;
446}
447
448void
449PhysicalMemory::serialize(ostream &os)
450{
451 gzFile compressedMem;
452 string filename = name() + ".physmem";
453
454 SERIALIZE_SCALAR(filename);
455
456 // write memory file
457 string thefile = Checkpoint::dir() + "/" + filename.c_str();
458 int fd = creat(thefile.c_str(), 0664);

--- 16 unchanged lines hidden (view full) ---

475 if (gzclose(compressedMem))
476 fatal("Close failed on physical memory checkpoint file '%s'\n",
477 filename);
478}
479
480void
481PhysicalMemory::unserialize(Checkpoint *cp, const string &section)
482{
483 gzFile compressedMem;
484 long *tempPage;
485 long *pmem_current;
486 uint64_t curSize;
487 uint32_t bytesRead;
488 const int chunkSize = 16384;
489
490
491 string filename;
492
493 UNSERIALIZE_SCALAR(filename);
494
495 filename = cp->cptDir + "/" + filename;
496
497 // mmap memoryfile
498 int fd = open(filename.c_str(), O_RDONLY);

--- 63 unchanged lines hidden ---