From bc3093488f72315d8474d45b3dfe34cdc15ef4d6 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Mon, 9 Jul 2012 09:03:11 +0100 Subject: [PATCH] Changes suggested by Ingo: style fix, and a system_time optimization. --- src/system/boot/platform/bios_ia32/mmu.cpp | 2 +- .../libroot/os/arch/x86_64/system_time_asm.S | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/system/boot/platform/bios_ia32/mmu.cpp b/src/system/boot/platform/bios_ia32/mmu.cpp index 05167e7c3c..4eef5defa5 100644 --- a/src/system/boot/platform/bios_ia32/mmu.cpp +++ b/src/system/boot/platform/bios_ia32/mmu.cpp @@ -522,7 +522,7 @@ mmu_get_virtual_mapping(addr_t virtualAddress, addr_t *_physicalAddress) if ((tableEntry & (1 << 0)) == 0) return false; - *_physicalAddress = tableEntry & 0xFFFFF000; + *_physicalAddress = tableEntry & 0xfffff000; return true; } diff --git a/src/system/libroot/os/arch/x86_64/system_time_asm.S b/src/system/libroot/os/arch/x86_64/system_time_asm.S index f63bdf35ba..135b54a4c3 100644 --- a/src/system/libroot/os/arch/x86_64/system_time_asm.S +++ b/src/system/libroot/os/arch/x86_64/system_time_asm.S @@ -28,7 +28,10 @@ FUNCTION_END(__x86_setup_system_time) /* int64 system_time(); */ FUNCTION(system_time): + // (rdtsc * cv_factor) >> 32. + movq cv_factor, %rcx + shl $32, %rcx // Load 64-bit TSC into %eax (low), %edx (high). rdtsc @@ -40,17 +43,19 @@ FUNCTION(system_time): // Multiply by conversion factor, result in %rax (low), %rdx (high). mulq %rcx - // Shift the result right by 32 bits. - shr $32, %rax - shl $32, %rdx - orq %rdx, %rax + // Conversion factor preshifted by 32, whole result in high. + movq %rdx, %rax ret FUNCTION_END(system_time) /* int64 system_time_nsecs(); */ FUNCTION(system_time_nsecs): - // Same algorithm as system_time(), just with a different factor. + // Same algorithm as system_time(), but with a different factor. + // (rdtsc * cv_factor_nsecs) >> 32. + // Cannot pre-shift the factor here, otherwise we may lose the upper + // 32 bits. + movq cv_factor_nsecs, %rcx // Load 64-bit TSC into %eax (low), %edx (high).