termios.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef _SPARC_TERMIOS_H
  2. #define _SPARC_TERMIOS_H
  3. #include <uapi/asm/termios.h>
  4. /*
  5. * c_cc characters in the termio structure. Oh, how I love being
  6. * backwardly compatible. Notice that character 4 and 5 are
  7. * interpreted differently depending on whether ICANON is set in
  8. * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise
  9. * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which
  10. * is compatible with sysV)...
  11. */
  12. #define _VMIN 4
  13. #define _VTIME 5
  14. /* intr=^C quit=^\ erase=del kill=^U
  15. eof=^D eol=\0 eol2=\0 sxtc=\0
  16. start=^Q stop=^S susp=^Z dsusp=^Y
  17. reprint=^R discard=^U werase=^W lnext=^V
  18. vmin=\1 vtime=\0
  19. */
  20. #define INIT_C_CC "\003\034\177\025\004\000\000\000\021\023\032\031\022\025\027\026\001"
  21. /*
  22. * Translate a "termio" structure into a "termios". Ugh.
  23. */
  24. #define user_termio_to_kernel_termios(termios, termio) \
  25. ({ \
  26. unsigned short tmp; \
  27. int err; \
  28. err = get_user(tmp, &(termio)->c_iflag); \
  29. (termios)->c_iflag = (0xffff0000 & ((termios)->c_iflag)) | tmp; \
  30. err |= get_user(tmp, &(termio)->c_oflag); \
  31. (termios)->c_oflag = (0xffff0000 & ((termios)->c_oflag)) | tmp; \
  32. err |= get_user(tmp, &(termio)->c_cflag); \
  33. (termios)->c_cflag = (0xffff0000 & ((termios)->c_cflag)) | tmp; \
  34. err |= get_user(tmp, &(termio)->c_lflag); \
  35. (termios)->c_lflag = (0xffff0000 & ((termios)->c_lflag)) | tmp; \
  36. err |= copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
  37. err; \
  38. })
  39. /*
  40. * Translate a "termios" structure into a "termio". Ugh.
  41. *
  42. * Note the "fun" _VMIN overloading.
  43. */
  44. #define kernel_termios_to_user_termio(termio, termios) \
  45. ({ \
  46. int err; \
  47. err = put_user((termios)->c_iflag, &(termio)->c_iflag); \
  48. err |= put_user((termios)->c_oflag, &(termio)->c_oflag); \
  49. err |= put_user((termios)->c_cflag, &(termio)->c_cflag); \
  50. err |= put_user((termios)->c_lflag, &(termio)->c_lflag); \
  51. err |= put_user((termios)->c_line, &(termio)->c_line); \
  52. err |= copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
  53. if (!((termios)->c_lflag & ICANON)) { \
  54. err |= put_user((termios)->c_cc[VMIN], &(termio)->c_cc[_VMIN]); \
  55. err |= put_user((termios)->c_cc[VTIME], &(termio)->c_cc[_VTIME]); \
  56. } \
  57. err; \
  58. })
  59. #define user_termios_to_kernel_termios(k, u) \
  60. ({ \
  61. int err; \
  62. err = get_user((k)->c_iflag, &(u)->c_iflag); \
  63. err |= get_user((k)->c_oflag, &(u)->c_oflag); \
  64. err |= get_user((k)->c_cflag, &(u)->c_cflag); \
  65. err |= get_user((k)->c_lflag, &(u)->c_lflag); \
  66. err |= get_user((k)->c_line, &(u)->c_line); \
  67. err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
  68. if ((k)->c_lflag & ICANON) { \
  69. err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
  70. err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
  71. } else { \
  72. err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
  73. err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
  74. } \
  75. err |= get_user((k)->c_ispeed, &(u)->c_ispeed); \
  76. err |= get_user((k)->c_ospeed, &(u)->c_ospeed); \
  77. err; \
  78. })
  79. #define kernel_termios_to_user_termios(u, k) \
  80. ({ \
  81. int err; \
  82. err = put_user((k)->c_iflag, &(u)->c_iflag); \
  83. err |= put_user((k)->c_oflag, &(u)->c_oflag); \
  84. err |= put_user((k)->c_cflag, &(u)->c_cflag); \
  85. err |= put_user((k)->c_lflag, &(u)->c_lflag); \
  86. err |= put_user((k)->c_line, &(u)->c_line); \
  87. err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
  88. if (!((k)->c_lflag & ICANON)) { \
  89. err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
  90. err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
  91. } else { \
  92. err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
  93. err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
  94. } \
  95. err |= put_user((k)->c_ispeed, &(u)->c_ispeed); \
  96. err |= put_user((k)->c_ospeed, &(u)->c_ospeed); \
  97. err; \
  98. })
  99. #define user_termios_to_kernel_termios_1(k, u) \
  100. ({ \
  101. int err; \
  102. err = get_user((k)->c_iflag, &(u)->c_iflag); \
  103. err |= get_user((k)->c_oflag, &(u)->c_oflag); \
  104. err |= get_user((k)->c_cflag, &(u)->c_cflag); \
  105. err |= get_user((k)->c_lflag, &(u)->c_lflag); \
  106. err |= get_user((k)->c_line, &(u)->c_line); \
  107. err |= copy_from_user((k)->c_cc, (u)->c_cc, NCCS); \
  108. if ((k)->c_lflag & ICANON) { \
  109. err |= get_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
  110. err |= get_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
  111. } else { \
  112. err |= get_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
  113. err |= get_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
  114. } \
  115. err; \
  116. })
  117. #define kernel_termios_to_user_termios_1(u, k) \
  118. ({ \
  119. int err; \
  120. err = put_user((k)->c_iflag, &(u)->c_iflag); \
  121. err |= put_user((k)->c_oflag, &(u)->c_oflag); \
  122. err |= put_user((k)->c_cflag, &(u)->c_cflag); \
  123. err |= put_user((k)->c_lflag, &(u)->c_lflag); \
  124. err |= put_user((k)->c_line, &(u)->c_line); \
  125. err |= copy_to_user((u)->c_cc, (k)->c_cc, NCCS); \
  126. if (!((k)->c_lflag & ICANON)) { \
  127. err |= put_user((k)->c_cc[VMIN], &(u)->c_cc[_VMIN]); \
  128. err |= put_user((k)->c_cc[VTIME], &(u)->c_cc[_VTIME]); \
  129. } else { \
  130. err |= put_user((k)->c_cc[VEOF], &(u)->c_cc[VEOF]); \
  131. err |= put_user((k)->c_cc[VEOL], &(u)->c_cc[VEOL]); \
  132. } \
  133. err; \
  134. })
  135. #endif /* _SPARC_TERMIOS_H */