github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/dwarf/regnum/amd64.go (about) 1 package regnum 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // The mapping between hardware registers and DWARF registers is specified 9 // in the System V ABI AMD64 Architecture Processor Supplement v. 1.0 page 61, 10 // figure 3.36 11 // https://gitlab.com/x86-psABIs/x86-64-ABI/-/tree/master 12 13 const ( 14 AMD64_Rax = 0 15 AMD64_Rdx = 1 16 AMD64_Rcx = 2 17 AMD64_Rbx = 3 18 AMD64_Rsi = 4 19 AMD64_Rdi = 5 20 AMD64_Rbp = 6 21 AMD64_Rsp = 7 22 AMD64_R8 = 8 23 AMD64_R9 = 9 24 AMD64_R10 = 10 25 AMD64_R11 = 11 26 AMD64_R12 = 12 27 AMD64_R13 = 13 28 AMD64_R14 = 14 29 AMD64_R15 = 15 30 AMD64_Rip = 16 31 AMD64_XMM0 = 17 // XMM1 through XMM15 follow 32 AMD64_ST0 = 33 // ST(1) through ST(7) follow 33 AMD64_Rflags = 49 34 AMD64_Es = 50 35 AMD64_Cs = 51 36 AMD64_Ss = 52 37 AMD64_Ds = 53 38 AMD64_Fs = 54 39 AMD64_Gs = 55 40 AMD64_Fs_base = 58 41 AMD64_Gs_base = 59 42 AMD64_MXCSR = 64 43 AMD64_CW = 65 44 AMD64_SW = 66 45 AMD64_XMM16 = 67 // XMM17 through XMM31 follow 46 AMD64_K0 = 118 // k1 through k7 follow 47 ) 48 49 var amd64DwarfToName = map[uint64]string{ 50 AMD64_Rax: "Rax", 51 AMD64_Rdx: "Rdx", 52 AMD64_Rcx: "Rcx", 53 AMD64_Rbx: "Rbx", 54 AMD64_Rsi: "Rsi", 55 AMD64_Rdi: "Rdi", 56 AMD64_Rbp: "Rbp", 57 AMD64_Rsp: "Rsp", 58 AMD64_R8: "R8", 59 AMD64_R9: "R9", 60 AMD64_R10: "R10", 61 AMD64_R11: "R11", 62 AMD64_R12: "R12", 63 AMD64_R13: "R13", 64 AMD64_R14: "R14", 65 AMD64_R15: "R15", 66 AMD64_Rip: "Rip", 67 AMD64_XMM0: "XMM0", 68 AMD64_XMM0 + 1: "XMM1", 69 AMD64_XMM0 + 2: "XMM2", 70 AMD64_XMM0 + 3: "XMM3", 71 AMD64_XMM0 + 4: "XMM4", 72 AMD64_XMM0 + 5: "XMM5", 73 AMD64_XMM0 + 6: "XMM6", 74 AMD64_XMM0 + 7: "XMM7", 75 AMD64_XMM0 + 8: "XMM8", 76 AMD64_XMM0 + 9: "XMM9", 77 AMD64_XMM0 + 10: "XMM10", 78 AMD64_XMM0 + 11: "XMM11", 79 AMD64_XMM0 + 12: "XMM12", 80 AMD64_XMM0 + 13: "XMM13", 81 AMD64_XMM0 + 14: "XMM14", 82 AMD64_XMM0 + 15: "XMM15", 83 AMD64_ST0: "ST(0)", 84 AMD64_ST0 + 1: "ST(1)", 85 AMD64_ST0 + 2: "ST(2)", 86 AMD64_ST0 + 3: "ST(3)", 87 AMD64_ST0 + 4: "ST(4)", 88 AMD64_ST0 + 5: "ST(5)", 89 AMD64_ST0 + 6: "ST(6)", 90 AMD64_ST0 + 7: "ST(7)", 91 AMD64_Rflags: "Rflags", 92 AMD64_Es: "Es", 93 AMD64_Cs: "Cs", 94 AMD64_Ss: "Ss", 95 AMD64_Ds: "Ds", 96 AMD64_Fs: "Fs", 97 AMD64_Gs: "Gs", 98 AMD64_Fs_base: "Fs_base", 99 AMD64_Gs_base: "Gs_base", 100 AMD64_MXCSR: "MXCSR", 101 AMD64_CW: "CW", 102 AMD64_SW: "SW", 103 AMD64_XMM16: "XMM16", 104 AMD64_XMM16 + 1: "XMM17", 105 AMD64_XMM16 + 2: "XMM18", 106 AMD64_XMM16 + 3: "XMM19", 107 AMD64_XMM16 + 4: "XMM20", 108 AMD64_XMM16 + 5: "XMM21", 109 AMD64_XMM16 + 6: "XMM22", 110 AMD64_XMM16 + 7: "XMM23", 111 AMD64_XMM16 + 8: "XMM24", 112 AMD64_XMM16 + 9: "XMM25", 113 AMD64_XMM16 + 10: "XMM26", 114 AMD64_XMM16 + 11: "XMM27", 115 AMD64_XMM16 + 12: "XMM28", 116 AMD64_XMM16 + 13: "XMM29", 117 AMD64_XMM16 + 14: "XMM30", 118 AMD64_XMM16 + 15: "XMM31", 119 AMD64_K0: "K0", 120 AMD64_K0 + 1: "K1", 121 AMD64_K0 + 2: "K2", 122 AMD64_K0 + 3: "K3", 123 AMD64_K0 + 4: "K4", 124 AMD64_K0 + 5: "K5", 125 AMD64_K0 + 6: "K6", 126 AMD64_K0 + 7: "K7", 127 } 128 129 var AMD64NameToDwarf = func() map[string]int { 130 r := make(map[string]int) 131 for regNum, regName := range amd64DwarfToName { 132 r[strings.ToLower(regName)] = int(regNum) 133 } 134 r["eflags"] = 49 135 r["st0"] = 33 136 r["st1"] = 34 137 r["st2"] = 35 138 r["st3"] = 36 139 r["st4"] = 37 140 r["st5"] = 38 141 r["st6"] = 39 142 r["st7"] = 40 143 return r 144 }() 145 146 func AMD64MaxRegNum() uint64 { 147 max := uint64(AMD64_Rip) 148 for i := range amd64DwarfToName { 149 if i > max { 150 max = i 151 } 152 } 153 return max 154 } 155 156 func AMD64ToName(num uint64) string { 157 name, ok := amd64DwarfToName[num] 158 if ok { 159 return name 160 } 161 return fmt.Sprintf("unknown%d", num) 162 }