bdoor_amd64.s 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "textflag.h"
  2. // Doc of the golang plan9 assembler
  3. // http://p9.nyx.link/labs/sys/doc/asm.html
  4. //
  5. // A good primer of how to write golang with some plan9 flavored assembly
  6. // http://www.doxsey.net/blog/go-and-assembly
  7. //
  8. // Some x86 references
  9. // http://www.eecg.toronto.edu/~amza/www.mindsec.com/files/x86regs.html
  10. // https://cseweb.ucsd.edu/classes/sp10/cse141/pdf/02/S01_x86_64.key.pdf
  11. // https://en.wikibooks.org/wiki/X86_Assembly/Other_Instructions
  12. //
  13. // (This one is invaluable. Has a working example of how a standard function
  14. // call looks on the stack with the associated assembly.)
  15. // https://www.recurse.com/blog/7-understanding-c-by-learning-assembly
  16. //
  17. // Reference with raw form of the Opcode
  18. // http://x86.renejeschke.de/html/file_module_x86_id_139.html
  19. //
  20. // Massive x86_64 reference
  21. // http://ref.x86asm.net/coder64.html#xED
  22. //
  23. // Adding instructions to the go assembler
  24. // https://blog.klauspost.com/adding-unsupported-instructions-in-golang-assembler/
  25. //
  26. // Backdoor commands
  27. // https://sites.google.com/site/chitchatvmback/backdoor
  28. // func bdoor_inout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  29. TEXT ·bdoor_inout(SB), NOSPLIT|WRAPPER, $0
  30. MOVQ ax+0(FP), AX
  31. MOVQ bx+8(FP), BX
  32. MOVQ cx+16(FP), CX
  33. MOVQ dx+24(FP), DX
  34. MOVQ si+32(FP), SI
  35. MOVQ di+40(FP), DI
  36. MOVQ bp+48(FP), BP
  37. // IN to DX from EAX
  38. INL
  39. MOVQ AX, retax+56(FP)
  40. MOVQ BX, retbx+64(FP)
  41. MOVQ CX, retcx+72(FP)
  42. MOVQ DX, retdx+80(FP)
  43. MOVQ SI, retsi+88(FP)
  44. MOVQ DI, retdi+96(FP)
  45. MOVQ BP, retbp+104(FP)
  46. RET
  47. // func bdoor_hbout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  48. TEXT ·bdoor_hbout(SB), NOSPLIT|WRAPPER, $0
  49. MOVQ ax+0(FP), AX
  50. MOVQ bx+8(FP), BX
  51. MOVQ cx+16(FP), CX
  52. MOVQ dx+24(FP), DX
  53. MOVQ si+32(FP), SI
  54. MOVQ di+40(FP), DI
  55. MOVQ bp+48(FP), BP
  56. CLD; REP; OUTSB
  57. MOVQ AX, retax+56(FP)
  58. MOVQ BX, retbx+64(FP)
  59. MOVQ CX, retcx+72(FP)
  60. MOVQ DX, retdx+80(FP)
  61. MOVQ SI, retsi+88(FP)
  62. MOVQ DI, retdi+96(FP)
  63. MOVQ BP, retbp+104(FP)
  64. RET
  65. // func bdoor_hbin(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  66. TEXT ·bdoor_hbin(SB), NOSPLIT|WRAPPER, $0
  67. MOVQ ax+0(FP), AX
  68. MOVQ bx+8(FP), BX
  69. MOVQ cx+16(FP), CX
  70. MOVQ dx+24(FP), DX
  71. MOVQ si+32(FP), SI
  72. MOVQ di+40(FP), DI
  73. MOVQ bp+48(FP), BP
  74. CLD; REP; INSB
  75. MOVQ AX, retax+56(FP)
  76. MOVQ BX, retbx+64(FP)
  77. MOVQ CX, retcx+72(FP)
  78. MOVQ DX, retdx+80(FP)
  79. MOVQ SI, retsi+88(FP)
  80. MOVQ DI, retdi+96(FP)
  81. MOVQ BP, retbp+104(FP)
  82. RET
  83. // func bdoor_inout_test(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  84. TEXT ·bdoor_inout_test(SB), NOSPLIT|WRAPPER, $0
  85. MOVQ ax+0(FP), AX
  86. MOVQ bx+8(FP), BX
  87. MOVQ cx+16(FP), CX
  88. MOVQ dx+24(FP), DX
  89. MOVQ si+32(FP), SI
  90. MOVQ di+40(FP), DI
  91. MOVQ bp+48(FP), BP
  92. MOVQ AX, retax+56(FP)
  93. MOVQ BX, retbx+64(FP)
  94. MOVQ CX, retcx+72(FP)
  95. MOVQ DX, retdx+80(FP)
  96. MOVQ SI, retsi+88(FP)
  97. MOVQ DI, retdi+96(FP)
  98. MOVQ BP, retbp+104(FP)
  99. RET