112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com/***************************************************************************** 2112855Sgabeblack@google.com 2212855Sgabeblack@google.com cycle_model.h -- 2312855Sgabeblack@google.com 2412855Sgabeblack@google.com Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 2512855Sgabeblack@google.com 2612855Sgabeblack@google.com *****************************************************************************/ 2712855Sgabeblack@google.com 2812855Sgabeblack@google.com/***************************************************************************** 2912855Sgabeblack@google.com 3012855Sgabeblack@google.com MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112855Sgabeblack@google.com changes you are making here. 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com Name, Affiliation, Date: 3412855Sgabeblack@google.com Description of Modification: 3512855Sgabeblack@google.com 3612855Sgabeblack@google.com *****************************************************************************/ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com#include "common.h" 3912855Sgabeblack@google.com 4012855Sgabeblack@google.com#define MEM_SIZE 65536 4112855Sgabeblack@google.com#define INT_SIZE 2048 4212855Sgabeblack@google.com 4312855Sgabeblack@google.com/* types of operands */ 4412855Sgabeblack@google.comenum op_type { 4512855Sgabeblack@google.com o_null, 4612855Sgabeblack@google.com o_acc, // accumulator 4712855Sgabeblack@google.com o_reg, // registers Ri 4812855Sgabeblack@google.com o_dir, // internal register direct 4912855Sgabeblack@google.com o_ind, // internal register pointed to by R0 or R1 5012855Sgabeblack@google.com o_ext, // external memory pointed to by R0 or R1 5112855Sgabeblack@google.com o_rel, // 2complement offset byte 5212855Sgabeblack@google.com o_cst, // 8bit constant 5312855Sgabeblack@google.com o_lcst, // 16bit constant 5412855Sgabeblack@google.com o_add, // 11bit destination address 5512855Sgabeblack@google.com o_ladd // 16bit destination address 5612855Sgabeblack@google.com}; 5712855Sgabeblack@google.com 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com/* limited set of instruction types */ 6012855Sgabeblack@google.comenum instr_type { 6112855Sgabeblack@google.com // arithmetic operations 6212855Sgabeblack@google.com i_add, // 0 6312855Sgabeblack@google.com i_sub, // 1 6412855Sgabeblack@google.com i_inc, // 2 6512855Sgabeblack@google.com i_dec, // 3 6612855Sgabeblack@google.com i_mul, // 4 6712855Sgabeblack@google.com i_div, // 5 6812855Sgabeblack@google.com // logic operations 6912855Sgabeblack@google.com i_and, // 6 7012855Sgabeblack@google.com i_or, // 7 7112855Sgabeblack@google.com i_xor, // 8 7212855Sgabeblack@google.com i_clr, // 9 7312855Sgabeblack@google.com i_cpl, // 10 7412855Sgabeblack@google.com i_rl, // 11 7512855Sgabeblack@google.com i_rr, // 12 7612855Sgabeblack@google.com // data transfer 7712855Sgabeblack@google.com i_mov, // 13 7812855Sgabeblack@google.com // branching 7912855Sgabeblack@google.com i_call,// 14 8012855Sgabeblack@google.com i_ret, // 15 8112855Sgabeblack@google.com i_jmp, // 16 8212855Sgabeblack@google.com i_sjmp,// 17 8312855Sgabeblack@google.com i_jz, // 18 8412855Sgabeblack@google.com i_jnz, // 19 8512855Sgabeblack@google.com i_cjne,// 20 8612855Sgabeblack@google.com i_djnz,// 21 8712855Sgabeblack@google.com i_nop // 22 8812855Sgabeblack@google.com}; 8912855Sgabeblack@google.com 9012855Sgabeblack@google.com 9112855Sgabeblack@google.com/* cycle types for memory bus */ 9212855Sgabeblack@google.comenum bus_cycle_type { 9312855Sgabeblack@google.com OP_IDLE, 9412855Sgabeblack@google.com OP_MEM_READ, 9512855Sgabeblack@google.com OP_MEM_WRITE 9612855Sgabeblack@google.com}; 9712855Sgabeblack@google.com 9812855Sgabeblack@google.com 9912855Sgabeblack@google.com/* ------------------------------------------------------------------------ 10012855Sgabeblack@google.com * struct operand 10112855Sgabeblack@google.com * ----------------------------------------------------------------------*/ 10212855Sgabeblack@google.comstruct operand { 10312855Sgabeblack@google.com op_type type; 10412855Sgabeblack@google.com int val; /* value encoded with the opcode (i.e. register number) */ 10512855Sgabeblack@google.com}; 10612855Sgabeblack@google.com 10712855Sgabeblack@google.com 10812855Sgabeblack@google.com/* ------------------------------------------------------------------------ 10912855Sgabeblack@google.com * struct instr ( instruction ) 11012855Sgabeblack@google.com * ----------------------------------------------------------------------*/ 11112855Sgabeblack@google.comstruct instr { 11212855Sgabeblack@google.com instr_type type; 11312855Sgabeblack@google.com int n_src; /* number of source operands */ 11412855Sgabeblack@google.com operand src1; /* source operand 1 */ 11512855Sgabeblack@google.com operand src2; /* source operand 2 */ 11612855Sgabeblack@google.com operand dst; /* destination operand */ 11712855Sgabeblack@google.com int cycle; // number of cycles 11812855Sgabeblack@google.com}; 11912855Sgabeblack@google.com 12012855Sgabeblack@google.com 12112855Sgabeblack@google.com/* ------------------------------------------------------------------------ 12212855Sgabeblack@google.com * struct stack_el ( stack element ) 12312855Sgabeblack@google.com * ----------------------------------------------------------------------*/ 12412855Sgabeblack@google.comstruct stack_el { 12512855Sgabeblack@google.com int address; 12612855Sgabeblack@google.com stack_el *up; 12712855Sgabeblack@google.com}; 12812855Sgabeblack@google.com 12912855Sgabeblack@google.com 13012855Sgabeblack@google.com 13112855Sgabeblack@google.com/* ------------------------------------------------------------------------ 13212855Sgabeblack@google.com * struct cycle_model: public sc_aproc 13312855Sgabeblack@google.com * 13412855Sgabeblack@google.com * ----------------------------------------------------------------------*/ 13512855Sgabeblack@google.com 13612855Sgabeblack@google.comSC_MODULE( cycle_model ) 13712855Sgabeblack@google.com{ 13812855Sgabeblack@google.com SC_HAS_PROCESS( cycle_model ); 13912855Sgabeblack@google.com 14012855Sgabeblack@google.com sc_in_clk clk; 14112855Sgabeblack@google.com 14212855Sgabeblack@google.com /* functions */ 14312855Sgabeblack@google.com void init(); 14412855Sgabeblack@google.com void parse_hex(char *name); 14512855Sgabeblack@google.com void exec_bus_cycle(bus_cycle_type op, int addr, int data, int* result); 14612855Sgabeblack@google.com bool request_address(int addr); 14712855Sgabeblack@google.com int fetch_instr(int ad); 14812855Sgabeblack@google.com int fetch_data(int ad); 14912855Sgabeblack@google.com int write_data(int ad, int data); 15012855Sgabeblack@google.com int fetch_operand(operand* op); 15112855Sgabeblack@google.com int write_back(operand *, int); 15212855Sgabeblack@google.com void execute(instr *i); 15312855Sgabeblack@google.com void decode(int opcode, instr* i); 15412855Sgabeblack@google.com 15512855Sgabeblack@google.com 15612855Sgabeblack@google.com /* memory bus */ 15712855Sgabeblack@google.com signal_bool_vector16& mem_addr; 15812855Sgabeblack@google.com signal_bool_vector8& mem_data_out; 15912855Sgabeblack@google.com const signal_bool_vector8& mem_data_in; 16012855Sgabeblack@google.com sc_signal<bool>& mem_wr_n; 16112855Sgabeblack@google.com sc_signal<bool>& mem_rd_n; 16212855Sgabeblack@google.com sc_signal<bool>& mem_pswr_n; 16312855Sgabeblack@google.com sc_signal<bool>& mem_psrd_n; 16412855Sgabeblack@google.com sc_signal<bool>& mem_ale; 16512855Sgabeblack@google.com const sc_signal<bool>& mem_ea_n; 16612855Sgabeblack@google.com 16712855Sgabeblack@google.com sc_signal<bool>& p0_mem_reg_n; 16812855Sgabeblack@google.com sc_signal<bool>& p0_addr_data_n; 16912855Sgabeblack@google.com sc_signal<bool>& p2_mem_reg_n; 17012855Sgabeblack@google.com 17112855Sgabeblack@google.com /* internal variables */ 17212855Sgabeblack@google.com /* memories registers and stack */ 17312855Sgabeblack@google.com int instr_mem[MEM_SIZE]; /* instruction memory */ 17412855Sgabeblack@google.com int ext_mem[MEM_SIZE]; /* 'external' data memory */ 17512855Sgabeblack@google.com int int_mem[INT_SIZE]; /* internal data memory */ 17612855Sgabeblack@google.com int A; /* accumulator */ 17712855Sgabeblack@google.com int R[8]; /* registers */ 17812855Sgabeblack@google.com stack_el *my_stack; /* stack */ 17912855Sgabeblack@google.com /* others */ 18012855Sgabeblack@google.com int cycles2execute; /* number of cycles to execute */ 18112855Sgabeblack@google.com int cycle_count; /* total number of cycles executed */ 18212855Sgabeblack@google.com int stretch_cycles; /* memory stretch cycles */ 18312855Sgabeblack@google.com 18412855Sgabeblack@google.com 18512855Sgabeblack@google.com 18612855Sgabeblack@google.com /* Constructor */ 18712855Sgabeblack@google.com cycle_model(sc_module_name NAME, 18812855Sgabeblack@google.com const sc_signal_in_if<bool>& CLK, 18912855Sgabeblack@google.com char* hex_file_name, 19012855Sgabeblack@google.com 19112855Sgabeblack@google.com signal_bool_vector16& MEM_ADDR, 19212855Sgabeblack@google.com signal_bool_vector8& MEM_DATA_OUT, 19312855Sgabeblack@google.com const signal_bool_vector8& MEM_DATA_IN, 19412855Sgabeblack@google.com sc_signal<bool>& MEM_WR_N, 19512855Sgabeblack@google.com sc_signal<bool>& MEM_RD_N, 19612855Sgabeblack@google.com sc_signal<bool>& MEM_PSWR_N, 19712855Sgabeblack@google.com sc_signal<bool>& MEM_PSRD_N, 19812855Sgabeblack@google.com sc_signal<bool>& MEM_ALE, 19912855Sgabeblack@google.com const sc_signal<bool>& MEM_EA_N, 20012855Sgabeblack@google.com 20112855Sgabeblack@google.com sc_signal<bool>& P0_MEM_REG_N, 20212855Sgabeblack@google.com sc_signal<bool>& P0_ADDR_DATA_N, 20312855Sgabeblack@google.com sc_signal<bool>& P2_MEM_REG_N 20412855Sgabeblack@google.com ) 20512855Sgabeblack@google.com : 20612855Sgabeblack@google.com 20712855Sgabeblack@google.com mem_addr(MEM_ADDR), 20812855Sgabeblack@google.com mem_data_out(MEM_DATA_OUT), 20912855Sgabeblack@google.com mem_data_in(MEM_DATA_IN), 21012855Sgabeblack@google.com mem_wr_n(MEM_WR_N), 21112855Sgabeblack@google.com mem_rd_n(MEM_RD_N), 21212855Sgabeblack@google.com mem_pswr_n(MEM_PSWR_N), 21312855Sgabeblack@google.com mem_psrd_n(MEM_PSRD_N), 21412855Sgabeblack@google.com mem_ale(MEM_ALE), 21512855Sgabeblack@google.com mem_ea_n(MEM_EA_N), 21612855Sgabeblack@google.com p0_mem_reg_n(P0_MEM_REG_N), 21712855Sgabeblack@google.com p0_addr_data_n(P0_ADDR_DATA_N), 21812855Sgabeblack@google.com p2_mem_reg_n(P2_MEM_REG_N) 21912855Sgabeblack@google.com { 22012855Sgabeblack@google.com clk(CLK); 22112855Sgabeblack@google.com SC_THREAD( entry ); 22212855Sgabeblack@google.com sensitive << clk; 22312855Sgabeblack@google.com 22412855Sgabeblack@google.com parse_hex(hex_file_name); 22512855Sgabeblack@google.com init(); 22612855Sgabeblack@google.com } 22712855Sgabeblack@google.com 22812855Sgabeblack@google.com /* Process functionality in member function below */ 22912855Sgabeblack@google.com void entry(); 23012855Sgabeblack@google.com}; 231