DASM
DExecHWAdapter.pm
Go to the documentation of this file.
00001 #!/usr/bin/perl -w
00002 ##
00003 # Hardware execution adapter.
00004 #
00005 # This class provides a simple interface to hardware implementations.
00006 # Instances of the class can be created which associate a hardware
00007 # offset with the object instance. The instance will dispatch 'read' and
00008 # 'write' functions with the offset.
00009 #
00010 # Example use:
00011 #
00012 # @code
00013 #   my $exec; # Execution object
00014 #   my @core;
00015 #   for my $offset (0..15)
00016 #   {
00017 #       $core[$offset] = new DExecHW($hw, $offset);
00018 #   }
00019 #   $core[4]->write($number, $exec);    # will call $hw->write(4, $number, $exec);
00020 #   my $value = $core[4]->read($exec);  # will call $hw->read(4, $exec);
00021 # @endcode
00022 #
00023 # @file
00024 # @author Justin Fletcher
00025 #
00026 
00027 package DExecHWAdapter;
00028 
00029 
00030 ##
00031 # Construct a new hardware adapter object.
00032 #
00033 # @param[in]  $proto   This class object, or prototype to add to
00034 # @param[in]  $object  The object to proxy for
00035 # @param[in]  $offset  The offset this object is created for
00036 #
00037 # @return Assembler object
00038 sub new
00039 {
00040     my $proto = shift;
00041     my $object = shift;
00042     my $offset = shift || 0;
00043     my $class = ref($proto) || $proto;
00044     my $self = {
00045             'object' => $object,
00046             'offset' => $offset
00047         };
00048 
00049     bless $self, $class;
00050     
00051     return $self;
00052 }
00053 
00054 
00055 ##
00056 # Describe this object.
00057 #
00058 # @param[in]  $self   This Adapter object
00059 #
00060 # @return string describing this object
00061 sub describe
00062 {
00063     my ($self) = @_;
00064     return ref($self->{'object'}) . sprintf "[0x%x]", $self->{'offset'};
00065 }
00066 
00067 
00068 ##
00069 # Retrieve a symbol name for this object.
00070 #
00071 # @param[in]  $self   This Adapter object
00072 #
00073 # @return a symbol name for this register
00074 # @retval undef if no symbol name should be assigned
00075 sub symbol
00076 {
00077     my ($self) = @_;
00078 
00079     if ($self->{'object'}->can('symbol'))
00080     {
00081         my $name = $self->{'object'}->symbol($self->{'offset'});
00082         return undef if (defined $name && $name eq '');
00083         return $name if (defined $name);
00084     }
00085 
00086     my $window = $self->{'object'}->window();
00087     if ($window >= 0x1000)
00088     {
00089         return sprintf("%04x", $self->{'offset'});
00090     }
00091     if ($window >= 0x100)
00092     {
00093         return sprintf("%03x", $self->{'offset'});
00094     }
00095     return sprintf("%02x", $self->{'offset'});
00096 }
00097 
00098 
00099 ##
00100 # 'Read' function; intended to be used to read data from a hardware
00101 # register, supplying an offset.
00102 #
00103 # @param[in] $self   DExecHW object
00104 # @param[in] @args   Arguments to pass to the object's read function,
00105 #                    usually the execution environment object.
00106 #
00107 # @return read value
00108 sub read
00109 {
00110     my $self = shift;
00111     return $self->{'object'}->read($self->{'offset'}, @_);
00112 }
00113 
00114 
00115 ##
00116 # 'Write' function; intended to be used to write data to a hardware
00117 # register, supplying an offset.
00118 #
00119 # @param[in] $self   DExecHW object
00120 # @param[in] @args   Arguments to pass to the object's write function,
00121 #                    usually the value to write and the execution
00122 #                    environment object
00123 #
00124 # @return return value
00125 sub write
00126 {
00127     my $self = shift;
00128     return $self->{'object'}->write($self->{'offset'}, @_);
00129 }
00130 
00131 
00132 # Must return true
00133 1;