Skip to content

Commit a617083

Browse files
nordic-krchnashif
authored andcommitted
lib: os: cbprintf: Fix static packaging for sparc
Sparc architecture is strange. Va_list arguments are packed (1 byte alignment) while unaligned access fails. Added dedicated handling of Z_CBPRINTF_STORE_ARG which is copying the data word by word. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent beb62d2 commit a617083

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/sys/cbprintf_internal.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ extern "C" {
120120
*
121121
* @param arg Argument.
122122
*/
123+
#ifdef __sparc__
124+
static inline void cbprintf_wcpy(int *dst, int *src, uint32_t len)
125+
{
126+
for (int i = 0; i < len; i++) {
127+
dst[i] = src[i];
128+
}
129+
}
130+
/* Sparc is expecting va_list to be packed but don't support unaligned access.*/
131+
#define Z_CBPRINTF_STORE_ARG(buf, arg) do {\
132+
__auto_type _v = (arg) + 0; \
133+
double _d = _Generic((arg) + 0, \
134+
float : (arg) + 0, \
135+
default : \
136+
0.0); \
137+
uint32_t _wsize = Z_CBPRINTF_ARG_SIZE(arg) / sizeof(int); \
138+
cbprintf_wcpy((int *)buf, \
139+
(int *) _Generic((arg) + 0, float : &_d, default : &_v), \
140+
_wsize); \
141+
} while (0)
142+
#else /* __sparc__ */
123143
#define Z_CBPRINTF_STORE_ARG(buf, arg) \
124144
*_Generic((arg) + 0, \
125145
char : (int *)buf, \
@@ -137,6 +157,7 @@ extern "C" {
137157
long double : (long double *)buf, \
138158
default : \
139159
(const void **)buf) = arg
160+
#endif
140161

141162
/** @brief Return alignment needed for given argument.
142163
*

0 commit comments

Comments
 (0)