sh_bios.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * linux/arch/sh/kernel/sh_bios.c
  3. * C interface for trapping into the standard LinuxSH BIOS.
  4. *
  5. * Copyright (C) 2000 Greg Banks, Mitch Davis
  6. *
  7. */
  8. #include <asm/sh_bios.h>
  9. #define BIOS_CALL_CONSOLE_WRITE 0
  10. #define BIOS_CALL_READ_BLOCK 1
  11. #define BIOS_CALL_ETH_NODE_ADDR 10
  12. #define BIOS_CALL_SHUTDOWN 11
  13. #define BIOS_CALL_CHAR_OUT 0x1f /* TODO: hack */
  14. #define BIOS_CALL_GDB_GET_MODE_PTR 0xfe
  15. #define BIOS_CALL_GDB_DETACH 0xff
  16. static __inline__ long sh_bios_call(long func, long arg0, long arg1, long arg2, long arg3)
  17. {
  18. register long r0 __asm__("r0") = func;
  19. register long r4 __asm__("r4") = arg0;
  20. register long r5 __asm__("r5") = arg1;
  21. register long r6 __asm__("r6") = arg2;
  22. register long r7 __asm__("r7") = arg3;
  23. __asm__ __volatile__("trapa #0x3f"
  24. : "=z" (r0)
  25. : "0" (r0), "r" (r4), "r" (r5), "r" (r6), "r" (r7)
  26. : "memory");
  27. return r0;
  28. }
  29. void sh_bios_console_write(const char *buf, unsigned int len)
  30. {
  31. sh_bios_call(BIOS_CALL_CONSOLE_WRITE, (long)buf, (long)len, 0, 0);
  32. }
  33. void sh_bios_char_out(char ch)
  34. {
  35. sh_bios_call(BIOS_CALL_CHAR_OUT, ch, 0, 0, 0);
  36. }
  37. int sh_bios_in_gdb_mode(void)
  38. {
  39. static char queried = 0;
  40. static char *gdb_mode_p = 0;
  41. if (!queried)
  42. {
  43. /* Query the gdb stub for address of its gdb mode variable */
  44. long r = sh_bios_call(BIOS_CALL_GDB_GET_MODE_PTR, 0, 0, 0, 0);
  45. if (r != ~0) /* BIOS returns -1 for unknown function */
  46. gdb_mode_p = (char *)r;
  47. queried = 1;
  48. }
  49. return (gdb_mode_p != 0 ? *gdb_mode_p : 0);
  50. }
  51. void sh_bios_gdb_detach(void)
  52. {
  53. sh_bios_call(BIOS_CALL_GDB_DETACH, 0, 0, 0, 0);
  54. }
  55. void sh_bios_get_node_addr (unsigned char *node_addr)
  56. {
  57. sh_bios_call(BIOS_CALL_ETH_NODE_ADDR, 0, (long)node_addr, 0, 0);
  58. }
  59. void sh_bios_shutdown(unsigned int how)
  60. {
  61. sh_bios_call(BIOS_CALL_SHUTDOWN, how, 0, 0, 0);
  62. }