Subversion Repositories HelenOS-historic

Rev

Rev 1570 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2005 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29.  /** @addtogroup ia64  
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <arch/ski/ski.h>
  36. #include <console/console.h>
  37. #include <console/chardev.h>
  38. #include <arch/interrupt.h>
  39. #include <sysinfo/sysinfo.h>
  40.  
  41. chardev_t ski_console;
  42. chardev_t ski_uconsole;
  43. static bool kb_disable;
  44. int kbd_uspace=0;
  45.  
  46. static void ski_putchar(chardev_t *d, const char ch);
  47. static __s32 ski_getchar(void);
  48.  
  49. /** Display character on debug console
  50.  *
  51.  * Use SSC (Simulator System Call) to
  52.  * display character on debug console.
  53.  *
  54.  * @param d Character device.
  55.  * @param ch Character to be printed.
  56.  */
  57. void ski_putchar(chardev_t *d, const char ch)
  58. {
  59.     __asm__ volatile (
  60.         "mov r15=%0\n"
  61.         "mov r32=%1\n"      /* r32 is in0 */
  62.         "break 0x80000\n"   /* modifies r8 */
  63.         :
  64.         : "i" (SKI_PUTCHAR), "r" (ch)
  65.         : "r15", "in0", "r8"
  66.     );
  67.    
  68.     if (ch == '\n')
  69.         ski_putchar(d, '\r');
  70. }
  71.  
  72. /** Ask debug console if a key was pressed.
  73.  *
  74.  * Use SSC (Simulator System Call) to
  75.  * get character from debug console.
  76.  *
  77.  * This call is non-blocking.
  78.  *
  79.  * @return ASCII code of pressed key or 0 if no key pressed.
  80.  */
  81. __s32 ski_getchar(void)
  82. {
  83.     __u64 ch;
  84.    
  85.     __asm__ volatile (
  86.         "mov r15=%1\n"
  87.         "break 0x80000;;\n" /* modifies r8 */
  88.         "mov %0=r8;;\n"    
  89.  
  90.         : "=r" (ch)
  91.         : "i" (SKI_GETCHAR)
  92.         : "r15",  "r8"
  93.     );
  94.  
  95.     return (__s32) ch;
  96. }
  97.  
  98. /**
  99.  * This is a blocking wrapper for ski_getchar().
  100.  * To be used when the kernel crashes.
  101.  */
  102. static char ski_getchar_blocking(chardev_t *d)
  103. {
  104.     int ch;
  105.  
  106.     while(!(ch=ski_getchar()))
  107.         ;
  108.     if(ch == '\r')
  109.         ch = '\n';
  110.     return (char) ch;
  111. }
  112.  
  113. /** Ask keyboard if a key was pressed. */
  114. void poll_keyboard(void)
  115. {
  116.     char ch;
  117.     static char last;
  118.  
  119.     if (kb_disable)
  120.         return;
  121.  
  122.     ch = ski_getchar();
  123.     if(ch == '\r')
  124.         ch = '\n';
  125.     if (ch){
  126.         if(kbd_uspace){
  127.             chardev_push_character(&ski_uconsole, ch);
  128.             virtual_interrupt(IRQ_KBD,NULL);
  129.         }
  130.         else {
  131.             chardev_push_character(&ski_console, ch);
  132.         }  
  133.         last = ch;     
  134.         return;
  135.     }  
  136.  
  137.     if (last){
  138.         if(kbd_uspace){
  139.             chardev_push_character(&ski_uconsole, 0);
  140.             virtual_interrupt(IRQ_KBD,NULL);
  141.         }
  142.         else {
  143.         }  
  144.         last = 0;      
  145.     }  
  146.  
  147. }
  148.  
  149. /* Called from getc(). */
  150. static void ski_kb_enable(chardev_t *d)
  151. {
  152.     kb_disable = false;
  153. }
  154.  
  155. /* Called from getc(). */
  156. static void ski_kb_disable(chardev_t *d)
  157. {
  158.     kb_disable = true; 
  159. }
  160.  
  161.  
  162. static chardev_operations_t ski_ops = {
  163.     .resume = ski_kb_enable,
  164.     .suspend = ski_kb_disable,
  165.     .write = ski_putchar,
  166.     .read = ski_getchar_blocking
  167. };
  168.  
  169.  
  170. /** Initialize debug console
  171.  *
  172.  * Issue SSC (Simulator System Call) to
  173.  * to open debug console.
  174.  */
  175. void ski_init_console(void)
  176. {
  177.     __asm__ volatile (
  178.         "mov r15=%0\n"
  179.         "break 0x80000\n"
  180.         :
  181.         : "i" (SKI_INIT_CONSOLE)
  182.         : "r15", "r8"
  183.     );
  184.  
  185.     chardev_initialize("ski_console", &ski_console, &ski_ops);
  186.     chardev_initialize("ski_uconsole", &ski_uconsole, &ski_ops);
  187.     stdin = &ski_console;
  188.     stdout = &ski_console;
  189.  
  190. }
  191. /** Setup console sysinfo (i.e. Keyboard IRQ)
  192.  *
  193.  * Because sysinfo neads memory allocation/dealocation
  194.  * this functions should be called separetely from init.
  195.  *
  196.  */
  197. void ski_set_console_sysinfo(void)
  198. {
  199.     sysinfo_set_item_val("kbd",NULL,true);
  200.     sysinfo_set_item_val("kbd.irq",NULL,IRQ_KBD);
  201. }
  202.  
  203.  /** @}
  204.  */
  205.  
  206.