blob: f2145cfa12a66830e834718340c4cc88e64a731a [file] [log] [blame]
Jan Beulich8d379da2006-09-26 10:52:32 +02001#include <linux/linkage.h>
2#include <asm/dwarf2.h>
Fenghua Yue365c9d2011-05-17 15:29:14 -07003#include <asm/alternative-asm.h>
Jan Beulich8d379da2006-09-26 10:52:32 +02004
Linus Torvalds1da177e2005-04-16 15:20:36 -07005/*
6 * Zero a page.
7 * rdi page
8 */
Mike Galbraith9e314992009-06-30 15:00:20 +02009ENTRY(clear_page_c)
Jan Beulich8d379da2006-09-26 10:52:32 +020010 CFI_STARTPROC
11 movl $4096/8,%ecx
12 xorl %eax,%eax
13 rep stosq
14 ret
15 CFI_ENDPROC
Mike Galbraith9e314992009-06-30 15:00:20 +020016ENDPROC(clear_page_c)
Jan Beulich8d379da2006-09-26 10:52:32 +020017
Fenghua Yue365c9d2011-05-17 15:29:14 -070018ENTRY(clear_page_c_e)
19 CFI_STARTPROC
20 movl $4096,%ecx
21 xorl %eax,%eax
22 rep stosb
23 ret
24 CFI_ENDPROC
25ENDPROC(clear_page_c_e)
26
Jan Beulich8d379da2006-09-26 10:52:32 +020027ENTRY(clear_page)
28 CFI_STARTPROC
Andi Kleen7bcd3f32006-02-03 21:51:02 +010029 xorl %eax,%eax
30 movl $4096/64,%ecx
31 .p2align 4
32.Lloop:
33 decl %ecx
34#define PUT(x) movq %rax,x*8(%rdi)
35 movq %rax,(%rdi)
36 PUT(1)
37 PUT(2)
38 PUT(3)
39 PUT(4)
40 PUT(5)
41 PUT(6)
42 PUT(7)
43 leaq 64(%rdi),%rdi
44 jnz .Lloop
45 nop
46 ret
Jan Beulich8d379da2006-09-26 10:52:32 +020047 CFI_ENDPROC
48.Lclear_page_end:
49ENDPROC(clear_page)
Andi Kleen7bcd3f32006-02-03 21:51:02 +010050
Fenghua Yue365c9d2011-05-17 15:29:14 -070051 /*
52 * Some CPUs support enhanced REP MOVSB/STOSB instructions.
53 * It is recommended to use this when possible.
54 * If enhanced REP MOVSB/STOSB is not available, try to use fast string.
55 * Otherwise, use original function.
56 *
57 */
Andi Kleen7bcd3f32006-02-03 21:51:02 +010058
59#include <asm/cpufeature.h>
60
Jan Beulich8d379da2006-09-26 10:52:32 +020061 .section .altinstr_replacement,"ax"
621: .byte 0xeb /* jmp <disp8> */
63 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
Fenghua Yue365c9d2011-05-17 15:29:14 -0700642: .byte 0xeb /* jmp <disp8> */
65 .byte (clear_page_c_e - clear_page) - (3f - 2b) /* offset */
663:
Jan Beulich8d379da2006-09-26 10:52:32 +020067 .previous
Andi Kleen7bcd3f32006-02-03 21:51:02 +010068 .section .altinstructions,"a"
Fenghua Yue365c9d2011-05-17 15:29:14 -070069 altinstruction_entry clear_page,1b,X86_FEATURE_REP_GOOD,\
70 .Lclear_page_end-clear_page, 2b-1b
71 altinstruction_entry clear_page,2b,X86_FEATURE_ERMS, \
72 .Lclear_page_end-clear_page,3b-2b
Andi Kleen7bcd3f32006-02-03 21:51:02 +010073 .previous