sh_bios.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <linux/module.h>
  9. #include <asm/sh_bios.h>
  10. #define BIOS_CALL_CONSOLE_WRITE 0
  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_DETACH 0xff
  15. static inline long sh_bios_call(long func, long arg0, long arg1, long arg2,
  16. 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":"=z"(r0)
  24. :"0"(r0), "r"(r4), "r"(r5), "r"(r6), "r"(r7)
  25. :"memory");
  26. return r0;
  27. }
  28. void sh_bios_console_write(const char *buf, unsigned int len)
  29. {
  30. sh_bios_call(BIOS_CALL_CONSOLE_WRITE, (long)buf, (long)len, 0, 0);
  31. }
  32. void sh_bios_char_out(char ch)
  33. {
  34. sh_bios_call(BIOS_CALL_CHAR_OUT, ch, 0, 0, 0);
  35. }
  36. void sh_bios_gdb_detach(void)
  37. {
  38. sh_bios_call(BIOS_CALL_GDB_DETACH, 0, 0, 0, 0);
  39. }
  40. EXPORT_SYMBOL_GPL(sh_bios_gdb_detach);
  41. void sh_bios_get_node_addr(unsigned char *node_addr)
  42. {
  43. sh_bios_call(BIOS_CALL_ETH_NODE_ADDR, 0, (long)node_addr, 0, 0);
  44. }
  45. EXPORT_SYMBOL_GPL(sh_bios_get_node_addr);
  46. void sh_bios_shutdown(unsigned int how)
  47. {
  48. sh_bios_call(BIOS_CALL_SHUTDOWN, how, 0, 0, 0);
  49. }
  50. void *gdb_vbr_vector = NULL;
  51. /*
  52. * Read the old value of the VBR register to initialise the vector
  53. * through which debug and BIOS traps are delegated by the Linux trap
  54. * handler.
  55. */
  56. void sh_bios_vbr_init(void)
  57. {
  58. unsigned long vbr;
  59. if (unlikely(gdb_vbr_vector))
  60. return;
  61. __asm__ __volatile__ ("stc vbr, %0" : "=r" (vbr));
  62. gdb_vbr_vector = (void *)(vbr + 0x100);
  63. printk(KERN_NOTICE "Setting GDB trap vector to %p\n", gdb_vbr_vector);
  64. }
  65. /**
  66. * sh_bios_vbr_reload - Re-load the system VBR from the BIOS vector.
  67. *
  68. * This can be used by save/restore code to reinitialize the system VBR
  69. * from the fixed BIOS VBR. A no-op if no BIOS VBR is known.
  70. */
  71. void sh_bios_vbr_reload(void)
  72. {
  73. if (gdb_vbr_vector)
  74. __asm__ __volatile__ (
  75. "ldc %0, vbr"
  76. :
  77. : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
  78. : "memory"
  79. );
  80. }