apmjump.s 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Far call, absolute indirect.
  3. * The argument is the offset.
  4. * We use a global structure for the jump params,
  5. * so this is *not* reentrant or thread safe.
  6. */
  7. #include "mem.h"
  8. #define SSOVERRIDE BYTE $0x36
  9. #define CSOVERRIDE BYTE $0x2E
  10. #define RETF BYTE $0xCB
  11. GLOBL apmjumpstruct+0(SB), $8
  12. TEXT fortytwo(SB), $0
  13. MOVL $42, AX
  14. RETF
  15. TEXT getcs(SB), $0
  16. PUSHL CS
  17. POPL AX
  18. RET
  19. TEXT apmfarcall(SB), $0
  20. /*
  21. * We call push and pop ourselves.
  22. * As soon as we do the first push or pop,
  23. * we can't use FP anymore.
  24. */
  25. MOVL off+4(FP), BX
  26. MOVL seg+0(FP), CX
  27. MOVL BX, apmjumpstruct+0(SB)
  28. MOVL CX, apmjumpstruct+4(SB)
  29. /* load necessary registers from Ureg */
  30. MOVL ureg+8(FP), DI
  31. MOVL 28(DI), AX
  32. MOVL 16(DI), BX
  33. MOVL 24(DI), CX
  34. MOVL 20(DI), DX
  35. /* save registers, segments */
  36. PUSHL DS
  37. PUSHL ES
  38. PUSHL FS
  39. PUSHL GS
  40. PUSHL BP
  41. PUSHL DI
  42. /*
  43. * paranoia: zero the segments, since it's the
  44. * BIOS's responsibility to initialize them.
  45. * (trick picked up from Linux driver).
  46. PUSHL DX
  47. XORL DX, DX
  48. PUSHL DX
  49. POPL DS
  50. PUSHL DX
  51. POPL ES
  52. PUSHL DX
  53. POPL FS
  54. PUSHL DX
  55. POPL GS
  56. POPL DX
  57. */
  58. PUSHL $APMDSEG
  59. POPL DS
  60. /*
  61. * The actual call.
  62. */
  63. CSOVERRIDE; BYTE $0xFF; BYTE $0x1D
  64. LONG $apmjumpstruct+0(SB)
  65. /* restore segments, registers */
  66. POPL DI
  67. POPL BP
  68. POPL GS
  69. POPL FS
  70. POPL ES
  71. POPL DS
  72. PUSHFL
  73. POPL 64(DI)
  74. /* store interesting registers back in Ureg */
  75. MOVL AX, 28(DI)
  76. MOVL BX, 16(DI)
  77. MOVL CX, 24(DI)
  78. MOVL DX, 20(DI)
  79. MOVL SI, 4(DI)
  80. PUSHFL
  81. POPL AX
  82. ANDL $1, AX /* carry flag */
  83. RET