Home | History | Annotate | Download | only in ppc64
      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 ppc64
     32 
     33 import "cmd/internal/obj/ppc64"
     34 import "cmd/compile/internal/gc"
     35 
     36 const (
     37 	NREGVAR = 64 /* 32 general + 32 floating */
     38 )
     39 
     40 var regname = []string{
     41 	".R0",
     42 	".R1",
     43 	".R2",
     44 	".R3",
     45 	".R4",
     46 	".R5",
     47 	".R6",
     48 	".R7",
     49 	".R8",
     50 	".R9",
     51 	".R10",
     52 	".R11",
     53 	".R12",
     54 	".R13",
     55 	".R14",
     56 	".R15",
     57 	".R16",
     58 	".R17",
     59 	".R18",
     60 	".R19",
     61 	".R20",
     62 	".R21",
     63 	".R22",
     64 	".R23",
     65 	".R24",
     66 	".R25",
     67 	".R26",
     68 	".R27",
     69 	".R28",
     70 	".R29",
     71 	".R30",
     72 	".R31",
     73 	".F0",
     74 	".F1",
     75 	".F2",
     76 	".F3",
     77 	".F4",
     78 	".F5",
     79 	".F6",
     80 	".F7",
     81 	".F8",
     82 	".F9",
     83 	".F10",
     84 	".F11",
     85 	".F12",
     86 	".F13",
     87 	".F14",
     88 	".F15",
     89 	".F16",
     90 	".F17",
     91 	".F18",
     92 	".F19",
     93 	".F20",
     94 	".F21",
     95 	".F22",
     96 	".F23",
     97 	".F24",
     98 	".F25",
     99 	".F26",
    100 	".F27",
    101 	".F28",
    102 	".F29",
    103 	".F30",
    104 	".F31",
    105 }
    106 
    107 func regnames(n *int) []string {
    108 	*n = NREGVAR
    109 	return regname
    110 }
    111 
    112 func excludedregs() uint64 {
    113 	// Exclude registers with fixed functions
    114 	regbits := uint64(1<<0 | RtoB(ppc64.REGSP) | RtoB(ppc64.REGG) | RtoB(ppc64.REGTLS))
    115 
    116 	// Also exclude floating point registers with fixed constants
    117 	regbits |= RtoB(ppc64.REG_F27) | RtoB(ppc64.REG_F28) | RtoB(ppc64.REG_F29) | RtoB(ppc64.REG_F30) | RtoB(ppc64.REG_F31)
    118 
    119 	return regbits
    120 }
    121 
    122 func doregbits(r int) uint64 {
    123 	return 0
    124 }
    125 
    126 /*
    127  * track register variables including external registers:
    128  *	bit	reg
    129  *	0	R0
    130  *	1	R1
    131  *	...	...
    132  *	31	R31
    133  *	32+0	F0
    134  *	32+1	F1
    135  *	...	...
    136  *	32+31	F31
    137  */
    138 func RtoB(r int) uint64 {
    139 	if r > ppc64.REG_R0 && r <= ppc64.REG_R31 {
    140 		return 1 << uint(r-ppc64.REG_R0)
    141 	}
    142 	if r >= ppc64.REG_F0 && r <= ppc64.REG_F31 {
    143 		return 1 << uint(32+r-ppc64.REG_F0)
    144 	}
    145 	return 0
    146 }
    147 
    148 func BtoR(b uint64) int {
    149 	b &= 0xffffffff
    150 	if b == 0 {
    151 		return 0
    152 	}
    153 	return gc.Bitno(b) + ppc64.REG_R0
    154 }
    155 
    156 func BtoF(b uint64) int {
    157 	b >>= 32
    158 	if b == 0 {
    159 		return 0
    160 	}
    161 	return gc.Bitno(b) + ppc64.REG_F0
    162 }
    163