Subversion Repositories HelenOS

Rev

Rev 4344 | Go to most recent revision | Blame | 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 <sysinfo/sysinfo.h>
  39. #include <arch/types.h>
  40. #include <proc/thread.h>
  41. #include <synch/spinlock.h>
  42. #include <arch/asm.h>
  43. #include <arch/drivers/kbd.h>
  44. #include <arch.h>
  45.  
  46. static indev_t skiin;       /**< Ski input device. */
  47. static outdev_t skiout;     /**< Ski output device. */
  48.  
  49. static bool kbd_disabled;
  50.  
  51. /** Display character on debug console
  52.  *
  53.  * Use SSC (Simulator System Call) to
  54.  * display character on debug console.
  55.  *
  56.  * @param d Character device.
  57.  * @param ch Character to be printed.
  58.  */
  59. static void ski_putchar(outdev_t *d, const char ch, bool silent)
  60. {
  61.     if (!silent) {
  62.         asm volatile (
  63.             "mov r15 = %0\n"
  64.             "mov r32 = %1\n"   /* r32 is in0 */
  65.             "break 0x80000\n"  /* modifies r8 */
  66.             :
  67.             : "i" (SKI_PUTCHAR), "r" (ch)
  68.             : "r15", "in0", "r8"
  69.         );
  70.        
  71.         if (ch == '\n')
  72.             ski_putchar(d, '\r', false);
  73.     }
  74. }
  75.  
  76. static indev_operations_t skiin_ops = {
  77.     .poll = NULL
  78. };
  79.  
  80. static outdev_operations_t skiout_ops = {
  81.     .write = ski_putchar
  82. };
  83.  
  84. /** Ask debug console if a key was pressed.
  85.  *
  86.  * Use SSC (Simulator System Call) to
  87.  * get character from debug console.
  88.  *
  89.  * This call is non-blocking.
  90.  *
  91.  * @return ASCII code of pressed key or 0 if no key pressed.
  92.  */
  93. static int32_t ski_getchar(void)
  94. {
  95.     uint64_t ch;
  96.    
  97.     asm volatile (
  98.         "mov r15 = %1\n"
  99.         "break 0x80000;;\n" /* modifies r8 */
  100.         "mov %0 = r8;;\n"      
  101.  
  102.         : "=r" (ch)
  103.         : "i" (SKI_GETCHAR)
  104.         : "r15", "r8"
  105.     );
  106.  
  107.     return (int32_t) ch;
  108. }
  109.  
  110. /** Ask keyboard if a key was pressed. */
  111. static void poll_keyboard(void)
  112. {
  113.     char ch;
  114.    
  115.     if (kbd_disabled)
  116.         return;
  117.     ch = ski_getchar();
  118.     if(ch == '\r')
  119.         ch = '\n';
  120.     if (ch) {
  121.         indev_push_character(&skiin, ch);
  122.         return;
  123.     }
  124. }
  125.  
  126. #define POLL_INTERVAL           10000           /* 10 ms */
  127.  
  128. /** Kernel thread for polling keyboard. */
  129. static void kkbdpoll(void *arg)
  130. {
  131.     while (1) {
  132.         if (!silent) {
  133.             poll_keyboard();
  134.         }
  135.         thread_usleep(POLL_INTERVAL);
  136.     }
  137. }
  138.  
  139. /** Initialize debug console
  140.  *
  141.  * Issue SSC (Simulator System Call) to
  142.  * to open debug console.
  143.  */
  144. static void ski_init(void)
  145. {
  146.     static bool initialized;
  147.  
  148.     if (initialized)
  149.         return;
  150.    
  151.     asm volatile (
  152.         "mov r15 = %0\n"
  153.         "break 0x80000\n"
  154.         :
  155.         : "i" (SKI_INIT_CONSOLE)
  156.         : "r15", "r8"
  157.     );
  158.    
  159.     initialized = true;
  160. }
  161.  
  162. indev_t *skiin_init(void)
  163. {
  164.     ski_init();
  165.  
  166.     indev_initialize("skiin", &skiin, &skiin_ops);
  167.     thread_t *t = thread_create(kkbdpoll, NULL, TASK, 0, "kkbdpoll", true);
  168.     if (t)
  169.         thread_ready(t);
  170.     else
  171.         return NULL;
  172.  
  173.     sysinfo_set_item_val("kbd", NULL, true);
  174.     sysinfo_set_item_val("kbd.type", NULL, KBD_SKI);
  175.  
  176.     return &skiin;
  177. }
  178.  
  179.  
  180. void skiout_init(void)
  181. {
  182.     ski_init();
  183.  
  184.     outdev_initialize("skiout", &skiout, &skiout_ops);
  185.     stdout = &skiout;
  186.  
  187.     sysinfo_set_item_val("fb", NULL, false);
  188. }
  189.  
  190. void ski_kbd_grab(void)
  191. {
  192.     kbd_disabled = true;
  193. }
  194.  
  195. void ski_kbd_release(void)
  196. {
  197.     kbd_disabled = false;
  198. }
  199.  
  200. /** @}
  201.  */
  202.