physical.cc (4870:fcc39d001154) | physical.cc (4918:3214e3694fb2) |
---|---|
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; --- 30 unchanged lines hidden (view full) --- 39#include <iostream> 40#include <string> 41 42#include "arch/isa_traits.hh" 43#include "base/misc.hh" 44#include "config/full_system.hh" 45#include "mem/packet_access.hh" 46#include "mem/physical.hh" | 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; --- 30 unchanged lines hidden (view full) --- 39#include <iostream> 40#include <string> 41 42#include "arch/isa_traits.hh" 43#include "base/misc.hh" 44#include "config/full_system.hh" 45#include "mem/packet_access.hh" 46#include "mem/physical.hh" |
47#include "sim/builder.hh" | |
48#include "sim/eventq.hh" 49#include "sim/host.hh" 50 51using namespace std; 52using namespace TheISA; 53 | 47#include "sim/eventq.hh" 48#include "sim/host.hh" 49 50using namespace std; 51using namespace TheISA; 52 |
54PhysicalMemory::PhysicalMemory(Params *p) 55 : MemObject(p->name), pmemAddr(NULL), lat(p->latency), _params(p) | 53PhysicalMemory::PhysicalMemory(const Params *p) 54 : MemObject(p), pmemAddr(NULL), lat(p->latency) |
56{ | 55{ |
57 if (params()->addrRange.size() % TheISA::PageBytes != 0) | 56 if (params()->range.size() % TheISA::PageBytes != 0) |
58 panic("Memory Size not divisible by page size\n"); 59 60 int map_flags = MAP_ANON | MAP_PRIVATE; | 57 panic("Memory Size not divisible by page size\n"); 58 59 int map_flags = MAP_ANON | MAP_PRIVATE; |
61 pmemAddr = 62 (uint8_t *)mmap(NULL, params()->addrRange.size(), 63 PROT_READ | PROT_WRITE, map_flags, -1, 0); | 60 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(), 61 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 | 62 63 if (pmemAddr == (void *)MAP_FAILED) { 64 perror("mmap"); 65 fatal("Could not mmap!\n"); 66 } 67 68 //If requested, initialize all the memory to 0 |
71 if(params()->zero) 72 memset(pmemAddr, 0, params()->addrRange.size()); | 69 if (p->zero) 70 memset(pmemAddr, 0, p->range.size()); |
73 74 pagePtr = 0; 75} 76 77void 78PhysicalMemory::init() 79{ 80 if (ports.size() == 0) { --- 4 unchanged lines hidden (view full) --- 85 if (*pi) 86 (*pi)->sendStatusChange(Port::RangeChange); 87 } 88} 89 90PhysicalMemory::~PhysicalMemory() 91{ 92 if (pmemAddr) | 71 72 pagePtr = 0; 73} 74 75void 76PhysicalMemory::init() 77{ 78 if (ports.size() == 0) { --- 4 unchanged lines hidden (view full) --- 83 if (*pi) 84 (*pi)->sendStatusChange(Port::RangeChange); 85 } 86} 87 88PhysicalMemory::~PhysicalMemory() 89{ 90 if (pmemAddr) |
93 munmap((char*)pmemAddr, params()->addrRange.size()); | 91 munmap((char*)pmemAddr, params()->range.size()); |
94 //Remove memPorts? 95} 96 97Addr 98PhysicalMemory::new_page() 99{ 100 Addr return_addr = pagePtr << LogVMPageSize; 101 return_addr += start(); --- 277 unchanged lines hidden (view full) --- 379 memory->getAddressRanges(resp, snoop); 380} 381 382void 383PhysicalMemory::getAddressRanges(AddrRangeList &resp, bool &snoop) 384{ 385 snoop = false; 386 resp.clear(); | 92 //Remove memPorts? 93} 94 95Addr 96PhysicalMemory::new_page() 97{ 98 Addr return_addr = pagePtr << LogVMPageSize; 99 return_addr += start(); --- 277 unchanged lines hidden (view full) --- 377 memory->getAddressRanges(resp, snoop); 378} 379 380void 381PhysicalMemory::getAddressRanges(AddrRangeList &resp, bool &snoop) 382{ 383 snoop = false; 384 resp.clear(); |
387 resp.push_back(RangeSize(start(), params()->addrRange.size())); | 385 resp.push_back(RangeSize(start(), params()->range.size())); |
388} 389 390int 391PhysicalMemory::MemoryPort::deviceBlockSize() 392{ 393 return memory->deviceBlockSize(); 394} 395 --- 45 unchanged lines hidden (view full) --- 441 fatal("Can't open physical memory checkpoint file '%s'\n", filename); 442 } 443 444 compressedMem = gzdopen(fd, "wb"); 445 if (compressedMem == NULL) 446 fatal("Insufficient memory to allocate compression state for %s\n", 447 filename); 448 | 386} 387 388int 389PhysicalMemory::MemoryPort::deviceBlockSize() 390{ 391 return memory->deviceBlockSize(); 392} 393 --- 45 unchanged lines hidden (view full) --- 439 fatal("Can't open physical memory checkpoint file '%s'\n", filename); 440 } 441 442 compressedMem = gzdopen(fd, "wb"); 443 if (compressedMem == NULL) 444 fatal("Insufficient memory to allocate compression state for %s\n", 445 filename); 446 |
449 if (gzwrite(compressedMem, pmemAddr, params()->addrRange.size()) != params()->addrRange.size()) { | 447 if (gzwrite(compressedMem, pmemAddr, params()->range.size()) != 448 params()->range.size()) { |
450 fatal("Write failed on physical memory checkpoint file '%s'\n", 451 filename); 452 } 453 454 if (gzclose(compressedMem)) 455 fatal("Close failed on physical memory checkpoint file '%s'\n", 456 filename); 457} --- 25 unchanged lines hidden (view full) --- 483 compressedMem = gzdopen(fd, "rb"); 484 if (compressedMem == NULL) 485 fatal("Insufficient memory to allocate compression state for %s\n", 486 filename); 487 488 // unmap file that was mmaped in the constructor 489 // This is done here to make sure that gzip and open don't muck with our 490 // nice large space of memory before we reallocate it | 449 fatal("Write failed on physical memory checkpoint file '%s'\n", 450 filename); 451 } 452 453 if (gzclose(compressedMem)) 454 fatal("Close failed on physical memory checkpoint file '%s'\n", 455 filename); 456} --- 25 unchanged lines hidden (view full) --- 482 compressedMem = gzdopen(fd, "rb"); 483 if (compressedMem == NULL) 484 fatal("Insufficient memory to allocate compression state for %s\n", 485 filename); 486 487 // unmap file that was mmaped in the constructor 488 // This is done here to make sure that gzip and open don't muck with our 489 // nice large space of memory before we reallocate it |
491 munmap((char*)pmemAddr, params()->addrRange.size()); | 490 munmap((char*)pmemAddr, params()->range.size()); |
492 | 491 |
493 pmemAddr = (uint8_t *)mmap(NULL, params()->addrRange.size(), PROT_READ | PROT_WRITE, 494 MAP_ANON | MAP_PRIVATE, -1, 0); | 492 pmemAddr = (uint8_t *)mmap(NULL, params()->range.size(), 493 PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); |
495 496 if (pmemAddr == (void *)MAP_FAILED) { 497 perror("mmap"); 498 fatal("Could not mmap physical memory!\n"); 499 } 500 501 curSize = 0; 502 tempPage = (long*)malloc(chunkSize); 503 if (tempPage == NULL) 504 fatal("Unable to malloc memory to read file %s\n", filename); 505 506 /* Only copy bytes that are non-zero, so we don't give the VM system hell */ | 494 495 if (pmemAddr == (void *)MAP_FAILED) { 496 perror("mmap"); 497 fatal("Could not mmap physical memory!\n"); 498 } 499 500 curSize = 0; 501 tempPage = (long*)malloc(chunkSize); 502 if (tempPage == NULL) 503 fatal("Unable to malloc memory to read file %s\n", filename); 504 505 /* Only copy bytes that are non-zero, so we don't give the VM system hell */ |
507 while (curSize < params()->addrRange.size()) { | 506 while (curSize < params()->range.size()) { |
508 bytesRead = gzread(compressedMem, tempPage, chunkSize); | 507 bytesRead = gzread(compressedMem, tempPage, chunkSize); |
509 if (bytesRead != chunkSize && bytesRead != params()->addrRange.size() - curSize) | 508 if (bytesRead != chunkSize && 509 bytesRead != params()->range.size() - curSize) |
510 fatal("Read failed on physical memory checkpoint file '%s'" 511 " got %d bytes, expected %d or %d bytes\n", | 510 fatal("Read failed on physical memory checkpoint file '%s'" 511 " got %d bytes, expected %d or %d bytes\n", |
512 filename, bytesRead, chunkSize, params()->addrRange.size()-curSize); | 512 filename, bytesRead, chunkSize, 513 params()->range.size() - curSize); |
513 514 assert(bytesRead % sizeof(long) == 0); 515 516 for (int x = 0; x < bytesRead/sizeof(long); x++) 517 { 518 if (*(tempPage+x) != 0) { 519 pmem_current = (long*)(pmemAddr + curSize + x * sizeof(long)); 520 *pmem_current = *(tempPage+x); --- 5 unchanged lines hidden (view full) --- 526 free(tempPage); 527 528 if (gzclose(compressedMem)) 529 fatal("Close failed on physical memory checkpoint file '%s'\n", 530 filename); 531 532} 533 | 514 515 assert(bytesRead % sizeof(long) == 0); 516 517 for (int x = 0; x < bytesRead/sizeof(long); x++) 518 { 519 if (*(tempPage+x) != 0) { 520 pmem_current = (long*)(pmemAddr + curSize + x * sizeof(long)); 521 *pmem_current = *(tempPage+x); --- 5 unchanged lines hidden (view full) --- 527 free(tempPage); 528 529 if (gzclose(compressedMem)) 530 fatal("Close failed on physical memory checkpoint file '%s'\n", 531 filename); 532 533} 534 |
534 535BEGIN_DECLARE_SIM_OBJECT_PARAMS(PhysicalMemory) 536 537 Param<string> file; 538 Param<Range<Addr> > range; 539 Param<Tick> latency; 540 Param<bool> zero; 541 542END_DECLARE_SIM_OBJECT_PARAMS(PhysicalMemory) 543 544BEGIN_INIT_SIM_OBJECT_PARAMS(PhysicalMemory) 545 546 INIT_PARAM_DFLT(file, "memory mapped file", ""), 547 INIT_PARAM(range, "Device Address Range"), 548 INIT_PARAM(latency, "Memory access latency"), 549 INIT_PARAM(zero, "Zero initialize memory") 550 551END_INIT_SIM_OBJECT_PARAMS(PhysicalMemory) 552 553CREATE_SIM_OBJECT(PhysicalMemory) | 535PhysicalMemory * 536PhysicalMemoryParams::create() |
554{ | 537{ |
555 PhysicalMemory::Params *p = new PhysicalMemory::Params; 556 p->name = getInstanceName(); 557 p->addrRange = range; 558 p->latency = latency; 559 p->zero = zero; 560 return new PhysicalMemory(p); | 538 return new PhysicalMemory(this); |
561} | 539} |
562 563REGISTER_SIM_OBJECT("PhysicalMemory", PhysicalMemory) | |