-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunslice.h
69 lines (54 loc) · 1.84 KB
/
runslice.h
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
#include <cstdint>
#include <vector>
#include <unistd.h>
#define ALIGN_UP(_v, _a) (((_v) + (_a) - 1) & ~(static_cast<uintptr_t>(_a) - 1))
struct Options
{
const char* kernel_path = nullptr;
const char* initrd_path = nullptr;
const char* kernel_cmdline = nullptr;
const char* dsdt_path = nullptr;
uint64_t rambase = 0;
uint64_t ramsize = 0;
uint64_t lowmem = 0x6000;
std::vector<uint32_t> apic_ids;
void validate();
};
class AutoFd
{
public:
AutoFd() : m_fd(-1) {}
AutoFd(AutoFd&& other) : m_fd(other.m_fd) { other.m_fd = -1; }
AutoFd(int fd) : m_fd(fd) {}
~AutoFd() { reset(); }
operator int() const { return m_fd; }
int operator= (int fd) { reset(); return (m_fd = fd); }
void operator= (AutoFd&& other) { reset(); m_fd = other.m_fd; other.m_fd = -1; }
private:
int m_fd;
void reset() { if (m_fd >= 0) close(m_fd); m_fd = -1; }
};
static inline void cpuid(uint32_t eax, uint32_t ecx, uint32_t& a, uint32_t& b, uint32_t& c, uint32_t& d)
{
asm("cpuid"
: "=a" (a), "=b" (b), "=c" (c), "=d" (d)
: "a" (eax), "c" (ecx));
}
bool send_startup_ipi(AutoFd& devmem, uint32_t apic_id, uint64_t startup_pa);
uint8_t acpi_checksum(const void* data, size_t size);
uintptr_t build_acpi(
const Options& options,
uintptr_t& loadaddr_phys,
char*& loadaddr_virt,
uintptr_t& mmconfig_base);
bool acpi_get_host_apic_ids(
std::vector<uint32_t>& apic_ids);
bool read_to_devmem(std::ifstream& file, uint64_t offset, void* dest, size_t size);
bool load_linux(
const Options& options,
void* slice_ram,
uintptr_t& kernel_entry_phys,
uintptr_t& kernel_entry_arg);
bool lowmem_init(const Options& options, const AutoFd& devmem, uintptr_t kernel_entry, uintptr_t kernel_arg, uintptr_t &boot_ip);
extern "C" const size_t realmode_blob_size;
uint32_t get_local_apic_id();