Path: blob/master/arch/cris/arch-v32/mach-fs/vcs_hook.c
15125 views
/*1* Call simulator hook. This is the part running in the2* simulated program.3*/45#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>910#define HOOK_TRIG_ADDR 0xb7000000 /* hook cvlog model reg address */11#define HOOK_MEM_BASE_ADDR 0xa0000000 /* csp4 (shared mem) base addr */1213#define HOOK_DATA(offset) ((unsigned *)HOOK_MEM_BASE_ADDR)[offset]14#define VHOOK_DATA(offset) ((volatile unsigned *)HOOK_MEM_BASE_ADDR)[offset]15#define HOOK_TRIG(funcid) \16do { \17*((unsigned *) HOOK_TRIG_ADDR) = funcid; \18} while (0)19#define HOOK_DATA_BYTE(offset) ((unsigned char *)HOOK_MEM_BASE_ADDR)[offset]2021int hook_call(unsigned id, unsigned pcnt, ...)22{23va_list ap;24unsigned i;25unsigned ret;26#ifdef USING_SOS27PREEMPT_OFF_SAVE();28#endif2930/* pass parameters */31HOOK_DATA(0) = id;3233/* Have to make hook_print_str a special case since we call with a34* parameter of byte type. Should perhaps be a separate35* hook_call. */3637if (id == hook_print_str) {38int i;39char *str;4041HOOK_DATA(1) = pcnt;4243va_start(ap, pcnt);44str = (char *)va_arg(ap, unsigned);4546for (i = 0; i != pcnt; i++)47HOOK_DATA_BYTE(8 + i) = str[i];4849HOOK_DATA_BYTE(8 + i) = 0; /* null byte */50} else {51va_start(ap, pcnt);52for (i = 1; i <= pcnt; i++)53HOOK_DATA(i) = va_arg(ap, unsigned);54va_end(ap);55}5657/* read from mem to make sure data has propagated to memory before58* trigging */59ret = *((volatile unsigned *)HOOK_MEM_BASE_ADDR);6061/* trigger hook */62HOOK_TRIG(id);6364/* wait for call to finish */65while (VHOOK_DATA(0) > 0) ;6667/* extract return value */6869ret = VHOOK_DATA(1);7071#ifdef USING_SOS72PREEMPT_RESTORE();73#endif74return ret;75}7677unsigned hook_buf(unsigned i)78{79return (HOOK_DATA(i));80}8182void print_str(const char *str)83{84int i;85/* find null at end of string */86for (i = 1; str[i]; i++) ;87hook_call(hook_print_str, i, str);88}8990void CPU_KICK_DOG(void)91{92(void)hook_call(hook_kick_dog, 0);93}9495void CPU_WATCHDOG_TIMEOUT(unsigned t)96{97(void)hook_call(hook_dog_timeout, 1, t);98}99100101102