1 -------------------------------------------------------------------------- 2 -- 3 -- Copyright (C) 1993, Peter J. Ashenden 4 -- Mail: Dept. Computer Science 5 -- University of Adelaide, SA 5005, Australia 6 -- e-mail: petera@cs.adelaide.edu.au 7 -- 8 -- This program is free software; you can redistribute it and/or modify 9 -- it under the terms of the GNU General Public License as published by 10 -- the Free Software Foundation; either version 1, or (at your option) 11 -- any later version. 12 -- 13 -- This program is distributed in the hope that it will be useful, 14 -- but WITHOUT ANY WARRANTY; without even the implied warranty of 15 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 -- GNU General Public License for more details. 17 -- 18 -- You should have received a copy of the GNU General Public License 19 -- along with this program; if not, write to the Free Software 20 -- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 -- 22 -------------------------------------------------------------------------- 23 -- 24 -- $RCSfile: dlx_instr-body.vhdl,v $ $Revision: 1.1 $ $Date: 2000/05/08 14:36:48 $ 25 -- 26 -------------------------------------------------------------------------- 27 -- 28 -- Package body for DLX instructions 29 -- 30 31 32 use std.textio.all, 33 work.bv_arithmetic.bv_to_natural, 34 work.bv_arithmetic.bv_to_integer; 35 36 37 package body dlx_instr is 38 39 constant opcode_names : opcode_name_array := 40 ( "SPECIAL ", "FPARITH ", "J ", "JAL ", 41 "BEQZ ", "BNEZ ", "BFPT ", "BFPF ", 42 "ADDI ", "ADDUI ", "SUBI ", "SUBUI ", 43 "ANDI ", "ORI ", "XORI ", "LHI ", 44 "RFE ", "TRAP ", "JR ", "JALR ", 45 "SLLI ", "UNDEF_15", "SRLI ", "SRAI ", 46 "SEQI ", "SNEI ", "SLTI ", "SGTI ", 47 "SLEI ", "SGEI ", "UNDEF_1E", "UNDEF_1F", 48 "LB ", "LH ", "UNDEF_22", "LW ", 49 "LBU ", "LHU ", "LF ", "LD ", 50 "SB ", "SH ", "UNDEF_2A", "SW ", 51 "UNDEF_2C", "UNDEF_2D", "SF ", "SD ", 52 "SEQUI ", "SNEUI ", "SLTUI ", "SGTUI ", 53 "SLEUI ", "SGEUI ", "UNDEF_36", "UNDEF_37", 54 "UNDEF_38", "UNDEF_39", "UNDEF_3A", "UNDEF_3B", 55 "UNDEF_3C", "UNDEF_3D", "UNDEF_3E", "UNDEF_3F" ); 56 57 constant sp_func_names : sp_func_name_array := 58 ( "NOP ", "UNDEF_01", "UNDEF_02", "UNDEF_03", 59 "SLL ", "UNDEF_05", "SRL ", "SRA ", 60 "UNDEF_08", "UNDEF_09", "UNDEF_0A", "UNDEF_0B", 61 "UNDEF_0C", "UNDEF_0D", "UNDEF_0E", "UNDEF_0F", 62 "SEQU ", "SNEU ", "SLTU ", "SGTU ", 63 "SLEU ", "SGEU ", "UNDEF_16", "UNDEF_17", 64 "UNDEF_18", "UNDEF_19", "UNDEF_1A", "UNDEF_1B", 65 "UNDEF_1C", "UNDEF_1D", "UNDEF_1E", "UNDEF_1F", 66 "ADD ", "ADDU ", "SUB ", "SUBU ", 67 "AND ", "OR ", "XOR ", "UNDEF_27", 68 "SEQ ", "SNE ", "SLT ", "SGT ", 69 "SLE ", "SGE ", "UNDEF_2E", "UNDEF_2F", 70 "MOVI2S ", "MOVS2I ", "MOVF ", "MOVD ", 71 "MOVFP2I ", "MOVI2FP ", "UNDEF_36", "UNDEF_37", 72 "UNDEF_38", "UNDEF_39", "UNDEF_3A", "UNDEF_3B", 73 "UNDEF_3C", "UNDEF_3D", "UNDEF_3E", "UNDEF_3F" ); 74 75 constant fp_func_names : fp_func_name_array := 76 ( "ADDF ", "SUBF ", "MULTF ", "DIVF ", 77 "ADDD ", "SUBD ", "MULTD ", "DIVD ", 78 "CVTF2D ", "CVTF2I ", "CVTD2F ", "CVTD2I ", 79 "CVTI2F ", "CVTI2D ", "MULT ", "DIV ", 80 "EQF ", "NEF ", "LTF ", "GTF ", 81 "LEF ", "GEF ", "MULTU ", "DIVU ", 82 "EQD ", "NED ", "LTD ", "GTD ", 83 "LED ", "GED ", "UNDEF_1E", "UNDEF_1F" ); 84 85 86 procedure write_reg (L : inout line; reg : reg_index) is 87 88 begin 89 write(L, 'R'); 90 write(L, reg); 91 end write_reg; 92 93 94 procedure write_freg (L : inout line; freg : reg_index) is 95 96 begin 97 write(L, 'F'); 98 write(L, freg); 99 end write_freg; 100 101 102 procedure write_special_reg (L : inout line; reg : reg_index) is 103 104 begin 105 case reg is 106 when 0 => 107 write(L, string'("IAR")); 108 WHEN 1 => 109 write(L, string'("FSR")); 110 when others => 111 write(L, string'("SR")); 112 write(L, reg); 113 end case; 114 end write_special_reg; 115 116 117 procedure write_instr (L : inout line; instr : in dlx_word) is 118 119 alias instr_opcode : dlx_opcode is instr(0 to 5); 120 alias instr_sp_func : dlx_sp_func is instr(26 to 31); 121 alias instr_fp_func : dlx_fp_func is instr(27 to 31); 122 alias instr_rs1 : dlx_reg_addr is instr(6 to 10); 123 alias instr_rs2 : dlx_reg_addr is instr(11 to 15); 124 alias instr_Itype_rd : dlx_reg_addr is instr(11 to 15); 125 alias instr_Rtype_rd : dlx_reg_addr is instr(16 to 20); 126 alias instr_immed16 : dlx_immed16 is instr(16 to 31); 127 alias instr_immed26 : dlx_immed26 is instr(6 to 31); 128 129 variable instr_opcode_num : dlx_opcode_num; 130 variable instr_sp_func_num : dlx_sp_func_num; 131 variable instr_fp_func_num : dlx_fp_func_num; 132 variable rs1 : reg_index; 133 variable rs2 : reg_index; 134 variable Itype_rd : reg_index; 135 variable Rtype_rd : reg_index; 136 137 begin 138 instr_opcode_num := bv_to_natural(instr_opcode); 139 instr_sp_func_num := bv_to_natural(instr_sp_func); 140 instr_fp_func_num := bv_to_natural(instr_fp_func); 141 rs1 := bv_to_natural(instr_rs1); 142 rs2 := bv_to_natural(instr_rs2); 143 Itype_rd := bv_to_natural(instr_Itype_rd); 144 Rtype_rd := bv_to_natural(instr_Rtype_rd); 145 -- 146 if (instr_opcode /= op_special) and (instr_opcode /= op_fparith) then 147 write(L, opcode_names(instr_opcode_num)); 148 write(L, ' '); 149 end if; 150 case instr_opcode is 151 when op_special => 152 write(L, sp_func_names(instr_sp_func_num)); 153 write(L, ' '); 154 case instr_sp_func is 155 when sp_func_nop => 156 null; 157 when sp_func_sll | sp_func_srl | sp_func_sra | 158 sp_func_sequ | sp_func_sneu | sp_func_sltu | 159 sp_func_sgtu | sp_func_sleu | sp_func_sgeu | 160 sp_func_add | sp_func_addu | sp_func_sub | sp_func_subu | 161 sp_func_and | sp_func_or | sp_func_xor | 162 sp_func_seq | sp_func_sne | sp_func_slt | 163 sp_func_sgt | sp_func_sle | sp_func_sge => 164 write_reg(L, Rtype_rd); write(L, string'(", ")); 165 write_reg(L, rs1); write(L, string'(", ")); 166 write_reg(L, rs2); 167 when sp_func_movi2s => 168 write_special_reg(L, Rtype_rd); write(L, string'(", ")); 169 write_reg(L, rs1); 170 when sp_func_movs2i => 171 write_reg(L, Rtype_rd); write(L, string'(", ")); 172 write_special_reg(L, rs1); 173 when sp_func_movf | sp_func_movd => 174 write_freg(L, Rtype_rd); write(L, string'(", ")); 175 write_freg(L, rs1); 176 when sp_func_movfp2i => 177 write_reg(L, Rtype_rd); write(L, string'(", ")); 178 write_freg(L, rs1); 179 when sp_func_movi2fp => 180 write_freg(L, Rtype_rd); write(L, string'(", ")); 181 write_reg(L, rs1); 182 when others => 183 null; 184 end case; 185 when op_fparith => 186 write(L, fp_func_names(instr_fp_func_num)); 187 write(L, ' '); 188 case instr_fp_func is 189 when fp_func_addf | fp_func_subf | fp_func_multf | fp_func_divf | 190 fp_func_addd | fp_func_subd | fp_func_multd | fp_func_divd | 191 fp_func_mult | fp_func_div | fp_func_multu | fp_func_divu => 192 write_freg(L, Rtype_rd); write(L, string'(", ")); 193 write_freg(L, rs1); write(L, string'(", ")); 194 write_freg(L, rs2); 195 when fp_func_cvtf2d | fp_func_cvtd2f => 196 write_freg(L, Rtype_rd); write(L, string'(", ")); 197 write_freg(L, rs1); 198 when fp_func_cvtf2i | fp_func_cvtd2i => 199 write_reg(L, Rtype_rd); write(L, string'(", ")); 200 write_freg(L, rs1); 201 when fp_func_cvti2f | fp_func_cvti2d => 202 write_freg(L, Rtype_rd); write(L, string'(", ")); 203 write_reg(L, rs1); 204 when fp_func_eqf | fp_func_nef | fp_func_ltf | 205 fp_func_gtf | fp_func_lef | fp_func_gef | 206 fp_func_eqd | fp_func_ned | fp_func_ltd | 207 fp_func_gtd | fp_func_led | fp_func_ged => 208 write_freg(L, rs1); write(L, string'(", ")); 209 write_freg(L, rs2); 210 when others => 211 null; 212 end case; 213 when op_j | op_jal => 214 write(L, bv_to_integer(instr_immed26)); 215 when op_beqz | op_bnez => 216 write_reg(L, rs1); write(L, string'(", ")); 217 write(L, bv_to_integer(instr_immed16)); 218 when op_bfpt | op_bfpf => 219 write(L, bv_to_integer(instr_immed16)); 220 when op_slli | op_srli | op_srai => 221 write_reg(L, Itype_rd); write(L, string'(", ")); 222 write_reg(L, rs1); write(L, string'(", ")); 223 write(L, bv_to_natural(instr_immed16(11 to 15))); 224 when op_addi | op_subi | 225 op_seqi | op_snei | op_slti | op_sgti | op_slei | op_sgei => 226 write_reg(L, Itype_rd); write(L, string'(", ")); 227 write_reg(L, rs1); write(L, string'(", ")); 228 write(L, bv_to_integer(instr_immed16)); 229 when op_addui | op_subui | op_andi | op_ori | op_xori | 230 op_sequi | op_sneui | op_sltui | op_sgtui | op_sleui | op_sgeui => 231 write_reg(L, Itype_rd); write(L, string'(", ")); 232 write_reg(L, rs1); write(L, string'(", ")); 233 write(L, bv_to_natural(instr_immed16)); 234 when op_lhi => 235 write_reg(L, Itype_rd); write(L, string'(", ")); 236 write(L, bv_to_natural(instr_immed16)); 237 when op_rfe => 238 null; 239 when op_trap => 240 write(L, bv_to_natural(instr_immed26)); 241 when op_jr | op_jalr => 242 write_reg(L, rs1); 243 when op_lb | op_lh | op_lw | 244 op_lbu | op_lhu | op_lf | op_ld => 245 write_reg(L, Itype_rd); write(L, string'(", ")); 246 write(L, bv_to_integer(instr_immed16)); write(L, '('); 247 write_reg(L, rs1); write(L, ')'); 248 when op_sb | op_sh | op_sw | op_sf | op_sd => 249 write(L, bv_to_integer(instr_immed16)); 250 write(L, '('); write_reg(L, rs1); write(L, string'("), ")); 251 write_reg(L, Itype_rd); 252 when others => 253 null; 254 end case; 255 end write_instr; 256 257 258 end dlx_instr; 259
This page was generated using GHDL 0.14 (20040829) [Sokcho edition], a program written by Tristan Gingold