1106184Smarcel/* SPDX-License-Identifier: GPL-2.0 */ 2106184Smarcel/* 3106184Smarcel * Machine specific APM BIOS functions for generic. 4106184Smarcel * Split out from apm.c by Osamu Tomita <tomita@cinet.co.jp> 5106184Smarcel */ 6106184Smarcel 7106184Smarcel#ifndef _ASM_X86_MACH_DEFAULT_APM_H 8106184Smarcel#define _ASM_X86_MACH_DEFAULT_APM_H 9106184Smarcel 10106184Smarcel#ifdef APM_ZERO_SEGS 11106184Smarcel# define APM_DO_ZERO_SEGS \ 12106184Smarcel "pushl %%ds\n\t" \ 13106184Smarcel "pushl %%es\n\t" \ 14106184Smarcel "xorl %%edx, %%edx\n\t" \ 15106184Smarcel "mov %%dx, %%ds\n\t" \ 16106184Smarcel "mov %%dx, %%es\n\t" \ 17106184Smarcel "mov %%dx, %%fs\n\t" \ 18106184Smarcel "mov %%dx, %%gs\n\t" 19106184Smarcel# define APM_DO_POP_SEGS \ 20106184Smarcel "popl %%es\n\t" \ 21106184Smarcel "popl %%ds\n\t" 22106184Smarcel#else 23106184Smarcel# define APM_DO_ZERO_SEGS 24106184Smarcel# define APM_DO_POP_SEGS 25106184Smarcel#endif 26106184Smarcel 27106184Smarcelstatic inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in, 28106184Smarcel u32 *eax, u32 *ebx, u32 *ecx, 29106184Smarcel u32 *edx, u32 *esi) 30106184Smarcel{ 31106184Smarcel /* 32106184Smarcel * N.B. We do NOT need a cld after the BIOS call 33106184Smarcel * because we always save and restore the flags. 34106184Smarcel */ 35106184Smarcel __asm__ __volatile__(APM_DO_ZERO_SEGS 36106184Smarcel "pushl %%edi\n\t" 37106184Smarcel "pushl %%ebp\n\t" 38106184Smarcel "lcall *%%cs:apm_bios_entry\n\t" 39106184Smarcel "setc %%al\n\t" 40106184Smarcel "popl %%ebp\n\t" 41106184Smarcel "popl %%edi\n\t" 42106184Smarcel APM_DO_POP_SEGS 43106184Smarcel : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx), 44106184Smarcel "=S" (*esi) 45106184Smarcel : "a" (func), "b" (ebx_in), "c" (ecx_in) 46106184Smarcel : "memory", "cc"); 47106184Smarcel} 48106452Sjmallett 49106184Smarcelstatic inline bool apm_bios_call_simple_asm(u32 func, u32 ebx_in, 50106184Smarcel u32 ecx_in, u32 *eax) 51106184Smarcel{ 52106184Smarcel int cx, dx, si; 53106184Smarcel bool error; 54106184Smarcel 55106184Smarcel /* 56106184Smarcel * N.B. We do NOT need a cld after the BIOS call 57106452Sjmallett * because we always save and restore the flags. 58106184Smarcel */ 59106184Smarcel __asm__ __volatile__(APM_DO_ZERO_SEGS 60 "pushl %%edi\n\t" 61 "pushl %%ebp\n\t" 62 "lcall *%%cs:apm_bios_entry\n\t" 63 "setc %%bl\n\t" 64 "popl %%ebp\n\t" 65 "popl %%edi\n\t" 66 APM_DO_POP_SEGS 67 : "=a" (*eax), "=b" (error), "=c" (cx), "=d" (dx), 68 "=S" (si) 69 : "a" (func), "b" (ebx_in), "c" (ecx_in) 70 : "memory", "cc"); 71 return error; 72} 73 74#endif /* _ASM_X86_MACH_DEFAULT_APM_H */ 75