abstract_mem.hh revision 2391
12381SN/A/*
212780Snikos.nikoleris@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
38711SN/A * All rights reserved.
48711SN/A *
58711SN/A * Redistribution and use in source and binary forms, with or without
68711SN/A * modification, are permitted provided that the following conditions are
78711SN/A * met: redistributions of source code must retain the above copyright
88711SN/A * notice, this list of conditions and the following disclaimer;
98711SN/A * redistributions in binary form must reproduce the above copyright
108711SN/A * notice, this list of conditions and the following disclaimer in the
118711SN/A * documentation and/or other materials provided with the distribution;
128711SN/A * neither the name of the copyright holders nor the names of its
138711SN/A * contributors may be used to endorse or promote products derived from
142381SN/A * this software without specific prior written permission.
152381SN/A *
162381SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172381SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182381SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192381SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202381SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212381SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222381SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232381SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242381SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252381SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262381SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272381SN/A */
282381SN/A
292381SN/A/* @file
302381SN/A */
312381SN/A
322381SN/A#ifndef __PHYSICAL_MEMORY_HH__
332381SN/A#define __PHYSICAL_MEMORY_HH__
342381SN/A
352381SN/A#include "base/range.hh"
362381SN/A#include "mem/memory.hh"
372381SN/A
382381SN/A//
392665SN/A// Functional model for a contiguous block of physical memory. (i.e. RAM)
402665SN/A//
412772SN/Aclass PhysicalMemory : public Memory
428715SN/A{
438922SN/A  private:
442381SN/A    // prevent copying of a MainMemory object
452381SN/A    PhysicalMemory(const PhysicalMemory &specmem);
462381SN/A    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
472982SN/A
4810405Sandreas.hansson@arm.com  protected:
492381SN/A    Addr base_addr;
502381SN/A    Addr pmem_size;
5110405Sandreas.hansson@arm.com    uint8_t *pmem_addr;
5210405Sandreas.hansson@arm.com    int page_ptr;
532381SN/A
549291SN/A  public:
5511168Sandreas.hansson@arm.com    Addr new_page();
562381SN/A    uint64_t size() { return pmem_size; }
579235SN/A
586215SN/A  public:
592381SN/A    PhysicalMemory(const std::string &n);
6010888Sandreas.hansson@arm.com    virtual ~PhysicalMemory();
6110405Sandreas.hansson@arm.com
629712SN/A  protected:
632381SN/A    // error handling for prot_* functions
649036SN/A    void prot_access_error(Addr addr, int size, const std::string &func);
6510405Sandreas.hansson@arm.com
6610405Sandreas.hansson@arm.com  public:
6710405Sandreas.hansson@arm.com
6810405Sandreas.hansson@arm.com    // Read/Write arbitrary amounts of data to simulated memory space
699036SN/A    virtual void prot_read(Addr addr, uint8_t *p, int size);
7010405Sandreas.hansson@arm.com    virtual void prot_write(Addr addr, const uint8_t *p, int size);
719036SN/A    virtual void prot_memset(Addr addr, uint8_t val, int size);
729036SN/A
7310405Sandreas.hansson@arm.com    // fast back-door memory access for vtophys(), remote gdb, etc.
742381SN/A    uint64_t phys_read_qword(Addr addr) const;
759031SN/A
769036SN/A  public:
772381SN/A    virtual void serialize(std::ostream &os);
789091SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
7910405Sandreas.hansson@arm.com};
8010405Sandreas.hansson@arm.com
8110405Sandreas.hansson@arm.comPhysicalMemory::phys_read_qword(Addr addr) const
8210405Sandreas.hansson@arm.com{
8310405Sandreas.hansson@arm.com    if (addr + sizeof(uint64_t) > pmem_size)
8410405Sandreas.hansson@arm.com        return 0;
859093SN/A
869093SN/A    return *(uint64_t *)(pmem_addr + addr);
8710405Sandreas.hansson@arm.com}
8810405Sandreas.hansson@arm.com
8910405Sandreas.hansson@arm.com
9010405Sandreas.hansson@arm.com#endif //__PHYSICAL_MEMORY_HH__
919091SN/A