termios.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. /* line disciplines */
  62. #define N_TTY 0
  63. #define N_SLIP 1
  64. #define N_MOUSE 2
  65. #define N_PPP 3
  66. #define N_STRIP 4
  67. #define N_AX25 5
  68. #define N_X25 6 /* X.25 async */
  69. #define N_6PACK 7
  70. #define N_MASC 8 /* Reserved for Mobitex module <kaz@cafe.net> */
  71. #define N_R3964 9 /* Reserved for Simatic R3964 module */
  72. #define N_PROFIBUS_FDL 10 /* Reserved for Profibus <Dave@mvhi.com> */
  73. #define N_IRDA 11 /* Linux IrDa - http://irda.sourceforge.net/ */
  74. #define N_SMSBLOCK 12 /* SMS block mode - for talking to GSM data cards about SMS messages */
  75. #define N_HDLC 13 /* synchronous HDLC */
  76. #define N_SYNC_PPP 14
  77. #define N_HCI 15 /* Bluetooth HCI UART */
  78. #ifdef __KERNEL__
  79. /* eof=^D eol=\0 eol2=\0 erase=del
  80. werase=^W kill=^U reprint=^R sxtc=\0
  81. intr=^C quit=^\ susp=^Z <OSF/1 VDSUSP>
  82. start=^Q stop=^S lnext=^V discard=^U
  83. vmin=\1 vtime=\0
  84. */
  85. #define INIT_C_CC "\004\000\000\177\027\025\022\000\003\034\032\000\021\023\026\025\001\000"
  86. /*
  87. * Translate a "termio" structure into a "termios". Ugh.
  88. */
  89. #define user_termio_to_kernel_termios(a_termios, u_termio) \
  90. ({ \
  91. struct termios *k_termios = (a_termios); \
  92. struct termio k_termio; \
  93. int canon, ret; \
  94. \
  95. ret = copy_from_user(&k_termio, u_termio, sizeof(k_termio)); \
  96. if (!ret) { \
  97. /* Overwrite only the low bits. */ \
  98. *(unsigned short *)&k_termios->c_iflag = k_termio.c_iflag; \
  99. *(unsigned short *)&k_termios->c_oflag = k_termio.c_oflag; \
  100. *(unsigned short *)&k_termios->c_cflag = k_termio.c_cflag; \
  101. *(unsigned short *)&k_termios->c_lflag = k_termio.c_lflag; \
  102. canon = k_termio.c_lflag & ICANON; \
  103. \
  104. k_termios->c_cc[VINTR] = k_termio.c_cc[_VINTR]; \
  105. k_termios->c_cc[VQUIT] = k_termio.c_cc[_VQUIT]; \
  106. k_termios->c_cc[VERASE] = k_termio.c_cc[_VERASE]; \
  107. k_termios->c_cc[VKILL] = k_termio.c_cc[_VKILL]; \
  108. k_termios->c_cc[VEOL2] = k_termio.c_cc[_VEOL2]; \
  109. k_termios->c_cc[VSWTC] = k_termio.c_cc[_VSWTC]; \
  110. k_termios->c_cc[canon ? VEOF : VMIN] = k_termio.c_cc[_VEOF]; \
  111. k_termios->c_cc[canon ? VEOL : VTIME] = k_termio.c_cc[_VEOL]; \
  112. } \
  113. ret; \
  114. })
  115. /*
  116. * Translate a "termios" structure into a "termio". Ugh.
  117. *
  118. * Note the "fun" _VMIN overloading.
  119. */
  120. #define kernel_termios_to_user_termio(u_termio, a_termios) \
  121. ({ \
  122. struct termios *k_termios = (a_termios); \
  123. struct termio k_termio; \
  124. int canon; \
  125. \
  126. k_termio.c_iflag = k_termios->c_iflag; \
  127. k_termio.c_oflag = k_termios->c_oflag; \
  128. k_termio.c_cflag = k_termios->c_cflag; \
  129. canon = (k_termio.c_lflag = k_termios->c_lflag) & ICANON; \
  130. \
  131. k_termio.c_line = k_termios->c_line; \
  132. k_termio.c_cc[_VINTR] = k_termios->c_cc[VINTR]; \
  133. k_termio.c_cc[_VQUIT] = k_termios->c_cc[VQUIT]; \
  134. k_termio.c_cc[_VERASE] = k_termios->c_cc[VERASE]; \
  135. k_termio.c_cc[_VKILL] = k_termios->c_cc[VKILL]; \
  136. k_termio.c_cc[_VEOF] = k_termios->c_cc[canon ? VEOF : VMIN]; \
  137. k_termio.c_cc[_VEOL] = k_termios->c_cc[canon ? VEOL : VTIME]; \
  138. k_termio.c_cc[_VEOL2] = k_termios->c_cc[VEOL2]; \
  139. k_termio.c_cc[_VSWTC] = k_termios->c_cc[VSWTC]; \
  140. \
  141. copy_to_user(u_termio, &k_termio, sizeof(k_termio)); \
  142. })
  143. #define user_termios_to_kernel_termios(k, u) \
  144. copy_from_user(k, u, sizeof(struct termios))
  145. #define kernel_termios_to_user_termios(u, k) \
  146. copy_to_user(u, k, sizeof(struct termios))
  147. #endif /* __KERNEL__ */
  148. #endif /* _ALPHA_TERMIOS_H */