console_64.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. inline int
  19. prom_nbgetchar(void)
  20. {
  21. unsigned long args[7];
  22. char inc;
  23. args[0] = (unsigned long) "read";
  24. args[1] = 3;
  25. args[2] = 1;
  26. args[3] = (unsigned int) prom_stdin;
  27. args[4] = (unsigned long) &inc;
  28. args[5] = 1;
  29. args[6] = (unsigned long) -1;
  30. p1275_cmd_direct(args);
  31. if (args[6] == 1)
  32. return inc;
  33. return -1;
  34. }
  35. /* Non blocking put character to console device, returns -1 if
  36. * unsuccessful.
  37. */
  38. inline int
  39. prom_nbputchar(char c)
  40. {
  41. unsigned long args[7];
  42. char outc;
  43. outc = c;
  44. args[0] = (unsigned long) "write";
  45. args[1] = 3;
  46. args[2] = 1;
  47. args[3] = (unsigned int) prom_stdout;
  48. args[4] = (unsigned long) &outc;
  49. args[5] = 1;
  50. args[6] = (unsigned long) -1;
  51. p1275_cmd_direct(args);
  52. if (args[6] == 1)
  53. return 0;
  54. else
  55. return -1;
  56. }
  57. /* Blocking version of get character routine above. */
  58. char
  59. prom_getchar(void)
  60. {
  61. int character;
  62. while((character = prom_nbgetchar()) == -1) ;
  63. return (char) character;
  64. }
  65. /* Blocking version of put character routine above. */
  66. void
  67. prom_putchar(char c)
  68. {
  69. prom_nbputchar(c);
  70. }
  71. void
  72. prom_puts(const char *s, int len)
  73. {
  74. unsigned long args[7];
  75. args[0] = (unsigned long) "write";
  76. args[1] = 3;
  77. args[2] = 1;
  78. args[3] = (unsigned int) prom_stdout;
  79. args[4] = (unsigned long) s;
  80. args[5] = len;
  81. args[6] = (unsigned long) -1;
  82. p1275_cmd_direct(args);
  83. }