abstract_mem.hh revision 2391
14486Sbinkertn@umich.edu/*
24486Sbinkertn@umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
34486Sbinkertn@umich.edu * All rights reserved.
44486Sbinkertn@umich.edu *
54486Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without
64486Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are
74486Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright
84486Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer;
94486Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright
104486Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the
114486Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution;
124486Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its
134486Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from
144486Sbinkertn@umich.edu * this software without specific prior written permission.
154486Sbinkertn@umich.edu *
164486Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174486Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184486Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194486Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204486Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214486Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224486Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234486Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244486Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254486Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264486Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274486Sbinkertn@umich.edu */
284486Sbinkertn@umich.edu
294486Sbinkertn@umich.edu/* @file
304486Sbinkertn@umich.edu */
314486Sbinkertn@umich.edu
324486Sbinkertn@umich.edu#ifndef __PHYSICAL_MEMORY_HH__
334486Sbinkertn@umich.edu#define __PHYSICAL_MEMORY_HH__
344486Sbinkertn@umich.edu
354486Sbinkertn@umich.edu#include "base/range.hh"
364486Sbinkertn@umich.edu#include "mem/memory.hh"
374486Sbinkertn@umich.edu
384486Sbinkertn@umich.edu//
394486Sbinkertn@umich.edu// Functional model for a contiguous block of physical memory. (i.e. RAM)
404486Sbinkertn@umich.edu//
414486Sbinkertn@umich.educlass PhysicalMemory : public Memory
424486Sbinkertn@umich.edu{
434486Sbinkertn@umich.edu  private:
44    // prevent copying of a MainMemory object
45    PhysicalMemory(const PhysicalMemory &specmem);
46    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
47
48  protected:
49    Addr base_addr;
50    Addr pmem_size;
51    uint8_t *pmem_addr;
52    int page_ptr;
53
54  public:
55    Addr new_page();
56    uint64_t size() { return pmem_size; }
57
58  public:
59    PhysicalMemory(const std::string &n);
60    virtual ~PhysicalMemory();
61
62  protected:
63    // error handling for prot_* functions
64    void prot_access_error(Addr addr, int size, const std::string &func);
65
66  public:
67
68    // Read/Write arbitrary amounts of data to simulated memory space
69    virtual void prot_read(Addr addr, uint8_t *p, int size);
70    virtual void prot_write(Addr addr, const uint8_t *p, int size);
71    virtual void prot_memset(Addr addr, uint8_t val, int size);
72
73    // fast back-door memory access for vtophys(), remote gdb, etc.
74    uint64_t phys_read_qword(Addr addr) const;
75
76  public:
77    virtual void serialize(std::ostream &os);
78    virtual void unserialize(Checkpoint *cp, const std::string &section);
79};
80
81PhysicalMemory::phys_read_qword(Addr addr) const
82{
83    if (addr + sizeof(uint64_t) > pmem_size)
84        return 0;
85
86    return *(uint64_t *)(pmem_addr + addr);
87}
88
89
90#endif //__PHYSICAL_MEMORY_HH__
91