abstract_mem.hh revision 2413
12440SN/A/*
22440SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
32440SN/A * All rights reserved.
42440SN/A *
52440SN/A * Redistribution and use in source and binary forms, with or without
62440SN/A * modification, are permitted provided that the following conditions are
72440SN/A * met: redistributions of source code must retain the above copyright
82440SN/A * notice, this list of conditions and the following disclaimer;
92440SN/A * redistributions in binary form must reproduce the above copyright
102440SN/A * notice, this list of conditions and the following disclaimer in the
112440SN/A * documentation and/or other materials provided with the distribution;
122440SN/A * neither the name of the copyright holders nor the names of its
132440SN/A * contributors may be used to endorse or promote products derived from
142440SN/A * this software without specific prior written permission.
152440SN/A *
162440SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172440SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182440SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192440SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202440SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212440SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222440SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232440SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242440SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252440SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262440SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu/* @file
302440SN/A */
312440SN/A
322440SN/A#ifndef __PHYSICAL_MEMORY_HH__
332440SN/A#define __PHYSICAL_MEMORY_HH__
342440SN/A
352972Sgblack@eecs.umich.edu#include "base/range.hh"
366330Sgblack@eecs.umich.edu#include "mem/memory.hh"
378229Snate@binkert.org
3812334Sgabeblack@google.com//
397720Sgblack@eecs.umich.edu// Functional model for a contiguous block of physical memory. (i.e. RAM)
403120Sgblack@eecs.umich.edu//
418300Schander.sudanthi@arm.comclass PhysicalMemory : public Memory
422440SN/A{
435569Snate@binkert.org    class MemoryPort : public Port
445569Snate@binkert.org    {
457720Sgblack@eecs.umich.edu        PhysicalMemory *memory;
467720Sgblack@eecs.umich.edu
477720Sgblack@eecs.umich.edu      public:
487720Sgblack@eecs.umich.edu
497720Sgblack@eecs.umich.edu        MemoryPort(PhysicalMemory *_memory);
507720Sgblack@eecs.umich.edu
517720Sgblack@eecs.umich.edu      protected:
527720Sgblack@eecs.umich.edu
537707Sgblack@eecs.umich.edu        virtual bool recvTiming(Packet &pkt);
545569Snate@binkert.org
555569Snate@binkert.org        virtual Tick recvAtomic(Packet &pkt);
565569Snate@binkert.org
572440SN/A        virtual void recvFunctional(Packet &pkt);
585569Snate@binkert.org
595569Snate@binkert.org        virtual void recvStatusChange(Status status);
604826Ssaidi@eecs.umich.edu
615569Snate@binkert.org        virtual void getDeviceAddressRanges(AddrRangeList &range_list,
625569Snate@binkert.org                                            bool &owner);
635569Snate@binkert.org
645569Snate@binkert.org        virtual int deviceBlockSize();
655569Snate@binkert.org
665569Snate@binkert.org    };
672440SN/A
685569Snate@binkert.org    MemoryPort memoryPort;
695569Snate@binkert.org
709180Sandreas.hansson@arm.com    Port * PhysicalMemory::getPort(const char *if_name);
7110407Smitch.hayenga@arm.com
722440SN/A    int lat;
735569Snate@binkert.org
745569Snate@binkert.org    //event to send response needs to be here
755569Snate@binkert.org
765569Snate@binkert.org  private:
772440SN/A    // prevent copying of a MainMemory object
785569Snate@binkert.org    PhysicalMemory(const PhysicalMemory &specmem);
792440SN/A    const PhysicalMemory &operator=(const PhysicalMemory &specmem);
805569Snate@binkert.org
8111294Sandreas.hansson@arm.com  protected:
822440SN/A    Addr base_addr;
835569Snate@binkert.org    Addr pmem_size;
845569Snate@binkert.org    uint8_t *pmem_addr;
855569Snate@binkert.org    int page_ptr;
862440SN/A
875569Snate@binkert.org  public:
885569Snate@binkert.org    Addr new_page();
892440SN/A    uint64_t size() { return pmem_size; }
905569Snate@binkert.org
915569Snate@binkert.org  public:
925569Snate@binkert.org    PhysicalMemory(const std::string &n);
932440SN/A    virtual ~PhysicalMemory();
945569Snate@binkert.org
955569Snate@binkert.org  protected:
965569Snate@binkert.org    // error handling for prot_* functions
972440SN/A    void prot_access_error(Addr addr, int size, const std::string &func);
985569Snate@binkert.org
995569Snate@binkert.org  public:
1002440SN/A    virtual int deviceBlockSize();
1016329Sgblack@eecs.umich.edu
1026329Sgblack@eecs.umich.edu    // Read/Write arbitrary amounts of data to simulated memory space
1036329Sgblack@eecs.umich.edu    void prot_read(Addr addr, uint8_t *p, int size);
1046329Sgblack@eecs.umich.edu    void prot_write(Addr addr, const uint8_t *p, int size);
1057693SAli.Saidi@ARM.com    void prot_memset(Addr addr, uint8_t val, int size);
1067720Sgblack@eecs.umich.edu
1077720Sgblack@eecs.umich.edu    // fast back-door memory access for vtophys(), remote gdb, etc.
10810417Sandreas.hansson@arm.com    uint64_t phys_read_qword(Addr addr) const;
1097720Sgblack@eecs.umich.edu  private:
1107720Sgblack@eecs.umich.edu    bool doTimingAccess(Packet &pkt);
1117720Sgblack@eecs.umich.edu    Tick doAtomicAccess(Packet &pkt);
1127720Sgblack@eecs.umich.edu    void doFunctionalAccess(Packet &pkt);
1138300Schander.sudanthi@arm.com
1148300Schander.sudanthi@arm.com    void recvStatusChange(Port::Status status);
1158300Schander.sudanthi@arm.com
1168300Schander.sudanthi@arm.com  public:
1178300Schander.sudanthi@arm.com    virtual void serialize(std::ostream &os);
1188300Schander.sudanthi@arm.com    virtual void unserialize(Checkpoint *cp, const std::string &section);
1192440SN/A};
1202440SN/A
1215569Snate@binkert.org/*uint64_t
122PhysicalMemory::phys_read_qword(Addr addr) const
123{
124    if (addr + sizeof(uint64_t) > pmem_size)
125        return 0;
126
127    return *(uint64_t *)(pmem_addr + addr);
128}*/
129
130
131#endif //__PHYSICAL_MEMORY_HH__
132