bdoor.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2016 VMware, Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package bdoor
  15. const (
  16. BackdoorMagic = uint64(0x564D5868)
  17. BackdoorPort = uint16(0x5658)
  18. BackdoorHighBWPort = uint16(0x5659)
  19. CommandGetVersion = uint32(10)
  20. CommandMessage = uint16(0x1e)
  21. CommandHighBWMessage = uint16(0)
  22. CommandFlagCookie = uint32(0x80000000)
  23. )
  24. type BackdoorProto struct {
  25. // typedef union {
  26. // struct {
  27. // DECLARE_REG_NAMED_STRUCT(ax);
  28. // size_t size; /* Register bx. */
  29. // DECLARE_REG_NAMED_STRUCT(cx);
  30. // DECLARE_REG_NAMED_STRUCT(dx);
  31. // DECLARE_REG_NAMED_STRUCT(si);
  32. // DECLARE_REG_NAMED_STRUCT(di);
  33. // } in;
  34. // struct {
  35. // DECLARE_REG_NAMED_STRUCT(ax);
  36. // DECLARE_REG_NAMED_STRUCT(bx);
  37. // DECLARE_REG_NAMED_STRUCT(cx);
  38. // DECLARE_REG_NAMED_STRUCT(dx);
  39. // DECLARE_REG_NAMED_STRUCT(si);
  40. // DECLARE_REG_NAMED_STRUCT(di);
  41. // } out;
  42. // } proto;
  43. AX, BX, CX, DX, SI, DI, BP UInt64
  44. size uint32
  45. }
  46. func bdoor_inout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  47. func bdoor_hbout(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  48. func bdoor_hbin(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  49. func bdoor_inout_test(ax, bx, cx, dx, si, di, bp uint64) (retax, retbx, retcx, retdx, retsi, retdi, retbp uint64)
  50. func (p *BackdoorProto) InOut() *BackdoorProto {
  51. p.DX.Low.Low = BackdoorPort
  52. p.AX.SetQuad(BackdoorMagic)
  53. retax, retbx, retcx, retdx, retsi, retdi, retbp := bdoor_inout(
  54. p.AX.Quad(),
  55. p.BX.Quad(),
  56. p.CX.Quad(),
  57. p.DX.Quad(),
  58. p.SI.Quad(),
  59. p.DI.Quad(),
  60. p.BP.Quad(),
  61. )
  62. ret := &BackdoorProto{}
  63. ret.AX.SetQuad(retax)
  64. ret.BX.SetQuad(retbx)
  65. ret.CX.SetQuad(retcx)
  66. ret.DX.SetQuad(retdx)
  67. ret.SI.SetQuad(retsi)
  68. ret.DI.SetQuad(retdi)
  69. ret.BP.SetQuad(retbp)
  70. return ret
  71. }
  72. func (p *BackdoorProto) HighBandwidthOut() *BackdoorProto {
  73. p.DX.Low.Low = BackdoorHighBWPort
  74. p.AX.SetQuad(BackdoorMagic)
  75. retax, retbx, retcx, retdx, retsi, retdi, retbp := bdoor_hbout(
  76. p.AX.Quad(),
  77. p.BX.Quad(),
  78. p.CX.Quad(),
  79. p.DX.Quad(),
  80. p.SI.Quad(),
  81. p.DI.Quad(),
  82. p.BP.Quad(),
  83. )
  84. ret := &BackdoorProto{}
  85. ret.AX.SetQuad(retax)
  86. ret.BX.SetQuad(retbx)
  87. ret.CX.SetQuad(retcx)
  88. ret.DX.SetQuad(retdx)
  89. ret.SI.SetQuad(retsi)
  90. ret.DI.SetQuad(retdi)
  91. ret.BP.SetQuad(retbp)
  92. return ret
  93. }
  94. func (p *BackdoorProto) HighBandwidthIn() *BackdoorProto {
  95. p.DX.Low.Low = BackdoorHighBWPort
  96. p.AX.SetQuad(BackdoorMagic)
  97. retax, retbx, retcx, retdx, retsi, retdi, retbp := bdoor_hbin(
  98. p.AX.Quad(),
  99. p.BX.Quad(),
  100. p.CX.Quad(),
  101. p.DX.Quad(),
  102. p.SI.Quad(),
  103. p.DI.Quad(),
  104. p.BP.Quad(),
  105. )
  106. ret := &BackdoorProto{}
  107. ret.AX.SetQuad(retax)
  108. ret.BX.SetQuad(retbx)
  109. ret.CX.SetQuad(retcx)
  110. ret.DX.SetQuad(retdx)
  111. ret.SI.SetQuad(retsi)
  112. ret.DI.SetQuad(retdi)
  113. ret.BP.SetQuad(retbp)
  114. return ret
  115. }