[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. Device

The following classes are supported for representing internal devices in a computer. Each device only support the target hardware function. Communication with ports and packets, nor intelligent clock driven operation are not supported.

7.1 cache_line_base class  
7.2 simple_cache_line class  
7.3 cache_line_set class  
7.4 directmap_cache class  
7.5 set_associative_cache class  
7.6 instruction_buffer class  
7.7 register_file class  
7.8 write_buffer class  
7.9 memory class  
7.10 mapped_memory class  
7.11 memory_map class  
7.12 sysinfo_map class  
7.13 fileio_map class  
7.14 argument_map class  
7.15 crossbar class  
7.16 network_packet_sender class  
7.17 network_packet_receiver class  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.1 cache_line_base class

cache_line_base class is the base class for cache lines. In the object, address tag of the cache line and cache line data is included. This class is a class template with three parameters: the first parameter is address type, the second is data type and the third is the container type. The state of the cache line is not defined. Actual state of cache line is needed to be defined in the derived class.

In derived class, the following virtual functions must be defined.

virtual bool is_valid(void) const
Returns true if the state of the cache line is valid.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 simple_cache_line class

simple_cache_line class represents simple cache lines with a state, valid or invalid. It is a derived class of cache_line_base. See section 7.1 cache_line_base class.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.3 cache_line_set class

cache_line_set class represents cache lines corresponding to the number of ways. It is a template class whose parameter is type of the cache line. For a two-way cache, the object of this class includes two cache line. For management of the replacement, LRU counter is provided. See section 7.1 cache_line_base class.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.4 directmap_cache class

direct_map_cache class represents direct map caches. It is a class template whose parameter is type of cache line. Cache size and line size must be power of 2. If the size other than power of 2 is set, it is automatically truncated to the larger number of power of 2.

directmap_cache(address_type a, address_type b)
Creates a cache with the cache size a bytes and the line size b bytes.

address_type cache_size(void) const
Refers the cache size in bytes.

address_type line_size(void) const
Refers the cache line size in bytes.

size_t line_size_in_word(void) const
Refers the cache line size in words.

address_type tag_address(address_type) const
Returns the address at the beginning of the corresponding line of the argument.

bool is_hit(address_type) const
Returns true if the data addressed by the argument is cached.

bool is_valid(address_type) const
Returns true if the line addressed by the argument is valid.

address_type read_address(address_type) const
Returns the address of the tag addressed by the argument.

data_type read(address_type) const
Returns the cached data addressed by the argument.

void write(address_type a, data_type b)
Writes the data b to the tag specified by the address a.

void clear(void)
Clears the cache.

void resize(address_type, address_type)
Changes the cache size. The first parameter specifies the cache size, the second is the line size. Both values are represented in bytes. Negative value do nothing. Once the size is changed, all values in cache is removed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.5 set_associative_cache class

set associative cache class represents set associate cache devices. It is implemented as a class template with a parameter of cache line type. See section 7.1 cache_line_base class.

set_associative_cache(address_type a, address_type b, size_t c)
Creates a cache with the cache size a bytes, the line size b bytes and the way size c.

const line_set_type& cache_line_set(address_type) const
line_set_type& cache_line_set(address_type)
Refers the cache line set specified by the argument address.

address_type cache_size(void) const
Refers the cache size in bytes.

address_type line_size(void) const
Refers the cache line size in bytes.

size_t way_size(void) const
Refers the number of ways.

size_t line_size_in_word(void) const
Refers the cache line size in words.

int max_lru_counter(void) const
Refers the maximum number of the LRU counter which is used to select for cache line purging.

address_type tag_address(address_type) const
Returns the address at the beginning of the corresponding line of the argument.

size_t line_offset(address_type) const
Returns the offset in the corresponding line of the argument.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.6 instruction_buffer class

instruction_buffer class represents pipelined instruction buffers. It is a class template whose parameter is an instruction type. The stage is shifted by calling step function. For example, a stage referred in stage 0 is accessed in the stage 1 in the next time step.

size_t size(void) const
Refers the number of stages.

value_type& operator[](size_t i)
Refers specified stage.

void clear(void)
Clears the instruction buffer.

void step(void)
Advances the stage.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.7 register_file class

register_file class represents a register file. It is a class template whose parameter is a type of the register. Although its function is similar to that of a subset of STL vector, resizing after object generation is prohibited.

const_reference operator[](size_t i) const
reference operator[](size_t i)
Refers the register i.

size_type size(void) const
Refers the size of the register file.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.8 write_buffer class

write_buffer class represents a write buffer for CPU. It is a queue which stores a pair of address and data. It is a template class with address_type and data_type as parameters.

size_t size(void) const
Refers the maximum buffer length.

size_t length(void) const
Refers the length of the queue.

bool empty(void) const
Checks whether the queue is empty or not.
bool full(void) const
Checks whether the queue is full or not.

bool buffered(address_type) const
Returns true if the write access to the specified address is stored.

data_type read(address_type) const
Returns the data which is stored in the address if the target address was already filled. If multiple write requests have been issued to the target address, the last written value is returned. If no value is stored, dummy data is returned.

address_type address(void) const
Refers the address of the header element.

data_type data(void) const
Refers the data of the header element.

void clear(void)
Clears the queue.

void push(address_type, data_type&)
Appends the specified element to the tail of the queue.

void pop(void)
Removes the header element.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.9 memory class

memory class template represents hardware storages. The address type is indicated as the first parameter, and the data is with the second parameter. This class itself does not represents an unit. Neither state transition nor clock (time) is included. For using this memory in the simulator, the functions corresponding to the memory controller should be attached.

memory class manages the size of storage represented with bytes.

Miss aligned access is automatically aligned to the word boundary. Bytes are accessed according to the indicated endian. Default is a big endian.

7.9.1 memory class definition  
7.9.2 Using memory class  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.9.1 memory class definition

memory(void)
Creates a memory with size 0.

memory(address_type a)
Creates a memory with size a.

address_type size(void) const
Returns the size.

bool is_valid(address_type) const
Checks whether the specified address is in the range of the memory or not.

void resize(address_type)
Changes the size.

bool is_big_endian(void) const
Returns true if its endianness is big-endian.

bool is_little_endian(void) const
Returns true if its endianness is little-endian.

void set_big_endian(void)
Set the endianness to big-endian.

void set_little_endian(void)
Set the endianness to little-endian.

data_type read(address_type) const
Reads the word addressed by the argument.

char_type read_char(address_type) const
Reads the character addressed by the argument.

void write(address_type, data_type)
Writes the specified data to the specified address.

void write_char(address_type, char_type)
Writes the specified character to the specified address.

void clear(void)
Fills the whole memory with zero.

void dump(ostream&) const
Dumps the contents of the memory to the specified output stream.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.9.2 Using memory class

memory class internally uses dynamically page management, that is, a requested size is not allocated instantly. When the size other than 0 is written, the page is allocated. Thus, resource is only allocated when really used even if the huge memory size is requested.

The following example requests 1Gbyte memory starts from 0x10000000, and write data 0xffffffff into address from 0x2000 to 0x3000.

 
typedef unsigned word;

const word size = 1024 * 1024 * 1024; // size: 1G
const word area_top = 0x2000, area_size = 0x1000;
memory<word, word> mem(size);
for (int i = 0; i < area_size; i += sizeof(word)) {
    write(area_top + i, 0xffffffffU);
}


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.10 mapped_memory class

mapped_memory class represents memory block on the memory map. The top address and size are managed. Memory in the buffer is implemented with memory.

mapped_memory(void)
Creates a memory with size 0.

mapped_memory(address_type a, address_type b)
Creates a memory with top address a and size b.

address_type top(void) const
Returns the top address.

size_type size(void) const
Returns the size.

address_type bottom(void) const
Returns the end address(top address + size).

bool is_valid(address_type) const
Checks whether the specified address is in the range of the memory or not.

address_type top(address_type)
Changes the top address.

void resize(size_type)
Changes the size.

bool is_big_endian(void) const
Returns true if its endianness is big-endian.

bool is_little_endian(void) const
Returns true if its endianness is little-endian.

void set_big_endian(void)
Set the endianness to big-endian.

void set_little_endian(void)
Set the endianness to little-endian.

data_type read(address_type) const
Reads the word addressed by the argument.

char_type& read_char(address_type) const
Reads the character addressed by the argument.

void write(address_type, data_type)
Writes the specified data to the specified address.

void write_char(address_type, char_type)
Writes the specified character to the specified address.

void clear(void)
Fills the whole memory with zero.

void dump(ostream&) const
Dumps the contents of the memory to the specified output stream.

void dump(ostream&, address_type a, address_type b) const
Dumps the contents of the memory range starts from a, size b to the specified output stream.

virtual void disassemble(ostream&, address_type a, address_type b) const
Outputs dis-assemble results with the top address a and size b to the stream indicated in the first parameter. It is used in the derived classes with the dis-assemble function.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.11 memory_map class

memory_map class supports memory maps with integrated address space. It provides an interface for representing the entire memory.

bool is_valid(address_type) const
Checks whether the specified address is valid or not.

data_type read(address_type) const
Reads the word addressed by the argument.

char_type read_char(address_type) const
Reads the character addressed by the argument.

void write(address_type, data_type)
Writes the specified data to the specified address.

void write_char(address_type, char_type)
Writes the specified character to the specified address.

void insert(const mapped_memory_type&)
Adds the specified memory to the memory map.

void erase(const mapped_memory_type&)
Deletes the specified memory from the memory map.

void dump(ostream&) const
Dumps the contents of the memory to the specified output stream.

void dump(ostream&, address_type a, address_type b) const
Dumps the contents of the memory range starts from a, size b to the specified output stream.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.12 sysinfo_map class

sysinfo_map class generates the database including architecture specific information. It is used for communication of a memory map or execution results between a host machine and a simulator software. Each value can store an integer or a string.

void set(const string&, T)
Sets the variable specified by the first argument to the integer specified by the second.

void set(const string&, const string&)
Sets the variable specified by the first argument to the string specified by the second.

void unset(const string&)
Removes the specified variable.

void clear(void)
Removes all variables.

bool is_defined(const string&)
Returns true if the specified variable is defined.

bool is_integer(const string&)
Returns true if the specified variable is defined as an integer.

bool is_string(const string&)
Returns true if the specified variable is defined as a string.

T get_integer(const string&)
Returns the integer of the specified variable.

const string& get_string(const string&)
Returns the string of the specified variable.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.13 fileio_map class

fileio_map class generates a database for file tables. It is used for accessing files from simulated softwares. It maps file access requests to stream operations including standard input/output. A file table is 0-origin one dimensional array. Each file is managed with the following 3 attributes and the substance itself.

void fileio_map(void)
Creates an empty file table.

void fileio_map(size_t)
Creates a file table with the specific size.

void set_standard_io(void)
Connects with standard input/output. File 0 is connected with cin, file 1 is done with cout and file 2 is done with cerr.

size_t size(void) const
Returns the size of the file table.

void resize(size_t)
Changes the size of the file table.

bool is_readable(size_t)
Returns true if the specific file is readable.

bool is_writable(size_t)
Returns true if the specific file is writable.

bool is_opened(size_t)
Returns true if the specific file is opened.

void set_input_stream(size_t, istream&)
Connects the entry specified by the first argument to the input stream specified by the second.

void set_output_stream(size_t, ostream&)
Connects the entry specified by the first argument to the output stream specified by the second.

bool open(size_t, const char*, int)
Opens the file indicated in the second argument and connects it to the entry indicated in the first. When the file is opened, the flag indicated in the third is used. Values of flags is specified with the macro IO_FILE_OPEN_* in `io_protocol.h'. True is returned if it is successful.

bool close(size_t)
Closes the specific file. True is returned if the operation succeeded.

bool eof(size_t) const
Returns true if the specific input stream is terminated.

bool good_input_stream(size_t) const
Returns true if the next operation for the specific input stream will be success.

bool good_output_stream(size_t) const
Returns true if the next operation for the specific output stream will be success.

bool put(size_t, char)
Puts the character specified by the second argument to the output stream specified by the first. True is returned if the operation succeeded.

bool get(size_t, &char)
Gets a character from the input stream specified with the first argument and stores it to the variable specified with the second. True is returned if the operation succeeded.

long seek(size_t, long, int)
Applies lseek to the file indicated in the first argument. The third argument represents the position form and the second shows the position itself. The position form specification is shown in macro IO_FILE_SEEK_* in `io_protocol.h'.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.14 argument_map class

argument_map class generates a database which manages the command line parameters. It is used for reading command line information by a simulated software.

int argc(void) const
Refers argc.

const char* argv(size_t) const
Refers the specific argv.

void set(const char* const*)
Sets the command line arguments.

void clear(void)
Removes all values stored in.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.15 crossbar class

crossbar class represents crossbars. It includes (input line number x output line number) switches, and connections between input lines and output lines are controlled by them.

crossbar(void)
Creates a crossbar with input line size 0 and output line size 0.

crossbar(size_t a, size_t b)
Creates a crossbar with input line size a and output line size b.

size_t input_size(void) const
Returns the input line size.

size_t output_size(void) const
Returns the output line size.

void resize(size_t a, size_t b)
Sets the input line size as a and the output line size as b.

void clear(void)
Turns all inner switches OFF.

inline void connect_crosspoint(size_t a, size_t b)
Turns the switch (a, b) ON.

inline void disconnect_crosspoint(size_t a, size_t b)
Turns the switch (a, b) OFF.

bool is_connected_input_channel(size_t)
Returns true if the specific input line is connected to any output line.

bool is_connected_output_channel(size_t)
Returns true if the specific output line is connected to any input line.

inline void disconnect_input_channel(size_t)
Turns all switches related with the specific input line off.

inline void disconnect_output_channel(size_t)
Turns all switches related with the specific output line off.

size_t input_to_output_size(size_t)
Returns the number of output lines connected to the specific input line.

size_t input_to_output_index(size_t a, size_t b = 0)
Returns the index number of output lines connected to the input line a. b specifies the start index number for searching.

size_t output_to_input_index(size_t)
Returns the index number of input lines connected to the specific output line.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.16 network_packet_sender class

network_packet_sender class is a support class for implementation of the network interface units. It is used connecting with the router. Input packets are divided into multiple flits and sent to the network.

virtual_channel_output& channel(void)
Refers the output channel.

bool empty(void) const
Returns true if a caller can send a packet.

bool full(void) const
Returns true if a caller cannot send a packet.

void put(packet_type*)
Puts the packet.

void clock(void)
Triggers a clock.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.17 network_packet_receiver class

network_packet_receiver class is a support class for implementing network interface units. It is used connecting with the router. A set of flit from the network and forms a packet.

virtual_channel_input& channel(void)
Refers the input channel.

bool full(void) const
Returns true if the caller can receive a packet.

packet_type* get(void)
Receives the packet from the object.

void clock(void)
Triggers a clock.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Masaki WAKABAYASHI on September, 3 2003 using texi2html