windows.c 3.2 KB

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