vcs_hook.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Call simulator hook. This is the part running in the
  3. * simulated program.
  4. */
  5. #include "vcs_hook.h"
  6. #include <stdarg.h>
  7. #include <arch-v32/hwregs/reg_map.h>
  8. #include <arch-v32/hwregs/intr_vect_defs.h>
  9. #define HOOK_TRIG_ADDR 0xb7000000 /* hook cvlog model reg address */
  10. #define HOOK_MEM_BASE_ADDR 0xa0000000 /* csp4 (shared mem) base addr */
  11. #define HOOK_DATA(offset) ((unsigned *)HOOK_MEM_BASE_ADDR)[offset]
  12. #define VHOOK_DATA(offset) ((volatile unsigned *)HOOK_MEM_BASE_ADDR)[offset]
  13. #define HOOK_TRIG(funcid) \
  14. do { \
  15. *((unsigned *) HOOK_TRIG_ADDR) = funcid; \
  16. } while (0)
  17. #define HOOK_DATA_BYTE(offset) ((unsigned char *)HOOK_MEM_BASE_ADDR)[offset]
  18. int hook_call(unsigned id, unsigned pcnt, ...)
  19. {
  20. va_list ap;
  21. unsigned i;
  22. unsigned ret;
  23. #ifdef USING_SOS
  24. PREEMPT_OFF_SAVE();
  25. #endif
  26. /* pass parameters */
  27. HOOK_DATA(0) = id;
  28. /* Have to make hook_print_str a special case since we call with a
  29. * parameter of byte type. Should perhaps be a separate
  30. * hook_call. */
  31. if (id == hook_print_str) {
  32. int i;
  33. char *str;
  34. HOOK_DATA(1) = pcnt;
  35. va_start(ap, pcnt);
  36. str = (char *)va_arg(ap, unsigned);
  37. for (i = 0; i != pcnt; i++)
  38. HOOK_DATA_BYTE(8 + i) = str[i];
  39. HOOK_DATA_BYTE(8 + i) = 0; /* null byte */
  40. } else {
  41. va_start(ap, pcnt);
  42. for (i = 1; i <= pcnt; i++)
  43. HOOK_DATA(i) = va_arg(ap, unsigned);
  44. va_end(ap);
  45. }
  46. /* read from mem to make sure data has propagated to memory before
  47. * trigging */
  48. ret = *((volatile unsigned *)HOOK_MEM_BASE_ADDR);
  49. /* trigger hook */
  50. HOOK_TRIG(id);
  51. /* wait for call to finish */
  52. while (VHOOK_DATA(0) > 0) ;
  53. /* extract return value */
  54. ret = VHOOK_DATA(1);
  55. #ifdef USING_SOS
  56. PREEMPT_RESTORE();
  57. #endif
  58. return ret;
  59. }
  60. unsigned hook_buf(unsigned i)
  61. {
  62. return (HOOK_DATA(i));
  63. }
  64. void print_str(const char *str)
  65. {
  66. int i;
  67. /* find null at end of string */
  68. for (i = 1; str[i]; i++) ;
  69. hook_call(hook_print_str, i, str);
  70. }
  71. void CPU_KICK_DOG(void)
  72. {
  73. (void)hook_call(hook_kick_dog, 0);
  74. }
  75. void CPU_WATCHDOG_TIMEOUT(unsigned t)
  76. {
  77. (void)hook_call(hook_dog_timeout, 1, t);
  78. }