com.cmpware.gdb
Class FIF

java.lang.Object
  extended by com.cmpware.gdb.RSP
      extended by com.cmpware.gdb.FIF

public class FIF
extends RSP

This class provides a Funtional interFace (FIF) to the GDB server. It makes use of the underlying Remote Serial Protocol (RSP). This interface is mostly read / write registers / memory. Methods make use of caching to improve performance over the serial protocol. Note that while reads may be cached, writes are always direct. This resembles a 'write through' protocol.

Copyright (c) 2007 Cmpware, Inc. All Rights Reserved.

Author:
SAG

Field Summary
protected  int cacheSize
          The cache size / maximum buffer size
protected  int cacheStartAddr
          The current memory cache start address
static java.lang.String copyright
          Copyright string
static boolean DEBUG
          The debug flag
protected  java.lang.String memCache
          The memory cache
protected  java.lang.String regCache
          The register cache
protected  int regSize
          The register size (in bytes)
 
Fields inherited from class com.cmpware.gdb.RSP
in, out, socket
 
Constructor Summary
FIF()
           
 
Method Summary
 long[] getDebugRegisters()
          This method returns an array of longs representing the general purpose registers.
 long getRegister(int i)
          This method returns a long representing a register.
 long getRegisterImm(int i)
          This method returns a long representing a general purpose register.
 int[] getRegisters()
          This method returns an array of integers representing the general purpose registers.
 int getRegisterSize()
          This method returns the regiser size, in bytes.
static void main(java.lang.String[] args)
          This main program is used for testing.
 long read(int addr, int bytes)
          This method reads data and returns a long.
 long readImm(int addr, int bytes)
          This method reads data and returns a long.
 void setRegister(int i, long data)
          This method sets a register.
 void setRegisterSize(int regSize)
          This method sets the register size.
 void step(int i)
          This method steps the target.
 void write(int addr, byte[] data)
          This method writes a buffer of data to the host.
 void write(int addr, int bytes, long data)
          This method is used to write between one and eight bytes of data to the target.
 
Methods inherited from class com.cmpware.gdb.RSP
checksum, connect, disconnect, isError, isOk, isPacket, recv, recvPacket, send, sendPacket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
The debug flag

See Also:
Constant Field Values

copyright

public static final java.lang.String copyright
Copyright string

See Also:
Constant Field Values

cacheSize

protected int cacheSize
The cache size / maximum buffer size


cacheStartAddr

protected int cacheStartAddr
The current memory cache start address


memCache

protected java.lang.String memCache
The memory cache


regCache

protected java.lang.String regCache
The register cache


regSize

protected int regSize
The register size (in bytes)

Constructor Detail

FIF

public FIF()
Method Detail

main

public static void main(java.lang.String[] args)
This main program is used for testing.


setRegisterSize

public void setRegisterSize(int regSize)
This method sets the register size. Note that this size is in bytes.

Parameters:
regSize - the register size, in bytes.

getRegisterSize

public int getRegisterSize()
This method returns the regiser size, in bytes.

Returns:
this method returns the regiser size, in bytes.

getRegisters

public int[] getRegisters()
                   throws java.io.IOException
This method returns an array of integers representing the general purpose registers. Note that this breaks the registers into 32 bit values, no matter what the actual register size. This is for consumption by the Cmpware IDE.

Returns:
This method returns an array of integers representing the general purpose registers.
Throws:
java.io.IOException - if there is a communication error.

getDebugRegisters

public long[] getDebugRegisters()
                         throws java.io.IOException
This method returns an array of longs representing the general purpose registers. Note that this returns the natural values of the registers and not the values broken into 32-bit pieces. This is necessary for the DWARF2 data location, among other things.

Returns:
This method returns an array of longs representing the general purpose registers.
Throws:
java.io.IOException - if there is a communication error.

getRegister

public long getRegister(int i)
                 throws java.io.IOException
This method returns a long representing a register.

Parameters:
i - the index of the register.
Returns:
This method returns a long representing a register.
Throws:
java.io.IOException - if there is a communication error.

getRegisterImm

public long getRegisterImm(int i)
                    throws java.io.IOException
This method returns a long representing a general purpose register. It is assumed that registers will be no larger than 64 bits. Note that this register goes directly to the GDB target to get its value. Using the cached getRegister() method will be faster for repeated reads of values.

Parameters:
i - the index of the register.
Returns:
This method returns a long representing a register.
Throws:
java.io.IOException - if there is a communication error.

setRegister

public void setRegister(int i,
                        long data)
                 throws java.io.IOException
This method sets a register. Note that this happens immediately and bypasses any caching.

Parameters:
i - the register number
data - the register data to be written.
Throws:
java.io.IOException - if there is a communication error.

readImm

public long readImm(int addr,
                    int bytes)
             throws java.io.IOException
This method reads data and returns a long. Note that this is an immediate call and no caching is performed.

Parameters:
addr - the memory address.
bytes - the number of bytes to read (should be 1 - 8).
Returns:
this method returns 1 through 8 byte data from a given address as a 64 bit long.
Throws:
java.io.IOException - is thrown if any communication errors occur during this method call.

read

public long read(int addr,
                 int bytes)
          throws java.io.IOException
This method reads data and returns a long. Note that caching is performed to improve performance.

Parameters:
addr - the memory address.
bytes - the number of bytes to read (should be 1 - 8).
Returns:
this method returns 1 through 8 byte data from a given address as a 64 bit long.
Throws:
java.io.IOException - is thrown if any communication errors occur during this method call.

write

public void write(int addr,
                  int bytes,
                  long data)
           throws java.io.IOException
This method is used to write between one and eight bytes of data to the target.

Parameters:
addr - the address th which the data is written.
bytes - the number of bytes to be written. Should be a value between one and eight.
data - the data to be written, in the form of a 64-bit long integer.
Throws:
java.io.IOException - is thrown if any communication errors occur during this method call.

write

public void write(int addr,
                  byte[] data)
           throws java.io.IOException
This method writes a buffer of data to the host. This may take several packets depending on ths size of the data being written. Note that this function is 'immediate' and does not use the cache.

Parameters:
addr - the address to which to write the buffer.
data - the data to be written.
Throws:
java.io.IOException - is thrown if any communication errors occur during this method call.

step

public void step(int i)
          throws java.io.IOException
This method steps the target.

Parameters:
i - the number of cycles to step the tareget.
Throws:
java.io.IOException - is thrown if any communication errors occur during this method call.