ppc64.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // This file encapsulates some of the odd characteristics of the
  5. // 64-bit PowerPC (PPC64) instruction set, to minimize its interaction
  6. // with the core of the assembler.
  7. package arch
  8. import (
  9. "github.com/twitchyliquid64/golang-asm/obj"
  10. "github.com/twitchyliquid64/golang-asm/obj/ppc64"
  11. )
  12. func jumpPPC64(word string) bool {
  13. switch word {
  14. case "BC", "BCL", "BEQ", "BGE", "BGT", "BL", "BLE", "BLT", "BNE", "BR", "BVC", "BVS", "CALL", "JMP":
  15. return true
  16. }
  17. return false
  18. }
  19. // IsPPC64RLD reports whether the op (as defined by an ppc64.A* constant) is
  20. // one of the RLD-like instructions that require special handling.
  21. // The FMADD-like instructions behave similarly.
  22. func IsPPC64RLD(op obj.As) bool {
  23. switch op {
  24. case ppc64.ARLDC, ppc64.ARLDCCC, ppc64.ARLDCL, ppc64.ARLDCLCC,
  25. ppc64.ARLDCR, ppc64.ARLDCRCC, ppc64.ARLDMI, ppc64.ARLDMICC,
  26. ppc64.ARLWMI, ppc64.ARLWMICC, ppc64.ARLWNM, ppc64.ARLWNMCC:
  27. return true
  28. case ppc64.AFMADD, ppc64.AFMADDCC, ppc64.AFMADDS, ppc64.AFMADDSCC,
  29. ppc64.AFMSUB, ppc64.AFMSUBCC, ppc64.AFMSUBS, ppc64.AFMSUBSCC,
  30. ppc64.AFNMADD, ppc64.AFNMADDCC, ppc64.AFNMADDS, ppc64.AFNMADDSCC,
  31. ppc64.AFNMSUB, ppc64.AFNMSUBCC, ppc64.AFNMSUBS, ppc64.AFNMSUBSCC:
  32. return true
  33. }
  34. return false
  35. }
  36. func IsPPC64ISEL(op obj.As) bool {
  37. return op == ppc64.AISEL
  38. }
  39. // IsPPC64CMP reports whether the op (as defined by an ppc64.A* constant) is
  40. // one of the CMP instructions that require special handling.
  41. func IsPPC64CMP(op obj.As) bool {
  42. switch op {
  43. case ppc64.ACMP, ppc64.ACMPU, ppc64.ACMPW, ppc64.ACMPWU, ppc64.AFCMPU:
  44. return true
  45. }
  46. return false
  47. }
  48. // IsPPC64NEG reports whether the op (as defined by an ppc64.A* constant) is
  49. // one of the NEG-like instructions that require special handling.
  50. func IsPPC64NEG(op obj.As) bool {
  51. switch op {
  52. case ppc64.AADDMECC, ppc64.AADDMEVCC, ppc64.AADDMEV, ppc64.AADDME,
  53. ppc64.AADDZECC, ppc64.AADDZEVCC, ppc64.AADDZEV, ppc64.AADDZE,
  54. ppc64.ACNTLZDCC, ppc64.ACNTLZD, ppc64.ACNTLZWCC, ppc64.ACNTLZW,
  55. ppc64.AEXTSBCC, ppc64.AEXTSB, ppc64.AEXTSHCC, ppc64.AEXTSH,
  56. ppc64.AEXTSWCC, ppc64.AEXTSW, ppc64.ANEGCC, ppc64.ANEGVCC,
  57. ppc64.ANEGV, ppc64.ANEG, ppc64.ASLBMFEE, ppc64.ASLBMFEV,
  58. ppc64.ASLBMTE, ppc64.ASUBMECC, ppc64.ASUBMEVCC, ppc64.ASUBMEV,
  59. ppc64.ASUBME, ppc64.ASUBZECC, ppc64.ASUBZEVCC, ppc64.ASUBZEV,
  60. ppc64.ASUBZE:
  61. return true
  62. }
  63. return false
  64. }
  65. func ppc64RegisterNumber(name string, n int16) (int16, bool) {
  66. switch name {
  67. case "CR":
  68. if 0 <= n && n <= 7 {
  69. return ppc64.REG_CR0 + n, true
  70. }
  71. case "VS":
  72. if 0 <= n && n <= 63 {
  73. return ppc64.REG_VS0 + n, true
  74. }
  75. case "V":
  76. if 0 <= n && n <= 31 {
  77. return ppc64.REG_V0 + n, true
  78. }
  79. case "F":
  80. if 0 <= n && n <= 31 {
  81. return ppc64.REG_F0 + n, true
  82. }
  83. case "R":
  84. if 0 <= n && n <= 31 {
  85. return ppc64.REG_R0 + n, true
  86. }
  87. case "SPR":
  88. if 0 <= n && n <= 1024 {
  89. return ppc64.REG_SPR0 + n, true
  90. }
  91. }
  92. return 0, false
  93. }