asm.h 1.46 KB
/* -----------------------------------------------------------------------------
 *  Copyright (C) 2019 daiteq s.r.o.                     http://www.daiteq.com
 *
 *  This program is distributed WITHOUT ANY WARRANTY; without even
 *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE.
 *
 * -----------------------------------------------------------------------------
 *  Filename    : asm.h
 *  Authors     : Martin Danek
 *  Description : inline assembly routines
 *  Release     :
 *  Version     : 1.0
 *  Date        : 9.4.2019
 * -----------------------------------------------------------------------------
 */
#ifndef ASM_H

#define ASM_H

#define str(s) #s

#define rd_asr(A,R)     \
 __asm__ volatile (     \
    "\t rd " str(A) ", %0\n"     \
   : "=r" (R) \
  )          \



#define wr_asr(A,O)     \
 __asm__ volatile (     \
    "\t nop\n"          \
    "\t wr %0,  0, " str(A) " \n" \
    "\t nop\n"          \
    :                   \
    : "r" (O)           \
  )                     \
                        \


#define swar(A, B, RES)   \
 __asm__ volatile (       \
    "\t swar %1, %2, %0 \n" \
    : "=r" (RES)          \
    : "Ir" (A), "Ir" (B)  \
  )                       \
                          \

#define swarcc(A, B, RES) \
 __asm__ volatile (       \
    "\t swarcc %1, %2, %0 \n" \
    : "=r" (RES)          \
    : "Ir" (A), "Ir" (B)  \
    : "cc"                \
  )                       \
                          \

#endif