Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1 | #include <linux/linkage.h> |
| 2 | #include <asm/dwarf2.h> |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 3 | #include <asm/alternative-asm.h> |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | /* |
| 6 | * Zero a page. |
| 7 | * rdi page |
| 8 | */ |
Mike Galbraith | 9e31499 | 2009-06-30 15:00:20 +0200 | [diff] [blame] | 9 | ENTRY(clear_page_c) |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 10 | CFI_STARTPROC |
| 11 | movl $4096/8,%ecx |
| 12 | xorl %eax,%eax |
| 13 | rep stosq |
| 14 | ret |
| 15 | CFI_ENDPROC |
Mike Galbraith | 9e31499 | 2009-06-30 15:00:20 +0200 | [diff] [blame] | 16 | ENDPROC(clear_page_c) |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 17 | |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 18 | ENTRY(clear_page_c_e) |
| 19 | CFI_STARTPROC |
| 20 | movl $4096,%ecx |
| 21 | xorl %eax,%eax |
| 22 | rep stosb |
| 23 | ret |
| 24 | CFI_ENDPROC |
| 25 | ENDPROC(clear_page_c_e) |
| 26 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 27 | ENTRY(clear_page) |
| 28 | CFI_STARTPROC |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 29 | 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 Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 47 | CFI_ENDPROC |
| 48 | .Lclear_page_end: |
| 49 | ENDPROC(clear_page) |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 50 | |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 51 | /* |
| 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 Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 58 | |
| 59 | #include <asm/cpufeature.h> |
| 60 | |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 61 | .section .altinstr_replacement,"ax" |
| 62 | 1: .byte 0xeb /* jmp <disp8> */ |
| 63 | .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */ |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 64 | 2: .byte 0xeb /* jmp <disp8> */ |
| 65 | .byte (clear_page_c_e - clear_page) - (3f - 2b) /* offset */ |
| 66 | 3: |
Jan Beulich | 8d379da | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 67 | .previous |
Andi Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 68 | .section .altinstructions,"a" |
Fenghua Yu | e365c9d | 2011-05-17 15:29:14 -0700 | [diff] [blame] | 69 | 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 Kleen | 7bcd3f3 | 2006-02-03 21:51:02 +0100 | [diff] [blame] | 73 | .previous |