com.github.croesch.micro_debug.mic1.mem
Class Memory

java.lang.Object
  extended by com.github.croesch.micro_debug.mic1.mem.Memory
All Implemented Interfaces:
IReadableMemory

public final class Memory
extends Object
implements IReadableMemory

Represents the main memory of the processor.

Since:
Date: Nov 21, 2011
Author:
croesch

Field Summary
static int IJVM_MAGIC_NUMBER
          the magic number that is needed at the begin of a binary ijvm-file
static int MEMORY_MAPPED_IO_ADDRESS
          address which isn't an address in the memory, but is connected to memory mapped io
 
Constructor Summary
Memory(int maxSize, InputStream programStream)
          Constructs a new memory containing the given number of words.
 
Method Summary
 void doTick()
          Tells the memory to do its work.
 void fillRegisters(Register wordRegister, Register byteRegister)
          If at least the signal read or fetch has been set in the memory.
 int getByte(int addr)
          Returns a single byte, unsigned, read from the address in the memory.
 int getSize()
          Returns the size of the memory.
 int getWord(int addr)
          Returns the word value at the given address.
 void reset()
          Resets the Memory so that it behaves as when started.
 void setByteAddress(int addr)
          Sets the address of the byte, where to read from in the memory.
 void setFetch(boolean ft)
          Sets the input signal fetch, that enforces the main memory to read a byte from the memory.
 void setRead(boolean rd)
          Sets the input signal read, that enforces the main memory to read a word from the memory.
 void setWord(int addr, int value)
          Sets the word value at the given address to the given value.
 void setWordAddress(int addr)
          Sets the address of the word, where to read from or write to in the memory.
 void setWordValue(int value)
          Sets the value of the word to write to the memory.
 void setWrite(boolean wr)
          Sets the input signal write, that enforces the main memory to write a word to the memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEMORY_MAPPED_IO_ADDRESS

public static final int MEMORY_MAPPED_IO_ADDRESS
address which isn't an address in the memory, but is connected to memory mapped io

See Also:
Constant Field Values

IJVM_MAGIC_NUMBER

public static final int IJVM_MAGIC_NUMBER
the magic number that is needed at the begin of a binary ijvm-file

See Also:
Constant Field Values
Constructor Detail

Memory

public Memory(int maxSize,
              InputStream programStream)
       throws FileFormatException
Constructs a new memory containing the given number of words. The initial memory will contain only zeros and then filled with the bytes read from the given input stream.

Parameters:
maxSize - the size of the memory in words (32-bit-values)
programStream - the input stream
Throws:
FileFormatException - if the stream doesn't provide valid data.
Since:
Date: Nov 23, 2011
Method Detail

reset

public void reset()
Resets the Memory so that it behaves as when started.

Since:
Date: Jan 27, 2012

setRead

public void setRead(boolean rd)
Sets the input signal read, that enforces the main memory to read a word from the memory.

Parameters:
rd - true, if the memory should read a word.
Since:
Date: Nov 21, 2011
See Also:
setWordAddress(int)

setWrite

public void setWrite(boolean wr)
Sets the input signal write, that enforces the main memory to write a word to the memory.

Parameters:
wr - true, if the memory should write a word.
Since:
Date: Nov 21, 2011
See Also:
setWordAddress(int), setWordValue(int)

setFetch

public void setFetch(boolean ft)
Sets the input signal fetch, that enforces the main memory to read a byte from the memory.

Parameters:
ft - true, if the memory should read a byte.
Since:
Date: Nov 21, 2011
See Also:
setByteAddress(int)

setWordAddress

public void setWordAddress(int addr)
Sets the address of the word, where to read from or write to in the memory.

Parameters:
addr - 32-bit-value that defines the address where to read from or write to a word.
Since:
Date: Nov 21, 2011
See Also:
setRead(boolean), setWrite(boolean)

setWordValue

public void setWordValue(int value)
Sets the value of the word to write to the memory.

Parameters:
value - the word value to write to the memory.
Since:
Date: Nov 21, 2011
See Also:
setWrite(boolean), setWordAddress(int)

setByteAddress

public void setByteAddress(int addr)
Sets the address of the byte, where to read from in the memory.

Parameters:
addr - 32-bit-value that defines the address where to read a byte from.
Since:
Date: Nov 21, 2011
See Also:
setFetch(boolean)

fillRegisters

public void fillRegisters(Register wordRegister,
                          Register byteRegister)
If at least the signal read or fetch has been set in the memory. The values read will be stored in the given registers.
Note: You have to call doTick() before invoking this method.

Parameters:
wordRegister - if the signal read has been set, will be filled with the value read from the memory
byteRegister - if the signal fetch has been set, will be filled with the value read from the memory
Since:
Date: Nov 21, 2011
See Also:
doTick()

doTick

public void doTick()
Tells the memory to do its work. Based on the signals read, write and fetch it will do some work. It will store the value to write into the memory and the values read from the memory into variables.

Since:
Date: Nov 21, 2011
See Also:
fillRegisters(Register, Register)

getByte

public int getByte(int addr)
Returns a single byte, unsigned, read from the address in the memory.

Specified by:
getByte in interface IReadableMemory
Parameters:
addr - the byte address of the byte to read from the memory
Returns:
the byte from the memory at the given address.
Since:
Date: Jan 22, 2012

getWord

public int getWord(int addr)
Returns the word value at the given address.

Specified by:
getWord in interface IReadableMemory
Parameters:
addr - the address, from where to fetch the word
Returns:
the word value read from the memory
Since:
Date: Jan 21, 2012

setWord

public void setWord(int addr,
                    int value)
Sets the word value at the given address to the given value.

Parameters:
addr - the address, where to write the word to
value - the word to write to the memory
Since:
Date: Jan 21, 2012

getSize

public int getSize()
Returns the size of the memory.

Specified by:
getSize in interface IReadableMemory
Returns:
the size of the memory in words
Since:
Date: Feb 9, 2012


Copyright © 2012. All Rights Reserved.