vcs_hook.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Simulator hook mechanism
  3. */
  4. #include "vcs_hook.h"
  5. #include <asm/io.h>
  6. #include <stdarg.h>
  7. #define HOOK_TRIG_ADDR 0xb7000000
  8. #define HOOK_MEM_BASE_ADDR 0xce000000
  9. static volatile unsigned *hook_base;
  10. #define HOOK_DATA(offset) hook_base[offset]
  11. #define VHOOK_DATA(offset) hook_base[offset]
  12. #define HOOK_TRIG(funcid) \
  13. do { \
  14. *((unsigned *) HOOK_TRIG_ADDR) = funcid; \
  15. } while (0)
  16. #define HOOK_DATA_BYTE(offset) ((unsigned char *)hook_base)[offset]
  17. static void hook_init(void)
  18. {
  19. static int first = 1;
  20. if (first) {
  21. first = 0;
  22. hook_base = ioremap(HOOK_MEM_BASE_ADDR, 8192);
  23. }
  24. }
  25. static unsigned hook_trig(unsigned id)
  26. {
  27. unsigned ret;
  28. /* preempt_disable(); */
  29. /* Dummy read from mem to make sure data has propagated to memory
  30. * before trigging */
  31. ret = *hook_base;
  32. /* trigger hook */
  33. HOOK_TRIG(id);
  34. /* wait for call to finish */
  35. while (VHOOK_DATA(0) > 0) ;
  36. /* extract return value */
  37. ret = VHOOK_DATA(1);
  38. return ret;
  39. }
  40. int hook_call(unsigned id, unsigned pcnt, ...)
  41. {
  42. va_list ap;
  43. int i;
  44. unsigned ret;
  45. hook_init();
  46. HOOK_DATA(0) = id;
  47. va_start(ap, pcnt);
  48. for (i = 1; i <= pcnt; i++)
  49. HOOK_DATA(i) = va_arg(ap, unsigned);
  50. va_end(ap);
  51. ret = hook_trig(id);
  52. return ret;
  53. }
  54. int hook_call_str(unsigned id, unsigned size, const char *str)
  55. {
  56. int i;
  57. unsigned ret;
  58. hook_init();
  59. HOOK_DATA(0) = id;
  60. HOOK_DATA(1) = size;
  61. for (i = 0; i < size; i++)
  62. HOOK_DATA_BYTE(8 + i) = str[i];
  63. HOOK_DATA_BYTE(8 + i) = 0;
  64. ret = hook_trig(id);
  65. return ret;
  66. }
  67. void print_str(const char *str)
  68. {
  69. int i;
  70. /* find null at end of string */
  71. for (i = 1; str[i]; i++) ;
  72. hook_call(hook_print_str, i, str);
  73. }
  74. void CPU_WATCHDOG_TIMEOUT(unsigned t)
  75. {
  76. }