-
Notifications
You must be signed in to change notification settings - Fork 1
/
bios.c
115 lines (91 loc) · 2.38 KB
/
bios.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "bios.h"
#define BIOS_GP_REGISTER(c) \
union { \
uint32_t e##c##x; \
uint16_t c##x; \
struct { \
uint8_t c##h; \
uint8_t c##l; \
}; \
}
#define BIOS_NV_REGISTER(c) \
union { \
uint32_t e##c; \
uint16_t c; \
uint8_t c##l; \
}
struct bios_regs {
uint16_t ds, es;
uint32_t rflags;
/*
* General Purpose Registers
*/
BIOS_GP_REGISTER(a);
BIOS_GP_REGISTER(b);
BIOS_GP_REGISTER(c);
BIOS_GP_REGISTER(d);
/*
* Subset: Non-volatile General Purpose Registers
*/
BIOS_NV_REGISTER(si);
BIOS_NV_REGISTER(di);
BIOS_NV_REGISTER(bp);
BIOS_NV_REGISTER(sp);
} __attribute__((packed));
struct bios_desc {
uint16_t limit;
uint32_t base;
} __attribute__((packed));
struct bios_cpu_mode {
struct bios_regs regs;
struct biod_desc desc;
} __attribute__((packed));
struct bios_trampoline {
struct bios_cpu_mode rmode;
struct bios_cpu_mode pmode;
} __attribute__((packed));
struct bios_trampoline bios_trampoline;
/*
* Get BIOS CPU modes
*/
static struct bios_trampoline *get_bios_trampoline(void)
{
return &bios_trampoline;
}
static struct bios_cpu_mode *get_bios_cpu_rmode(void)
{
return &get_bios_trampoline()->rmode;
}
static struct bios_cpu_mode *get_bios_cpu_pmode(void)
{
return &get_bios_trampoline()->pmode;
}
static struct bios_regs *get_bios_rmode_regs(void)
{
return &get_bios_cpu_rmode()->regs;
}
static struct bios_regs *get_bios_pmode_regs(void)
{
return &get_bios_cpu_pmode()->regs;
}
static struct bios_desc *get_bios_rmode_desc(void)
{
return &get_bios_cpu_rmode()->desc;
}
static struct bios_desc *get_bios_pmode_desc(void)
{
return &get_bios_cpu_pmode()->desc;
}
/*
* Store BIOS CPU modes
*/
void bios_store_rmode_state(struct bios_cpu_mode *rmode)
{
struct bios_cpu_mode *bios_rmode = get_bios_cpu_rmode();
bmemcpy(bios_rmode, rmode, sizeof(*rmode));
}
void bios_store_pmode_state(struct bios_cpu_mode *pmode)
{
struct bios_cpu_mode *bios_pmode = get_bios_cpu_pmode();
bmemcpy(bios_pmode, pmode, sizeof(*pmode));
}