diff --git a/arch/x86/include/asm/string.h b/arch/x86/include/asm/string.h index 206563b4..b2625069 100644 --- a/arch/x86/include/asm/string.h +++ b/arch/x86/include/asm/string.h @@ -32,10 +32,10 @@ inline static void *memcpy(void* dest, const void *src, size_t count) return dest; asm volatile ( - "cld; rep ; movsl\n\t" + "cld; rep movsl\n\t" "movl %4, %%ecx\n\t" "andl $3, %%ecx\n\t" - "rep ; movsb\n\t" + "rep movsb\n\t" : "=&c"(i), "=&D"(j), "=&S"(k) : "0"(count/4), "g"(count), "1"(dest), "2"(src) : "memory"); @@ -51,7 +51,7 @@ inline static void *memset(void* dest, int val, size_t count) if (BUILTIN_EXPECT(!dest, 0)) return dest; - asm volatile ("cld; rep ; stosb" + asm volatile ("cld; rep stosb" : "=&c"(i), "=&D"(j) : "a"(val), "1"(dest), "0"(count) : "memory"); @@ -68,7 +68,7 @@ inline static size_t strlen(const char* str) if (BUILTIN_EXPECT(!str, 0)) return len; - asm volatile("not %%ecx; cld; repne ; scasb; not %%ecx; dec %%ecx" + asm volatile("not %%ecx; cld; repne scasb; not %%ecx; dec %%ecx" : "=&c"(len), "=&D"(i), "=&a"(j) : "2"(0), "1"(str), "0"(len) : "memory"); diff --git a/arch/x86/kernel/string.asm b/arch/x86/kernel/string.asm index 27707b09..4d7fad19 100644 --- a/arch/x86/kernel/string.asm +++ b/arch/x86/kernel/string.asm @@ -60,39 +60,35 @@ L3: pop ebp ret -; The following function based on JamesM's kernel development tutorials +; The following function is derived from JamesM's kernel development tutorials ; (http://www.jamesmolloy.co.uk/tutorial_html/) global copy_page_physical copy_page_physical: - push ebx ; According to __cdecl, we must preserve the contents of EBX. + push esi ; According to __cdecl, we must preserve the contents of ESI + push edi ; and EDI. pushf ; push EFLAGS, so we can pop it and reenable interrupts ; later, if they were enabled anyway. cli ; Disable interrupts, so we aren't interrupted. ; Load these in BEFORE we disable paging! - mov ebx, [esp+16] ; Source address - mov ecx, [esp+12] ; Destination address + mov edi, [esp+12+4] ; Destination address + mov esi, [esp+12+8] ; Source address mov edx, cr0 ; Get the control register... and edx, 0x7fffffff ; and... mov cr0, edx ; Disable paging. - - mov edx, 1024 ; 1024*4bytes = 4096 bytes - -L4: - mov eax, [ebx] ; Get the word at the source address - mov [ecx], eax ; Store it at the dest address - add ebx, 4 ; Source address += sizeof(word) - add ecx, 4 ; Dest address += sizeof(word) - dec edx ; One less word to do - jnz L4 - + + cld + mov ecx, 0x400 ; 1024*4bytes = 4096 bytes = page size + rep movsd ; copy page + mov edx, cr0 ; Get the control register again or edx, 0x80000000 ; and... mov cr0, edx ; Enable paging. popf ; Pop EFLAGS back. - pop ebx ; Get the original value of EBX back. + pop edi ; Get the original value of EDI + pop esi ; and ESI back. ret SECTION .note.GNU-stack noalloc noexec nowrite progbits