coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mode_switch.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stddef.h>
4 #include <stdint.h>
5 
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);
11 
12 /*
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.
16  *
17  * The called function doesn't have arguments and returns an int.
18  */
19 static inline int protected_mode_call(void *func)
20 {
21  return protected_mode_call_narg(0, (uintptr_t)func, 0, 0);
22 }
23 
24 /*
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.
29  *
30  * The called function have one argument and returns an int.
31  */
32 static inline int protected_mode_call_1arg(void *func, uint32_t arg1)
33 {
34  return protected_mode_call_narg(1, (uintptr_t)func, arg1, 0);
35 }
36 
37 /*
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.
42  *
43  * The called function has two arguments and returns an int.
44  */
45 static inline int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
46 {
47  return protected_mode_call_narg(2, (uintptr_t)func, arg1, arg2);
48 }
49 #else
50 static inline int protected_mode_call(void *func)
51 {
52  int (*doit)(void) = func;
53 
54  return doit();
55 }
56 
57 static inline int protected_mode_call_1arg(void *func, uint32_t arg1)
58 {
59  int (*doit)(uint32_t arg1) = func;
60 
61  return doit(arg1);
62 }
63 
64 static inline int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
65 {
66  int (*doit)(uint32_t arg1, uint32_t arg2) = func;
67 
68  return doit(arg1, arg2);
69 }
70 #endif
static int protected_mode_call(void *func)
Definition: mode_switch.h:50
static int protected_mode_call_1arg(void *func, uint32_t arg1)
Definition: mode_switch.h:57
static int protected_mode_call_2arg(void *func, uint32_t arg1, uint32_t arg2)
Definition: mode_switch.h:64
unsigned int uint32_t
Definition: stdint.h:14
unsigned long uintptr_t
Definition: stdint.h:21
typedef void(X86APIP X86EMU_intrFuncs)(int num)