-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_ss.c
More file actions
67 lines (54 loc) · 1.16 KB
/
get_ss.c
File metadata and controls
67 lines (54 loc) · 1.16 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
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define SEGMENTS X(cs) X(ds) X(es) X(fs) X(gs) X(ss)
#define ARRSZE(X) (sizeof(X) / sizeof(*(X)))
union selector {
uint16_t n;
struct {
uint16_t rpl:2;
uint16_t ti:1;
uint16_t index:13;
};
};
#define GET(X) uint16_t get_##X(void); \
__asm__(".global get_" #X "\n" \
"get_" #X ":\n\t" \
"movw %" #X ", %ax\n\t" \
"ret\n")
#define SET(X) void set_##X(uint16_t eax) { \
__asm__ volatile("mov %[ax], %%" #X "\n" : : [ax] "r"(eax)); \
}
#define X(S) GET(S); SET(S);
SEGMENTS
#undef X
const char* all[] = {
#define X(S) #S,
SEGMENTS
#undef X
NULL
};
static const struct {
const char* s;
uint16_t (*f)(void);
} regs[] = {
#define X(S) { #S, get_##S },
SEGMENTS
#undef X
};
int main(int argc, const char** argv) {
const char** to_read = all;
if (argc > 1)
to_read = argv + 1;
set_ds(43);
for (size_t i = 0; to_read[i]; i++) {
for (size_t j = 0; j < ARRSZE(regs); j++) {
if (strcmp(to_read[i], regs[j].s))
continue;
union selector s = { .n = regs[j].f() };
printf("%s: %u (index: %u, ti: %u, rpl: %u)\n",
regs[j].s, s.n, s.index, s.ti, s.rpl);
break;
}
}
}