sh_bios.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_gdb_detach(void)
  33. {
  34. sh_bios_call(BIOS_CALL_GDB_DETACH, 0, 0, 0, 0);
  35. }
  36. EXPORT_SYMBOL_GPL(sh_bios_gdb_detach);
  37. void sh_bios_get_node_addr(unsigned char *node_addr)
  38. {
  39. sh_bios_call(BIOS_CALL_ETH_NODE_ADDR, 0, (long)node_addr, 0, 0);
  40. }
  41. EXPORT_SYMBOL_GPL(sh_bios_get_node_addr);
  42. void sh_bios_shutdown(unsigned int how)
  43. {
  44. sh_bios_call(BIOS_CALL_SHUTDOWN, how, 0, 0, 0);
  45. }
  46. void *gdb_vbr_vector = NULL;
  47. /*
  48. * Read the old value of the VBR register to initialise the vector
  49. * through which debug and BIOS traps are delegated by the Linux trap
  50. * handler.
  51. */
  52. void sh_bios_vbr_init(void)
  53. {
  54. unsigned long vbr;
  55. if (unlikely(gdb_vbr_vector))
  56. return;
  57. __asm__ __volatile__ ("stc vbr, %0" : "=r" (vbr));
  58. gdb_vbr_vector = (void *)(vbr + 0x100);
  59. printk(KERN_NOTICE "Setting GDB trap vector to %p\n", gdb_vbr_vector);
  60. }
  61. /**
  62. * sh_bios_vbr_reload - Re-load the system VBR from the BIOS vector.
  63. *
  64. * This can be used by save/restore code to reinitialize the system VBR
  65. * from the fixed BIOS VBR. A no-op if no BIOS VBR is known.
  66. */
  67. void sh_bios_vbr_reload(void)
  68. {
  69. if (gdb_vbr_vector)
  70. __asm__ __volatile__ (
  71. "ldc %0, vbr"
  72. :
  73. : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
  74. : "memory"
  75. );
  76. }