mips.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // MIPS (MIPS64) 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/mips"
  11. )
  12. func jumpMIPS(word string) bool {
  13. switch word {
  14. case "BEQ", "BFPF", "BFPT", "BGEZ", "BGEZAL", "BGTZ", "BLEZ", "BLTZ", "BLTZAL", "BNE", "JMP", "JAL", "CALL":
  15. return true
  16. }
  17. return false
  18. }
  19. // IsMIPSCMP reports whether the op (as defined by an mips.A* constant) is
  20. // one of the CMP instructions that require special handling.
  21. func IsMIPSCMP(op obj.As) bool {
  22. switch op {
  23. case mips.ACMPEQF, mips.ACMPEQD, mips.ACMPGEF, mips.ACMPGED,
  24. mips.ACMPGTF, mips.ACMPGTD:
  25. return true
  26. }
  27. return false
  28. }
  29. // IsMIPSMUL reports whether the op (as defined by an mips.A* constant) is
  30. // one of the MUL/DIV/REM/MADD/MSUB instructions that require special handling.
  31. func IsMIPSMUL(op obj.As) bool {
  32. switch op {
  33. case mips.AMUL, mips.AMULU, mips.AMULV, mips.AMULVU,
  34. mips.ADIV, mips.ADIVU, mips.ADIVV, mips.ADIVVU,
  35. mips.AREM, mips.AREMU, mips.AREMV, mips.AREMVU,
  36. mips.AMADD, mips.AMSUB:
  37. return true
  38. }
  39. return false
  40. }
  41. func mipsRegisterNumber(name string, n int16) (int16, bool) {
  42. switch name {
  43. case "F":
  44. if 0 <= n && n <= 31 {
  45. return mips.REG_F0 + n, true
  46. }
  47. case "FCR":
  48. if 0 <= n && n <= 31 {
  49. return mips.REG_FCR0 + n, true
  50. }
  51. case "M":
  52. if 0 <= n && n <= 31 {
  53. return mips.REG_M0 + n, true
  54. }
  55. case "R":
  56. if 0 <= n && n <= 31 {
  57. return mips.REG_R0 + n, true
  58. }
  59. case "W":
  60. if 0 <= n && n <= 31 {
  61. return mips.REG_W0 + n, true
  62. }
  63. }
  64. return 0, false
  65. }