termios.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef _ALPHA_TERMIOS_H
  2. #define _ALPHA_TERMIOS_H
  3. #include <asm/ioctls.h>
  4. #include <asm/termbits.h>
  5. struct sgttyb {
  6. char sg_ispeed;
  7. char sg_ospeed;
  8. char sg_erase;
  9. char sg_kill;
  10. short sg_flags;
  11. };
  12. struct tchars {
  13. char t_intrc;
  14. char t_quitc;
  15. char t_startc;
  16. char t_stopc;
  17. char t_eofc;
  18. char t_brkc;
  19. };
  20. struct ltchars {
  21. char t_suspc;
  22. char t_dsuspc;
  23. char t_rprntc;
  24. char t_flushc;
  25. char t_werasc;
  26. char t_lnextc;
  27. };
  28. struct winsize {
  29. unsigned short ws_row;
  30. unsigned short ws_col;
  31. unsigned short ws_xpixel;
  32. unsigned short ws_ypixel;
  33. };
  34. #define NCC 8
  35. struct termio {
  36. unsigned short c_iflag; /* input mode flags */
  37. unsigned short c_oflag; /* output mode flags */
  38. unsigned short c_cflag; /* control mode flags */
  39. unsigned short c_lflag; /* local mode flags */
  40. unsigned char c_line; /* line discipline */
  41. unsigned char c_cc[NCC]; /* control characters */
  42. };
  43. /*
  44. * c_cc characters in the termio structure. Oh, how I love being
  45. * backwardly compatible. Notice that character 4 and 5 are
  46. * interpreted differently depending on whether ICANON is set in
  47. * c_lflag. If it's set, they are used as _VEOF and _VEOL, otherwise
  48. * as _VMIN and V_TIME. This is for compatibility with OSF/1 (which
  49. * is compatible with sysV)...
  50. */
  51. #define _VINTR 0
  52. #define _VQUIT 1
  53. #define _VERASE 2
  54. #define _VKILL 3
  55. #define _VEOF 4
  56. #define _VMIN 4
  57. #define _VEOL 5
  58. #define _VTIME 5
  59. #define _VEOL2 6
  60. #define _VSWTC 7
  61. #ifdef __KERNEL__
  62. /* eof=^D eol=\0 eol2=\0 erase=del
  63. werase=^W kill=^U reprint=^R sxtc=\0
  64. intr=^C quit=^\ susp=^Z <OSF/1 VDSUSP>
  65. start=^Q stop=^S lnext=^V discard=^U
  66. vmin=\1 vtime=\0
  67. */
  68. #define INIT_C_CC "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000"
  69. /*
  70. * Translate a "termio" structure into a "termios". Ugh.
  71. */
  72. #define user_termio_to_kernel_termios(a_termios, u_termio) \
  73. ({ \
  74. struct ktermios *k_termios = (a_termios); \
  75. struct termio k_termio; \
  76. int canon, ret; \
  77. \
  78. ret = copy_from_user(&k_termio, u_termio, sizeof(k_termio)); \
  79. if (!ret) { \
  80. /* Overwrite only the low bits. */ \
  81. *(unsigned short *)&k_termios->c_iflag = k_termio.c_iflag; \
  82. *(unsigned short *)&k_termios->c_oflag = k_termio.c_oflag; \
  83. *(unsigned short *)&k_termios->c_cflag = k_termio.c_cflag; \
  84. *(unsigned short *)&k_termios->c_lflag = k_termio.c_lflag; \
  85. canon = k_termio.c_lflag & ICANON; \
  86. \
  87. k_termios->c_cc[VINTR] = k_termio.c_cc[_VINTR]; \
  88. k_termios->c_cc[VQUIT] = k_termio.c_cc[_VQUIT]; \
  89. k_termios->c_cc[VERASE] = k_termio.c_cc[_VERASE]; \
  90. k_termios->c_cc[VKILL] = k_termio.c_cc[_VKILL]; \
  91. k_termios->c_cc[VEOL2] = k_termio.c_cc[_VEOL2]; \
  92. k_termios->c_cc[VSWTC] = k_termio.c_cc[_VSWTC]; \
  93. k_termios->c_cc[canon ? VEOF : VMIN] = k_termio.c_cc[_VEOF]; \
  94. k_termios->c_cc[canon ? VEOL : VTIME] = k_termio.c_cc[_VEOL]; \
  95. } \
  96. ret; \
  97. })
  98. /*
  99. * Translate a "termios" structure into a "termio". Ugh.
  100. *
  101. * Note the "fun" _VMIN overloading.
  102. */
  103. #define kernel_termios_to_user_termio(u_termio, a_termios) \
  104. ({ \
  105. struct ktermios *k_termios = (a_termios); \
  106. struct termio k_termio; \
  107. int canon; \
  108. \
  109. k_termio.c_iflag = k_termios->c_iflag; \
  110. k_termio.c_oflag = k_termios->c_oflag; \
  111. k_termio.c_cflag = k_termios->c_cflag; \
  112. canon = (k_termio.c_lflag = k_termios->c_lflag) & ICANON; \
  113. \
  114. k_termio.c_line = k_termios->c_line; \
  115. k_termio.c_cc[_VINTR] = k_termios->c_cc[VINTR]; \
  116. k_termio.c_cc[_VQUIT] = k_termios->c_cc[VQUIT]; \
  117. k_termio.c_cc[_VERASE] = k_termios->c_cc[VERASE]; \
  118. k_termio.c_cc[_VKILL] = k_termios->c_cc[VKILL]; \
  119. k_termio.c_cc[_VEOF] = k_termios->c_cc[canon ? VEOF : VMIN]; \
  120. k_termio.c_cc[_VEOL] = k_termios->c_cc[canon ? VEOL : VTIME]; \
  121. k_termio.c_cc[_VEOL2] = k_termios->c_cc[VEOL2]; \
  122. k_termio.c_cc[_VSWTC] = k_termios->c_cc[VSWTC]; \
  123. \
  124. copy_to_user(u_termio, &k_termio, sizeof(k_termio)); \
  125. })
  126. #define user_termios_to_kernel_termios(k, u) \
  127. copy_from_user(k, u, sizeof(struct termios))
  128. #define kernel_termios_to_user_termios(u, k) \
  129. copy_to_user(u, k, sizeof(struct termios))
  130. #endif /* __KERNEL__ */
  131. #endif /* _ALPHA_TERMIOS_H */