1 /* SPDX-License-Identifier: GPL-2.0-only */
7 * Assembly code that drops into protected mode and calls the function
8 * specified as first argument, which must have been compiled for x86_32.
9 * After the function returns it enters long mode again.
10 * The function pointer destination must be below 4GiB in physical memory.
12 * The called function has 0-3 arguments and returns an int.
14 int protected_mode_call_wrapper(uint32_t func_ptr
,
20 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
21 * After the function returns it enters long mode again.
22 * The function pointer destination must be below 4GiB in physical memory.
24 * The called function doesn't have arguments and returns an int.
26 static inline int protected_mode_call(void *func
)
28 return protected_mode_call_wrapper((uintptr_t)func
, 0, 0, 0);
32 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
33 * After the function returns it enters long mode again.
34 * The function pointer destination must be below 4GiB in physical memory.
35 * Only the lower 32bits of the argument are passed to the called function.
37 * The called function have one argument and returns an int.
39 static inline int protected_mode_call_1arg(void *func
, uint32_t arg1
)
41 return protected_mode_call_wrapper((uintptr_t)func
, arg1
, 0, 0);
45 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
46 * After the function returns it enters long mode again.
47 * The function pointer destination must be below 4GiB in physical memory.
48 * Only the lower 32bits of the argument are passed to the called function.
50 * The called function has two arguments and returns an int.
52 static inline int protected_mode_call_2arg(void *func
, uint32_t arg1
, uint32_t arg2
)
54 return protected_mode_call_wrapper((uintptr_t)func
, arg1
, arg2
, 0);
58 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
59 * After the function returns it enters long mode again.
60 * The function pointer destination must be below 4GiB in physical memory.
61 * Only the lower 32bits of the argument are passed to the called function.
63 * The called function has two arguments and returns an int.
65 static inline int protected_mode_call_3arg(void *func
, uint32_t arg1
, uint32_t arg2
,
68 return protected_mode_call_wrapper((uintptr_t)func
, arg1
, arg2
, arg3
);
71 static inline int protected_mode_call(void *func
)
73 int (*doit
)(void) = func
;
78 static inline int protected_mode_call_1arg(void *func
, uint32_t arg1
)
80 int (*doit
)(uint32_t arg1
) = func
;
85 static inline int protected_mode_call_2arg(void *func
, uint32_t arg1
, uint32_t arg2
)
87 int (*doit
)(uint32_t arg1
, uint32_t arg2
) = func
;
89 return doit(arg1
, arg2
);
92 static inline int protected_mode_call_3arg(void *func
, uint32_t arg1
, uint32_t arg2
,
95 int (*doit
)(uint32_t arg1
, uint32_t arg2
, uint32_t arg3
) = func
;
97 return doit(arg1
, arg2
, arg3
);