tcb.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $OpenBSD: tcb.h,v 1.4 2014/03/29 18:09:30 guenther Exp $ */
  2. /*
  3. * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _MACHINE_TCB_H_
  18. #define _MACHINE_TCB_H_
  19. #ifdef _KERNEL
  20. #include <machine/reg.h>
  21. /*
  22. * In userspace, register %g7 contains the address of the thread's TCB
  23. */
  24. #define TCB_GET(p) \
  25. ((void *)(p)->p_md.md_tf->tf_global[7])
  26. #define TCB_SET(p, addr) \
  27. ((p)->p_md.md_tf->tf_global[7] = (int)(addr))
  28. #else /* _KERNEL */
  29. /* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */
  30. #define TLS_VARIANT 2
  31. #if 0 /* XXX perhaps use the gcc global register extension? */
  32. struct thread_control_block;
  33. __register__ struct thread_control_block *__tcb __asm__ ("%g7");
  34. #define TCB_GET() (__tcb)
  35. #define TCB_GET_MEMBER(member) ((void *)(__tcb->member))
  36. #define TCB_SET(tcb) ((__tcb) = (tcb))
  37. #else
  38. #include <stddef.h> /* for offsetof */
  39. /* Get a pointer to the TCB itself */
  40. static inline void *
  41. __sparc_get_tcb(void)
  42. {
  43. void *val;
  44. __asm__ ("mov %%g7, %0" : "=r" (val));
  45. return val;
  46. }
  47. #define TCB_GET() __sparc_get_tcb()
  48. /* Get the value of a specific member in the TCB */
  49. static inline void *
  50. __sparc_read_tcb(int offset)
  51. {
  52. void *val;
  53. __asm__ ("ld [%%g7 + %1], %0" : "=r" (val) : "r" (offset));
  54. return val;
  55. }
  56. #define TCB_GET_MEMBER(member) \
  57. __sparc_read_tcb(offsetof(struct thread_control_block, member))
  58. #define TCB_SET(tcb) __asm volatile("mov %0, %%g7" : : "r" (tcb))
  59. #endif /* 0 */
  60. #endif /* _KERNEL */
  61. #endif /* _MACHINE_TCB_H_ */