From 1eba40776dad1af70c3e04ede9cb543c6aa04195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dziepak?= Date: Mon, 25 Aug 2014 22:51:46 +0200 Subject: [PATCH] kernel/x86_64: rewrite cpuid.S -> cpuid.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Just getting rid of some assembly, no functional change. Signed-off-by: Paweł Dziepak --- src/system/kernel/arch/x86/64/cpuid.S | 47 ------------------------- src/system/kernel/arch/x86/64/cpuid.cpp | 37 +++++++++++++++++++ src/system/kernel/arch/x86/Jamfile | 2 +- 3 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 src/system/kernel/arch/x86/64/cpuid.S create mode 100644 src/system/kernel/arch/x86/64/cpuid.cpp diff --git a/src/system/kernel/arch/x86/64/cpuid.S b/src/system/kernel/arch/x86/64/cpuid.S deleted file mode 100644 index 1085359a1f..0000000000 --- a/src/system/kernel/arch/x86/64/cpuid.S +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. - * Distributed under the terms of the MIT License. - */ - - -#include - - -.text - - -/* status_t get_current_cpuid(cpuid_info* info, uint32 eaxRegister, - uint32 ecxRegister) */ -FUNCTION(get_current_cpuid): - push %rbx - movl %esi, %eax - movl %edx, %ecx - cpuid - movl %eax, 0(%rdi) - movl %ebx, 4(%rdi) - movl %edx, 8(%rdi) - movl %ecx, 12(%rdi) - xorl %eax, %eax - // B_OK - pop %rbx - ret -FUNCTION_END(get_current_cpuid) - - -/* uint32 get_eflags(void) */ -FUNCTION(get_eflags): - // The top 32 bits of RFLAGS are reserved, we can ignore them. - pushf - pop %rax - mov %eax, %eax - ret -FUNCTION_END(get_eflags) - - -/* void set_eflags(uint32 val) */ -FUNCTION(set_eflags): - mov %edi, %edi - push %rdi - popf - ret -FUNCTION_END(set_eflags) diff --git a/src/system/kernel/arch/x86/64/cpuid.cpp b/src/system/kernel/arch/x86/64/cpuid.cpp new file mode 100644 index 0000000000..7d14b71bbd --- /dev/null +++ b/src/system/kernel/arch/x86/64/cpuid.cpp @@ -0,0 +1,37 @@ +/* + * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org. + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + */ + + +#include + + +status_t +get_current_cpuid(cpuid_info* info, uint32 eax, uint32 ecx) +{ + __asm__("cpuid" + : "=a" (info->regs.eax), "=b" (info->regs.ebx), "=c" (info->regs.ecx), + "=d" (info->regs.edx) + : "a" (eax), "c" (ecx)); + return B_OK; +} + + +uint32 +get_eflags() +{ + uint64_t flags; + __asm__("pushf; popq %0;" : "=r" (flags)); + return flags; +} + + +void +set_eflags(uint32 value) +{ + uint64_t flags = value; + __asm__("pushq %0; popf;" : : "r" (flags) : "cc"); +} + diff --git a/src/system/kernel/arch/x86/Jamfile b/src/system/kernel/arch/x86/Jamfile index 773bc39153..c56cc50eec 100644 --- a/src/system/kernel/arch/x86/Jamfile +++ b/src/system/kernel/arch/x86/Jamfile @@ -22,7 +22,7 @@ if $(TARGET_ARCH) = x86_64 { archSpecificSources = arch.S - cpuid.S + cpuid.cpp descriptors.cpp interrupts.S signals.cpp