/**
 * @file   drUtils.h
 * @brief  Utility functionalities header file for FastCall driver.
 *
 * Copyright (C) 2012 Giesecke & Devrient GmbH
 */

#ifndef __DRDRMUTILS_H__
#define __DRDRMUTILS_H__

#include "DrApi/DrApiThread.h"
#include "DrApi/DrApiMm.h"
#include "DrApi/DrApiIpcMsg.h"

/* Macros */
#define PTR_AND(ptr, mask)	((addr_t)((uint32_t)(ptr) & (mask)))
#define PTR_MASK(p, m)		PTR_AND(p, m)
#define SIZE_TO_MASK(_size_)	(~((_size_) - 1))

/* Syscall definitions */
#define SYSCALL_THREAD_EX_REGS	12

/* Register ids for SYSCALL_THREAD_EX_REGS */
#define THREAD_EX_REGS_IP	(1U << 0)   /* Instruction pointer */
#define THREAD_EX_REGS_SP	(1U << 1)   /* Stack pointer */

/**
 * Restarts thread after setting sp (with clean stack) and ip accordingly
 *
 * @retval E_OK    no error.
 */
drApiResult_t drUtilsRestartThread(
	threadno_t threadno,
	addr_t ip,
	addr_t sp);

/**
 * Makes request to RTM to update notification thread
 *
 * @retval E_OK    no error.
 */
drApiResult_t drUtilsUpdateNotificationThread(threadno_t threadno);

#endif /* __DRDRMUTILS_H__ */
