00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _MEMCPY_H
00034 #define _MEMCPY_H
00035
00036 #define BUFSIZE (sizeof(mtm_word_t)*16)
00037
00038
00039
00040 #define MEMCPY_DEFINITION(PREFIX, VARIANT, READ, WRITE) \
00041 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memcpy##VARIANT(mtm_tx_t *tx, \
00042 void *dst, \
00043 const void *src, \
00044 size_t size) \
00045 { \
00046 volatile uint8_t *saddr=((volatile uint8_t *) src); \
00047 volatile uint8_t *daddr=((volatile uint8_t *) dst); \
00048 uint8_t buf[BUFSIZE]; \
00049 \
00050 if (size == 0) { \
00051 return; \
00052 } \
00053 while (size>BUFSIZE) { \
00054 mtm_##PREFIX##_load_bytes(tx, saddr, buf, BUFSIZE); \
00055 mtm_##PREFIX##_store_bytes(tx, daddr, buf, BUFSIZE); \
00056 saddr += BUFSIZE; \
00057 daddr += BUFSIZE; \
00058 size -= BUFSIZE; \
00059 } \
00060 if (size > 0) { \
00061 mtm_##PREFIX##_load_bytes(tx, saddr, buf, size); \
00062 mtm_##PREFIX##_store_bytes(tx, daddr, buf, size); \
00063 } \
00064 }
00065
00066
00067 #define MEMMOVE_DEFINITION(PREFIX, VARIANT, READ, WRITE) \
00068 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memmove##VARIANT(mtm_tx_t *tx, \
00069 void *dst, \
00070 const void *src, \
00071 size_t size) \
00072 { \
00073 volatile uint8_t *saddr=((volatile uint8_t *) src); \
00074 volatile uint8_t *daddr=((volatile uint8_t *) dst); \
00075 uint8_t buf[BUFSIZE]; \
00076 \
00077 if (size == 0) { \
00078 return; \
00079 } \
00080 if (saddr < daddr && daddr < saddr + size) { \
00081 \
00082 saddr=((volatile uint8_t *) src) +size; \
00083 daddr=((volatile uint8_t *) dst) +size; \
00084 while (size>BUFSIZE) { \
00085 mtm_##PREFIX##_load_bytes(tx, saddr-BUFSIZE, buf, BUFSIZE); \
00086 mtm_##PREFIX##_store_bytes(tx, daddr-BUFSIZE, buf, BUFSIZE); \
00087 saddr -= BUFSIZE; \
00088 daddr -= BUFSIZE; \
00089 size -= BUFSIZE; \
00090 } \
00091 if (size > 0) { \
00092 mtm_##PREFIX##_load_bytes(tx, saddr-size, buf, size); \
00093 mtm_##PREFIX##_store_bytes(tx, daddr-size, buf, size); \
00094 } \
00095 } else { \
00096 saddr=((volatile uint8_t *) src); \
00097 daddr=((volatile uint8_t *) dst); \
00098 while (size>BUFSIZE) { \
00099 mtm_##PREFIX##_load_bytes(tx, saddr, buf, BUFSIZE); \
00100 mtm_##PREFIX##_store_bytes(tx, daddr, buf, BUFSIZE); \
00101 saddr += BUFSIZE; \
00102 daddr += BUFSIZE; \
00103 size -= BUFSIZE; \
00104 } \
00105 if (size > 0) { \
00106 mtm_##PREFIX##_load_bytes(tx, saddr, buf, size); \
00107 mtm_##PREFIX##_store_bytes(tx, daddr, buf, size); \
00108 } \
00109 } \
00110 }
00111
00112
00113 #define MEMCPY_DECLARATION(PREFIX, VARIANT, READ, WRITE) \
00114 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memcpy##VARIANT(mtm_tx_t *tx, \
00115 void *dst, \
00116 const void *src, \
00117 size_t size);
00118
00119 #define MEMMOVE_DECLARATION(PREFIX, VARIANT, READ, WRITE) \
00120 void _ITM_CALL_CONVENTION mtm_##PREFIX##_memmove##VARIANT(mtm_tx_t *tx, \
00121 void *dst, \
00122 const void *src, \
00123 size_t size);
00124
00125
00126 #define FORALL_MEMCOPY_VARIANTS(ACTION, prefix) \
00127 ACTION(prefix, RnWt, false, true) \
00128 ACTION(prefix, RnWtaR, false, true) \
00129 ACTION(prefix, RnWtaW, false, true) \
00130 ACTION(prefix, RtWn, true, false) \
00131 ACTION(prefix, RtWt, true, true) \
00132 ACTION(prefix, RtWtaR, true, true) \
00133 ACTION(prefix, RtWtaW, true, true) \
00134 ACTION(prefix, RtaRWn, true, false) \
00135 ACTION(prefix, RtaRWt, true, true) \
00136 ACTION(prefix, RtaRWtaR, true, true) \
00137 ACTION(prefix, RtaRWtaW, true, true) \
00138 ACTION(prefix, RtaWWn, true, false) \
00139 ACTION(prefix, RtaWWt, true, true) \
00140 ACTION(prefix, RtaWWtaR, true, true) \
00141 ACTION(prefix, RtaWWtaW, true, true)
00142
00143
00144 #define FORALL_MEMMOVE_VARIANTS(ACTION, prefix) \
00145 ACTION(prefix, RnWt, false, true) \
00146 ACTION(prefix, RnWtaR, false, true) \
00147 ACTION(prefix, RnWtaW, false, true) \
00148 ACTION(prefix, RtWn, true, false) \
00149 ACTION(prefix, RtWt, true, true) \
00150 ACTION(prefix, RtWtaR, true, true) \
00151 ACTION(prefix, RtWtaW, true, true) \
00152 ACTION(prefix, RtaRWn, true, false) \
00153 ACTION(prefix, RtaRWt, true, true) \
00154 ACTION(prefix, RtaRWtaR, true, true) \
00155 ACTION(prefix, RtaRWtaW, true, true) \
00156 ACTION(prefix, RtaWWn, true, false) \
00157 ACTION(prefix, RtaWWt, true, true) \
00158 ACTION(prefix, RtaWWtaR, true, true) \
00159 ACTION(prefix, RtaWWtaW, true, true)
00160
00161
00162 #endif