Skip to content

Commit

Permalink
lib: implement read and write EFLAGS helper functions
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Nov 13, 2023
1 parent 31d23bf commit 62ea54f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 2 additions & 0 deletions include/arch/x86/asm-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,10 @@ name ## _end:
"pop %%" STR(_ASM_BX) "\n"

#if defined(__x86_64__)
#define PUSHF() "pushfq\n"
#define POPF() "popfq\n"
#else
#define PUSHF() "pushf\n"
#define POPF() "popf\n"
#endif

Expand Down
16 changes: 6 additions & 10 deletions include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,18 @@ static inline void int3(void) {
asm volatile("int3");
}

static inline unsigned long read_flags(void) {
static inline unsigned long read_eflags(void) {
unsigned long flags;

asm volatile(
#if defined(__i386__)
"pushfd;"
"popl %0"
#elif defined(__x86_64__)
"pushfq;"
"popq %0"
#endif
: "=r"(flags));
asm volatile(PUSHF() "pop %0" : "=r"(flags));

return flags;
}

static inline void write_eflags(unsigned long flags) {
asm volatile("push %0\n" POPF()::"r"(flags));
}

static inline unsigned long read_cs(void) {
unsigned long cs;

Expand Down

0 comments on commit 62ea54f

Please sign in to comment.