1 /* Definitions to support mapping ranges.
2    Copyright 2001, 2003 Brian R. Gaeke.
3 
4 This file is part of VMIPS.
5 
6 VMIPS is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10 
11 VMIPS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15 
16 You should have received a copy of the GNU General Public License along
17 with VMIPS; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19 
20 #ifndef _RANGE_H_
21 #define _RANGE_H_
22 
23 #include "accesstypes.h"
24 #include "types.h"
25 #include <sys/types.h>
26 class DeviceExc;
27 
28 /* Base class for managing a range of mapped memory. Memory-mapped
29  * devices (class DeviceMap) derive from this.
30  */
31 class Range {
32 protected:
33 	uint32 base;        // first physical address represented
34 	uint32 extent;      // number of bytes of memory provided
35 	void *address;      // host machine pointer to start of memory
36 	int perms;          // MEM_READ, MEM_WRITE, ... in accesstypes.h
37 
38 public:
Range(uint32 _base,uint32 _extent,caddr_t _address,int _perms)39 	Range(uint32 _base, uint32 _extent, caddr_t _address, int _perms) :
40 		base(_base), extent(_extent), address(_address), perms(_perms) { }
~Range()41 	virtual ~Range() { }
42 
43 	bool incorporates(uint32 addr);
44 	bool overlaps(Range *r);
getBase()45 	uint32 getBase () const { return base; }
getExtent()46 	uint32 getExtent () const { return extent; }
getAddress()47 	void *getAddress () const { return address; }
getPerms()48 	int getPerms () const { return perms; }
setBase(uint32 newBase)49 	void setBase (uint32 newBase) { base = newBase; }
setPerms(int newPerms)50 	void setPerms (int newPerms) { perms = newPerms; }
51 
canRead(uint32 offset)52 	virtual bool canRead (uint32 offset) { return perms & MEM_READ; }
canWrite(uint32 offset)53 	virtual bool canWrite (uint32 offset) { return perms & MEM_WRITE; }
54 
55 	virtual uint32 fetch_word(uint32 offset, int mode, DeviceExc *client);
56 	virtual uint16 fetch_halfword(uint32 offset, DeviceExc *client);
57 	virtual uint8 fetch_byte(uint32 offset, DeviceExc *client);
58 	virtual void store_word(uint32 offset, uint32 data, DeviceExc *client);
59 	virtual void store_halfword(uint32 offset, uint16 data,
60 		DeviceExc *client);
61 	virtual void store_byte(uint32 offset, uint8 data, DeviceExc *client);
62 };
63 
64 
65 #endif /* _RANGE_H_ */
66