00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #include <arch/ski/ski.h>
00036 #include <console/console.h>
00037 #include <console/chardev.h>
00038 #include <arch/interrupt.h>
00039 #include <sysinfo/sysinfo.h>
00040
00041 chardev_t ski_console;
00042 chardev_t ski_uconsole;
00043 static bool kb_disable;
00044 int kbd_uspace=0;
00045
00046 static void ski_putchar(chardev_t *d, const char ch);
00047 static __s32 ski_getchar(void);
00048
00057 void ski_putchar(chardev_t *d, const char ch)
00058 {
00059 __asm__ volatile (
00060 "mov r15=%0\n"
00061 "mov r32=%1\n"
00062 "break 0x80000\n"
00063 :
00064 : "i" (SKI_PUTCHAR), "r" (ch)
00065 : "r15", "in0", "r8"
00066 );
00067
00068 if (ch == '\n')
00069 ski_putchar(d, '\r');
00070 }
00071
00081 __s32 ski_getchar(void)
00082 {
00083 __u64 ch;
00084
00085 __asm__ volatile (
00086 "mov r15=%1\n"
00087 "break 0x80000;;\n"
00088 "mov %0=r8;;\n"
00089
00090 : "=r" (ch)
00091 : "i" (SKI_GETCHAR)
00092 : "r15", "r8"
00093 );
00094
00095 return (__s32) ch;
00096 }
00097
00102 static char ski_getchar_blocking(chardev_t *d)
00103 {
00104 int ch;
00105
00106 while(!(ch=ski_getchar()))
00107 ;
00108 if(ch == '\r')
00109 ch = '\n';
00110 return (char) ch;
00111 }
00112
00114 void poll_keyboard(void)
00115 {
00116 char ch;
00117 static char last;
00118
00119 if (kb_disable)
00120 return;
00121
00122 ch = ski_getchar();
00123 if(ch == '\r')
00124 ch = '\n';
00125 if (ch){
00126 if(kbd_uspace){
00127 chardev_push_character(&ski_uconsole, ch);
00128 virtual_interrupt(IRQ_KBD,NULL);
00129 }
00130 else {
00131 chardev_push_character(&ski_console, ch);
00132 }
00133 last = ch;
00134 return;
00135 }
00136
00137 if (last){
00138 if(kbd_uspace){
00139 chardev_push_character(&ski_uconsole, 0);
00140 virtual_interrupt(IRQ_KBD,NULL);
00141 }
00142 else {
00143 }
00144 last = 0;
00145 }
00146
00147 }
00148
00149
00150 static void ski_kb_enable(chardev_t *d)
00151 {
00152 kb_disable = false;
00153 }
00154
00155
00156 static void ski_kb_disable(chardev_t *d)
00157 {
00158 kb_disable = true;
00159 }
00160
00161
00162 static chardev_operations_t ski_ops = {
00163 .resume = ski_kb_enable,
00164 .suspend = ski_kb_disable,
00165 .write = ski_putchar,
00166 .read = ski_getchar_blocking
00167 };
00168
00169
00175 void ski_init_console(void)
00176 {
00177 __asm__ volatile (
00178 "mov r15=%0\n"
00179 "break 0x80000\n"
00180 :
00181 : "i" (SKI_INIT_CONSOLE)
00182 : "r15", "r8"
00183 );
00184
00185 chardev_initialize("ski_console", &ski_console, &ski_ops);
00186 chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
00187 stdin = &ski_console;
00188 stdout = &ski_console;
00189
00190 }
00197 void ski_set_console_sysinfo(void)
00198 {
00199 sysinfo_set_item_val("kbd",NULL,true);
00200 sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD);
00201 }
00202