mb/google/skyrim: Enable Chrome EC
[coreboot.git] / src / arch / x86 / include / mode_switch.h
blob0c46da5c629f5d9021dc3c157d6fbc20eb694555
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <stddef.h>
4 #include <stdint.h>
6 #if ENV_X86_64
7 int protected_mode_call_narg(uint32_t arg_count,
8 uint32_t func_ptr,
9 uint32_t opt_arg1,
10 uint32_t opt_arg2);
13 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
14 * After the function returns it enters long mode again.
15 * The function pointer destination must be below 4GiB in physical memory.
17 * The called function doesn't have arguments and returns an int.
19 static inline int protected_mode_call(void *func)
21 return protected_mode_call_narg(0, (uintptr_t)func, 0, 0);
25 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
26 * After the function returns it enters long mode again.
27 * The function pointer destination must be below 4GiB in physical memory.
28 * Only the lower 32bits of the argument are passed to the called function.
30 * The called function have one argument and returns an int.
32 static inline int protected_mode_call_1arg(void *func, uint32_t arg1)
34 return protected_mode_call_narg(1, (uintptr_t)func, arg1, 0);
38 * Drops into protected mode and calls the function, which must have been compiled for x86_32.
39 * After the function returns it enters long mode again.
40 * The function pointer destination must be below 4GiB in physical memory.
41 * Only the lower 32bits of the argument are passed to the called function.
43 * The called function has two arguments and returns an int.
45 static inline int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
47 return protected_mode_call_narg(2, (uintptr_t)func, arg1, arg2);
49 #else
50 static inline int protected_mode_call(void *func)
52 int (*doit)(void) = func;
54 return doit();
57 static inline int protected_mode_call_1arg(void *func, uint32_t arg1)
59 int (*doit)(uint32_t arg1) = func;
61 return doit(arg1);
64 static inline int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
66 int (*doit)(uint32_t arg1, uint32_t arg2) = func;
68 return doit(arg1, arg2);
70 #endif