2
0

target_cpu.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * SPARC specific CPU ABI and functions for linux-user
  3. *
  4. * Copyright (C) 2003 Thomas M. Ogrisegg <tom@fnord.at>
  5. * Copyright (C) 2003-2005 Fabrice Bellard
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef SPARC_TARGET_CPU_H
  21. #define SPARC_TARGET_CPU_H
  22. #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
  23. # define TARGET_STACK_BIAS 2047
  24. #else
  25. # define TARGET_STACK_BIAS 0
  26. #endif
  27. static void set_syscall_C(CPUSPARCState *env, bool val)
  28. {
  29. #ifndef TARGET_SPARC64
  30. env->icc_C = val;
  31. #elif defined(TARGET_ABI32)
  32. env->icc_C = (uint64_t)val << 32;
  33. #else
  34. env->xcc_C = val;
  35. #endif
  36. }
  37. static inline void cpu_clone_regs_child(CPUSPARCState *env, target_ulong newsp,
  38. unsigned flags)
  39. {
  40. /*
  41. * After cpu_copy, env->regwptr is pointing into the old env.
  42. * Update the new cpu to use its own register window.
  43. */
  44. env->regwptr = env->regbase + (env->cwp * 16);
  45. if (newsp) {
  46. /* When changing stacks, do it with clean register windows. */
  47. #ifdef TARGET_SPARC64
  48. env->cansave = env->nwindows - 2;
  49. env->cleanwin = env->nwindows - 2;
  50. env->canrestore = 0;
  51. #else
  52. env->wim = 1 << env->cwp;
  53. #endif
  54. /* ??? The kernel appears to copy one stack frame to the new stack. */
  55. /* ??? The kernel force aligns the new stack. */
  56. /* Userspace provides a biased stack pointer value. */
  57. env->regwptr[WREG_SP] = newsp;
  58. }
  59. if (flags & CLONE_VM) {
  60. /*
  61. * Syscall return for clone child: %o0 = 0 and clear CF since this
  62. * counts as a success return value. Advance the PC past the syscall.
  63. * For fork child, all of this happens in cpu_loop, and we must not
  64. * do the pc advance twice.
  65. */
  66. env->regwptr[WREG_O0] = 0;
  67. set_syscall_C(env, 0);
  68. env->pc = env->npc;
  69. env->npc = env->npc + 4;
  70. }
  71. /* Set the second return value for the child: %o1 = 1. */
  72. env->regwptr[WREG_O1] = 1;
  73. }
  74. static inline void cpu_clone_regs_parent(CPUSPARCState *env, unsigned flags)
  75. {
  76. /* Set the second return value for the parent: %o1 = 0. */
  77. env->regwptr[WREG_O1] = 0;
  78. }
  79. static inline void cpu_set_tls(CPUSPARCState *env, target_ulong newtls)
  80. {
  81. env->gregs[7] = newtls;
  82. }
  83. static inline abi_ulong get_sp_from_cpustate(CPUSPARCState *state)
  84. {
  85. return state->regwptr[WREG_SP] + TARGET_STACK_BIAS;
  86. }
  87. #endif