00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __TTYVAR_H__
00011 #define __TTYVAR_H__ 1
00012 #include <libc.h>
00013 #include <libtty.h>
00014
00015 struct s_ttydev;
00016 struct s_tty;
00017 typedef int (*t_ttydev_init_fn)(struct s_ttydev *ttydev,
00018 struct s_tty *tty,
00019 void **ttydev_data);
00020 typedef void (*t_ttydev_destroy_fn)(void *ttydev_data);
00021 typedef ssize_t (*t_ttydev_write_fn)(void *ttydev_data,
00022 char *buf, int len);
00023 typedef int (*t_ttydev_start_fn)(void *ttydev_data);
00024 typedef int (*t_ttydev_ioctl_fn)(void *ttydev_data,
00025 int cmd,
00026 void *input);
00027
00028 typedef struct s_ttydev
00029 {
00030 char name[MAXTTYDEVNAME + 1];
00031
00032 t_ttydev_init_fn init_fn;
00033 t_ttydev_destroy_fn destroy_fn;
00034 t_ttydev_write_fn write_fn;
00035 t_ttydev_start_fn start_fn;
00036 t_ttydev_ioctl_fn ioctl_fn;
00037
00038 } t_ttydev;
00039
00040 typedef struct s_tty
00041 {
00042 u_int32_t avail:1;
00043 u_int32_t eof:1;
00045 struct termios termios;
00046 struct winsize ws;
00047 pid_t pgrp;
00048
00049 #define TTY_BUFSIZ 4096
00050 char buf[TTY_BUFSIZ];
00051 int pos;
00052 u_int32_t cond;
00053
00054 t_ttydev *ttydev;
00055 void *ttydev_data;
00056
00057 } t_tty;
00058
00059 typedef struct s_tty_info
00060 {
00061 __cpu_simple_lock_t lock;
00062 } t_tty_info;
00063
00064 #define MAXTTY 128
00065
00066
00067
00068
00069 #define TTYDEV_PCCONS 0
00070 #define TTYDEV_SERIAL1 1
00071 #define TTYDEV_SERIAL2 2
00072 #define TTYDEV_VCONS0 3
00073 #define TTYDEVNVCONS 10
00074 #define TTYDEV_PTY0 (TTYDEV_VCONS0+TTYDEVNVCONS)
00075 #define TTYDEVNPTY 42
00076 #define TTYDEV_PTYS0 (TTYDEV_PTY0+TTYDEVNPTY)
00077 #define TTYDEVNPTYS TTYDEVNPTY
00078 #define MAXTTYDEV (TTYDEV_PTYS0+TTYDEVNPTYS)
00079
00080
00081
00082 void tty_init(t_tty *tty);
00083 ssize_t tty_fill_buf(t_tty *tty, char *buf, int len);
00084 void sys_fd_tty_open(t_tcb *caller);
00085 void sys_fd_tty_write(t_tcb *caller, int *do_yield);
00086 void sys_fd_tty_read(t_tcb *caller, int *do_yield);
00087 void sys_fd_tty_close(t_tcb *caller);
00088 void sys_fd_tty_fstat(t_tcb *caller);
00089 void sys_fd_tty_dump(t_tcb *caller);
00090 void sys_fd_tty_ioctl(t_tcb *caller);
00091 void sys_fd_tty_poll(t_tcb *caller);
00092 void do_ttysrv_syscall(void);
00093 void ttysrv_syscall(void);
00094 void create_ttysrv(void);
00095 void treat_dead(pid_t deadpid);
00096 void signotify(int sig);
00097 void ttyd_main(void);
00098 pid_t create_ttyd(void);
00099 int main(int argc, char **argv);
00100 #endif