apm.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Machine specific APM BIOS functions for generic.
  4. * Split out from apm.c by Osamu Tomita <[email protected]>
  5. */
  6. #ifndef _ASM_X86_MACH_DEFAULT_APM_H
  7. #define _ASM_X86_MACH_DEFAULT_APM_H
  8. #ifdef APM_ZERO_SEGS
  9. # define APM_DO_ZERO_SEGS \
  10. "pushl %%ds\n\t" \
  11. "pushl %%es\n\t" \
  12. "xorl %%edx, %%edx\n\t" \
  13. "mov %%dx, %%ds\n\t" \
  14. "mov %%dx, %%es\n\t" \
  15. "mov %%dx, %%fs\n\t" \
  16. "mov %%dx, %%gs\n\t"
  17. # define APM_DO_POP_SEGS \
  18. "popl %%es\n\t" \
  19. "popl %%ds\n\t"
  20. #else
  21. # define APM_DO_ZERO_SEGS
  22. # define APM_DO_POP_SEGS
  23. #endif
  24. static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
  25. u32 *eax, u32 *ebx, u32 *ecx,
  26. u32 *edx, u32 *esi)
  27. {
  28. /*
  29. * N.B. We do NOT need a cld after the BIOS call
  30. * because we always save and restore the flags.
  31. */
  32. __asm__ __volatile__(APM_DO_ZERO_SEGS
  33. "pushl %%edi\n\t"
  34. "pushl %%ebp\n\t"
  35. "lcall *%%cs:apm_bios_entry\n\t"
  36. "setc %%al\n\t"
  37. "popl %%ebp\n\t"
  38. "popl %%edi\n\t"
  39. APM_DO_POP_SEGS
  40. : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx),
  41. "=S" (*esi)
  42. : "a" (func), "b" (ebx_in), "c" (ecx_in)
  43. : "memory", "cc");
  44. }
  45. static inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in,
  46. u32 ecx_in, u32 *eax)
  47. {
  48. int cx, dx, si;
  49. bool error;
  50. /*
  51. * N.B. We do NOT need a cld after the BIOS call
  52. * because we always save and restore the flags.
  53. */
  54. __asm__ __volatile__(APM_DO_ZERO_SEGS
  55. "pushl %%edi\n\t"
  56. "pushl %%ebp\n\t"
  57. "lcall *%%cs:apm_bios_entry\n\t"
  58. "setc %%bl\n\t"
  59. "popl %%ebp\n\t"
  60. "popl %%edi\n\t"
  61. APM_DO_POP_SEGS
  62. : "=a" (*eax), "=b" (error), "=c" (cx), "=d" (dx),
  63. "=S" (si)
  64. : "a" (func), "b" (ebx_in), "c" (ecx_in)
  65. : "memory", "cc");
  66. return error;
  67. }
  68. #endif /* _ASM_X86_MACH_DEFAULT_APM_H */