1 // busif.cxx - a component for testing word_bus<>. -*- C++ -*-
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
14 #include <sidcomputil.h>
17 #include <sidbusutil.h>
20 using namespace sidutil;
23 template <typename DataType>
24 class Busif : public virtual component,
25 public no_accessor_component,
26 public no_attribute_component,
27 public no_relation_component,
28 public fixed_bus_map_component,
29 public no_pin_component
32 class BusInterface : public word_bus<DataType> {
34 unsigned char mem[0x100];
36 typedef typename DataType::value_type internal_type;
40 for( int i=0; i<0x100; i++ ) mem[i] = i + 1;
43 sid::bus::status word_write( host_int_4 addr,
46 host_int_4 a = addr * sizeof( internal_type );
47 internal_type m = mask;
48 internal_type d = data;
50 if( sizeof(internal_type) == 8 )
51 printf( "write>>addr %d mask 0x%016llx data 0x%llx<<write\n", a, m, d );
53 printf( "write>>addr %d mask 0x%08x data 0x%x<<write\n", a, m, d );
55 for( int i=0; i<sizeof(internal_type); i++ ) {
56 if( mask.read_byte( i ) ) {
57 if( data.read_byte( i ) != mem[a + i] ) {
58 printf( "mismatch in byte %d: %02x != %02x\n", i,
59 data.read_byte(i), mem[a+i] );
67 sid::bus::status word_read( host_int_4 addr,
70 host_int_4 a = addr * sizeof( internal_type );
72 for( int i=0; i<sizeof(internal_type); i++ ) {
73 if( mask.read_byte( i ) )
74 data.write_byte( i, mem[a + i] );
77 internal_type m = mask;
78 internal_type d = data;
80 if( sizeof(internal_type) == 8 )
81 printf( "read>>addr %d mask 0x%016llx data 0x%llx<<read\n", a, m, d );
83 printf( "read>>addr %d mask 0x%08x data 0x%x<<read\n", a, m, d );
94 add_bus( "bus", &bus );
100 static vector<string>
102 vector<string> types;
103 types.push_back(string("busif-big-1"));
104 types.push_back(string("busif-big-2"));
105 types.push_back(string("busif-big-4"));
106 types.push_back(string("busif-big-8"));
107 types.push_back(string("busif-little-1"));
108 types.push_back(string("busif-little-2"));
109 types.push_back(string("busif-little-4"));
110 types.push_back(string("busif-little-8"));
115 BusifCreate( const string& instance ) {
116 if( instance == "busif-big-1" )
117 return new Busif<big_int_1>();
118 else if( instance == "busif-little-1" )
119 return new Busif<little_int_1>();
120 else if( instance == "busif-big-2" )
121 return new Busif<big_int_2>();
122 else if( instance == "busif-little-2" )
123 return new Busif<little_int_2>();
124 else if( instance == "busif-big-4" )
125 return new Busif<big_int_4>();
126 else if( instance == "busif-little-4" )
127 return new Busif<little_int_4>();
128 else if( instance == "busif-big-8" )
129 return new Busif<big_int_8>();
130 else if( instance == "busif-little-8" )
131 return new Busif<little_int_8>();
137 BusifDelete( component* c ) {
141 extern const component_library busif_component_library;
143 const component_library busif_component_library DLLEXPORT =
145 COMPONENT_LIBRARY_MAGIC,