console_64.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* console.c: Routines that deal with sending and receiving IO
  2. * to/from the current console device using the PROM.
  3. *
  4. * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
  5. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <asm/openprom.h>
  11. #include <asm/oplib.h>
  12. #include <asm/system.h>
  13. #include <linux/string.h>
  14. extern int prom_stdin, prom_stdout;
  15. /* Non blocking get character from console input device, returns -1
  16. * if no input was taken. This can be used for polling.
  17. */
  18. static int prom_nbgetchar(void)
  19. {
  20. unsigned long args[7];
  21. char inc;
  22. args[0] = (unsigned long) "read";
  23. args[1] = 3;
  24. args[2] = 1;
  25. args[3] = (unsigned int) prom_stdin;
  26. args[4] = (unsigned long) &inc;
  27. args[5] = 1;
  28. args[6] = (unsigned long) -1;
  29. p1275_cmd_direct(args);
  30. if (args[6] == 1)
  31. return inc;
  32. return -1;
  33. }
  34. /* Non blocking put character to console device, returns -1 if
  35. * unsuccessful.
  36. */
  37. static int prom_nbputchar(char c)
  38. {
  39. unsigned long args[7];
  40. char outc;
  41. outc = c;
  42. args[0] = (unsigned long) "write";
  43. args[1] = 3;
  44. args[2] = 1;
  45. args[3] = (unsigned int) prom_stdout;
  46. args[4] = (unsigned long) &outc;
  47. args[5] = 1;
  48. args[6] = (unsigned long) -1;
  49. p1275_cmd_direct(args);
  50. if (args[6] == 1)
  51. return 0;
  52. else
  53. return -1;
  54. }
  55. /* Blocking version of get character routine above. */
  56. char
  57. prom_getchar(void)
  58. {
  59. int character;
  60. while((character = prom_nbgetchar()) == -1) ;
  61. return (char) character;
  62. }
  63. /* Blocking version of put character routine above. */
  64. void
  65. prom_putchar(char c)
  66. {
  67. prom_nbputchar(c);
  68. }