Subversion Repositories HelenOS-historic

Rev

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

  1. /*
  2.  * Copyright (C) 2006 Josef Cejka
  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 kbdmips32 mips32
  30.  * @brief   HelenOS mips32 arch dependent parts of uspace keyboard handler.
  31.  * @ingroup  kbd
  32.  * @{
  33.  */
  34. /** @file
  35.  */
  36. #include <arch/kbd.h>
  37. #include <ipc/ipc.h>
  38. #include <sysinfo.h>
  39.  
  40.  
  41. #define MSIM_KEY_F1 0x504f1bL
  42. #define MSIM_KEY_F2 0x514f1bL
  43. #define MSIM_KEY_F3 0x524f1bL
  44. #define MSIM_KEY_F4 0x534f1bL
  45. #define MSIM_KEY_F5 0x35315b1bL
  46. #define MSIM_KEY_F6 0x37315b1bL
  47. #define MSIM_KEY_F7 0x38315b1bL
  48. #define MSIM_KEY_F8 0x39315b1bL
  49. #define MSIM_KEY_F9 0x30325b1bL
  50. #define MSIM_KEY_F10 0x31325b1bL
  51. #define MSIM_KEY_F11 0x33325b1bL
  52. #define MSIM_KEY_F12 0x34325b1bL
  53.  
  54.  
  55. #define GXEMUL_KEY_F1 0x504f5b1bL
  56. #define GXEMUL_KEY_F2 0x514f5b1bL
  57. #define GXEMUL_KEY_F3 0x524f5b1bL
  58. #define GXEMUL_KEY_F4 0x534f5b1bL
  59. #define GXEMUL_KEY_F5 0x35315b1bL
  60. #define GXEMUL_KEY_F6 0x37315b1bL
  61. #define GXEMUL_KEY_F7 0x38315b1bL
  62. #define GXEMUL_KEY_F8 0x39315b1bL
  63. #define GXEMUL_KEY_F9 0x38325b1bL
  64. #define GXEMUL_KEY_F10 0x39325b1bL
  65. #define GXEMUL_KEY_F11 0x33325b1bL
  66. #define GXEMUL_KEY_F12 0x34325b1bL
  67.  
  68.  
  69. #define FUNCTION_KEYS 0x100
  70.  
  71.  
  72. irq_cmd_t msim_cmds[1] = {
  73.     { CMD_MEM_READ_1, (void *)0xB0000000, 0 }
  74. };
  75.  
  76. irq_code_t msim_kbd = {
  77.     1,
  78.     msim_cmds
  79. };
  80.  
  81. static int msim,gxemul;
  82.  
  83. int kbd_arch_init(void)
  84. {
  85.     ipc_register_irq(2, &msim_kbd);
  86.     msim=sysinfo_value("machine.msim");
  87.     gxemul=sysinfo_value("machine.lgxemul");
  88.     return 1;
  89. }
  90.  
  91.  
  92. //*
  93. //*
  94. //* Please preserve this code (it can be used to determine scancodes)
  95. //*
  96. int to_hex(int v)
  97. {
  98.         return "0123456789ABCDEF"[v];
  99. }
  100. //*/
  101.  
  102. static int kbd_arch_process_msim(keybuffer_t *keybuffer, int scan_code)
  103. {
  104.  
  105.     static unsigned long buf=0;
  106.     static int count=0;
  107.  
  108.  
  109.     //* Please preserve this code (it can be used to determine scancodes)
  110.     //*
  111.     //keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
  112.     //keybuffer_push(keybuffer, to_hex(scan_code&0xf));
  113.     //keybuffer_push(keybuffer, ' ');
  114.     //keybuffer_push(keybuffer, ' ');
  115.     //*/
  116.     //return 1;
  117.    
  118.    
  119.     if(scan_code==0x7e)
  120.     {
  121.         switch (buf){
  122.             case MSIM_KEY_F5:
  123.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
  124.                 buf=count=0;
  125.                 return 1;
  126.             case MSIM_KEY_F6:
  127.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
  128.                 buf=count=0;
  129.                 return 1;
  130.             case MSIM_KEY_F7:
  131.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
  132.                 buf=count=0;
  133.                 return 1;
  134.             case MSIM_KEY_F8:
  135.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
  136.                 buf=count=0;
  137.                 return 1;
  138.  
  139.             case MSIM_KEY_F9:
  140.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
  141.                 buf=count=0;
  142.                 return 1;
  143.             case MSIM_KEY_F10:
  144.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
  145.                 buf=count=0;
  146.                 return 1;
  147.  
  148.             case MSIM_KEY_F11:
  149.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
  150.                 buf=count=0;
  151.                 return 1;
  152.             case MSIM_KEY_F12:
  153.                 keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
  154.                 buf=count=0;
  155.                 return 1;
  156.             default:
  157.                 keybuffer_push(keybuffer, buf & 0xff );
  158.                 keybuffer_push(keybuffer, (buf >> 8) &0xff );
  159.                 keybuffer_push(keybuffer, (buf >> 16) &0xff );
  160.                 keybuffer_push(keybuffer, (buf >> 24) &0xff );
  161.                 keybuffer_push(keybuffer, scan_code );
  162.                 buf=count=0;
  163.                 return 1;
  164.    
  165.         }
  166.     }
  167.  
  168.     buf|=((unsigned long) scan_code)<<(8*(count++));
  169.    
  170.    
  171.     if((buf & 0xff)!= (MSIM_KEY_F1 & 0xff)) {
  172.  
  173.         keybuffer_push(keybuffer,buf );
  174.         buf=count=0;
  175.         return 1;
  176.     }
  177.  
  178.     if ( count <= 1 )
  179.         return 1;
  180.  
  181.     if(    (buf & 0xffff) != (MSIM_KEY_F1 & 0xffff)
  182.         && (buf & 0xffff) != (MSIM_KEY_F5 & 0xffff) ) {
  183.  
  184.         keybuffer_push(keybuffer, buf & 0xff );
  185.         keybuffer_push(keybuffer, (buf >> 8) &0xff );
  186.         buf=count=0;
  187.         return 1;
  188.     }
  189.  
  190.     if ( count <= 2)
  191.         return 1;
  192.  
  193.     switch (buf){
  194.         case MSIM_KEY_F1:
  195.             keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
  196.             buf=count=0;
  197.             return 1;
  198.         case MSIM_KEY_F2:
  199.             keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
  200.             buf=count=0;
  201.             return 1;
  202.         case MSIM_KEY_F3:
  203.             keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
  204.             buf=count=0;
  205.             return 1;
  206.         case MSIM_KEY_F4:
  207.             keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
  208.             buf=count=0;
  209.             return 1;
  210.     }
  211.  
  212.  
  213.     if(    (buf & 0xffffff) != (MSIM_KEY_F5 & 0xffffff)
  214.         && (buf & 0xffffff) != (MSIM_KEY_F9 & 0xffffff) ) {
  215.  
  216.         keybuffer_push(keybuffer, buf & 0xff );
  217.         keybuffer_push(keybuffer, (buf >> 8) &0xff );
  218.         keybuffer_push(keybuffer, (buf >> 16) &0xff );
  219.         buf=count=0;
  220.         return 1;
  221.     }
  222.  
  223.     if ( count <= 3 )
  224.         return 1;
  225.    
  226.  
  227.    
  228.    
  229.     switch (buf){
  230.         case MSIM_KEY_F5:
  231.         case MSIM_KEY_F6:
  232.         case MSIM_KEY_F7:
  233.         case MSIM_KEY_F8:
  234.         case MSIM_KEY_F9:
  235.         case MSIM_KEY_F10:
  236.         case MSIM_KEY_F11:
  237.         case MSIM_KEY_F12:
  238.             return 1;
  239.         default:
  240.             keybuffer_push(keybuffer, buf & 0xff );
  241.             keybuffer_push(keybuffer, (buf >> 8) &0xff );
  242.             keybuffer_push(keybuffer, (buf >> 16) &0xff );
  243.             keybuffer_push(keybuffer, (buf >> 24) &0xff );
  244.             buf=count=0;
  245.             return 1;
  246.        
  247.         }
  248.     return 1;
  249. }
  250.  
  251.  
  252.  
  253. static int kbd_arch_process_gxemul(keybuffer_t *keybuffer, int scan_code)
  254. {
  255.  
  256.     static unsigned long buf=0;
  257.     static int count=0;
  258.  
  259.  
  260.     //* Please preserve this code (it can be used to determine scancodes)
  261.     //*
  262.     //keybuffer_push(keybuffer, to_hex((scan_code>>4)&0xf));
  263.     //keybuffer_push(keybuffer, to_hex(scan_code&0xf));
  264.     //keybuffer_push(keybuffer, ' ');
  265.     //keybuffer_push(keybuffer, ' ');
  266.     //*/
  267.     //return 1;
  268.    
  269.    
  270.     if ( scan_code == '\r' )
  271.         scan_code = '\n' ;
  272.    
  273.     buf|=((unsigned long) scan_code)<<(8*(count++));
  274.    
  275.    
  276.     if((buf & 0xff)!= (GXEMUL_KEY_F1 & 0xff)) {
  277.  
  278.         keybuffer_push(keybuffer,buf );
  279.         buf=count=0;
  280.         return 1;
  281.     }
  282.  
  283.     if ( count <= 1 )
  284.         return 1;
  285.  
  286.     if(    (buf & 0xffff) != (GXEMUL_KEY_F1 & 0xffff)  ) {
  287.  
  288.         keybuffer_push(keybuffer, buf & 0xff );
  289.         keybuffer_push(keybuffer, (buf >> 8) &0xff );
  290.         buf=count=0;
  291.         return 1;
  292.     }
  293.  
  294.     if ( count <= 2)
  295.         return 1;
  296.  
  297.  
  298.     if(    (buf & 0xffffff) != (GXEMUL_KEY_F1 & 0xffffff)
  299.         && (buf & 0xffffff) != (GXEMUL_KEY_F5 & 0xffffff)
  300.         && (buf & 0xffffff) != (GXEMUL_KEY_F9 & 0xffffff) ) {
  301.  
  302.         keybuffer_push(keybuffer, buf & 0xff );
  303.         keybuffer_push(keybuffer, (buf >> 8) &0xff );
  304.         keybuffer_push(keybuffer, (buf >> 16) &0xff );
  305.         buf=count=0;
  306.         return 1;
  307.     }
  308.  
  309.     if ( count <= 3 )
  310.         return 1;
  311.    
  312.  
  313.     switch (buf){
  314.  
  315.         case GXEMUL_KEY_F1:
  316.             keybuffer_push(keybuffer,FUNCTION_KEYS | 1 );
  317.             buf=count=0;
  318.             return 1;
  319.         case GXEMUL_KEY_F2:
  320.             keybuffer_push(keybuffer,FUNCTION_KEYS | 2 );
  321.             buf=count=0;
  322.             return 1;
  323.         case GXEMUL_KEY_F3:
  324.             keybuffer_push(keybuffer,FUNCTION_KEYS | 3 );
  325.             buf=count=0;
  326.             return 1;
  327.         case GXEMUL_KEY_F4:
  328.             keybuffer_push(keybuffer,FUNCTION_KEYS | 4 );
  329.             buf=count=0;
  330.             return 1;
  331.         case GXEMUL_KEY_F5:
  332.             keybuffer_push(keybuffer,FUNCTION_KEYS | 5 );
  333.             buf=count=0;
  334.             return 1;
  335.         case GXEMUL_KEY_F6:
  336.             keybuffer_push(keybuffer,FUNCTION_KEYS | 6 );
  337.             buf=count=0;
  338.             return 1;
  339.         case GXEMUL_KEY_F7:
  340.             keybuffer_push(keybuffer,FUNCTION_KEYS | 7 );
  341.             buf=count=0;
  342.             return 1;
  343.         case GXEMUL_KEY_F8:
  344.             keybuffer_push(keybuffer,FUNCTION_KEYS | 8 );
  345.             buf=count=0;
  346.             return 1;
  347.         case GXEMUL_KEY_F9:
  348.             keybuffer_push(keybuffer,FUNCTION_KEYS | 9 );
  349.             buf=count=0;
  350.             return 1;
  351.         case GXEMUL_KEY_F10:
  352.             keybuffer_push(keybuffer,FUNCTION_KEYS | 10 );
  353.             buf=count=0;
  354.             return 1;
  355.         case GXEMUL_KEY_F11:
  356.             keybuffer_push(keybuffer,FUNCTION_KEYS | 11 );
  357.             buf=count=0;
  358.             return 1;
  359.         case GXEMUL_KEY_F12:
  360.             keybuffer_push(keybuffer,FUNCTION_KEYS | 12 );
  361.             buf=count=0;
  362.             return 1;
  363.  
  364.         default:
  365.             keybuffer_push(keybuffer, buf & 0xff );
  366.             keybuffer_push(keybuffer, (buf >> 8) &0xff );
  367.             keybuffer_push(keybuffer, (buf >> 16) &0xff );
  368.             keybuffer_push(keybuffer, (buf >> 24) &0xff );
  369.             buf=count=0;
  370.             return 1;
  371.        
  372.         }
  373.     return 1;
  374. }
  375.  
  376. int kbd_arch_process(keybuffer_t *keybuffer, int scan_code)
  377. {
  378.  
  379.     static int esc_count=0;
  380.  
  381.    
  382.     if ( scan_code == 0x1b ) {
  383.         esc_count++;
  384.         if ( esc_count == 3 ) {
  385.             __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE);
  386.         }  
  387.     } else {
  388.         esc_count=0;
  389.     }
  390.  
  391.     if(msim) return kbd_arch_process_msim(keybuffer, scan_code);
  392.     if(gxemul) return kbd_arch_process_gxemul(keybuffer, scan_code);
  393.  
  394.     return 0;
  395. }
  396.  
  397. /**
  398.  * @}
  399.  */
  400.