00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <agnix/agnix.h>
00015 #include <agnix/adi/adi.h>
00016 #include <agnix/fs.h>
00017 #include <agnix/terminal.h>
00018 #include <agnix/resources.h>
00019 #include <agnix/list.h>
00020 #include <agnix/spinlock.h>
00021 #include <agnix/sprintf.h>
00022 #include <agnix/console.h>
00023
00024 #define MOD_NAME "TERM: "
00025
00026 LIST_HEAD(terminal_list);
00027 LIST_HEAD(terminal_sys_list);
00028 spinlock_t terminal_list_lock;
00029
00030 extern struct terminal_s term_sys[MAX_TERMINALS];
00031 extern int term_cur;
00032 int term_nr = 0;
00033
00034 int terminal_switch(int term_switch)
00035 {
00036 struct terminal_s *term = &term_sys[term_cur];
00037 struct terminal_s *term_new = &term_sys[term_switch];
00038
00039 if (term_new->term_driver && term_new->term_driver->ops->refresh) {
00040 term_cur = term_switch;
00041 term_new->term_driver->ops->refresh(term_new, 0);
00042 term->term_active = 0;
00043 term_new->term_active = 1;
00044 }
00045
00046 return 0;
00047 }
00048
00049 int terminal_open(struct file_s *file, int flag, int mode)
00050 {
00051 int tty_nr = (int)file->file_data;
00052
00053 if (term_sys[tty_nr].term_pgrp != 0)
00054 return -1;
00055
00056 term_sys[tty_nr].term_pgrp = current_task->t_pid;
00057 current_task->term = &term_sys[tty_nr];
00058 file->file_data = (void *)&term_sys[tty_nr];
00059
00060 return 0;
00061 }
00062
00063 int terminal_read(struct file_s *file, char *buf, int count)
00064 {
00065 struct terminal_s *term = (struct terminal_s *)file->file_data;
00066
00067 if (term == NULL)
00068 return -1;
00069
00070 return syscons_read(term, buf, count);
00071 }
00072
00073 int terminal_write(struct file_s *file, char *buf, int count)
00074 {
00075 struct terminal_s *term = (struct terminal_s *)file->file_data;
00076
00077 if (term == NULL)
00078 return -1;
00079
00080 return syscons_write(term, buf, count);
00081 }
00082
00083 int put_free_terminal(int terminal_desc)
00084 {
00085 return 0;
00086 }
00087
00088 int get_free_terminal(void)
00089 {
00090 return term_nr++;
00091 }
00092
00093 int set_terminal_var(int term_nr, struct terminal_var_s *term_var)
00094 {
00095 return 0;
00096 }
00097
00098 struct file_ops_s term_file_ops = {
00099 .open = terminal_open,
00100 .read = terminal_read,
00101 .write = terminal_write,
00102 };
00103
00104 struct adi_chrdev_s term_chrdev = {
00105 .file_ops = &term_file_ops,
00106 };
00107
00108 int register_terminal(struct terminal_s *term)
00109 {
00110 term->term_nr = get_free_terminal();
00111
00112 if (term->ops && term->ops->init)
00113 term->ops->init(term);
00114
00115 list_add(&term->term_list, &terminal_list);
00116
00117 sprintf(term_chrdev.dev_name, "tty%d", term->term_nr);
00118 term_chrdev.dev_nr = (DEV_TTY_MAJOR << 8) | (u8)term->term_nr;
00119 adi_register_chrdev(&term_chrdev);
00120
00121 return term->term_nr;
00122 }
00123
00124 int register_sys_terminal(struct terminal_s *term)
00125 {
00126 spin_lock(&terminal_list_lock);
00127 list_add(&term->term_list, &terminal_sys_list);
00128 spin_unlock(&terminal_list_lock);
00129
00130 return 0;
00131 }
00132
00133 int register_terminal_driver(struct terminal_s *term, struct terminal_driver_s *term_driver)
00134 {
00135 term->term_driver = term_driver;
00136
00137 if (term_driver->ops && term_driver->ops->init)
00138 term_driver->ops->init();
00139
00140 return 0;
00141 }
00142
00143 int terminals_init(void)
00144 {
00145 spin_lock_init(&terminal_list_lock);
00146
00147 return 0;
00148 }