Package ghidra.pcode.memstate
Class MemoryBank
java.lang.Object
ghidra.pcode.memstate.MemoryBank
- Direct Known Subclasses:
MemoryImage
,MemoryPageBank
,UniqueMemoryBank
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMemoryBank
(AddressSpace spc, boolean isBigEndian, int ps, MemoryFaultHandler faultHandler) A MemoryBank must be associated with a specific address space, have a preferred or natural pagesize. -
Method Summary
Modifier and TypeMethodDescriptionstatic long
constructValue
(byte[] ptr, int offset, int size, boolean bigendian) This is a static convenience routine for decoding a value from a sequence of bytes depending on the desired endiannessstatic void
deconstructValue
(byte[] ptr, int offset, long val, int size, boolean bigendian) This is a static convenience routine for encoding bytes from a given value, depending on the desired endiannessint
getChunk
(long addrOffset, int size, byte[] res, boolean stopOnUnintialized) This is the most general method for reading a sequence of bytes from the memory bank.int
protected abstract MemoryPage
getPage
(long addr) int
A MemoryBank is instantiated with a natural page size.getSpace()
boolean
void
setChunk
(long offset, int size, byte[] val) This the most general method for writing a sequence of bytes into the memory bank.void
setInitialized
(long offset, int size, boolean initialized) This method allows ranges of bytes to marked as initialized or not.protected abstract void
setPage
(long addr, byte[] val, int skip, int size, int bufOffset) This routine writes data only to a single page of the memory bank.protected abstract void
setPageInitialized
(long addr, boolean initialized, int skip, int size, int bufOffset) This routine marks a range within a single page of the memory bank as initialized or uninitialized.
-
Field Details
-
faultHandler
-
-
Constructor Details
-
MemoryBank
A MemoryBank must be associated with a specific address space, have a preferred or natural pagesize. The pagesize must be a power of 2.- Parameters:
spc
- is the associated address spaceisBigEndian
- memory endiannessps
- ps is the number of bytes in a page (must be a power of 2)faultHandler
- memory fault handler
-
-
Method Details
-
getMemoryFaultHandler
- Returns:
- memory fault handler (may be null)
-
isBigEndian
public boolean isBigEndian()- Returns:
- true if memory bank is big endian
-
getPageSize
public int getPageSize()A MemoryBank is instantiated with a natural page size. Requests for large chunks of data may be broken down into units of this size.- Returns:
- the number of bytes in a page.
-
getInitializedMaskSize
public int getInitializedMaskSize()- Returns:
- the size of a page initialized mask in bytes. Each bit within the mask corresponds to a data byte within a page.
-
getSpace
- Returns:
- the AddressSpace associated with this bank.
-
getPage
-
setPage
protected abstract void setPage(long addr, byte[] val, int skip, int size, int bufOffset) This routine writes data only to a single page of the memory bank. Bytes need not be written to the exact start of the page, but all bytes must be written to only one page when using this routine. A page is a fixed number of bytes, and the address of a page is always aligned based on this size. This routine may be overridden for a page based implementation of the MemoryBank. The default implementation writes the page as a sequence of aligned words, using the insert method.- Parameters:
addr
- is the aligned offset of the desired pageval
- is a pointer to the bytes to be written into the pageskip
- is the offset into the page where bytes will be writtensize
- is the number of bytes to be writtenbufOffset
- the offset in val from which to get the bytes
-
setPageInitialized
protected abstract void setPageInitialized(long addr, boolean initialized, int skip, int size, int bufOffset) This routine marks a range within a single page of the memory bank as initialized or uninitialized. A page is a fixed number of bytes, and the address of a page is always aligned based on this size. This routine may be overridden for a page based implementation of the MemoryBank. The default implementation writes the page as a sequence of aligned words, using the insert method.- Parameters:
addr
- is the aligned offset of the desired pageinitialized
- true if range should be marked as initialized, false if uninitializedskip
- is the offset into the page where bytes will be writtensize
- is the number of bytes to be writtenbufOffset
- the offset in val from which to get the bytes
-
setChunk
public void setChunk(long offset, int size, byte[] val) This the most general method for writing a sequence of bytes into the memory bank. The initial offset and page writes will be wrapped within the address space.- Parameters:
offset
- is the start of the byte range to be written. This offset will be wrapped within the spacesize
- is the number of bytes to writeval
- is a pointer to the sequence of bytes to be written into the bank
-
setInitialized
public void setInitialized(long offset, int size, boolean initialized) This method allows ranges of bytes to marked as initialized or not. There is no restriction on the offset to write to or the number of bytes to be written, except that the range must be contained in the address space.- Parameters:
offset
- is the start of the byte range to be writtensize
- is the number of bytes to writeinitialized
- indicates if the range should be marked as initialized or not
-
getChunk
public int getChunk(long addrOffset, int size, byte[] res, boolean stopOnUnintialized) This is the most general method for reading a sequence of bytes from the memory bank. There is no restriction on the offset or the number of bytes to read, except that the range must be contained in the address space.- Parameters:
addrOffset
- is the start of the byte range to readsize
- is the number of bytes to readres
- is a pointer to where the retrieved bytes should be storedstopOnUnintialized
- if true a partial read is permitted and returned size may be smaller than size requested if uninitialized data is encountered.- Returns:
- number of bytes actually read
-
constructValue
public static long constructValue(byte[] ptr, int offset, int size, boolean bigendian) This is a static convenience routine for decoding a value from a sequence of bytes depending on the desired endianness- Parameters:
ptr
- is the pointer to the bytes to decodeoffset
- a fixed offset fromptr
used during decodesize
- is the number of bytesbigendian
- is true if the bytes are encoded in big endian form- Returns:
- the decoded value
-
deconstructValue
public static void deconstructValue(byte[] ptr, int offset, long val, int size, boolean bigendian) This is a static convenience routine for encoding bytes from a given value, depending on the desired endianness- Parameters:
ptr
- is a pointer to the location to write the encoded bytesoffset
- a fixed offset fromptr
to where to write the bytesval
- is the value to be encodedsize
- is the number of bytes to encodebigendian
- is true if a big endian encoding is desired
-