-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmisc.h
More file actions
executable file
·29 lines (25 loc) · 854 Bytes
/
misc.h
File metadata and controls
executable file
·29 lines (25 loc) · 854 Bytes
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
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define NAKED __attribute__((naked))
#define PACKED __attribute__((packed))
size_t strlen(const char* str);
void wrmsr_ptr(uint32_t msr_id, void* msr_value);
uint64_t rdmsr(uint32_t msr_id);
uint8_t inb(uint16_t port);
void outb(uint16_t port, uint8_t val);
void io_wait(void);
void reboot();
void memset(void* stuff, uint8_t newval, unsigned int len);
bool memcmp(void* stuff1, void* stuff2, unsigned int len);
void initAndDisablePIC();
__attribute__((always_inline)) inline void wrmsr(uint32_t msr_id, uint64_t msr_value)
{
#ifdef __x86_64
uint32_t low = msr_value & 0xFFFFFFFF;
uint32_t high = msr_value >> 32;
asm volatile ("wrmsr" : : "c"(msr_id), "a"(low), "d"(high));
#else
__asm__ __volatile__("wrmsr" : : "c" (msr_id), "A" (msr_value));
#endif
}