1 // Derived from Inferno utils/6c/reg.c 2 // http://code.google.com/p/inferno-os/source/browse/utils/6c/reg.c 3 // 4 // Copyright 1994-1999 Lucent Technologies Inc. All rights reserved. 5 // Portions Copyright 1995-1997 C H Forsyth (forsyth (a] terzarima.net) 6 // Portions Copyright 1997-1999 Vita Nuova Limited 7 // Portions Copyright 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com) 8 // Portions Copyright 2004,2006 Bruce Ellis 9 // Portions Copyright 2005-2007 C H Forsyth (forsyth (a] terzarima.net) 10 // Revisions Copyright 2000-2007 Lucent Technologies Inc. and others 11 // Portions Copyright 2009 The Go Authors. All rights reserved. 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a copy 14 // of this software and associated documentation files (the "Software"), to deal 15 // in the Software without restriction, including without limitation the rights 16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 // copies of the Software, and to permit persons to whom the Software is 18 // furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included in 21 // all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 // THE SOFTWARE. 30 31 package arm64 32 33 import ( 34 "cmd/compile/internal/gc" 35 "cmd/internal/obj/arm64" 36 ) 37 38 const ( 39 NREGVAR = 64 /* 32 general + 32 floating */ 40 ) 41 42 var regname = []string{ 43 ".R0", 44 ".R1", 45 ".R2", 46 ".R3", 47 ".R4", 48 ".R5", 49 ".R6", 50 ".R7", 51 ".R8", 52 ".R9", 53 ".R10", 54 ".R11", 55 ".R12", 56 ".R13", 57 ".R14", 58 ".R15", 59 ".R16", 60 ".R17", 61 ".R18", 62 ".R19", 63 ".R20", 64 ".R21", 65 ".R22", 66 ".R23", 67 ".R24", 68 ".R25", 69 ".R26", 70 ".R27", 71 ".R28", 72 ".R29", 73 ".R30", 74 ".R31", 75 ".F0", 76 ".F1", 77 ".F2", 78 ".F3", 79 ".F4", 80 ".F5", 81 ".F6", 82 ".F7", 83 ".F8", 84 ".F9", 85 ".F10", 86 ".F11", 87 ".F12", 88 ".F13", 89 ".F14", 90 ".F15", 91 ".F16", 92 ".F17", 93 ".F18", 94 ".F19", 95 ".F20", 96 ".F21", 97 ".F22", 98 ".F23", 99 ".F24", 100 ".F25", 101 ".F26", 102 ".F27", 103 ".F28", 104 ".F29", 105 ".F30", 106 ".F31", 107 } 108 109 func regnames(n *int) []string { 110 *n = NREGVAR 111 return regname 112 } 113 114 func excludedregs() uint64 { 115 // Exclude registers with fixed functions 116 regbits := uint64(RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2) | RtoB(arm64.REGPR)) 117 118 // Exclude R26 - R31. 119 for r := arm64.REGMAX + 1; r <= arm64.REGZERO; r++ { 120 regbits |= RtoB(r) 121 } 122 123 // Also exclude floating point registers with fixed constants 124 regbits |= RtoB(arm64.REG_F27) | RtoB(arm64.REG_F28) | RtoB(arm64.REG_F29) | RtoB(arm64.REG_F30) | RtoB(arm64.REG_F31) 125 126 return regbits 127 } 128 129 func doregbits(r int) uint64 { 130 return 0 131 } 132 133 /* 134 * track register variables including external registers: 135 * bit reg 136 * 0 R0 137 * 1 R1 138 * ... ... 139 * 31 R31 140 * 32+0 F0 141 * 32+1 F1 142 * ... ... 143 * 32+31 F31 144 */ 145 func RtoB(r int) uint64 { 146 if r >= arm64.REG_R0 && r <= arm64.REG_R31 { 147 return 1 << uint(r-arm64.REG_R0) 148 } 149 if r >= arm64.REG_F0 && r <= arm64.REG_F31 { 150 return 1 << uint(32+r-arm64.REG_F0) 151 } 152 return 0 153 } 154 155 func BtoR(b uint64) int { 156 b &= 0xffffffff 157 if b == 0 { 158 return 0 159 } 160 return gc.Bitno(b) + arm64.REG_R0 161 } 162 163 func BtoF(b uint64) int { 164 b >>= 32 165 if b == 0 { 166 return 0 167 } 168 return gc.Bitno(b) + arm64.REG_F0 169 } 170