ski.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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"          /* r32 is in0 */
00062                 "break 0x80000\n"       /* modifies r8 */
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"     /* modifies r8 */
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 /* Called from getc(). */
00150 static void ski_kb_enable(chardev_t *d)
00151 {
00152         kb_disable = false;
00153 }
00154 
00155 /* Called from getc(). */
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 

Generated on Sun Jun 18 16:51:20 2006 for HelenOS Kernel (ia64) by  doxygen 1.4.6