github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/obj/ppc64/list9.go (about) 1 // cmd/9l/list.c from Vita Nuova. 2 // 3 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 4 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 5 // Portions Copyright © 1997-1999 Vita Nuova Limited 6 // Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com) 7 // Portions Copyright © 2004,2006 Bruce Ellis 8 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 9 // Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others 10 // Portions Copyright © 2009 The Go Authors. All rights reserved. 11 // 12 // Permission is hereby granted, free of charge, to any person obtaining a copy 13 // of this software and associated documentation files (the "Software"), to deal 14 // in the Software without restriction, including without limitation the rights 15 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 // copies of the Software, and to permit persons to whom the Software is 17 // furnished to do so, subject to the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be included in 20 // all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 // THE SOFTWARE. 29 30 package ppc64 31 32 import ( 33 "fmt" 34 35 "github.com/go-asm/go/cmd/obj" 36 ) 37 38 func init() { 39 obj.RegisterRegister(obj.RBasePPC64, REG_SPR0+1024, rconv) 40 // Note, the last entry in Anames is "LASTAOUT", it is not a real opcode. 41 obj.RegisterOpcode(obj.ABasePPC64, Anames[:len(Anames)-1]) 42 obj.RegisterOpcode(AFIRSTGEN, GenAnames) 43 } 44 45 func rconv(r int) string { 46 if r == 0 { 47 return "NONE" 48 } 49 if r == REGG { 50 // Special case. 51 return "g" 52 } 53 if REG_R0 <= r && r <= REG_R31 { 54 return fmt.Sprintf("R%d", r-REG_R0) 55 } 56 if REG_F0 <= r && r <= REG_F31 { 57 return fmt.Sprintf("F%d", r-REG_F0) 58 } 59 if REG_V0 <= r && r <= REG_V31 { 60 return fmt.Sprintf("V%d", r-REG_V0) 61 } 62 if REG_VS0 <= r && r <= REG_VS63 { 63 return fmt.Sprintf("VS%d", r-REG_VS0) 64 } 65 if REG_CR0 <= r && r <= REG_CR7 { 66 return fmt.Sprintf("CR%d", r-REG_CR0) 67 } 68 if REG_CR0LT <= r && r <= REG_CR7SO { 69 bits := [4]string{"LT", "GT", "EQ", "SO"} 70 crf := (r - REG_CR0LT) / 4 71 return fmt.Sprintf("CR%d%s", crf, bits[r%4]) 72 } 73 if REG_A0 <= r && r <= REG_A7 { 74 return fmt.Sprintf("A%d", r-REG_A0) 75 } 76 if r == REG_CR { 77 return "CR" 78 } 79 if REG_SPR0 <= r && r <= REG_SPR0+1023 { 80 switch r { 81 case REG_XER: 82 return "XER" 83 84 case REG_LR: 85 return "LR" 86 87 case REG_CTR: 88 return "CTR" 89 } 90 91 return fmt.Sprintf("SPR(%d)", r-REG_SPR0) 92 } 93 94 if r == REG_FPSCR { 95 return "FPSCR" 96 } 97 if r == REG_MSR { 98 return "MSR" 99 } 100 101 return fmt.Sprintf("Rgok(%d)", r-obj.RBasePPC64) 102 } 103 104 func DRconv(a int) string { 105 s := "C_??" 106 if a >= C_NONE && a <= C_NCLASS { 107 s = cnames9[a] 108 } 109 var fp string 110 fp += s 111 return fp 112 } 113 114 func ConstantToCRbit(c int64) (int16, bool) { 115 reg64 := REG_CRBIT0 + c 116 success := reg64 >= REG_CR0LT && reg64 <= REG_CR7SO 117 return int16(reg64), success 118 }