-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBIOS.cpp
More file actions
58 lines (49 loc) · 1.94 KB
/
BIOS.cpp
File metadata and controls
58 lines (49 loc) · 1.94 KB
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
//=============================================================================
// ■ BIOS.cpp
//-----------------------------------------------------------------------------
// ASM76固件BIOS。
//=============================================================================
#include "ASM76.hpp"
namespace ASM76 {
//-------------------------------------------------------------------------
// ● BIOS mutex锁
//-------------------------------------------------------------------------
mutex bios_lock;
//-------------------------------------------------------------------------
// ● BIOS空回调
//-------------------------------------------------------------------------
static uint32_t NULL_Call(uint8_t* d) {
// 返回输入值与0x76ABCDEF的异或值并取反
// 程序*可以*使用这种方式校验,虽然没卵用(
return ~(((uintptr_t) d & 0xFFFFFF) ^ 0x76ABCDEF);
}
//-------------------------------------------------------------------------
// ● 构造
//-------------------------------------------------------------------------
BIOS::BIOS(size_t function_table_count) {
function_table = new BIOS_call[function_table_count];
// 用固定NULL回调填充
for (size_t i = 0; i < function_table_count; i++) {
function_table[i] = &NULL_Call;
}
// 自我校验
if (call(0, (uint8_t*) 0x76) != 0x89543266) {
printf("Error: VM BIOS self test failed!");
exit(76);
}
}
//-------------------------------------------------------------------------
// ● 销毁
//-------------------------------------------------------------------------
BIOS::~BIOS() {
delete[] function_table;
}
//-------------------------------------------------------------------------
// ● 调用
//-------------------------------------------------------------------------
uint32_t BIOS::call(int fid, uint8_t* d) {
// Lock will release after function called
lock_guard<mutex> lock(bios_lock);
return function_table[fid](d);
}
}