static string rt_imm(uint iw) { if (!First_Parse && PrintRelocations && RelocationLabels.ContainsKey(pc)) { var label = GetRelocLabel(pc); return($"{gpr_rn[RT(iw)]}, %hi({label})"); } return($"{gpr_rn[RT(iw)]}, 0x{IMM(iw):X4}"); }
private static void InitRelocationLabels(BinaryReader br, DisassemblyTask task) { N64Ptr hi_addr = 0; Rel_Parse = true; N64Ptr start = task.VRam.Start; List <(N64Ptr start, N64Ptr end)> textSections = GetTextSectionRanges(task); foreach (var reloc in task.Relocations) { N64Ptr relAddr = task.VRam.Start + reloc.Offset; br.BaseStream.Position = reloc.Offset; if (reloc.RelocType == Reloc.R_MIPS_HI16 || reloc.RelocType == Reloc.R_MIPS_LO16) { GetOP(br.ReadBigInt32()); if (reloc.RelocType == Reloc.R_MIPS_HI16) { hi_addr = relAddr; } else if (reloc.RelocType == Reloc.R_MIPS_LO16) { //Fixes bug where gcc generates a R_MIPS_HI16 //after LO16 that is part of the same chain of LO16s if (!RelocationLabels.ContainsKey(hi_addr)) { RelocationLabels[hi_addr] = Rel_Label_Addr; } RelocationLabels[relAddr] = Rel_Label_Addr; } } else if (reloc.RelocType == Reloc.R_MIPS32) { N64Ptr ptr = br.ReadBigInt32(); if (textSections.Exists(x => x.start >= ptr && ptr < x.end)) { AddLabel(ptr, false); } else { Symbols[ptr] = new Label(Label.Type.VAR, ptr); } } } Rel_Parse = false; br.BaseStream.Position = 0; }
static string rt_rs_imm(uint iw) { if (Rel_Parse) { Rel_Label_Addr = gpr_regs[RT(iw)]; } if (!First_Parse && RelocationLabels.ContainsKey(pc)) { if (PrintRelocations) { var label = GetRelocLabel(pc); return($"{gpr_rn[RT(iw)]}, {gpr_rn[RS(iw)]}, %lo({label})"); } } return($"{gpr_rn[RT(iw)]}, {gpr_rn[RS(iw)]}, 0x{IMM(iw):X4}"); }
static string base_imm(uint iw, string reg) { var addr = gpr_regs[BASE(iw)] + IMM(iw); if (Rel_Parse) { Rel_Label_Addr = addr; } if (!First_Parse && RelocationLabels.ContainsKey(pc)) { if (PrintRelocations) { var label = GetRelocLabel(pc); return($"{reg}, %lo({label})({gpr_rn[BASE(iw)]})"); } } string result = $"{reg}, {IMM_P(iw)}({gpr_rn[BASE(iw)]})"; if (BASE(iw) != 29) { result += $"\t## {addr:X8}"; } return(result); }