Blame view
arch/sparc/kernel/windows.c
3.22 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 |
/* windows.c: Routines to deal with register window management * at the C-code level. * * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) */ #include <linux/kernel.h> #include <linux/sched.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/smp.h> |
1da177e4c
|
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <asm/uaccess.h> /* Do save's until all user register windows are out of the cpu. */ void flush_user_windows(void) { register int ctr asm("g5"); ctr = 0; __asm__ __volatile__( " 1: \t" "ld [%%g6 + %2], %%g4 \t" "orcc %%g0, %%g4, %%g0 \t" "add %0, 1, %0 \t" "bne 1b \t" " save %%sp, -64, %%sp " "2: \t" "subcc %0, 1, %0 \t" "bne 2b \t" " restore %%g0, %%g0, %%g0 " : "=&r" (ctr) : "0" (ctr), "i" ((const unsigned long)TI_UWINMASK) : "g4", "cc"); } static inline void shift_window_buffer(int first_win, int last_win, struct thread_info *tp) { int i; for(i = first_win; i < last_win; i++) { tp->rwbuf_stkptrs[i] = tp->rwbuf_stkptrs[i+1]; |
4d7b92ad5
|
55 |
memcpy(&tp->reg_window[i], &tp->reg_window[i+1], sizeof(struct reg_window32)); |
1da177e4c
|
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
} } /* Place as many of the user's current register windows * on the stack that we can. Even if the %sp is unaligned * we still copy the window there, the only case that we don't * succeed is if the %sp points to a bum mapping altogether. * setup_frame() and do_sigreturn() use this before shifting * the user stack around. Future instruction and hardware * bug workaround routines will need this functionality as * well. */ void synchronize_user_stack(void) { struct thread_info *tp = current_thread_info(); int window; flush_user_windows(); if(!tp->w_saved) return; /* Ok, there is some dirty work to do. */ for(window = tp->w_saved - 1; window >= 0; window--) { unsigned long sp = tp->rwbuf_stkptrs[window]; /* Ok, let it rip. */ if (copy_to_user((char __user *) sp, &tp->reg_window[window], |
4d7b92ad5
|
83 |
sizeof(struct reg_window32))) |
1da177e4c
|
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
continue; shift_window_buffer(window, tp->w_saved - 1, tp); tp->w_saved--; } } #if 0 /* An optimization. */ static inline void copy_aligned_window(void *dest, const void *src) { __asm__ __volatile__("ldd [%1], %%g2 \t" "ldd [%1 + 0x8], %%g4 \t" "std %%g2, [%0] \t" "std %%g4, [%0 + 0x8] \t" "ldd [%1 + 0x10], %%g2 \t" "ldd [%1 + 0x18], %%g4 \t" "std %%g2, [%0 + 0x10] \t" "std %%g4, [%0 + 0x18] \t" "ldd [%1 + 0x20], %%g2 \t" "ldd [%1 + 0x28], %%g4 \t" "std %%g2, [%0 + 0x20] \t" "std %%g4, [%0 + 0x28] \t" "ldd [%1 + 0x30], %%g2 \t" "ldd [%1 + 0x38], %%g4 \t" "std %%g2, [%0 + 0x30] \t" "std %%g4, [%0 + 0x38] \t" : : "r" (dest), "r" (src) : "g2", "g3", "g4", "g5"); } #endif /* Try to push the windows in a threads window buffer to the * user stack. Unaligned %sp's are not allowed here. */ void try_to_clear_window_buffer(struct pt_regs *regs, int who) { struct thread_info *tp = current_thread_info(); int window; |
1da177e4c
|
140 141 142 143 144 145 |
flush_user_windows(); for(window = 0; window < tp->w_saved; window++) { unsigned long sp = tp->rwbuf_stkptrs[window]; if ((sp & 7) || copy_to_user((char __user *) sp, &tp->reg_window[window], |
4d7b92ad5
|
146 |
sizeof(struct reg_window32))) |
1da177e4c
|
147 148 149 |
do_exit(SIGILL); } tp->w_saved = 0; |
1da177e4c
|
150 |
} |