// gcc_inline_asm_unknown_mnemonics_problems.txt
To: gcc-help@xxxxxxxxxxx
From: Mike Bennett
gmbgmb@xxxxxxxxxxxxxx
Before I forget; Thanks for all your good work. I seldom get good info
that has not originated from our efforts.
I am having a problem using ldrexb and strexb using inline assembler. The
code is running on a RPi4 on ubuntu 20.04LTS.
I get an error message "Error: unknown mnemonic `ldrexb' -- `ldrexb
x0,[[sp,8]]'"
I upgraded from gcc 9.4 to gcc 10.3 . It made no difference.
I found a bug report with the following title that may be the cause.
"Bug# 1017961: mozjs102: Fails to build on armel"
The latest versions of gcc are prior to the date on the bug report.
My questions are:
1. Is this bug the cause of my problem?
2. If this is the problem, is there a work around?
3. If the problem is something else please identify the problem?
If you can, please send me an email at the address above.
Thanks Mike.
The test program that illustrates the problem is shown below along with the
make file output.
//***************
// test_ie.h
//***************
#ifndef MACHINE_TYPE_ARM_PI
/* take out WINAPI in "static FORCEINLINE long WINAPI" line below */
static inline long InterlockedExchange( long volatile *dest, long val )
{
long ret;
__asm__ __volatile__( "lock; xchgl %k0,(%1)"
: "=r" (ret) :"r" (dest), "0" (val) : "memory" );
return ret;
}
#else
/* %1 is output = __ret,
%3= *dest is the mutex location,
%2= val the value to put in the mutex
when locked or unlocked,
locked=1, 0=unlocked
*/
static inline volatile long InterlockedExchange( long volatile
*dest, long val )
{
long __ret; /* return value, is the value of lockflag
loaded by ldrex */
/* success/fail result of strex, 0 = success */
if (val != 0)
{
long reg_val;
__asm__ __volatile__
(
"mov %0, %2 \n\t" /* put
lock value in reg */
"ldrexb %1, [%3] \n\t" /* load
mutex lock word */
"cmp %1, #0 \n\t" /* see
if mutex is free, ie lock = 0 */
/****** this cmp is required to set the condition
that
allows strexb to write. ********/
"strexb %1, %0, [%3] \n\t" /* store
lock value in %0 at mem addr %3, */
" \n\t" /* put
result status in r1 */
"cmp %1, #0 \n\t" /* if
strex was successful %1 will be
" \n\t" /* a zero */
"beq ok \n\t" /* if
success, set return value */
:[reg_val] "=r" (reg_val), [__ret] "=r"
(__ret)
:[val] "m" (val), [dest] "m" (dest)
: "cc","memory"
);
__ret = 1; /* failed to get control of mutex */
goto n_ok;
ok: __ret = 0;
}
else
{
*dest = val;
__ret = val;
}
n_ok:
return __ret;
}
#endif
//*******************
// gcc_pi_asm_test.c
//*******************
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <pthread.h>
#define MACHINE_TYPE_ARM_PI TRUE
#include <test_ie.h>
struct timespec delay_0___1_sec = {0, 1000000 }; //delay 0.001 sec
int nanosleep(const struct timespec *, struct timespec *);
long lock_flag;
//**********************************
// int main()
//**********************************
int main()
{
long ret_val;
while ( (ret_val = InterlockedExchange( &lock_flag, 1) ) != 0)
{
ret_val = nanosleep( &delay_0___1_sec, NULL); // 1 msec
}
return 0;
}
//*********************
// make output
//*********************
mike@pi44:/media/mike/F512_5/Mike/Software/0_Pi4_builds/gcc_pi_asm_test/source$
make
gcc -g -c -std=iso9899:1999 -o obj/gcc_pi_asm_test.o gcc_pi_asm_test.c
-I../include
/tmp/ccVbuJ1z.s: Assembler messages:
/tmp/ccVbuJ1z.s:26: Error: unknown mnemonic `ldrexb' -- `ldrexb x0,[[sp,8]]'
/tmp/ccVbuJ1z.s:28: Error: unknown mnemonic `strexb' -- `strexb
x0,x1,[[sp,8]]'
/tmp/ccVbuJ1z.s:25: Error: undefined symbol sp used as an immediate value
make: *** [makefile:37: obj/gcc_pi_asm_test.o] Error 1
mike@pi44:/media/mike/F512_5/Mike/Software/0_Pi4_builds/gcc_pi_asm_test/source$