diff options
author | Glauber de Oliveira Costa <gcosta@redhat.com> | 2007-07-22 05:12:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-22 14:03:37 -0400 |
commit | f51c94528a9bc73504928926ca4d791a2b7ddd7c (patch) | |
tree | 1562581d26098916a35a27ee58021f483c85b3da | |
parent | abd4f7505bafdd6c5319fe3cb5caf9af6104e17a (diff) |
x86_64: Use read and write crX in .c files
This patch uses the read and write functions provided at system.h
for control registers instead of writting raw assembly over and
over again in .c files. Functions to manipulate cr2 and cr8 were
provided, as they were lacking.
Also, removed some extra space after closing brackets
Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/x86_64/kernel/process.c | 8 | ||||
-rw-r--r-- | arch/x86_64/kernel/suspend.c | 20 | ||||
-rw-r--r-- | arch/x86_64/mm/fault.c | 4 | ||||
-rw-r--r-- | arch/x86_64/mm/init.c | 2 | ||||
-rw-r--r-- | include/asm-x86_64/system.h | 34 |
5 files changed, 46 insertions, 22 deletions
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c index 92fade4a62cf..e7ac629d4c46 100644 --- a/arch/x86_64/kernel/process.c +++ b/arch/x86_64/kernel/process.c | |||
@@ -342,10 +342,10 @@ void __show_regs(struct pt_regs * regs) | |||
342 | rdmsrl(MSR_GS_BASE, gs); | 342 | rdmsrl(MSR_GS_BASE, gs); |
343 | rdmsrl(MSR_KERNEL_GS_BASE, shadowgs); | 343 | rdmsrl(MSR_KERNEL_GS_BASE, shadowgs); |
344 | 344 | ||
345 | asm("movq %%cr0, %0": "=r" (cr0)); | 345 | cr0 = read_cr0(); |
346 | asm("movq %%cr2, %0": "=r" (cr2)); | 346 | cr2 = read_cr2(); |
347 | asm("movq %%cr3, %0": "=r" (cr3)); | 347 | cr3 = read_cr3(); |
348 | asm("movq %%cr4, %0": "=r" (cr4)); | 348 | cr4 = read_cr4(); |
349 | 349 | ||
350 | printk("FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n", | 350 | printk("FS: %016lx(%04x) GS:%016lx(%04x) knlGS:%016lx\n", |
351 | fs,fsindex,gs,gsindex,shadowgs); | 351 | fs,fsindex,gs,gsindex,shadowgs); |
diff --git a/arch/x86_64/kernel/suspend.c b/arch/x86_64/kernel/suspend.c index 6a5a98f2a75c..ea83a9f91965 100644 --- a/arch/x86_64/kernel/suspend.c +++ b/arch/x86_64/kernel/suspend.c | |||
@@ -55,11 +55,11 @@ void __save_processor_state(struct saved_context *ctxt) | |||
55 | * control registers | 55 | * control registers |
56 | */ | 56 | */ |
57 | rdmsrl(MSR_EFER, ctxt->efer); | 57 | rdmsrl(MSR_EFER, ctxt->efer); |
58 | asm volatile ("movq %%cr0, %0" : "=r" (ctxt->cr0)); | 58 | ctxt->cr0 = read_cr0(); |
59 | asm volatile ("movq %%cr2, %0" : "=r" (ctxt->cr2)); | 59 | ctxt->cr2 = read_cr2(); |
60 | asm volatile ("movq %%cr3, %0" : "=r" (ctxt->cr3)); | 60 | ctxt->cr3 = read_cr3(); |
61 | asm volatile ("movq %%cr4, %0" : "=r" (ctxt->cr4)); | 61 | ctxt->cr4 = read_cr4(); |
62 | asm volatile ("movq %%cr8, %0" : "=r" (ctxt->cr8)); | 62 | ctxt->cr8 = read_cr8(); |
63 | } | 63 | } |
64 | 64 | ||
65 | void save_processor_state(void) | 65 | void save_processor_state(void) |
@@ -81,11 +81,11 @@ void __restore_processor_state(struct saved_context *ctxt) | |||
81 | * control registers | 81 | * control registers |
82 | */ | 82 | */ |
83 | wrmsrl(MSR_EFER, ctxt->efer); | 83 | wrmsrl(MSR_EFER, ctxt->efer); |
84 | asm volatile ("movq %0, %%cr8" :: "r" (ctxt->cr8)); | 84 | write_cr8(ctxt->cr8); |
85 | asm volatile ("movq %0, %%cr4" :: "r" (ctxt->cr4)); | 85 | write_cr4(ctxt->cr4); |
86 | asm volatile ("movq %0, %%cr3" :: "r" (ctxt->cr3)); | 86 | write_cr3(ctxt->cr3); |
87 | asm volatile ("movq %0, %%cr2" :: "r" (ctxt->cr2)); | 87 | write_cr2(ctxt->cr2); |
88 | asm volatile ("movq %0, %%cr0" :: "r" (ctxt->cr0)); | 88 | write_cr0(ctxt->cr0); |
89 | 89 | ||
90 | /* | 90 | /* |
91 | * now restore the descriptor tables to their proper values | 91 | * now restore the descriptor tables to their proper values |
diff --git a/arch/x86_64/mm/fault.c b/arch/x86_64/mm/fault.c index 5e9ac70c135e..327c9f2fa626 100644 --- a/arch/x86_64/mm/fault.c +++ b/arch/x86_64/mm/fault.c | |||
@@ -159,7 +159,7 @@ void dump_pagetable(unsigned long address) | |||
159 | pmd_t *pmd; | 159 | pmd_t *pmd; |
160 | pte_t *pte; | 160 | pte_t *pte; |
161 | 161 | ||
162 | asm("movq %%cr3,%0" : "=r" (pgd)); | 162 | pgd = (pgd_t *)read_cr3(); |
163 | 163 | ||
164 | pgd = __va((unsigned long)pgd & PHYSICAL_PAGE_MASK); | 164 | pgd = __va((unsigned long)pgd & PHYSICAL_PAGE_MASK); |
165 | pgd += pgd_index(address); | 165 | pgd += pgd_index(address); |
@@ -316,7 +316,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs, | |||
316 | prefetchw(&mm->mmap_sem); | 316 | prefetchw(&mm->mmap_sem); |
317 | 317 | ||
318 | /* get the address */ | 318 | /* get the address */ |
319 | __asm__("movq %%cr2,%0":"=r" (address)); | 319 | address = read_cr2(); |
320 | 320 | ||
321 | info.si_code = SEGV_MAPERR; | 321 | info.si_code = SEGV_MAPERR; |
322 | 322 | ||
diff --git a/arch/x86_64/mm/init.c b/arch/x86_64/mm/init.c index 88678e82e23d..2044fa961c07 100644 --- a/arch/x86_64/mm/init.c +++ b/arch/x86_64/mm/init.c | |||
@@ -383,7 +383,7 @@ void __meminit init_memory_mapping(unsigned long start, unsigned long end) | |||
383 | } | 383 | } |
384 | 384 | ||
385 | if (!after_bootmem) | 385 | if (!after_bootmem) |
386 | asm volatile("movq %%cr4,%0" : "=r" (mmu_cr4_features)); | 386 | mmu_cr4_features = read_cr4(); |
387 | __flush_tlb_all(); | 387 | __flush_tlb_all(); |
388 | } | 388 | } |
389 | 389 | ||
diff --git a/include/asm-x86_64/system.h b/include/asm-x86_64/system.h index 6313d33a0686..02175aa1d16a 100644 --- a/include/asm-x86_64/system.h +++ b/include/asm-x86_64/system.h | |||
@@ -75,19 +75,31 @@ static inline unsigned long read_cr0(void) | |||
75 | unsigned long cr0; | 75 | unsigned long cr0; |
76 | asm volatile("movq %%cr0,%0" : "=r" (cr0)); | 76 | asm volatile("movq %%cr0,%0" : "=r" (cr0)); |
77 | return cr0; | 77 | return cr0; |
78 | } | 78 | } |
79 | 79 | ||
80 | static inline void write_cr0(unsigned long val) | 80 | static inline void write_cr0(unsigned long val) |
81 | { | 81 | { |
82 | asm volatile("movq %0,%%cr0" :: "r" (val)); | 82 | asm volatile("movq %0,%%cr0" :: "r" (val)); |
83 | } | 83 | } |
84 | |||
85 | static inline unsigned long read_cr2(void) | ||
86 | { | ||
87 | unsigned long cr2; | ||
88 | asm("movq %%cr2,%0" : "=r" (cr2)); | ||
89 | return cr2; | ||
90 | } | ||
91 | |||
92 | static inline void write_cr2(unsigned long val) | ||
93 | { | ||
94 | asm volatile("movq %0,%%cr2" :: "r" (val)); | ||
95 | } | ||
84 | 96 | ||
85 | static inline unsigned long read_cr3(void) | 97 | static inline unsigned long read_cr3(void) |
86 | { | 98 | { |
87 | unsigned long cr3; | 99 | unsigned long cr3; |
88 | asm("movq %%cr3,%0" : "=r" (cr3)); | 100 | asm("movq %%cr3,%0" : "=r" (cr3)); |
89 | return cr3; | 101 | return cr3; |
90 | } | 102 | } |
91 | 103 | ||
92 | static inline void write_cr3(unsigned long val) | 104 | static inline void write_cr3(unsigned long val) |
93 | { | 105 | { |
@@ -99,12 +111,24 @@ static inline unsigned long read_cr4(void) | |||
99 | unsigned long cr4; | 111 | unsigned long cr4; |
100 | asm("movq %%cr4,%0" : "=r" (cr4)); | 112 | asm("movq %%cr4,%0" : "=r" (cr4)); |
101 | return cr4; | 113 | return cr4; |
102 | } | 114 | } |
103 | 115 | ||
104 | static inline void write_cr4(unsigned long val) | 116 | static inline void write_cr4(unsigned long val) |
105 | { | 117 | { |
106 | asm volatile("movq %0,%%cr4" :: "r" (val) : "memory"); | 118 | asm volatile("movq %0,%%cr4" :: "r" (val) : "memory"); |
107 | } | 119 | } |
120 | |||
121 | static inline unsigned long read_cr8(void) | ||
122 | { | ||
123 | unsigned long cr8; | ||
124 | asm("movq %%cr8,%0" : "=r" (cr8)); | ||
125 | return cr8; | ||
126 | } | ||
127 | |||
128 | static inline void write_cr8(unsigned long val) | ||
129 | { | ||
130 | asm volatile("movq %0,%%cr8" :: "r" (val) : "memory"); | ||
131 | } | ||
108 | 132 | ||
109 | #define stts() write_cr0(8 | read_cr0()) | 133 | #define stts() write_cr0(8 | read_cr0()) |
110 | 134 | ||