vcs_hook.c 2.3 KB

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