📄 debug.vhd
字号:
variable op3 : std_logic_vector(5 downto 0); variable opf : std_logic_vector(8 downto 0); variable cond : std_logic_vector(3 downto 0); variable rs1, rs2, rd : std_logic_vector(4 downto 0); variable addr : std_logic_vector(31 downto 0); variable annul : std_logic; variable i : std_logic; variable simm : std_logic_vector(12 downto 0); variable disen : boolean := true;begin if disen then op := insn.op(31 downto 30); op2 := insn.op(24 downto 22); op3 := insn.op(24 downto 19); opf := insn.op(13 downto 5); cond := insn.op(28 downto 25); annul := insn.op(29); rs1 := insn.op(18 downto 14); rs2 := insn.op(4 downto 0); rd := insn.op(29 downto 25); i := insn.op(13); simm := insn.op(12 downto 0); case op is when CALL => addr := insn.pc + (insn.op(29 downto 0) & "00"); return(tostf(insn.pc) & bb & "call" & bl2 & tost(addr)); when FMT2 => case op2 is when UNIMP => return(tostf(insn.pc) & bb & "unimp"); when SETHI => if rd = "00000" then return(tostf(insn.pc) & bb & "nop"); else return(tostf(insn.pc) & bb & "sethi" & bl2 & "%hi(" & tost(insn.op(21 downto 0) & "0000000000") & "), " & regdec(rd)); end if; when BICC | FBFCC => addr(31 downto 24) := (others => '0'); addr(1 downto 0) := (others => '0'); addr(23 downto 2) := insn.op(21 downto 0); if addr(23) = '1' then addr(31 downto 24) := (others => '1'); else addr(31 downto 24) := (others => '0'); end if; addr := addr + insn.pc; if op2 = BICC then if insn.op(29) = '1' then return(tostf(insn.pc) & bb & 'b' & branchop(insn) & ",a" & bl2 & tost(addr)); else return(tostf(insn.pc) & bb & 'b' & branchop(insn) & bl2 & tost(addr)); end if; else if insn.op(29) = '1' then return(tostf(insn.pc) & bb & "fb" & fbranchop(insn) & ",a" & bl2 & tost(addr)); else return(tostf(insn.pc) & bb & "fb" & fbranchop(insn) & bl2 & tost(addr)); end if; end if;-- when CBCCC => cptrap := '1'; when others => return(tostf(insn.pc) & bb & "unknown opcode: " & tost(insn.op)); end case; when FMT3 => case op3 is when IAND => return(tostf(insn.pc) & bb & "and" & bl2 & regres(insn,hex)); when IADD => return(tostf(insn.pc) & bb & "add" & bl2 & regres(insn,dec)); when IOR => if ((i = '0') and (rs1 = "00000") and (rs2 = "00000")) then return(tostf(insn.pc) & bb & "clr" & bl2 & regdec(rd)); elsif ((i = '1') and (simm = "0000000000000")) or (rs1 = "00000") then return(tostf(insn.pc) & bb & "mov" & bl2 & regres(insn,hex)); else return(tostf(insn.pc) & bb & "or " & bl2 & regres(insn,hex)); end if; when IXOR => return(tostf(insn.pc) & bb & "xor" & bl2 & regres(insn,hex)); when ISUB => return(tostf(insn.pc) & bb & "sub" & bl2 & regres(insn,dec)); when ANDN => return(tostf(insn.pc) & bb & "andn" & bl2 & regres(insn,hex)); when ORN => return(tostf(insn.pc) & bb & "orn" & bl2 & regres(insn,hex)); when IXNOR => if ((i = '0') and ((rs1 = rd) or (rs2 = "00000"))) then return(tostf(insn.pc) & bb & "not" & bl2 & regdec(rd)); else return(tostf(insn.pc) & bb & "xnor" & bl2 & regdec(rd)); end if; when ADDX => return(tostf(insn.pc) & bb & "addx" & bl2 & regres(insn,dec)); when SUBX => return(tostf(insn.pc) & bb & "subx" & bl2 & regres(insn,dec)); when ADDCC => return(tostf(insn.pc) & bb & "addcc" & bl2 & regres(insn,dec)); when ANDCC => return(tostf(insn.pc) & bb & "andcc" & bl2 & regres(insn,hex)); when ORCC => return(tostf(insn.pc) & bb & "orcc" & bl2 & regres(insn,hex)); when XORCC => return(tostf(insn.pc) & bb & "xorcc" & bl2 & regres(insn,hex)); when SUBCC => return(tostf(insn.pc) & bb & "subcc" & bl2 & regres(insn,dec)); when ANDNCC => return(tostf(insn.pc) & bb & "andncc" & bl2 & regres(insn,hex)); when ORNCC => return(tostf(insn.pc) & bb & "orncc" & bl2 & regres(insn,hex)); when XNORCC => return(tostf(insn.pc) & bb & "xnorcc" & bl2 & regres(insn,hex)); when ADDXCC => return(tostf(insn.pc) & bb & "addxcc" & bl2 & regres(insn,hex)); when UMUL => return(tostf(insn.pc) & bb & "umul" & bl2 & regres(insn,dec)); when SMUL => return(tostf(insn.pc) & bb & "smul" & bl2 & regres(insn,dec)); when UMULCC => return(tostf(insn.pc) & bb & "umulcc" & bl2 & regres(insn,dec)); when SMULCC => return(tostf(insn.pc) & bb & "smulcc" & bl2 & regres(insn,dec)); when SUBXCC => return(tostf(insn.pc) & bb & "subxcc" & bl2 & regres(insn,dec)); when UDIVCC => return(tostf(insn.pc) & bb & "udivcc" & bl2 & regres(insn,dec)); when SDIVCC => return(tostf(insn.pc) & bb & "sdivcc" & bl2 & regres(insn,dec)); when TADDCC => return(tostf(insn.pc) & bb & "taddcc" & bl2 & regres(insn,dec)); when TSUBCC => return(tostf(insn.pc) & bb & "tsubcc" & bl2 & regres(insn,dec)); when TADDCCTV => return(tostf(insn.pc) & bb & "taddcctv" & bl2 & regres(insn,dec)); when TSUBCCTV => return(tostf(insn.pc) & bb & "tsubcctv" & bl2 & regres(insn,dec)); when MULSCC => return(tostf(insn.pc) & bb & "mulscc" & bl2 & regres(insn,dec)); when ISLL => return(tostf(insn.pc) & bb & "sll" & bl2 & regres(insn,dec)); when ISRL => return(tostf(insn.pc) & bb & "srl" & bl2 & regres(insn,dec)); when ISRA => return(tostf(insn.pc) & bb & "sra" & bl2 & regres(insn,dec)); when RDY => if rs1 /= "00000" then return(tostf(insn.pc) & bb & "mov" & bl2 & "%asr" & tost(rs1) & ", " & regdec(rd)); else return(tostf(insn.pc) & bb & "mov" & bl2 & "%y, " & regdec(rd)); end if; when RDPSR => return(tostf(insn.pc) & bb & "mov" & bl2 & "%psr, " & regdec(rd)); when RDWIM => return(tostf(insn.pc) & bb & "mov" & bl2 & "%wim, " & regdec(rd)); when RDTBR => return(tostf(insn.pc) & bb & "mov" & bl2 & "%tbr, " & regdec(rd)); when WRY => if (rs1 = "00000") or (rs2 = "00000") then if rd /= "00000" then return(tostf(insn.pc) & bb & "mov" & bl2 & regimm(insn,hex,false) & ", %asr" & tost(rd)); else return(tostf(insn.pc) & bb & "mov" & bl2 & regimm(insn,hex,false) & ", %y"); end if; else if rd /= "00000" then return(tostf(insn.pc) & bb & "wr " & bl2 & "%asr" & regimm(insn,hex,false) & ", %asr" & tost(rd)); else return(tostf(insn.pc) & bb & "wr " & bl2 & regimm(insn,hex,false) & ", %y"); end if; end if; when WRPSR => if (rs1 = "00000") or (rs2 = "00000") then return(tostf(insn.pc) & bb & "mov" & bl2 & regimm(insn,hex,false) & ", %psr"); else return(tostf(insn.pc) & bb & "wr " & bl2 & regimm(insn,hex,false) & ", %psr"); end if; when WRWIM => if (rs1 = "00000") or (rs2 = "00000") then return(tostf(insn.pc) & bb & "mov" & bl2 & regimm(insn,hex,false) & ", %wim"); else return(tostf(insn.pc) & bb & "wr " & bl2 & regimm(insn,hex,false) & ", %wim"); end if; when WRTBR => if (rs1 = "00000") or (rs2 = "00000") then return(tostf(insn.pc) & bb & "mov" & bl2 & regimm(insn,hex,false) & ", %tbr"); else return(tostf(insn.pc) & bb & "wr " & bl2 & regimm(insn,hex,false) & ", %tbr"); end if; when JMPL => if (rd = "00000") then if (i = '1') and (simm = "0000000001000") then if (rs1 = "11111") then return(tostf(insn.pc) & bb & "ret"); elsif (rs1 = "01111") then return(tostf(insn.pc) & bb & "retl"); else return(tostf(insn.pc) & bb & "jmp" & bl2 & regimm(insn,dec,true)); end if; else return(tostf(insn.pc) & bb & "jmp" & bl2 & regimm(insn,dec,true)); end if; else return(tostf(insn.pc) & bb & "jmpl" & bl2 & regres(insn,dec)); end if; when TICC => return(tostf(insn.pc) & bb & 't' & branchop(insn) & bl2 & regimm(insn,hex,false)); when FLUSH => return(tostf(insn.pc) & bb & "flush" & bl2 & regimm(insn,hex,false)); when RETT => return(tostf(insn.pc) & bb & "rett" & bl2 & regimm(insn,dec,false)); when RESTORE => if (rd = "00000") then return(tostf(insn.pc) & bb & "restore"); else return(tostf(insn.pc) & bb & "restore" & bl2 & regres(insn,hex)); end if; when SAVE => if (rd = "00000") then return(tostf(insn.pc) & bb & "save"); else return(tostf(insn.pc) & bb & "save" & bl2 & regres(insn,dec)); end if; when FPOP1 => case opf is when FITOS => return(tostf(insn.pc) & bb & "fitos" & bl2 & freg2(insn)); when FITOD => return(tostf(insn.pc) & bb & "fitod" & bl2 & freg2(insn)); when FDTOI => return(tostf(insn.pc) & bb & "fdtoi" & bl2 & freg2(insn)); when FSTOD => return(tostf(insn.pc) & bb & "fstod" & bl2 & freg2(insn)); when FDTOS => return(tostf(insn.pc) & bb & "fdtos" & bl2 & freg2(insn)); when FMOVS => return(tostf(insn.pc) & bb & "fmovs" & bl2 & freg2(insn)); when FNEGS => return(tostf(insn.pc) & bb & "fnegs" & bl2 & freg2(insn)); when FABSS => return(tostf(insn.pc) & bb & "fabss" & bl2 & freg2(insn)); when FSQRTS => return(tostf(insn.pc) & bb & "fsqrts" & bl2 & freg2(insn)); when FSQRTD => return(tostf(insn.pc) & bb & "fsqrtd" & bl2 & freg2(insn)); when FADDS => return(tostf(insn.pc) & bb & "fadds" & bl2 & freg3(insn)); when FADDD => return(tostf(insn.pc) & bb & "faddd" & bl2 & freg3(insn)); when FSUBS => return(tostf(insn.pc) & bb & "fsubs" & bl2 & freg3(insn)); when FSUBD => return(tostf(insn.pc) & bb & "fsubd" & bl2 & freg3(insn)); when FMULS => return(tostf(insn.pc) & bb & "fmuls" & bl2 & freg3(insn)); when FMULD => return(tostf(insn.pc) & bb & "fmuld" & bl2 & freg3(insn)); when FSMULD => return(tostf(insn.pc) & bb & "fsmuld" & bl2 & freg3(insn)); when FDIVS => return(tostf(insn.pc) & bb & "fdivs" & bl2 & freg3(insn)); when FDIVD => return(tostf(insn.pc) & bb & "fdivd" & bl2 & freg3(insn)); when others => return(tostf(insn.pc) & bb & "unknown Fopcode: " & tost(insn.op)); end case; when FPOP2 => case opf is when FCMPS => return(tostf(insn.pc) & bb & "fcmps" & bl2 & fregc(insn)); when FCMPD => return(tostf(insn.pc) & bb & "fcmpd" & bl2 & fregc(insn)); when FCMPES => return(tostf(insn.pc) & bb & "fcmpes" & bl2 & fregc(insn)); when FCMPED => return(tostf(insn.pc) & bb & "fcmped" & bl2 & fregc(insn)); when others => return(tostf(insn.pc) & bb & "unknown Fopcode: " & tost(insn.op)); end case; when CPOP1 => return(tostf(insn.pc) & bb & "cpop1" & bl2 & tost("000"&opf) & ", " &creg3(insn)); when CPOP2 => return(tostf(insn.pc) & bb & "cpop2" & bl2 & tost("000"&opf) & ", " &creg3(insn)); when others => return(tostf(insn.pc) & bb & "unknown opcode: " & tost(insn.op)); end case; when LDST => case op3 is when STC => return(tostf(insn.pc) & bb & "st" & bl2 & stparcp(insn, rd, dec)); when STF => return(tostf(insn.pc) & bb & "st" & bl2 & stparf(insn, rd, dec)); when ST => if rd = "00000" then return(tostf(insn.pc) & bb & "clr" & bl2 & stparc(insn, rd, dec)); else return(tostf(insn.pc) & bb & "st" & bl2 & stpar(insn, rd, dec)); end if; when STB => if rd = "00000" then return(tostf(insn.pc) & bb & "clrb" & bl2 & stparc(insn, rd, dec)); else return(tostf(insn.pc) & bb & "stb" & bl2 & stpar(insn, rd, dec)); end if; when STH => if rd = "00000" then return(tostf(insn.pc) & bb & "clrh" & bl2 & stparc(insn, rd, dec)); else return(tostf(insn.pc) & bb & "sth" & bl2 & stpar(insn, rd, dec)); end if; when STDC => return(tostf(insn.pc) & bb & "std" & bl2 & stparcp(insn, rd, dec)); when STDF => return(tostf(insn.pc) & bb & "std" & bl2 & stparf(insn, rd, dec)); when STCSR => return(tostf(insn.pc) & bb & "st" & bl2 & "%csr, [" & regimm(insn,dec,true) & "]"); when STFSR => return(tostf(insn.pc) & bb & "st" & bl2 & "%fsr, [" & regimm(insn,dec,true) & "]"); when STDCQ => return(tostf(insn.pc) & bb & "std" & bl2 & "%cq, [" & regimm(insn,dec,true) & "]"); when STDFQ => return(tostf(insn.pc) & bb & "std" & bl2 & "%fq, [" & regimm(insn,dec,true) & "]"); when ISTD => return(tostf(insn.pc) & bb & "std" & bl2 & stpar(insn, rd, dec)); when STA => return(tostf(insn.pc) & bb & "sta" & bl2 & stpara(insn, rd, dec)); when STBA => return(tostf(insn.pc) & bb & "stba" & bl2 & stpara(insn, rd, dec)); when STHA => return(tostf(insn.pc) & bb & "stha" & bl2 & stpara(insn, rd, dec)); when STDA => return(tostf(insn.pc) & bb & "stda" & bl2 & stpara(insn, rd, dec)); when LDC => return(tostf(insn.pc) & bb & "ld" & bl2 & ldparcp(insn, rd, dec)); when LDF => return(tostf(insn.pc) & bb & "ld" & bl2 & ldparf(insn, rd, dec)); when LDCSR => return(tostf(insn.pc) & bb & "ld" & bl2 & "[" & regimm(insn,dec,true) & "]" & ", %csr"); when LDFSR => return(tostf(insn.pc) & bb & "ld" & bl2 & "[" & regimm(insn,dec,true) & "]" & ", %fsr"); when LD => return(tostf(insn.pc) & bb & "ld" & bl2 & ldpar(insn, rd, dec)); when LDUB => return(tostf(insn.pc) & bb & "ldub" & bl2 & ldpar(insn, rd, dec)); when LDUH => return(tostf(insn.pc) & bb & "lduh" & bl2 & ldpar(insn, rd, dec)); when LDDC => return(tostf(insn.pc) & bb & "ldd" & bl2 & ldparcp(insn, rd, dec)); when LDDF => return(tostf(insn.pc) & bb & "ldd" & bl2 & ldparf(insn, rd, dec)); when LDD => return(tostf(insn.pc) & bb & "ldd" & bl2 & ldpar(insn, rd, dec)); when LDSB => return(tostf(insn.pc) & bb & "ldsb" & bl2 & ldpar(insn, rd, dec)); when LDSH => return(tostf(insn.pc) & bb & "ldsh" & bl2 & ldpar(insn, rd, dec)); when LDSTUB => return(tostf(insn.pc) & bb & "ldstub" & bl2 & ldpar(insn, rd, dec)); when SWAP => return(tostf(insn.pc) & bb & "swap" & bl2 & ldpar(insn, rd, dec)); when LDA => return(tostf(insn.pc) & bb & "lda" & bl2 & ldpara(insn, rd, dec)); when LDUBA => return(tostf(insn.pc) & bb & "lduba" & bl2 & ldpara(insn, rd, dec)); when LDUHA => return(tostf(insn.pc) & bb & "lduha" & bl2 & ldpara(insn, rd, dec)); when LDDA => return(tostf(insn.pc) & bb & "ldda" & bl2 & ldpara(insn, rd, dec)); when LDSBA => return(tostf(insn.pc) & bb & "ldsba" & bl2 & ldpara(insn, rd, dec)); when LDSHA => return(tostf(insn.pc) & bb & "ldsha" & bl2 & ldpara(insn, rd, dec)); when LDSTUBA => return(tostf(insn.pc) & bb & "ldstuba" & bl2 & ldpara(insn, rd, dec)); when SWAPA => return(tostf(insn.pc) & bb & "swapa" & bl2 & ldpara(insn, rd, dec)); when others => return(tostf(insn.pc) & bb & "unknown opcode: " & tost(insn.op)); end case; when others => return(tostf(insn.pc) & bb & "unknown opcode: " & tost(insn.op)); end case; end if;end;procedure print(s : string) is variable L1 : line;begin L1:= new string'(s); --'-- write(L1, s); writeline(output,L1);end;procedure trace(signal debug : in iu_debug_type; DISASS : boolean) is variable insn : debug_info;begin if DISASS or DEBUGFPU then if (debug.rst = '1') and debug.clk'event and (debug.clk = '1') and ((debug.holdn = '1') or GATEDCLK) then --' insn.op := debug.wr.inst; insn.pc := debug.wr.pc(31 downto 2) & "00"; if (debug.wr.annul or not debug.wr.pv) = '0' then if DISASS then if debug.trap = '1' then print (disas(insn) & " (trapped, tt = " & tostf(debug.tt) & ")"); else print (disas(insn)); end if; end if; end if; if debug.wr.annul = '0' then if DEBUGIURF then if (debug.write_reg = '1') then print(tostf(insn.pc) & ": %r" & tost(debug.wr.rd) & " = " & tost(debug.result)); end if; end if; if DEBUGFPU and (FPTYPE = meiko) then if (debug.write_reg = '1') and (debug.wr.rd(7 downto 5) = "100") then print(tostf(insn.pc) & ": %f" & tost(debug.wr.rd(4 downto 0)) & " = " & tost(debug.result)); end if; end if; end if; end if; end if;end;end debug;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -